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.78 2004-03-14 21:10:37 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 */
372 #define BGP_EXT_COM_CISCO_MCAST 0x0009 /* cisco proprietary */
374 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
375 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
376 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
377 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
379 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
380 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
382 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
383 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
385 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
387 static struct tok bgp_extd_comm_flag_values
[] = {
388 { 0x8000, "vendor-specific"},
389 { 0x4000, "non-transitive"},
393 static struct tok bgp_extd_comm_subtype_values
[] = {
394 { BGP_EXT_COM_RT_0
, "target"},
395 { BGP_EXT_COM_RT_1
, "target"},
396 { BGP_EXT_COM_RT_2
, "target"},
397 { BGP_EXT_COM_RO_0
, "origin"},
398 { BGP_EXT_COM_RO_1
, "origin"},
399 { BGP_EXT_COM_RO_2
, "origin"},
400 { BGP_EXT_COM_LINKBAND
, "link-BW"},
401 { BGP_EXT_COM_CISCO_MCAST
, "mdt-group"},
402 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
403 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
404 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
405 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
406 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
407 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
408 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
409 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
410 { BGP_EXT_COM_L2INFO
, "layer2-info"},
414 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
415 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
416 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
417 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
418 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
419 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
420 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
421 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
423 static struct tok bgp_extd_comm_ospf_rtype_values
[] = {
424 { BGP_OSPF_RTYPE_RTR
, "Router" },
425 { BGP_OSPF_RTYPE_NET
, "Network" },
426 { BGP_OSPF_RTYPE_SUM
, "Summary" },
427 { BGP_OSPF_RTYPE_EXT
, "External" },
428 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
429 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
433 static struct tok bgp_l2vpn_encaps_values
[] = {
436 { 2, "ATM AAL5 VCC transport"},
437 { 3, "ATM transparent cell transport"},
438 { 4, "Ethernet VLAN"},
443 { 9, "ATM VCC cell transport"},
444 { 10, "ATM VPC cell transport"},
447 { 64, "IP-interworking"},
452 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
461 memset(&addr
, 0, sizeof(addr
));
462 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
464 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
465 ((0xff00 >> (plen
% 8)) & 0xff);
467 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
468 return 1 + (plen
+ 7) / 8;
472 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
477 plen
= pptr
[0]; /* get prefix length */
479 /* this is one of the weirdnesses of rfc3107
480 the label length (actually the label + COS bits)
481 is added to the prefix length;
482 we also do only read out just one label -
483 there is no real application for advertisement of
484 stacked labels in a a single BGP message
487 plen
-=24; /* adjust prefixlen - labellength */
492 memset(&addr
, 0, sizeof(addr
));
493 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
495 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
496 ((0xff00 >> (plen
% 8)) & 0xff);
498 /* the label may get offsetted by 4 bits so lets shift it right */
499 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
500 getname((u_char
*)&addr
),
502 EXTRACT_24BITS(pptr
+1)>>4,
503 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
505 return 4 + (plen
+ 7) / 8;
508 /* RDs and RTs share the same semantics
509 * we use bgp_vpn_rd_print for
510 * printing route targets inside a NLRI */
512 bgp_vpn_rd_print (const u_char
*pptr
) {
514 /* allocate space for the following string
515 * xxx.xxx.xxx.xxx:xxxxx
516 * 21 bytes plus one termination byte */
520 /* ok lets load the RD format */
521 switch (EXTRACT_16BITS(pptr
)) {
523 /* AS:IP-address fmt*/
525 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u.%u.%u.%u",
526 EXTRACT_16BITS(pptr
+2), *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
528 /* IP-address:AS fmt*/
531 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
532 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
535 /* 4-byte-AS:number fmt*/
537 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u",
538 EXTRACT_32BITS(pptr
+2), EXTRACT_16BITS(pptr
+6));
541 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
550 decode_rt_routing_info(const u_char
*pptr
, char *buf
, u_int buflen
)
552 u_int8_t route_target
[8];
555 plen
= pptr
[0]; /* get prefix length */
557 plen
-=32; /* adjust prefix length */
562 memset(&route_target
, 0, sizeof(route_target
));
563 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
565 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
566 ((0xff00 >> (plen
% 8)) & 0xff);
568 snprintf(buf
, buflen
, "origin AS: %u, route target %s",
569 EXTRACT_32BITS(pptr
+1),
570 bgp_vpn_rd_print((u_char
*)&route_target
));
572 return 5 + (plen
+ 7) / 8;
576 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
581 plen
= pptr
[0]; /* get prefix length */
583 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
588 memset(&addr
, 0, sizeof(addr
));
589 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
591 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
592 ((0xff00 >> (plen
% 8)) & 0xff);
594 /* the label may get offsetted by 4 bits so lets shift it right */
595 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
596 bgp_vpn_rd_print(pptr
+4),
597 getname((u_char
*)&addr
),
599 EXTRACT_24BITS(pptr
+1)>>4,
600 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
602 return 12 + (plen
+ 7) / 8;
606 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
608 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
609 plen
=EXTRACT_16BITS(pptr
);
612 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
613 bgp_vpn_rd_print(pptr
),
614 EXTRACT_16BITS(pptr
+8),
615 EXTRACT_16BITS(pptr
+10),
616 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
620 /* ok now the variable part - lets read out TLVs*/
623 tlv_len
=EXTRACT_16BITS(pptr
);
629 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
632 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
634 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "%02x",*pptr
++);
639 snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tunknown TLV #%u, length: %u",
644 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it tright */
651 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
653 struct in6_addr addr
;
660 memset(&addr
, 0, sizeof(addr
));
661 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
663 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
664 ((0xff00 >> (plen
% 8)) & 0xff);
666 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
667 return 1 + (plen
+ 7) / 8;
671 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
673 struct in6_addr addr
;
676 plen
= pptr
[0]; /* get prefix length */
677 plen
-=24; /* adjust prefixlen - labellength */
682 memset(&addr
, 0, sizeof(addr
));
683 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
685 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
686 ((0xff00 >> (plen
% 8)) & 0xff);
688 /* the label may get offsetted by 4 bits so lets shift it right */
689 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
690 getname6((u_char
*)&addr
),
692 EXTRACT_24BITS(pptr
+1)>>4,
693 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
695 return 4 + (plen
+ 7) / 8;
699 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
701 struct in6_addr addr
;
704 plen
= pptr
[0]; /* get prefix length */
706 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
711 memset(&addr
, 0, sizeof(addr
));
712 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
714 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
715 ((0xff00 >> (plen
% 8)) & 0xff);
717 /* the label may get offsetted by 4 bits so lets shift it right */
718 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
719 bgp_vpn_rd_print(pptr
+4),
720 getname6((u_char
*)&addr
),
722 EXTRACT_24BITS(pptr
+1)>>4,
723 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
725 return 12 + (plen
+ 7) / 8;
730 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
735 union { /* copy buffer for bandwidth values */
742 char buf
[MAXHOSTNAMELEN
+ 100];
747 switch (attr
->bgpa_type
) {
750 printf("invalid len");
752 printf("%s", tok2str(bgp_origin_values
, "Unknown Origin Typecode", tptr
[0]));
754 case BGPTYPE_AS_PATH
:
756 printf("invalid len");
764 while (tptr
< pptr
+ len
) {
765 printf("%s", tok2str(bgp_as_path_segment_open_values
, "?", tptr
[0]));
766 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
767 printf("%u ", EXTRACT_16BITS(&tptr
[2 + i
]));
769 printf("%s", tok2str(bgp_as_path_segment_close_values
, "?", tptr
[0]));
770 tptr
+= 2 + tptr
[1] * 2;
773 case BGPTYPE_NEXT_HOP
:
775 printf("invalid len");
777 printf("%s", getname(tptr
));
779 case BGPTYPE_MULTI_EXIT_DISC
:
780 case BGPTYPE_LOCAL_PREF
:
782 printf("invalid len");
784 printf("%u", EXTRACT_32BITS(tptr
));
786 case BGPTYPE_ATOMIC_AGGREGATE
:
788 printf("invalid len");
790 case BGPTYPE_AGGREGATOR
:
792 printf("invalid len");
795 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
798 case BGPTYPE_COMMUNITIES
:
800 printf("invalid len");
805 comm
= EXTRACT_32BITS(tptr
);
807 case BGP_COMMUNITY_NO_EXPORT
:
808 printf(" NO_EXPORT");
810 case BGP_COMMUNITY_NO_ADVERT
:
811 printf(" NO_ADVERTISE");
813 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
814 printf(" NO_EXPORT_SUBCONFED");
818 (comm
>> 16) & 0xffff,
820 (tlen
>4) ? ", " : "");
827 case BGPTYPE_ORIGINATOR_ID
:
829 printf("invalid len");
832 printf("%s",getname(tptr
));
834 case BGPTYPE_CLUSTER_LIST
:
838 (tlen
>4) ? ", " : "");
843 case BGPTYPE_MP_REACH_NLRI
:
844 af
= EXTRACT_16BITS(tptr
);
847 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
848 tok2str(bgp_afi_values
, "Unknown AFI", af
),
850 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
851 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
854 if (af
== AFNUM_INET
|| af
==AFNUM_L2VPN
)
857 else if (af
== AFNUM_INET6
)
861 printf("\n\t no AFI %u decoder",af
);
863 print_unknown_data(tptr
,"\n\t ",tlen
);
873 printf("\n\t nexthop: ");
879 case SAFNUM_MULTICAST
:
880 case SAFNUM_UNIMULTICAST
:
881 case SAFNUM_LABUNICAST
:
882 case SAFNUM_RT_ROUTING_INFO
:
883 printf("%s",getname(tptr
));
884 tlen
-= sizeof(struct in_addr
);
885 tptr
+= sizeof(struct in_addr
);
887 case SAFNUM_VPNUNICAST
:
888 case SAFNUM_VPNMULTICAST
:
889 case SAFNUM_VPNUNIMULTICAST
:
891 bgp_vpn_rd_print(tptr
),
892 getname(tptr
+BGP_VPN_RD_LEN
));
893 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
894 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
897 printf("no SAFI %u decoder",safi
);
899 print_unknown_data(tptr
,"\n\t ",tlen
);
907 case SAFNUM_MULTICAST
:
908 case SAFNUM_UNIMULTICAST
:
909 case SAFNUM_LABUNICAST
:
910 case SAFNUM_RT_ROUTING_INFO
:
911 printf("%s", getname6(tptr
));
912 tlen
-= sizeof(struct in6_addr
);
913 tptr
+= sizeof(struct in6_addr
);
915 case SAFNUM_VPNUNICAST
:
916 case SAFNUM_VPNMULTICAST
:
917 case SAFNUM_VPNUNIMULTICAST
:
919 bgp_vpn_rd_print(tptr
),
920 getname6(tptr
+BGP_VPN_RD_LEN
));
921 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
922 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
925 printf("no SAFI %u decoder",safi
);
927 print_unknown_data(tptr
,"\n\t ",tlen
);
934 case SAFNUM_VPNUNICAST
:
935 case SAFNUM_VPNMULTICAST
:
936 case SAFNUM_VPNUNIMULTICAST
:
937 printf("%s", getname(tptr
));
938 tlen
-= (sizeof(struct in_addr
));
939 tptr
+= (sizeof(struct in_addr
));
942 printf("no SAFI %u decoder",safi
);
944 print_unknown_data(tptr
,"\n\t ",tlen
);
950 printf("no AFI %u decoder",af
);
952 print_unknown_data(tptr
,"\n\t ",tlen
);
963 printf("\n\t %u SNPA", snpa
);
964 for (/*nothing*/; snpa
> 0; snpa
--) {
965 printf("\n\t %d bytes", tptr
[0]);
972 while (len
- (tptr
- pptr
) > 0) {
977 case SAFNUM_MULTICAST
:
978 case SAFNUM_UNIMULTICAST
:
979 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
981 printf("\n\t %s", buf
);
983 printf("\n\t (illegal prefix length)");
985 case SAFNUM_LABUNICAST
:
986 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
987 printf("\n\t %s", buf
);
989 case SAFNUM_VPNUNICAST
:
990 case SAFNUM_VPNMULTICAST
:
991 case SAFNUM_VPNUNIMULTICAST
:
992 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
993 printf("\n\t %s", buf
);
995 case SAFNUM_RT_ROUTING_INFO
:
996 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
997 printf("\n\t %s", buf
);
1000 printf("\n\t no SAFI %u decoder",safi
);
1002 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1011 case SAFNUM_UNICAST
:
1012 case SAFNUM_MULTICAST
:
1013 case SAFNUM_UNIMULTICAST
:
1014 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1015 printf("\n\t %s", buf
);
1017 case SAFNUM_LABUNICAST
:
1018 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1019 printf("\n\t %s", buf
);
1021 case SAFNUM_VPNUNICAST
:
1022 case SAFNUM_VPNMULTICAST
:
1023 case SAFNUM_VPNUNIMULTICAST
:
1024 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1025 printf("\n\t %s", buf
);
1027 case SAFNUM_RT_ROUTING_INFO
:
1028 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1029 printf("\n\t %s", buf
);
1032 printf("\n\t no SAFI %u decoder ",safi
);
1034 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1043 case SAFNUM_VPNUNICAST
:
1044 case SAFNUM_VPNMULTICAST
:
1045 case SAFNUM_VPNUNIMULTICAST
:
1046 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1047 printf("\n\t %s", buf
);
1050 printf("no SAFI %u decoder",safi
);
1052 print_unknown_data(tptr
,"\n\t ",tlen
);
1061 printf("\n\t no AFI %u decoder ",af
);
1063 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1072 case BGPTYPE_MP_UNREACH_NLRI
:
1073 af
= EXTRACT_16BITS(tptr
);
1076 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1077 tok2str(bgp_afi_values
, "Unknown AFI", af
),
1079 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1080 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1085 while (len
- (tptr
- pptr
) > 0) {
1089 case SAFNUM_UNICAST
:
1090 case SAFNUM_MULTICAST
:
1091 case SAFNUM_UNIMULTICAST
:
1092 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1094 printf("\n\t %s", buf
);
1096 printf("\n\t (illegal prefix length)");
1098 case SAFNUM_LABUNICAST
:
1099 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1100 printf("\n\t %s", buf
);
1102 case SAFNUM_VPNUNICAST
:
1103 case SAFNUM_VPNMULTICAST
:
1104 case SAFNUM_VPNUNIMULTICAST
:
1105 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1106 printf("\n\t %s", buf
);
1109 printf("\n\t no SAFI %u decoder",safi
);
1111 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1121 case SAFNUM_UNICAST
:
1122 case SAFNUM_MULTICAST
:
1123 case SAFNUM_UNIMULTICAST
:
1124 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1125 printf("\n\t %s", buf
);
1127 case SAFNUM_LABUNICAST
:
1128 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1129 printf("\n\t %s", buf
);
1131 case SAFNUM_VPNUNICAST
:
1132 case SAFNUM_VPNMULTICAST
:
1133 case SAFNUM_VPNUNIMULTICAST
:
1134 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1135 printf("\n\t %s", buf
);
1138 printf("\n\t no SAFI %u decoder",safi
);
1140 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1150 case SAFNUM_VPNUNICAST
:
1151 case SAFNUM_VPNMULTICAST
:
1152 case SAFNUM_VPNUNIMULTICAST
:
1153 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1154 printf("\n\t %s", buf
);
1157 printf("no SAFI %u decoder",safi
);
1159 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1167 printf("\n\t no AFI %u decoder",af
);
1169 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1178 case BGPTYPE_EXTD_COMMUNITIES
:
1180 printf("invalid len");
1184 u_int16_t extd_comm
;
1185 extd_comm
=EXTRACT_16BITS(tptr
);
1187 printf("\n\t %s (0x%04x), Flags [%s]",
1188 tok2str(bgp_extd_comm_subtype_values
, "unknown extd community typecode", extd_comm
),
1190 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1193 case BGP_EXT_COM_RT_0
:
1194 case BGP_EXT_COM_RO_0
:
1196 EXTRACT_16BITS(tptr
+2),
1199 case BGP_EXT_COM_RT_1
:
1200 case BGP_EXT_COM_RO_1
:
1203 EXTRACT_16BITS(tptr
+6));
1205 case BGP_EXT_COM_RT_2
:
1206 case BGP_EXT_COM_RO_2
:
1208 EXTRACT_32BITS(tptr
+2),
1209 EXTRACT_16BITS(tptr
+6));
1211 case BGP_EXT_COM_LINKBAND
:
1212 bw
.i
= EXTRACT_32BITS(tptr
+2);
1213 printf(": bandwidth: %.3f Mbps",
1216 case BGP_EXT_COM_CISCO_MCAST
:
1217 printf(": AS %u, group %s",
1218 EXTRACT_16BITS(tptr
+2),
1221 case BGP_EXT_COM_VPN_ORIGIN
:
1222 case BGP_EXT_COM_VPN_ORIGIN2
:
1223 case BGP_EXT_COM_VPN_ORIGIN3
:
1224 case BGP_EXT_COM_VPN_ORIGIN4
:
1225 case BGP_EXT_COM_OSPF_RID
:
1226 case BGP_EXT_COM_OSPF_RID2
:
1227 printf("%s", getname(tptr
+2));
1229 case BGP_EXT_COM_OSPF_RTYPE
:
1230 case BGP_EXT_COM_OSPF_RTYPE2
:
1231 printf(": area:%s, router-type:%s, metric-type:%s%s",
1233 tok2str(bgp_extd_comm_ospf_rtype_values
,
1236 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1237 (*(tptr
+6) == (BGP_OSPF_RTYPE_EXT
||BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1239 case BGP_EXT_COM_L2INFO
:
1240 printf(": %s Control Flags [0x%02x]:MTU %u",
1241 tok2str(bgp_l2vpn_encaps_values
,
1245 EXTRACT_16BITS(tptr
+4));
1248 print_unknown_data(tptr
,"\n\t ",8);
1256 case BGPTYPE_ATTR_SET
:
1257 printf("\n\t Origin AS: %u", EXTRACT_32BITS(tptr
));
1263 struct bgp_attr bgpa
;
1265 memcpy(&bgpa
, tptr
, sizeof(bgpa
));
1266 alen
= bgp_attr_len(&bgpa
);
1267 tptr
+= bgp_attr_off(&bgpa
);
1268 len
-= bgp_attr_off(&bgpa
);
1270 printf("\n\t %s (%u), length: %u",
1271 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
1275 if (bgpa
.bgpa_flags
) {
1276 printf(", Flags [%s%s%s%s",
1277 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1278 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1279 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1280 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1281 if (bgpa
.bgpa_flags
& 0xf)
1282 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1285 bgp_attr_print(&bgpa
, tptr
, alen
); /* FIXME check for recursion */
1293 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1295 print_unknown_data(pptr
,"\n\t ",len
);
1298 if (vflag
> 1 && len
) /* omit zero length attributes*/
1299 print_unknown_data(pptr
,"\n\t ",len
);
1303 bgp_open_print(const u_char
*dat
, int length
)
1305 struct bgp_open bgpo
;
1306 struct bgp_opt bgpopt
;
1309 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
1311 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1312 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1313 hlen
= ntohs(bgpo
.bgpo_len
);
1315 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1316 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1317 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1318 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1319 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1321 /* some little sanity checking */
1322 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
1326 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1330 while (i
< bgpo
.bgpo_optlen
) {
1331 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1332 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1333 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1334 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1338 printf("\n\t Option %s (%u), length: %u",
1339 tok2str(bgp_opt_values
,"Unknown", bgpopt
.bgpopt_type
),
1343 /* now lets decode the options we know*/
1344 switch(bgpopt
.bgpopt_type
) {
1346 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1347 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1349 printf("\n\t %s, length: %u",
1350 tok2str(bgp_capcode_values
,"Unknown", cap_type
),
1353 case BGP_CAPCODE_MP
:
1354 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1355 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)),
1356 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1357 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+5]),
1358 opt
[i
+BGP_OPT_SIZE
+5]);
1360 case BGP_CAPCODE_RESTART
:
1361 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
1362 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
1363 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
1366 while(tcap_len
>=4) {
1367 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1368 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
)),
1369 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1370 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+cap_offset
+2]),
1371 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1372 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
1377 case BGP_CAPCODE_RR
:
1378 case BGP_CAPCODE_RR_CISCO
:
1381 printf("\n\t\tno decoder for Capability %u",
1384 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1388 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1392 printf("\n\t no decoder for option %u",
1393 bgpopt
.bgpopt_type
);
1397 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1405 bgp_update_print(const u_char
*dat
, int length
)
1408 struct bgp_attr bgpa
;
1414 TCHECK2(dat
[0], BGP_SIZE
);
1415 memcpy(&bgp
, dat
, BGP_SIZE
);
1416 hlen
= ntohs(bgp
.bgp_len
);
1417 p
= dat
+ BGP_SIZE
; /*XXX*/
1419 /* Unfeasible routes */
1420 len
= EXTRACT_16BITS(p
);
1423 * Without keeping state from the original NLRI message,
1424 * it's not possible to tell if this a v4 or v6 route,
1425 * so only try to decode it if we're not v6 enabled.
1428 printf("\n\t Withdrawn routes: %d bytes", len
);
1430 char buf
[MAXHOSTNAMELEN
+ 100];
1436 printf("\n\t Withdrawn routes:");
1438 while(i
< 2 + len
) {
1439 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1442 printf("\n\t %s", buf
);
1444 printf("\n\t (illegal prefix length)");
1453 len
= EXTRACT_16BITS(p
);
1455 /* do something more useful!*/
1457 while (i
< 2 + len
) {
1460 TCHECK2(p
[i
], sizeof(bgpa
));
1461 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
1462 alen
= bgp_attr_len(&bgpa
);
1463 aoff
= bgp_attr_off(&bgpa
);
1465 printf("\n\t %s (%u), length: %u",
1466 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
1470 if (bgpa
.bgpa_flags
) {
1471 printf(", Flags [%s%s%s%s",
1472 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1473 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1474 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1475 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1476 if (bgpa
.bgpa_flags
& 0xf)
1477 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1480 bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
);
1486 if (dat
+ length
> p
) {
1487 printf("\n\t Updated routes:");
1488 while (dat
+ length
> p
) {
1489 char buf
[MAXHOSTNAMELEN
+ 100];
1490 i
= decode_prefix4(p
, buf
, sizeof(buf
));
1492 printf("\n\t %s", buf
);
1495 printf("\n\t (illegal prefix length)");
1506 bgp_notification_print(const u_char
*dat
, int length
)
1508 struct bgp_notification bgpn
;
1512 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1513 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1514 hlen
= ntohs(bgpn
.bgpn_len
);
1516 /* some little sanity checking */
1517 if (length
<BGP_NOTIFICATION_SIZE
)
1521 tok2str(bgp_notify_major_values
, "Unknown Error", bgpn
.bgpn_major
),
1524 switch (bgpn
.bgpn_major
) {
1526 case BGP_NOTIFY_MAJOR_MSG
:
1527 printf(", subcode %s (%u)",
1528 tok2str(bgp_notify_minor_msg_values
, "Unknown", bgpn
.bgpn_minor
),
1531 case BGP_NOTIFY_MAJOR_OPEN
:
1532 printf(", subcode %s (%u)",
1533 tok2str(bgp_notify_minor_open_values
, "Unknown", bgpn
.bgpn_minor
),
1536 case BGP_NOTIFY_MAJOR_UPDATE
:
1537 printf(", subcode %s (%u)",
1538 tok2str(bgp_notify_minor_update_values
, "Unknown", bgpn
.bgpn_minor
),
1541 case BGP_NOTIFY_MAJOR_CAP
:
1542 printf(" subcode %s (%u)",
1543 tok2str(bgp_notify_minor_cap_values
, "Unknown", bgpn
.bgpn_minor
),
1545 case BGP_NOTIFY_MAJOR_CEASE
:
1546 printf(", subcode %s (%u)",
1547 tok2str(bgp_notify_minor_cease_values
, "Unknown", bgpn
.bgpn_minor
),
1550 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
1551 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
1553 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
1554 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
1556 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
1557 tok2str(bgp_afi_values
, "Unknown", EXTRACT_16BITS(tptr
)),
1558 EXTRACT_16BITS(tptr
),
1559 tok2str(bgp_safi_values
, "Unknown", *(tptr
+2)),
1561 EXTRACT_32BITS(tptr
+3));
1574 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1576 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1577 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
1579 printf("\n\t AFI %s (%u), SAFI %s (%u)",
1580 tok2str(bgp_afi_values
,"Unknown",
1581 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
)), /* this stinks but the compiler pads the structure weird */
1582 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1583 tok2str(bgp_safi_values
,"Unknown",
1584 bgp_route_refresh_header
->safi
),
1585 bgp_route_refresh_header
->safi
);
1588 print_unknown_data(pptr
,"\n\t ", len
);
1594 bgp_header_print(const u_char
*dat
, int length
)
1598 TCHECK2(dat
[0], BGP_SIZE
);
1599 memcpy(&bgp
, dat
, BGP_SIZE
);
1600 printf("\n\t%s Message (%u), length: %u",
1601 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
1605 switch (bgp
.bgp_type
) {
1607 bgp_open_print(dat
, length
);
1610 bgp_update_print(dat
, length
);
1612 case BGP_NOTIFICATION
:
1613 bgp_notification_print(dat
, length
);
1617 case BGP_ROUTE_REFRESH
:
1618 bgp_route_refresh_print(dat
, length
);
1621 /* we have no decoder for the BGP message */
1622 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
1623 print_unknown_data(dat
,"\n\t ",length
);
1632 bgp_print(const u_char
*dat
, int length
)
1636 const u_char
*start
;
1637 const u_char marker
[] = {
1638 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1639 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1645 if (snapend
< dat
+ length
)
1648 printf(": BGP, length: %u",length
);
1650 if (vflag
< 1) /* lets be less chatty */
1655 while (p
< snapend
) {
1656 if (!TTEST2(p
[0], 1))
1663 if (!TTEST2(p
[0], sizeof(marker
)))
1665 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
1670 /* found BGP header */
1671 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
1672 memcpy(&bgp
, p
, BGP_SIZE
);
1677 hlen
= ntohs(bgp
.bgp_len
);
1678 if (hlen
< BGP_SIZE
) {
1679 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
1684 if (TTEST2(p
[0], hlen
)) {
1685 bgp_header_print(p
, hlen
);
1689 printf("\n[|BGP %s]", tok2str(bgp_msg_values
, "Unknown Message Type",bgp
.bgp_type
));