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
[] =
39 "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.63 2003-05-27 13:09:02 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];
99 u_int8_t bgpn_data
[0]; /* data should follow */
101 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
103 struct bgp_route_refresh
{
104 u_int8_t bgp_marker
[16];
107 u_int8_t afi
[2]; /* the compiler messes this structure up */
108 u_int8_t res
; /* when doing misaligned sequences of int8 and int16 */
109 u_int8_t safi
; /* afi should be int16 - so we have to access it using */
110 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
111 #define BGP_ROUTE_REFRESH_SIZE 23
120 #define bgp_attr_len(p) \
121 (((p)->bgpa_flags & 0x10) ? \
122 EXTRACT_16BITS(&(p)->bgpa_len.elen) : (p)->bgpa_len.len)
123 #define bgp_attr_off(p) \
124 (((p)->bgpa_flags & 0x10) ? 4 : 3)
127 #define BGPTYPE_ORIGIN 1
128 #define BGPTYPE_AS_PATH 2
129 #define BGPTYPE_NEXT_HOP 3
130 #define BGPTYPE_MULTI_EXIT_DISC 4
131 #define BGPTYPE_LOCAL_PREF 5
132 #define BGPTYPE_ATOMIC_AGGREGATE 6
133 #define BGPTYPE_AGGREGATOR 7
134 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
135 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
136 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
137 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
138 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
139 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
140 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
141 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
142 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
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 { 255, "Reserved for development"},
165 #define BGP_OPT_AUTH 1
166 #define BGP_OPT_CAP 2
169 static struct tok bgp_opt_values
[] = {
170 { BGP_OPT_AUTH
, "Authentication Information"},
171 { BGP_OPT_CAP
, "Capabilities Advertisement"},
175 #define BGP_CAPCODE_MP 1
176 #define BGP_CAPCODE_RR 2
177 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
178 #define BGP_CAPCODE_RR_CISCO 128
180 static struct tok bgp_capcode_values
[] = {
181 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
182 { BGP_CAPCODE_RR
, "Route Refresh"},
183 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
184 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
188 #define BGP_NOTIFY_MAJOR_MSG 1
189 #define BGP_NOTIFY_MAJOR_OPEN 2
190 #define BGP_NOTIFY_MAJOR_UPDATE 3
191 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
192 #define BGP_NOTIFY_MAJOR_FSM 5
193 #define BGP_NOTIFY_MAJOR_CEASE 6
195 static struct tok bgp_notify_major_values
[] = {
196 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
197 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
198 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
199 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
200 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
201 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
205 /* draft-ietf-idr-cease-subcode-02 */
206 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
207 static struct tok bgp_notify_minor_cease_values
[] = {
208 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
209 { 2, "Administratively Shutdown"},
210 { 3, "Peer Unconfigured"},
211 { 4, "Administratively Reset"},
212 { 5, "Connection Rejected"},
213 { 6, "Other Configuration Change"},
214 { 7, "Connection Collision Resolution"},
218 static struct tok bgp_notify_minor_msg_values
[] = {
219 { 1, "Connection Not Synchronized"},
220 { 2, "Bad Message Length"},
221 { 3, "Bad Message Type"},
225 static struct tok bgp_notify_minor_open_values
[] = {
226 { 1, "Unsupported Version Number"},
228 { 3, "Bad BGP Identifier"},
229 { 4, "Unsupported Optional Parameter"},
230 { 5, "Authentication Failure"},
231 { 6, "Unacceptable Hold Time"},
235 static struct tok bgp_notify_minor_update_values
[] = {
236 { 1, "Malformed Attribute List"},
237 { 2, "Unrecognized Well-known Attribute"},
238 { 3, "Missing Well-known Attribute"},
239 { 4, "Attribute Flags Error"},
240 { 5, "Attribute Length Error"},
241 { 6, "Invalid ORIGIN Attribute"},
242 { 7, "AS Routing Loop"},
243 { 8, "Invalid NEXT_HOP Attribute"},
244 { 9, "Optional Attribute Error"},
245 { 10, "Invalid Network Field"},
246 { 11, "Malformed AS_PATH"},
250 static struct tok bgp_origin_values
[] = {
257 /* Subsequent address family identifier, RFC2283 section 7 */
259 #define SAFNUM_UNICAST 1
260 #define SAFNUM_MULTICAST 2
261 #define SAFNUM_UNIMULTICAST 3
262 /* labeled BGP RFC3107 */
263 #define SAFNUM_LABUNICAST 4
264 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
265 #define SAFNUM_VPNUNICAST 128
266 #define SAFNUM_VPNMULTICAST 129
267 #define SAFNUM_VPNUNIMULTICAST 130
269 #define BGP_VPN_RD_LEN 8
271 static struct tok bgp_safi_values
[] = {
272 { SAFNUM_RES
, "Reserved"},
273 { SAFNUM_UNICAST
, "Unicast"},
274 { SAFNUM_MULTICAST
, "Multicast"},
275 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
276 { SAFNUM_LABUNICAST
, "labeled Unicast"},
277 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
278 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
279 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
283 /* well-known community */
284 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
285 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
286 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
288 /* RFC1700 address family numbers */
290 #define AFNUM_INET6 2
293 #define AFNUM_BBN1822 5
298 #define AFNUM_X121 10
300 #define AFNUM_ATALK 12
301 #define AFNUM_DECNET 13
302 #define AFNUM_BANYAN 14
303 #define AFNUM_E164NSAP 15
304 /* draft-kompella-ppvpn-l2vpn */
305 #define AFNUM_L2VPN 196 /* still to be approved by IANA */
307 static struct tok bgp_afi_values
[] = {
309 { AFNUM_INET
, "IPv4"},
310 { AFNUM_INET6
, "IPv6"},
311 { AFNUM_NSAP
, "NSAP"},
312 { AFNUM_HDLC
, "HDLC"},
313 { AFNUM_BBN1822
, "BBN 1822"},
315 { AFNUM_E163
, "E.163"},
316 { AFNUM_E164
, "E.164"},
317 { AFNUM_F69
, "F.69"},
318 { AFNUM_X121
, "X.121"},
319 { AFNUM_IPX
, "Novell IPX"},
320 { AFNUM_ATALK
, "Appletalk"},
321 { AFNUM_DECNET
, "Decnet IV"},
322 { AFNUM_BANYAN
, "Banyan Vines"},
323 { AFNUM_E164NSAP
, "E.164 with NSAP subaddress"},
324 { AFNUM_L2VPN
, "Layer-2 VPN"},
328 /* Extended community type - draft-ramachandra-bgp-ext-communities */
329 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
330 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
331 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
332 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
333 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
334 /* rfc2547 bgp-mpls-vpns */
336 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
337 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
338 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
339 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
341 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
342 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
344 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
345 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
347 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
349 static struct tok bgp_extd_comm_subtype_values
[] = {
350 { BGP_EXT_COM_RT_0
, "target"},
351 { BGP_EXT_COM_RT_1
, "target"},
352 { BGP_EXT_COM_RO_0
, "origin"},
353 { BGP_EXT_COM_RO_1
, "origin"},
354 { BGP_EXT_COM_LINKBAND
, "link-BW"},
355 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
356 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
357 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
358 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
359 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
360 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
361 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
362 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
363 { BGP_EXT_COM_L2INFO
, "layer2-info"},
367 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
368 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
369 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
370 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
371 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
372 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
373 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
374 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
376 static struct tok bgp_extd_comm_ospf_rtype_values
[] = {
377 { BGP_OSPF_RTYPE_RTR
, "Router" },
378 { BGP_OSPF_RTYPE_NET
, "Network" },
379 { BGP_OSPF_RTYPE_SUM
, "Summary" },
380 { BGP_OSPF_RTYPE_EXT
, "External" },
381 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
382 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
386 static struct tok bgp_l2vpn_encaps_values
[] = {
389 { 2, "ATM AAL5 VCC transport"},
390 { 3, "ATM transparent cell transport"},
391 { 4, "Ethernet VLAN"},
396 { 9, "ATM VCC cell transport"},
397 { 10, "ATM VPC cell transport"},
400 { 64, "IP-interworking"},
405 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
414 memset(&addr
, 0, sizeof(addr
));
415 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
417 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
418 ((0xff00 >> (plen
% 8)) & 0xff);
420 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
421 return 1 + (plen
+ 7) / 8;
425 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
430 plen
= pptr
[0]; /* get prefix length */
432 /* this is one of the weirdnesses of rfc3107
433 the label length (actually the label + COS bits)
434 is added to the prefix length;
435 we also do only read out just one label -
436 there is no real application for advertisement of
437 stacked labels in a a single BGP message
440 plen
-=24; /* adjust prefixlen - labellength */
445 memset(&addr
, 0, sizeof(addr
));
446 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
448 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
449 ((0xff00 >> (plen
% 8)) & 0xff);
451 /* the label may get offsetted by 4 bits so lets shift it right */
452 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
453 getname((u_char
*)&addr
),
455 EXTRACT_24BITS(pptr
+1)>>4,
456 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
458 return 4 + (plen
+ 7) / 8;
462 bgp_vpn_rd_print (const u_char
*pptr
) {
464 /* allocate space for the following string
465 * xxx.xxx.xxx.xxx:xxxxx
466 * 21 bytes plus one termination byte */
470 /* ok lets load the RD format */
471 switch (EXTRACT_16BITS(pptr
)) {
472 /* AS:IP-address fmt*/
474 sprintf(pos
, "%u:%u.%u.%u.%u",
475 EXTRACT_16BITS(pptr
+2),
481 /* IP-address:AS fmt*/
483 sprintf(pos
, "%u.%u.%u.%u:%u",
488 EXTRACT_16BITS(pptr
+6));
491 sprintf(pos
, "unknown RD format");
500 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
505 plen
= pptr
[0]; /* get prefix length */
507 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
512 memset(&addr
, 0, sizeof(addr
));
513 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
515 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
516 ((0xff00 >> (plen
% 8)) & 0xff);
518 /* the label may get offsetted by 4 bits so lets shift it right */
519 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
520 bgp_vpn_rd_print(pptr
+4),
521 getname((u_char
*)&addr
),
523 EXTRACT_24BITS(pptr
+1)>>4,
524 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
526 return 12 + (plen
+ 7) / 8;
530 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
532 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
533 plen
=EXTRACT_16BITS(pptr
);
536 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
537 bgp_vpn_rd_print(pptr
),
538 EXTRACT_16BITS(pptr
+8),
539 EXTRACT_16BITS(pptr
+10),
540 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
544 /* ok now the variable part - lets read out TLVs*/
547 tlv_len
=EXTRACT_16BITS(pptr
);
553 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
556 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
558 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "%02x",*pptr
++);
563 snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tunknown TLV #%u, length: %u",
568 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it tright */
575 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
577 struct in6_addr addr
;
584 memset(&addr
, 0, sizeof(addr
));
585 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
587 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
588 ((0xff00 >> (plen
% 8)) & 0xff);
590 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
591 return 1 + (plen
+ 7) / 8;
595 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
597 struct in6_addr addr
;
600 plen
= pptr
[0]; /* get prefix length */
601 plen
-=24; /* adjust prefixlen - labellength */
606 memset(&addr
, 0, sizeof(addr
));
607 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
609 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
610 ((0xff00 >> (plen
% 8)) & 0xff);
612 /* the label may get offsetted by 4 bits so lets shift it right */
613 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
614 getname6((u_char
*)&addr
),
616 EXTRACT_24BITS(pptr
+1)>>4,
617 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
619 return 4 + (plen
+ 7) / 8;
623 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
625 struct in6_addr addr
;
628 plen
= pptr
[0]; /* get prefix length */
630 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
635 memset(&addr
, 0, sizeof(addr
));
636 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
638 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
639 ((0xff00 >> (plen
% 8)) & 0xff);
641 /* the label may get offsetted by 4 bits so lets shift it right */
642 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
643 bgp_vpn_rd_print(pptr
+4),
644 getname6((u_char
*)&addr
),
646 EXTRACT_24BITS(pptr
+1)>>4,
647 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
649 return 12 + (plen
+ 7) / 8;
654 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
659 float bw
; /* copy buffer for bandwidth values */
663 char buf
[MAXHOSTNAMELEN
+ 100];
668 switch (attr
->bgpa_type
) {
671 printf("invalid len");
673 printf("%s", tok2str(bgp_origin_values
, "Unknown Origin Typecode", tptr
[0]));
675 case BGPTYPE_AS_PATH
:
677 printf("invalid len");
684 while (tptr
< pptr
+ len
) {
686 * under RFC1965, p[0] means:
687 * 1: AS_SET 2: AS_SEQUENCE
688 * 3: AS_CONFED_SET 4: AS_CONFED_SEQUENCE
690 if (tptr
[0] == 3 || tptr
[0] == 4)
692 printf("%s", (tptr
[0] & 1) ? "{" : "");
693 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
694 printf("%s%u", i
== 0 ? "" : " ",
695 EXTRACT_16BITS(&tptr
[2 + i
]));
697 printf("%s", (tptr
[0] & 1) ? "}" : "");
698 tptr
+= 2 + tptr
[1] * 2;
701 case BGPTYPE_NEXT_HOP
:
703 printf("invalid len");
705 printf("%s", getname(tptr
));
707 case BGPTYPE_MULTI_EXIT_DISC
:
708 case BGPTYPE_LOCAL_PREF
:
710 printf("invalid len");
712 printf("%u", EXTRACT_32BITS(tptr
));
714 case BGPTYPE_ATOMIC_AGGREGATE
:
716 printf("invalid len");
718 case BGPTYPE_AGGREGATOR
:
720 printf("invalid len");
723 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
726 case BGPTYPE_COMMUNITIES
:
728 printf("invalid len");
733 comm
= EXTRACT_32BITS(tptr
);
735 case BGP_COMMUNITY_NO_EXPORT
:
736 printf(" NO_EXPORT");
738 case BGP_COMMUNITY_NO_ADVERT
:
739 printf(" NO_ADVERTISE");
741 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
742 printf(" NO_EXPORT_SUBCONFED");
746 (comm
>> 16) & 0xffff,
748 (tlen
>4) ? ", " : "");
755 case BGPTYPE_ORIGINATOR_ID
:
757 printf("invalid len");
760 printf("%s",getname(tptr
));
762 case BGPTYPE_CLUSTER_LIST
:
766 (tlen
>4) ? ", " : "");
771 case BGPTYPE_MP_REACH_NLRI
:
772 af
= EXTRACT_16BITS(tptr
);
775 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
776 tok2str(bgp_afi_values
, "Unknown AFI", af
),
778 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
779 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
782 if (af
== AFNUM_INET
|| af
==AFNUM_L2VPN
)
785 else if (af
== AFNUM_INET6
)
789 printf("\n\t no AFI %u decoder",af
);
791 print_unknown_data(tptr
,"\n\t ",tlen
);
801 printf("\n\t nexthop: ");
807 case SAFNUM_MULTICAST
:
808 case SAFNUM_UNIMULTICAST
:
809 case SAFNUM_LABUNICAST
:
810 printf("%s",getname(tptr
));
811 tlen
-= sizeof(struct in_addr
);
812 tptr
+= sizeof(struct in_addr
);
814 case SAFNUM_VPNUNICAST
:
815 case SAFNUM_VPNMULTICAST
:
816 case SAFNUM_VPNUNIMULTICAST
:
818 bgp_vpn_rd_print(tptr
),
819 getname(tptr
+BGP_VPN_RD_LEN
));
820 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
821 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
824 printf("no SAFI %u decoder",safi
);
826 print_unknown_data(tptr
,"\n\t ",tlen
);
834 case SAFNUM_MULTICAST
:
835 case SAFNUM_UNIMULTICAST
:
836 case SAFNUM_LABUNICAST
:
837 printf("%s", getname6(tptr
));
838 tlen
-= sizeof(struct in6_addr
);
839 tptr
+= sizeof(struct in6_addr
);
841 case SAFNUM_VPNUNICAST
:
842 case SAFNUM_VPNMULTICAST
:
843 case SAFNUM_VPNUNIMULTICAST
:
845 bgp_vpn_rd_print(tptr
),
846 getname6(tptr
+BGP_VPN_RD_LEN
));
847 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
848 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
851 printf("no SAFI %u decoder",safi
);
853 print_unknown_data(tptr
,"\n\t ",tlen
);
860 case SAFNUM_VPNUNICAST
:
861 case SAFNUM_VPNMULTICAST
:
862 case SAFNUM_VPNUNIMULTICAST
:
863 printf("%s", getname(tptr
));
864 tlen
-= (sizeof(struct in_addr
));
865 tptr
+= (sizeof(struct in_addr
));
868 printf("no SAFI %u decoder",safi
);
870 print_unknown_data(tptr
,"\n\t ",tlen
);
876 printf("no AFI %u decoder",af
);
878 print_unknown_data(tptr
,"\n\t ",tlen
);
889 printf("\n\t %u SNPA", snpa
);
890 for (/*nothing*/; snpa
> 0; snpa
--) {
891 printf("\n\t %d bytes", tptr
[0]);
898 while (len
- (tptr
- pptr
) > 0) {
903 case SAFNUM_MULTICAST
:
904 case SAFNUM_UNIMULTICAST
:
905 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
907 printf("\n\t %s", buf
);
909 printf("\n\t (illegal prefix length)");
911 case SAFNUM_LABUNICAST
:
912 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
913 printf("\n\t %s", buf
);
915 case SAFNUM_VPNUNICAST
:
916 case SAFNUM_VPNMULTICAST
:
917 case SAFNUM_VPNUNIMULTICAST
:
918 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
919 printf("\n\t %s", buf
);
922 printf("\n\t no SAFI %u decoder",safi
);
924 print_unknown_data(tptr
-3,"\n\t ",tlen
);
934 case SAFNUM_MULTICAST
:
935 case SAFNUM_UNIMULTICAST
:
936 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
937 printf("\n\t %s", buf
);
939 case SAFNUM_LABUNICAST
:
940 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
941 printf("\n\t %s", buf
);
943 case SAFNUM_VPNUNICAST
:
944 case SAFNUM_VPNMULTICAST
:
945 case SAFNUM_VPNUNIMULTICAST
:
946 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
947 printf("\n\t %s", buf
);
950 printf("\n\t no SAFI %u decoder ",safi
);
952 print_unknown_data(tptr
-3,"\n\t ",tlen
);
961 case SAFNUM_VPNUNICAST
:
962 case SAFNUM_VPNMULTICAST
:
963 case SAFNUM_VPNUNIMULTICAST
:
964 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
965 printf("\n\t %s", buf
);
968 printf("no SAFI %u decoder",safi
);
970 print_unknown_data(tptr
,"\n\t ",tlen
);
979 printf("\n\t no AFI %u decoder ",af
);
981 print_unknown_data(tptr
-3,"\n\t ",tlen
);
990 case BGPTYPE_MP_UNREACH_NLRI
:
991 af
= EXTRACT_16BITS(tptr
);
994 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
995 tok2str(bgp_afi_values
, "Unknown AFI", af
),
997 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
998 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1003 while (len
- (tptr
- pptr
) > 0) {
1007 case SAFNUM_UNICAST
:
1008 case SAFNUM_MULTICAST
:
1009 case SAFNUM_UNIMULTICAST
:
1010 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1012 printf("\n\t %s", buf
);
1014 printf("\n\t (illegal prefix length)");
1016 case SAFNUM_LABUNICAST
:
1017 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1018 printf("\n\t %s", buf
);
1020 case SAFNUM_VPNUNICAST
:
1021 case SAFNUM_VPNMULTICAST
:
1022 case SAFNUM_VPNUNIMULTICAST
:
1023 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1024 printf("\n\t %s", buf
);
1027 printf("\n\t no SAFI %u decoder",safi
);
1029 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1039 case SAFNUM_UNICAST
:
1040 case SAFNUM_MULTICAST
:
1041 case SAFNUM_UNIMULTICAST
:
1042 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1043 printf("\n\t %s", buf
);
1045 case SAFNUM_LABUNICAST
:
1046 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1047 printf("\n\t %s", buf
);
1049 case SAFNUM_VPNUNICAST
:
1050 case SAFNUM_VPNMULTICAST
:
1051 case SAFNUM_VPNUNIMULTICAST
:
1052 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1053 printf("\n\t %s", buf
);
1056 printf("\n\t no SAFI %u decoder",safi
);
1058 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1068 case SAFNUM_VPNUNICAST
:
1069 case SAFNUM_VPNMULTICAST
:
1070 case SAFNUM_VPNUNIMULTICAST
:
1071 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1072 printf("\n\t %s", buf
);
1075 printf("no SAFI %u decoder",safi
);
1077 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1085 printf("\n\t no AFI %u decoder",af
);
1087 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1096 case BGPTYPE_EXTD_COMMUNITIES
:
1098 printf("invalid len");
1102 u_int16_t extd_comm
;
1103 extd_comm
=EXTRACT_16BITS(tptr
);
1105 case BGP_EXT_COM_RT_0
:
1106 case BGP_EXT_COM_RO_0
:
1107 printf("\n\t %s%s%s(0x%04x):%u:%s",
1108 (extd_comm
&0x8000) ? "vendor-specific: " : "",
1109 (extd_comm
&0x4000) ? "non-transitive: " : "",
1110 tok2str(bgp_extd_comm_subtype_values
,
1114 EXTRACT_16BITS(tptr
+2),
1117 case BGP_EXT_COM_RT_1
:
1118 case BGP_EXT_COM_RO_1
:
1119 printf("\n\t %s%s%s(0x%04x):%s:%u",
1120 (extd_comm
&0x8000) ? "vendor-specific: " : "",
1121 (extd_comm
&0x4000) ? "non-transitive: " : "",
1122 tok2str(bgp_extd_comm_subtype_values
,
1127 EXTRACT_16BITS(tptr
+6));
1129 case BGP_EXT_COM_LINKBAND
:
1130 memcpy (&bw
, tptr
+2, 4);
1131 printf("\n\t %s%s%s(0x%04x):bandwidth: %.3f Mbps",
1132 (extd_comm
&0x8000) ? "vendor-specific: " : "",
1133 (extd_comm
&0x4000) ? "non-transitive: " : "",
1134 tok2str(bgp_extd_comm_subtype_values
,
1140 case BGP_EXT_COM_VPN_ORIGIN
:
1141 case BGP_EXT_COM_VPN_ORIGIN2
:
1142 case BGP_EXT_COM_VPN_ORIGIN3
:
1143 case BGP_EXT_COM_VPN_ORIGIN4
:
1144 case BGP_EXT_COM_OSPF_RID
:
1145 case BGP_EXT_COM_OSPF_RID2
:
1146 printf("\n\t %s%s%s(0x%04x):%s",
1147 (extd_comm
&0x8000) ? "vendor-specific: " : "",
1148 (extd_comm
&0x4000) ? "non-transitive: " : "",
1149 tok2str(bgp_extd_comm_subtype_values
,
1155 case BGP_EXT_COM_OSPF_RTYPE
:
1156 case BGP_EXT_COM_OSPF_RTYPE2
:
1157 printf("\n\t %s%s%s(0x%04x), area:%s, router-type:%s, metric-type:%s%s",
1158 (extd_comm
&0x8000) ? "vendor-specific: " : "",
1159 (extd_comm
&0x4000) ? "non-transitive: " : "",
1160 tok2str(bgp_extd_comm_subtype_values
,
1165 tok2str(bgp_extd_comm_ospf_rtype_values
,
1168 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1169 (*(tptr
+6) == (BGP_OSPF_RTYPE_EXT
||BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1171 case BGP_EXT_COM_L2INFO
:
1172 printf("\n\t %s%s(0x%04x):%s Control Flags [0x%02x]:MTU %u",
1173 (extd_comm
&0x4000) ? "non-transitive: " : "",
1174 tok2str(bgp_extd_comm_subtype_values
,
1178 tok2str(bgp_l2vpn_encaps_values
,
1182 EXTRACT_16BITS(tptr
+4));
1185 printf("\n\t unknown extd community typecode (0x%04x)",
1187 print_unknown_data(tptr
,"\n\t ",8);
1196 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1198 print_unknown_data(pptr
,"\n\t ",len
);
1201 if (vflag
> 1 && len
) /* omit zero length attributes*/
1202 print_unknown_data(pptr
,"\n\t ",len
);
1206 bgp_open_print(const u_char
*dat
, int length
)
1208 struct bgp_open bgpo
;
1209 struct bgp_opt bgpopt
;
1212 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
1214 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1215 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1216 hlen
= ntohs(bgpo
.bgpo_len
);
1218 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1219 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1220 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1221 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1222 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1224 /* some little sanity checking */
1225 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
1229 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1233 while (i
< bgpo
.bgpo_optlen
) {
1234 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1235 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1236 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1237 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1241 printf("\n\t Option %s (%u), length: %u",
1242 tok2str(bgp_opt_values
,"Unknown", bgpopt
.bgpopt_type
),
1246 /* now lets decode the options we know*/
1247 switch(bgpopt
.bgpopt_type
) {
1249 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1250 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1252 printf("\n\t %s, length: %u",
1253 tok2str(bgp_capcode_values
,"Unknown", cap_type
),
1256 case BGP_CAPCODE_MP
:
1257 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1258 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)),
1259 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1260 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+5]),
1261 opt
[i
+BGP_OPT_SIZE
+5]);
1263 case BGP_CAPCODE_RESTART
:
1264 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
1265 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
1266 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
1269 while(tcap_len
>=4) {
1270 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1271 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
)),
1272 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1273 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+cap_offset
+2]),
1274 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1275 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
1280 case BGP_CAPCODE_RR
:
1281 case BGP_CAPCODE_RR_CISCO
:
1284 printf("\n\t\tno decoder for Capability %u",
1287 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1291 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1295 printf("\n\t no decoder for option %u",
1296 bgpopt
.bgpopt_type
);
1300 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1308 bgp_update_print(const u_char
*dat
, int length
)
1311 struct bgp_attr bgpa
;
1317 TCHECK2(dat
[0], BGP_SIZE
);
1318 memcpy(&bgp
, dat
, BGP_SIZE
);
1319 hlen
= ntohs(bgp
.bgp_len
);
1320 p
= dat
+ BGP_SIZE
; /*XXX*/
1322 /* Unfeasible routes */
1323 len
= EXTRACT_16BITS(p
);
1326 * Without keeping state from the original NLRI message,
1327 * it's not possible to tell if this a v4 or v6 route,
1328 * so only try to decode it if we're not v6 enabled.
1331 printf("\n\t Withdrawn routes: %d bytes", len
);
1333 char buf
[MAXHOSTNAMELEN
+ 100];
1339 printf("\n\t Withdrawn routes:");
1341 while(i
< 2 + len
) {
1342 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1345 printf("\n\t %s", buf
);
1347 printf("\n\t (illegal prefix length)");
1356 len
= EXTRACT_16BITS(p
);
1358 /* do something more useful!*/
1360 while (i
< 2 + len
) {
1363 TCHECK2(p
[i
], sizeof(bgpa
));
1364 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
1365 alen
= bgp_attr_len(&bgpa
);
1366 aoff
= bgp_attr_off(&bgpa
);
1368 printf("\n\t %s (%u), length: %u",
1369 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
1373 if (bgpa
.bgpa_flags
) {
1374 printf(", flags [%s%s%s%s",
1375 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1376 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1377 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1378 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1379 if (bgpa
.bgpa_flags
& 0xf)
1380 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1383 bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
);
1389 if (dat
+ length
> p
) {
1390 printf("\n\t Updated routes:");
1391 while (dat
+ length
> p
) {
1392 char buf
[MAXHOSTNAMELEN
+ 100];
1393 i
= decode_prefix4(p
, buf
, sizeof(buf
));
1395 printf("\n\t %s", buf
);
1398 printf("\n\t (illegal prefix length)");
1409 bgp_notification_print(const u_char
*dat
, int length
)
1411 struct bgp_notification bgpn
;
1414 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1415 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1416 hlen
= ntohs(bgpn
.bgpn_len
);
1418 /* some little sanity checking */
1419 if (length
<BGP_NOTIFICATION_SIZE
)
1422 printf(", Error - %s", tok2str(bgp_notify_major_values
, "Unknown", bgpn
.bgpn_major
));
1424 switch (bgpn
.bgpn_major
) {
1426 case BGP_NOTIFY_MAJOR_MSG
:
1427 printf(" subcode %s (%u)",
1428 tok2str(bgp_notify_minor_msg_values
, "Unknown", bgpn
.bgpn_minor
),
1431 case BGP_NOTIFY_MAJOR_OPEN
:
1432 printf(" subcode %s (%u)",
1433 tok2str(bgp_notify_minor_open_values
, "Unknown", bgpn
.bgpn_minor
),
1436 case BGP_NOTIFY_MAJOR_UPDATE
:
1437 printf(" subcode %s (%u)",
1438 tok2str(bgp_notify_minor_update_values
, "Unknown", bgpn
.bgpn_minor
),
1441 case BGP_NOTIFY_MAJOR_CEASE
:
1442 printf(" subcode %s (%u)",
1443 tok2str(bgp_notify_minor_cease_values
, "Unknown", bgpn
.bgpn_minor
),
1446 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
1447 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
1449 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7)
1450 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
1451 tok2str(bgp_afi_values
, "Unknown", EXTRACT_16BITS(&bgpn
.bgpn_data
)),
1452 EXTRACT_16BITS(&bgpn
.bgpn_data
),
1453 tok2str(bgp_safi_values
, "Unknown", *(bgpn
.bgpn_data
+2)),
1454 *(bgpn
.bgpn_data
+2),
1455 EXTRACT_32BITS(&bgpn
.bgpn_data
+3));
1467 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1469 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1470 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
1472 printf("\n\t AFI %s (%u), SAFI %s (%u)",
1473 tok2str(bgp_afi_values
,"Unknown",
1474 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
)), /* this stinks but the compiler pads the structure weird */
1475 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1476 tok2str(bgp_safi_values
,"Unknown",
1477 bgp_route_refresh_header
->safi
),
1478 bgp_route_refresh_header
->safi
);
1481 print_unknown_data(pptr
,"\n\t ", len
);
1487 bgp_header_print(const u_char
*dat
, int length
)
1491 TCHECK2(dat
[0], BGP_SIZE
);
1492 memcpy(&bgp
, dat
, BGP_SIZE
);
1493 printf("\n\t%s Message (%u), length: %u",
1494 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
1498 switch (bgp
.bgp_type
) {
1500 bgp_open_print(dat
, length
);
1503 bgp_update_print(dat
, length
);
1505 case BGP_NOTIFICATION
:
1506 bgp_notification_print(dat
, length
);
1510 case BGP_ROUTE_REFRESH
:
1511 bgp_route_refresh_print(dat
, length
);
1514 /* we have no decoder for the BGP message */
1515 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
1516 print_unknown_data(dat
,"\n\t ",length
);
1525 bgp_print(const u_char
*dat
, int length
)
1529 const u_char
*start
;
1530 const u_char marker
[] = {
1531 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1532 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1538 if (snapend
< dat
+ length
)
1541 printf(": BGP, length: %u",length
);
1543 if (vflag
< 1) /* lets be less chatty */
1548 while (p
< snapend
) {
1549 if (!TTEST2(p
[0], 1))
1556 if (!TTEST2(p
[0], sizeof(marker
)))
1558 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
1563 /* found BGP header */
1564 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
1565 memcpy(&bgp
, p
, BGP_SIZE
);
1570 hlen
= ntohs(bgp
.bgp_len
);
1572 if (TTEST2(p
[0], hlen
)) {
1573 bgp_header_print(p
, hlen
);
1577 printf("\n[|BGP %s]", tok2str(bgp_msg_values
, "Unknown Message Type",bgp
.bgp_type
));