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.80 2004-03-18 11:14:45 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_ORF 3 /* XXX */
200 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
201 #define BGP_CAPCODE_AS_NEW 65 /* XXX */
202 #define BGP_CAPCODE_DYN_CAP 67 /* XXX */
203 #define BGP_CAPCODE_RR_CISCO 128
205 static struct tok bgp_capcode_values
[] = {
206 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
207 { BGP_CAPCODE_RR
, "Route Refresh"},
208 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
209 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
210 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
211 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
212 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
216 #define BGP_NOTIFY_MAJOR_MSG 1
217 #define BGP_NOTIFY_MAJOR_OPEN 2
218 #define BGP_NOTIFY_MAJOR_UPDATE 3
219 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
220 #define BGP_NOTIFY_MAJOR_FSM 5
221 #define BGP_NOTIFY_MAJOR_CEASE 6
222 #define BGP_NOTIFY_MAJOR_CAP 7
224 static struct tok bgp_notify_major_values
[] = {
225 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
226 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
227 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
228 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
229 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
230 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
231 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
235 /* draft-ietf-idr-cease-subcode-02 */
236 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
237 static struct tok bgp_notify_minor_cease_values
[] = {
238 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
239 { 2, "Administratively Shutdown"},
240 { 3, "Peer Unconfigured"},
241 { 4, "Administratively Reset"},
242 { 5, "Connection Rejected"},
243 { 6, "Other Configuration Change"},
244 { 7, "Connection Collision Resolution"},
248 static struct tok bgp_notify_minor_msg_values
[] = {
249 { 1, "Connection Not Synchronized"},
250 { 2, "Bad Message Length"},
251 { 3, "Bad Message Type"},
255 static struct tok bgp_notify_minor_open_values
[] = {
256 { 1, "Unsupported Version Number"},
258 { 3, "Bad BGP Identifier"},
259 { 4, "Unsupported Optional Parameter"},
260 { 5, "Authentication Failure"},
261 { 6, "Unacceptable Hold Time"},
265 static struct tok bgp_notify_minor_update_values
[] = {
266 { 1, "Malformed Attribute List"},
267 { 2, "Unrecognized Well-known Attribute"},
268 { 3, "Missing Well-known Attribute"},
269 { 4, "Attribute Flags Error"},
270 { 5, "Attribute Length Error"},
271 { 6, "Invalid ORIGIN Attribute"},
272 { 7, "AS Routing Loop"},
273 { 8, "Invalid NEXT_HOP Attribute"},
274 { 9, "Optional Attribute Error"},
275 { 10, "Invalid Network Field"},
276 { 11, "Malformed AS_PATH"},
280 static struct tok bgp_notify_minor_cap_values
[] = {
281 { 1, "Invalid Action Value" },
282 { 2, "Invalid Capability Length" },
283 { 3, "Malformed Capability Value" },
284 { 4, "Unsupported Capability Code" },
288 static struct tok bgp_origin_values
[] = {
295 /* Subsequent address family identifier, RFC2283 section 7 */
297 #define SAFNUM_UNICAST 1
298 #define SAFNUM_MULTICAST 2
299 #define SAFNUM_UNIMULTICAST 3
300 /* labeled BGP RFC3107 */
301 #define SAFNUM_LABUNICAST 4
302 #define SAFNUM_TUNNEL 64 /* XXX */
303 #define SAFNUM_VPLS 65 /* XXX */
304 #define SAFNUM_MDT 66 /* XXX */
305 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
306 #define SAFNUM_VPNUNICAST 128
307 #define SAFNUM_VPNMULTICAST 129
308 #define SAFNUM_VPNUNIMULTICAST 130
309 /* draft-marques-ppvpn-rt-constrain-01.txt */
310 #define SAFNUM_RT_ROUTING_INFO 132
312 #define BGP_VPN_RD_LEN 8
314 static struct tok bgp_safi_values
[] = {
315 { SAFNUM_RES
, "Reserved"},
316 { SAFNUM_UNICAST
, "Unicast"},
317 { SAFNUM_MULTICAST
, "Multicast"},
318 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
319 { SAFNUM_LABUNICAST
, "labeled Unicast"},
320 { SAFNUM_TUNNEL
, "Tunnel"},
321 { SAFNUM_VPLS
, "VPLS"},
322 { SAFNUM_MDT
, "MDT"},
323 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
324 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
325 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
326 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"}, /* draft-marques-ppvpn-rt-constrain-01.txt */
330 /* well-known community */
331 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
332 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
333 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
335 /* RFC1700 address family numbers */
337 #define AFNUM_INET6 2
340 #define AFNUM_BBN1822 5
345 #define AFNUM_X121 10
347 #define AFNUM_ATALK 12
348 #define AFNUM_DECNET 13
349 #define AFNUM_BANYAN 14
350 #define AFNUM_E164NSAP 15
351 /* draft-kompella-ppvpn-l2vpn */
352 #define AFNUM_L2VPN 196 /* still to be approved by IANA */
354 static struct tok bgp_afi_values
[] = {
356 { AFNUM_INET
, "IPv4"},
357 { AFNUM_INET6
, "IPv6"},
358 { AFNUM_NSAP
, "NSAP"},
359 { AFNUM_HDLC
, "HDLC"},
360 { AFNUM_BBN1822
, "BBN 1822"},
362 { AFNUM_E163
, "E.163"},
363 { AFNUM_E164
, "E.164"},
364 { AFNUM_F69
, "F.69"},
365 { AFNUM_X121
, "X.121"},
366 { AFNUM_IPX
, "Novell IPX"},
367 { AFNUM_ATALK
, "Appletalk"},
368 { AFNUM_DECNET
, "Decnet IV"},
369 { AFNUM_BANYAN
, "Banyan Vines"},
370 { AFNUM_E164NSAP
, "E.164 with NSAP subaddress"},
371 { AFNUM_L2VPN
, "Layer-2 VPN"},
375 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
376 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
377 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
378 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
379 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
380 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
381 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
382 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
383 /* rfc2547 bgp-mpls-vpns */
384 #define BGP_EXT_COM_CISCO_MCAST 0x0009 /* cisco proprietary */
386 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
387 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
388 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
389 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
391 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
392 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
394 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
395 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
397 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
399 static struct tok bgp_extd_comm_flag_values
[] = {
400 { 0x8000, "vendor-specific"},
401 { 0x4000, "non-transitive"},
405 static struct tok bgp_extd_comm_subtype_values
[] = {
406 { BGP_EXT_COM_RT_0
, "target"},
407 { BGP_EXT_COM_RT_1
, "target"},
408 { BGP_EXT_COM_RT_2
, "target"},
409 { BGP_EXT_COM_RO_0
, "origin"},
410 { BGP_EXT_COM_RO_1
, "origin"},
411 { BGP_EXT_COM_RO_2
, "origin"},
412 { BGP_EXT_COM_LINKBAND
, "link-BW"},
413 { BGP_EXT_COM_CISCO_MCAST
, "mdt-group"},
414 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
415 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
416 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
417 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
418 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
419 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
420 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
421 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
422 { BGP_EXT_COM_L2INFO
, "layer2-info"},
426 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
427 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
428 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
429 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
430 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
431 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
432 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
433 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
435 static struct tok bgp_extd_comm_ospf_rtype_values
[] = {
436 { BGP_OSPF_RTYPE_RTR
, "Router" },
437 { BGP_OSPF_RTYPE_NET
, "Network" },
438 { BGP_OSPF_RTYPE_SUM
, "Summary" },
439 { BGP_OSPF_RTYPE_EXT
, "External" },
440 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
441 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
445 static struct tok bgp_l2vpn_encaps_values
[] = {
448 { 2, "ATM AAL5 VCC transport"},
449 { 3, "ATM transparent cell transport"},
450 { 4, "Ethernet VLAN"},
455 { 9, "ATM VCC cell transport"},
456 { 10, "ATM VPC cell transport"},
459 { 64, "IP-interworking"},
464 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
473 memset(&addr
, 0, sizeof(addr
));
474 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
476 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
477 ((0xff00 >> (plen
% 8)) & 0xff);
479 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
480 return 1 + (plen
+ 7) / 8;
484 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
489 plen
= pptr
[0]; /* get prefix length */
491 /* this is one of the weirdnesses of rfc3107
492 the label length (actually the label + COS bits)
493 is added to the prefix length;
494 we also do only read out just one label -
495 there is no real application for advertisement of
496 stacked labels in a a single BGP message
499 plen
-=24; /* adjust prefixlen - labellength */
504 memset(&addr
, 0, sizeof(addr
));
505 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
507 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
508 ((0xff00 >> (plen
% 8)) & 0xff);
510 /* the label may get offsetted by 4 bits so lets shift it right */
511 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
512 getname((u_char
*)&addr
),
514 EXTRACT_24BITS(pptr
+1)>>4,
515 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
517 return 4 + (plen
+ 7) / 8;
520 /* RDs and RTs share the same semantics
521 * we use bgp_vpn_rd_print for
522 * printing route targets inside a NLRI */
524 bgp_vpn_rd_print (const u_char
*pptr
) {
526 /* allocate space for the largest possible string */
527 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
530 /* ok lets load the RD format */
531 switch (EXTRACT_16BITS(pptr
)) {
533 /* AS:IP-address fmt*/
535 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u.%u.%u.%u",
536 EXTRACT_16BITS(pptr
+2), *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
538 /* IP-address:AS fmt*/
541 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
542 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
545 /* 4-byte-AS:number fmt*/
547 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (%u.%u.%u.%u:%u)",
548 EXTRACT_32BITS(pptr
+2), EXTRACT_16BITS(pptr
+6),
549 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
552 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
561 decode_rt_routing_info(const u_char
*pptr
, char *buf
, u_int buflen
)
563 u_int8_t route_target
[8];
566 plen
= pptr
[0]; /* get prefix length */
568 plen
-=32; /* adjust prefix length */
573 memset(&route_target
, 0, sizeof(route_target
));
574 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
576 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
577 ((0xff00 >> (plen
% 8)) & 0xff);
579 snprintf(buf
, buflen
, "origin AS: %u, route target %s",
580 EXTRACT_32BITS(pptr
+1),
581 bgp_vpn_rd_print((u_char
*)&route_target
));
583 return 5 + (plen
+ 7) / 8;
587 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
592 plen
= pptr
[0]; /* get prefix length */
594 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
599 memset(&addr
, 0, sizeof(addr
));
600 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
602 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
603 ((0xff00 >> (plen
% 8)) & 0xff);
605 /* the label may get offsetted by 4 bits so lets shift it right */
606 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
607 bgp_vpn_rd_print(pptr
+4),
608 getname((u_char
*)&addr
),
610 EXTRACT_24BITS(pptr
+1)>>4,
611 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
613 return 12 + (plen
+ 7) / 8;
617 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
619 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
620 plen
=EXTRACT_16BITS(pptr
);
623 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
624 bgp_vpn_rd_print(pptr
),
625 EXTRACT_16BITS(pptr
+8),
626 EXTRACT_16BITS(pptr
+10),
627 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
631 /* ok now the variable part - lets read out TLVs*/
634 tlv_len
=EXTRACT_16BITS(pptr
);
640 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
643 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
645 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "%02x",*pptr
++);
650 snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tunknown TLV #%u, length: %u",
655 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it tright */
662 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
664 struct in6_addr addr
;
671 memset(&addr
, 0, sizeof(addr
));
672 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
674 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
675 ((0xff00 >> (plen
% 8)) & 0xff);
677 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
678 return 1 + (plen
+ 7) / 8;
682 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
684 struct in6_addr addr
;
687 plen
= pptr
[0]; /* get prefix length */
688 plen
-=24; /* adjust prefixlen - labellength */
693 memset(&addr
, 0, sizeof(addr
));
694 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
696 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
697 ((0xff00 >> (plen
% 8)) & 0xff);
699 /* the label may get offsetted by 4 bits so lets shift it right */
700 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
701 getname6((u_char
*)&addr
),
703 EXTRACT_24BITS(pptr
+1)>>4,
704 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
706 return 4 + (plen
+ 7) / 8;
710 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
712 struct in6_addr addr
;
715 plen
= pptr
[0]; /* get prefix length */
717 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
722 memset(&addr
, 0, sizeof(addr
));
723 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
725 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
726 ((0xff00 >> (plen
% 8)) & 0xff);
728 /* the label may get offsetted by 4 bits so lets shift it right */
729 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
730 bgp_vpn_rd_print(pptr
+4),
731 getname6((u_char
*)&addr
),
733 EXTRACT_24BITS(pptr
+1)>>4,
734 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
736 return 12 + (plen
+ 7) / 8;
741 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
746 union { /* copy buffer for bandwidth values */
753 char buf
[MAXHOSTNAMELEN
+ 100];
758 switch (attr
->bgpa_type
) {
761 printf("invalid len");
763 printf("%s", tok2str(bgp_origin_values
, "Unknown Origin Typecode", tptr
[0]));
765 case BGPTYPE_AS_PATH
:
767 printf("invalid len");
775 while (tptr
< pptr
+ len
) {
776 printf("%s", tok2str(bgp_as_path_segment_open_values
, "?", tptr
[0]));
777 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
778 printf("%u ", EXTRACT_16BITS(&tptr
[2 + i
]));
780 printf("%s", tok2str(bgp_as_path_segment_close_values
, "?", tptr
[0]));
781 tptr
+= 2 + tptr
[1] * 2;
784 case BGPTYPE_NEXT_HOP
:
786 printf("invalid len");
788 printf("%s", getname(tptr
));
790 case BGPTYPE_MULTI_EXIT_DISC
:
791 case BGPTYPE_LOCAL_PREF
:
793 printf("invalid len");
795 printf("%u", EXTRACT_32BITS(tptr
));
797 case BGPTYPE_ATOMIC_AGGREGATE
:
799 printf("invalid len");
801 case BGPTYPE_AGGREGATOR
:
803 printf("invalid len");
806 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
809 case BGPTYPE_COMMUNITIES
:
811 printf("invalid len");
816 comm
= EXTRACT_32BITS(tptr
);
818 case BGP_COMMUNITY_NO_EXPORT
:
819 printf(" NO_EXPORT");
821 case BGP_COMMUNITY_NO_ADVERT
:
822 printf(" NO_ADVERTISE");
824 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
825 printf(" NO_EXPORT_SUBCONFED");
829 (comm
>> 16) & 0xffff,
831 (tlen
>4) ? ", " : "");
838 case BGPTYPE_ORIGINATOR_ID
:
840 printf("invalid len");
843 printf("%s",getname(tptr
));
845 case BGPTYPE_CLUSTER_LIST
:
849 (tlen
>4) ? ", " : "");
854 case BGPTYPE_MP_REACH_NLRI
:
855 af
= EXTRACT_16BITS(tptr
);
858 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
859 tok2str(bgp_afi_values
, "Unknown AFI", af
),
861 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
862 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
865 if (af
== AFNUM_INET
|| af
==AFNUM_L2VPN
)
868 else if (af
== AFNUM_INET6
)
872 printf("\n\t no AFI %u decoder",af
);
874 print_unknown_data(tptr
,"\n\t ",tlen
);
884 printf("\n\t nexthop: ");
890 case SAFNUM_MULTICAST
:
891 case SAFNUM_UNIMULTICAST
:
892 case SAFNUM_LABUNICAST
:
893 case SAFNUM_RT_ROUTING_INFO
:
894 printf("%s",getname(tptr
));
895 tlen
-= sizeof(struct in_addr
);
896 tptr
+= sizeof(struct in_addr
);
898 case SAFNUM_VPNUNICAST
:
899 case SAFNUM_VPNMULTICAST
:
900 case SAFNUM_VPNUNIMULTICAST
:
902 bgp_vpn_rd_print(tptr
),
903 getname(tptr
+BGP_VPN_RD_LEN
));
904 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
905 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
908 printf("no SAFI %u decoder",safi
);
910 print_unknown_data(tptr
,"\n\t ",tlen
);
918 case SAFNUM_MULTICAST
:
919 case SAFNUM_UNIMULTICAST
:
920 case SAFNUM_LABUNICAST
:
921 case SAFNUM_RT_ROUTING_INFO
:
922 printf("%s", getname6(tptr
));
923 tlen
-= sizeof(struct in6_addr
);
924 tptr
+= sizeof(struct in6_addr
);
926 case SAFNUM_VPNUNICAST
:
927 case SAFNUM_VPNMULTICAST
:
928 case SAFNUM_VPNUNIMULTICAST
:
930 bgp_vpn_rd_print(tptr
),
931 getname6(tptr
+BGP_VPN_RD_LEN
));
932 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
933 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
936 printf("no SAFI %u decoder",safi
);
938 print_unknown_data(tptr
,"\n\t ",tlen
);
945 case SAFNUM_VPNUNICAST
:
946 case SAFNUM_VPNMULTICAST
:
947 case SAFNUM_VPNUNIMULTICAST
:
948 printf("%s", getname(tptr
));
949 tlen
-= (sizeof(struct in_addr
));
950 tptr
+= (sizeof(struct in_addr
));
953 printf("no SAFI %u decoder",safi
);
955 print_unknown_data(tptr
,"\n\t ",tlen
);
961 printf("no AFI %u decoder",af
);
963 print_unknown_data(tptr
,"\n\t ",tlen
);
974 printf("\n\t %u SNPA", snpa
);
975 for (/*nothing*/; snpa
> 0; snpa
--) {
976 printf("\n\t %d bytes", tptr
[0]);
983 while (len
- (tptr
- pptr
) > 0) {
988 case SAFNUM_MULTICAST
:
989 case SAFNUM_UNIMULTICAST
:
990 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
992 printf("\n\t %s", buf
);
994 printf("\n\t (illegal prefix length)");
996 case SAFNUM_LABUNICAST
:
997 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
998 printf("\n\t %s", buf
);
1000 case SAFNUM_VPNUNICAST
:
1001 case SAFNUM_VPNMULTICAST
:
1002 case SAFNUM_VPNUNIMULTICAST
:
1003 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1004 printf("\n\t %s", buf
);
1006 case SAFNUM_RT_ROUTING_INFO
:
1007 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1008 printf("\n\t %s", buf
);
1011 printf("\n\t no SAFI %u decoder",safi
);
1013 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1022 case SAFNUM_UNICAST
:
1023 case SAFNUM_MULTICAST
:
1024 case SAFNUM_UNIMULTICAST
:
1025 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1026 printf("\n\t %s", buf
);
1028 case SAFNUM_LABUNICAST
:
1029 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1030 printf("\n\t %s", buf
);
1032 case SAFNUM_VPNUNICAST
:
1033 case SAFNUM_VPNMULTICAST
:
1034 case SAFNUM_VPNUNIMULTICAST
:
1035 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1036 printf("\n\t %s", buf
);
1038 case SAFNUM_RT_ROUTING_INFO
:
1039 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1040 printf("\n\t %s", buf
);
1043 printf("\n\t no SAFI %u decoder ",safi
);
1045 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1054 case SAFNUM_VPNUNICAST
:
1055 case SAFNUM_VPNMULTICAST
:
1056 case SAFNUM_VPNUNIMULTICAST
:
1057 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1058 printf("\n\t %s", buf
);
1061 printf("no SAFI %u decoder",safi
);
1063 print_unknown_data(tptr
,"\n\t ",tlen
);
1072 printf("\n\t no AFI %u decoder ",af
);
1074 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1083 case BGPTYPE_MP_UNREACH_NLRI
:
1084 af
= EXTRACT_16BITS(tptr
);
1087 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1088 tok2str(bgp_afi_values
, "Unknown AFI", af
),
1090 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1091 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1096 while (len
- (tptr
- pptr
) > 0) {
1100 case SAFNUM_UNICAST
:
1101 case SAFNUM_MULTICAST
:
1102 case SAFNUM_UNIMULTICAST
:
1103 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1105 printf("\n\t %s", buf
);
1107 printf("\n\t (illegal prefix length)");
1109 case SAFNUM_LABUNICAST
:
1110 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1111 printf("\n\t %s", buf
);
1113 case SAFNUM_VPNUNICAST
:
1114 case SAFNUM_VPNMULTICAST
:
1115 case SAFNUM_VPNUNIMULTICAST
:
1116 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1117 printf("\n\t %s", buf
);
1120 printf("\n\t no SAFI %u decoder",safi
);
1122 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1132 case SAFNUM_UNICAST
:
1133 case SAFNUM_MULTICAST
:
1134 case SAFNUM_UNIMULTICAST
:
1135 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1136 printf("\n\t %s", buf
);
1138 case SAFNUM_LABUNICAST
:
1139 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1140 printf("\n\t %s", buf
);
1142 case SAFNUM_VPNUNICAST
:
1143 case SAFNUM_VPNMULTICAST
:
1144 case SAFNUM_VPNUNIMULTICAST
:
1145 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1146 printf("\n\t %s", buf
);
1149 printf("\n\t no SAFI %u decoder",safi
);
1151 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1161 case SAFNUM_VPNUNICAST
:
1162 case SAFNUM_VPNMULTICAST
:
1163 case SAFNUM_VPNUNIMULTICAST
:
1164 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1165 printf("\n\t %s", buf
);
1168 printf("no SAFI %u decoder",safi
);
1170 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1178 printf("\n\t no AFI %u decoder",af
);
1180 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1189 case BGPTYPE_EXTD_COMMUNITIES
:
1191 printf("invalid len");
1195 u_int16_t extd_comm
;
1196 extd_comm
=EXTRACT_16BITS(tptr
);
1198 printf("\n\t %s (0x%04x), Flags [%s]",
1199 tok2str(bgp_extd_comm_subtype_values
, "unknown extd community typecode", extd_comm
),
1201 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1204 case BGP_EXT_COM_RT_0
:
1205 case BGP_EXT_COM_RO_0
:
1207 EXTRACT_16BITS(tptr
+2),
1210 case BGP_EXT_COM_RT_1
:
1211 case BGP_EXT_COM_RO_1
:
1214 EXTRACT_16BITS(tptr
+6));
1216 case BGP_EXT_COM_RT_2
:
1217 case BGP_EXT_COM_RO_2
:
1219 EXTRACT_32BITS(tptr
+2),
1220 EXTRACT_16BITS(tptr
+6));
1222 case BGP_EXT_COM_LINKBAND
:
1223 bw
.i
= EXTRACT_32BITS(tptr
+2);
1224 printf(": bandwidth: %.3f Mbps",
1227 case BGP_EXT_COM_CISCO_MCAST
:
1228 printf(": AS %u, group %s",
1229 EXTRACT_16BITS(tptr
+2),
1232 case BGP_EXT_COM_VPN_ORIGIN
:
1233 case BGP_EXT_COM_VPN_ORIGIN2
:
1234 case BGP_EXT_COM_VPN_ORIGIN3
:
1235 case BGP_EXT_COM_VPN_ORIGIN4
:
1236 case BGP_EXT_COM_OSPF_RID
:
1237 case BGP_EXT_COM_OSPF_RID2
:
1238 printf("%s", getname(tptr
+2));
1240 case BGP_EXT_COM_OSPF_RTYPE
:
1241 case BGP_EXT_COM_OSPF_RTYPE2
:
1242 printf(": area:%s, router-type:%s, metric-type:%s%s",
1244 tok2str(bgp_extd_comm_ospf_rtype_values
,
1247 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1248 (*(tptr
+6) == (BGP_OSPF_RTYPE_EXT
||BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1250 case BGP_EXT_COM_L2INFO
:
1251 printf(": %s Control Flags [0x%02x]:MTU %u",
1252 tok2str(bgp_l2vpn_encaps_values
,
1256 EXTRACT_16BITS(tptr
+4));
1259 print_unknown_data(tptr
,"\n\t ",8);
1267 case BGPTYPE_ATTR_SET
:
1268 printf("\n\t Origin AS: %u", EXTRACT_32BITS(tptr
));
1274 struct bgp_attr bgpa
;
1276 memcpy(&bgpa
, tptr
, sizeof(bgpa
));
1277 alen
= bgp_attr_len(&bgpa
);
1278 tptr
+= bgp_attr_off(&bgpa
);
1279 len
-= bgp_attr_off(&bgpa
);
1281 printf("\n\t %s (%u), length: %u",
1282 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
1286 if (bgpa
.bgpa_flags
) {
1287 printf(", Flags [%s%s%s%s",
1288 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1289 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1290 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1291 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1292 if (bgpa
.bgpa_flags
& 0xf)
1293 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1296 bgp_attr_print(&bgpa
, tptr
, alen
); /* FIXME check for recursion */
1304 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1306 print_unknown_data(pptr
,"\n\t ",len
);
1309 if (vflag
> 1 && len
) /* omit zero length attributes*/
1310 print_unknown_data(pptr
,"\n\t ",len
);
1314 bgp_open_print(const u_char
*dat
, int length
)
1316 struct bgp_open bgpo
;
1317 struct bgp_opt bgpopt
;
1320 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
1322 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1323 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1324 hlen
= ntohs(bgpo
.bgpo_len
);
1326 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1327 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1328 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1329 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1330 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1332 /* some little sanity checking */
1333 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
1337 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1341 while (i
< bgpo
.bgpo_optlen
) {
1342 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1343 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1344 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1345 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1349 printf("\n\t Option %s (%u), length: %u",
1350 tok2str(bgp_opt_values
,"Unknown", bgpopt
.bgpopt_type
),
1354 /* now lets decode the options we know*/
1355 switch(bgpopt
.bgpopt_type
) {
1357 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1358 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1360 printf("\n\t %s, length: %u",
1361 tok2str(bgp_capcode_values
,"Unknown", cap_type
),
1364 case BGP_CAPCODE_MP
:
1365 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1366 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)),
1367 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1368 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+5]),
1369 opt
[i
+BGP_OPT_SIZE
+5]);
1371 case BGP_CAPCODE_RESTART
:
1372 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
1373 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
1374 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
1377 while(tcap_len
>=4) {
1378 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1379 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
)),
1380 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1381 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+cap_offset
+2]),
1382 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1383 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
1388 case BGP_CAPCODE_RR
:
1389 case BGP_CAPCODE_RR_CISCO
:
1392 printf("\n\t\tno decoder for Capability %u",
1395 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1399 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1403 printf("\n\t no decoder for option %u",
1404 bgpopt
.bgpopt_type
);
1408 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1416 bgp_update_print(const u_char
*dat
, int length
)
1419 struct bgp_attr bgpa
;
1425 TCHECK2(dat
[0], BGP_SIZE
);
1426 memcpy(&bgp
, dat
, BGP_SIZE
);
1427 hlen
= ntohs(bgp
.bgp_len
);
1428 p
= dat
+ BGP_SIZE
; /*XXX*/
1430 /* Unfeasible routes */
1431 len
= EXTRACT_16BITS(p
);
1434 * Without keeping state from the original NLRI message,
1435 * it's not possible to tell if this a v4 or v6 route,
1436 * so only try to decode it if we're not v6 enabled.
1439 printf("\n\t Withdrawn routes: %d bytes", len
);
1441 char buf
[MAXHOSTNAMELEN
+ 100];
1447 printf("\n\t Withdrawn routes:");
1449 while(i
< 2 + len
) {
1450 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1453 printf("\n\t %s", buf
);
1455 printf("\n\t (illegal prefix length)");
1464 len
= EXTRACT_16BITS(p
);
1466 /* do something more useful!*/
1468 while (i
< 2 + len
) {
1471 TCHECK2(p
[i
], sizeof(bgpa
));
1472 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
1473 alen
= bgp_attr_len(&bgpa
);
1474 aoff
= bgp_attr_off(&bgpa
);
1476 printf("\n\t %s (%u), length: %u",
1477 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
1481 if (bgpa
.bgpa_flags
) {
1482 printf(", Flags [%s%s%s%s",
1483 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1484 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1485 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1486 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1487 if (bgpa
.bgpa_flags
& 0xf)
1488 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1491 bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
);
1497 if (dat
+ length
> p
) {
1498 printf("\n\t Updated routes:");
1499 while (dat
+ length
> p
) {
1500 char buf
[MAXHOSTNAMELEN
+ 100];
1501 i
= decode_prefix4(p
, buf
, sizeof(buf
));
1503 printf("\n\t %s", buf
);
1506 printf("\n\t (illegal prefix length)");
1517 bgp_notification_print(const u_char
*dat
, int length
)
1519 struct bgp_notification bgpn
;
1523 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1524 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1525 hlen
= ntohs(bgpn
.bgpn_len
);
1527 /* some little sanity checking */
1528 if (length
<BGP_NOTIFICATION_SIZE
)
1532 tok2str(bgp_notify_major_values
, "Unknown Error", bgpn
.bgpn_major
),
1535 switch (bgpn
.bgpn_major
) {
1537 case BGP_NOTIFY_MAJOR_MSG
:
1538 printf(", subcode %s (%u)",
1539 tok2str(bgp_notify_minor_msg_values
, "Unknown", bgpn
.bgpn_minor
),
1542 case BGP_NOTIFY_MAJOR_OPEN
:
1543 printf(", subcode %s (%u)",
1544 tok2str(bgp_notify_minor_open_values
, "Unknown", bgpn
.bgpn_minor
),
1547 case BGP_NOTIFY_MAJOR_UPDATE
:
1548 printf(", subcode %s (%u)",
1549 tok2str(bgp_notify_minor_update_values
, "Unknown", bgpn
.bgpn_minor
),
1552 case BGP_NOTIFY_MAJOR_CAP
:
1553 printf(" subcode %s (%u)",
1554 tok2str(bgp_notify_minor_cap_values
, "Unknown", bgpn
.bgpn_minor
),
1556 case BGP_NOTIFY_MAJOR_CEASE
:
1557 printf(", subcode %s (%u)",
1558 tok2str(bgp_notify_minor_cease_values
, "Unknown", bgpn
.bgpn_minor
),
1561 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
1562 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
1564 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
1565 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
1567 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
1568 tok2str(bgp_afi_values
, "Unknown", EXTRACT_16BITS(tptr
)),
1569 EXTRACT_16BITS(tptr
),
1570 tok2str(bgp_safi_values
, "Unknown", *(tptr
+2)),
1572 EXTRACT_32BITS(tptr
+3));
1585 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1587 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1588 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
1590 printf("\n\t AFI %s (%u), SAFI %s (%u)",
1591 tok2str(bgp_afi_values
,"Unknown",
1592 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
)), /* this stinks but the compiler pads the structure weird */
1593 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1594 tok2str(bgp_safi_values
,"Unknown",
1595 bgp_route_refresh_header
->safi
),
1596 bgp_route_refresh_header
->safi
);
1599 print_unknown_data(pptr
,"\n\t ", len
);
1605 bgp_header_print(const u_char
*dat
, int length
)
1609 TCHECK2(dat
[0], BGP_SIZE
);
1610 memcpy(&bgp
, dat
, BGP_SIZE
);
1611 printf("\n\t%s Message (%u), length: %u",
1612 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
1616 switch (bgp
.bgp_type
) {
1618 bgp_open_print(dat
, length
);
1621 bgp_update_print(dat
, length
);
1623 case BGP_NOTIFICATION
:
1624 bgp_notification_print(dat
, length
);
1628 case BGP_ROUTE_REFRESH
:
1629 bgp_route_refresh_print(dat
, length
);
1632 /* we have no decoder for the BGP message */
1633 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
1634 print_unknown_data(dat
,"\n\t ",length
);
1643 bgp_print(const u_char
*dat
, int length
)
1647 const u_char
*start
;
1648 const u_char marker
[] = {
1649 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1650 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1656 if (snapend
< dat
+ length
)
1659 printf(": BGP, length: %u",length
);
1661 if (vflag
< 1) /* lets be less chatty */
1666 while (p
< snapend
) {
1667 if (!TTEST2(p
[0], 1))
1674 if (!TTEST2(p
[0], sizeof(marker
)))
1676 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
1681 /* found BGP header */
1682 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
1683 memcpy(&bgp
, p
, BGP_SIZE
);
1688 hlen
= ntohs(bgp
.bgp_len
);
1689 if (hlen
< BGP_SIZE
) {
1690 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
1695 if (TTEST2(p
[0], hlen
)) {
1696 bgp_header_print(p
, hlen
);
1700 printf("\n[|BGP %s]", tok2str(bgp_msg_values
, "Unknown Message Type",bgp
.bgp_type
));