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.70 2003-08-13 02:26:53 itojun Exp $";
42 #include <tcpdump-stdinc.h>
47 #include "interface.h"
48 #include "addrtoname.h"
52 u_int8_t bgp_marker
[16];
56 #define BGP_SIZE 19 /* unaligned */
60 #define BGP_NOTIFICATION 3
61 #define BGP_KEEPALIVE 4
62 #define BGP_ROUTE_REFRESH 5
64 static struct tok bgp_msg_values
[] = {
66 { BGP_UPDATE
, "Update"},
67 { BGP_NOTIFICATION
, "Notification"},
68 { BGP_KEEPALIVE
, "Keepalive"},
69 { BGP_ROUTE_REFRESH
, "Route Refresh"},
74 u_int8_t bgpo_marker
[16];
77 u_int8_t bgpo_version
;
79 u_int16_t bgpo_holdtime
;
82 /* options should follow */
84 #define BGP_OPEN_SIZE 29 /* unaligned */
91 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
93 struct bgp_notification
{
94 u_int8_t bgpn_marker
[16];
100 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
102 struct bgp_route_refresh
{
103 u_int8_t bgp_marker
[16];
106 u_int8_t afi
[2]; /* the compiler messes this structure up */
107 u_int8_t res
; /* when doing misaligned sequences of int8 and int16 */
108 u_int8_t safi
; /* afi should be int16 - so we have to access it using */
109 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
110 #define BGP_ROUTE_REFRESH_SIZE 23
119 #define bgp_attr_len(p) \
120 (((p)->bgpa_flags & 0x10) ? \
121 EXTRACT_16BITS(&(p)->bgpa_len.elen) : (p)->bgpa_len.len)
122 #define bgp_attr_off(p) \
123 (((p)->bgpa_flags & 0x10) ? 4 : 3)
126 #define BGPTYPE_ORIGIN 1
127 #define BGPTYPE_AS_PATH 2
128 #define BGPTYPE_NEXT_HOP 3
129 #define BGPTYPE_MULTI_EXIT_DISC 4
130 #define BGPTYPE_LOCAL_PREF 5
131 #define BGPTYPE_ATOMIC_AGGREGATE 6
132 #define BGPTYPE_AGGREGATOR 7
133 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
134 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
135 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
136 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
137 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
138 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
139 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
140 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
141 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
143 static struct tok bgp_attr_values
[] = {
144 { BGPTYPE_ORIGIN
, "Origin"},
145 { BGPTYPE_AS_PATH
, "AS Path"},
146 { BGPTYPE_NEXT_HOP
, "Next Hop"},
147 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
148 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
149 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
150 { BGPTYPE_AGGREGATOR
, "Aggregator"},
151 { BGPTYPE_COMMUNITIES
, "Community"},
152 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
153 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
154 { BGPTYPE_DPA
, "DPA"},
155 { BGPTYPE_ADVERTISERS
, "Advertisers"},
156 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
157 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
158 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
159 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
160 { 255, "Reserved for development"},
164 #define BGP_OPT_AUTH 1
165 #define BGP_OPT_CAP 2
168 static struct tok bgp_opt_values
[] = {
169 { BGP_OPT_AUTH
, "Authentication Information"},
170 { BGP_OPT_CAP
, "Capabilities Advertisement"},
174 #define BGP_CAPCODE_MP 1
175 #define BGP_CAPCODE_RR 2
176 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
177 #define BGP_CAPCODE_RR_CISCO 128
179 static struct tok bgp_capcode_values
[] = {
180 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
181 { BGP_CAPCODE_RR
, "Route Refresh"},
182 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
183 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
187 #define BGP_NOTIFY_MAJOR_MSG 1
188 #define BGP_NOTIFY_MAJOR_OPEN 2
189 #define BGP_NOTIFY_MAJOR_UPDATE 3
190 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
191 #define BGP_NOTIFY_MAJOR_FSM 5
192 #define BGP_NOTIFY_MAJOR_CEASE 6
193 #define BGP_NOTIFY_MAJOR_CAP 7
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"},
202 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
206 /* draft-ietf-idr-cease-subcode-02 */
207 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
208 static struct tok bgp_notify_minor_cease_values
[] = {
209 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
210 { 2, "Administratively Shutdown"},
211 { 3, "Peer Unconfigured"},
212 { 4, "Administratively Reset"},
213 { 5, "Connection Rejected"},
214 { 6, "Other Configuration Change"},
215 { 7, "Connection Collision Resolution"},
219 static struct tok bgp_notify_minor_msg_values
[] = {
220 { 1, "Connection Not Synchronized"},
221 { 2, "Bad Message Length"},
222 { 3, "Bad Message Type"},
226 static struct tok bgp_notify_minor_open_values
[] = {
227 { 1, "Unsupported Version Number"},
229 { 3, "Bad BGP Identifier"},
230 { 4, "Unsupported Optional Parameter"},
231 { 5, "Authentication Failure"},
232 { 6, "Unacceptable Hold Time"},
236 static struct tok bgp_notify_minor_update_values
[] = {
237 { 1, "Malformed Attribute List"},
238 { 2, "Unrecognized Well-known Attribute"},
239 { 3, "Missing Well-known Attribute"},
240 { 4, "Attribute Flags Error"},
241 { 5, "Attribute Length Error"},
242 { 6, "Invalid ORIGIN Attribute"},
243 { 7, "AS Routing Loop"},
244 { 8, "Invalid NEXT_HOP Attribute"},
245 { 9, "Optional Attribute Error"},
246 { 10, "Invalid Network Field"},
247 { 11, "Malformed AS_PATH"},
251 static struct tok bgp_notify_minor_cap_values
[] = {
252 { 1, "Invalid Action Value" },
253 { 2, "Invalid Capability Length" },
254 { 3, "Malformed Capability Value" },
255 { 4, "Unsupported Capability Code" },
259 static struct tok bgp_origin_values
[] = {
266 /* Subsequent address family identifier, RFC2283 section 7 */
268 #define SAFNUM_UNICAST 1
269 #define SAFNUM_MULTICAST 2
270 #define SAFNUM_UNIMULTICAST 3
271 /* labeled BGP RFC3107 */
272 #define SAFNUM_LABUNICAST 4
273 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
274 #define SAFNUM_VPNUNICAST 128
275 #define SAFNUM_VPNMULTICAST 129
276 #define SAFNUM_VPNUNIMULTICAST 130
278 #define BGP_VPN_RD_LEN 8
280 static struct tok bgp_safi_values
[] = {
281 { SAFNUM_RES
, "Reserved"},
282 { SAFNUM_UNICAST
, "Unicast"},
283 { SAFNUM_MULTICAST
, "Multicast"},
284 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
285 { SAFNUM_LABUNICAST
, "labeled Unicast"},
286 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
287 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
288 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
292 /* well-known community */
293 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
294 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
295 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
297 /* RFC1700 address family numbers */
299 #define AFNUM_INET6 2
302 #define AFNUM_BBN1822 5
307 #define AFNUM_X121 10
309 #define AFNUM_ATALK 12
310 #define AFNUM_DECNET 13
311 #define AFNUM_BANYAN 14
312 #define AFNUM_E164NSAP 15
313 /* draft-kompella-ppvpn-l2vpn */
314 #define AFNUM_L2VPN 196 /* still to be approved by IANA */
316 static struct tok bgp_afi_values
[] = {
318 { AFNUM_INET
, "IPv4"},
319 { AFNUM_INET6
, "IPv6"},
320 { AFNUM_NSAP
, "NSAP"},
321 { AFNUM_HDLC
, "HDLC"},
322 { AFNUM_BBN1822
, "BBN 1822"},
324 { AFNUM_E163
, "E.163"},
325 { AFNUM_E164
, "E.164"},
326 { AFNUM_F69
, "F.69"},
327 { AFNUM_X121
, "X.121"},
328 { AFNUM_IPX
, "Novell IPX"},
329 { AFNUM_ATALK
, "Appletalk"},
330 { AFNUM_DECNET
, "Decnet IV"},
331 { AFNUM_BANYAN
, "Banyan Vines"},
332 { AFNUM_E164NSAP
, "E.164 with NSAP subaddress"},
333 { AFNUM_L2VPN
, "Layer-2 VPN"},
337 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
338 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
339 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
340 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
341 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
342 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
343 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
344 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
345 /* rfc2547 bgp-mpls-vpns */
347 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
348 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
349 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
350 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
352 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
353 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
355 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
356 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
358 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
360 static struct tok bgp_extd_comm_flag_values
[] = {
361 { 0x8000, "vendor-specific"},
362 { 0x4000, "non-transitive"},
366 static struct tok bgp_extd_comm_subtype_values
[] = {
367 { BGP_EXT_COM_RT_0
, "target"},
368 { BGP_EXT_COM_RT_1
, "target"},
369 { BGP_EXT_COM_RT_2
, "target"},
370 { BGP_EXT_COM_RO_0
, "origin"},
371 { BGP_EXT_COM_RO_1
, "origin"},
372 { BGP_EXT_COM_RO_2
, "origin"},
373 { BGP_EXT_COM_LINKBAND
, "link-BW"},
374 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
375 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
376 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
377 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
378 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
379 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
380 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
381 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
382 { BGP_EXT_COM_L2INFO
, "layer2-info"},
386 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
387 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
388 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
389 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
390 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
391 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
392 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
393 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
395 static struct tok bgp_extd_comm_ospf_rtype_values
[] = {
396 { BGP_OSPF_RTYPE_RTR
, "Router" },
397 { BGP_OSPF_RTYPE_NET
, "Network" },
398 { BGP_OSPF_RTYPE_SUM
, "Summary" },
399 { BGP_OSPF_RTYPE_EXT
, "External" },
400 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
401 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
405 static struct tok bgp_l2vpn_encaps_values
[] = {
408 { 2, "ATM AAL5 VCC transport"},
409 { 3, "ATM transparent cell transport"},
410 { 4, "Ethernet VLAN"},
415 { 9, "ATM VCC cell transport"},
416 { 10, "ATM VPC cell transport"},
419 { 64, "IP-interworking"},
424 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
433 memset(&addr
, 0, sizeof(addr
));
434 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
436 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
437 ((0xff00 >> (plen
% 8)) & 0xff);
439 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
440 return 1 + (plen
+ 7) / 8;
444 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
449 plen
= pptr
[0]; /* get prefix length */
451 /* this is one of the weirdnesses of rfc3107
452 the label length (actually the label + COS bits)
453 is added to the prefix length;
454 we also do only read out just one label -
455 there is no real application for advertisement of
456 stacked labels in a a single BGP message
459 plen
-=24; /* adjust prefixlen - labellength */
464 memset(&addr
, 0, sizeof(addr
));
465 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
467 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
468 ((0xff00 >> (plen
% 8)) & 0xff);
470 /* the label may get offsetted by 4 bits so lets shift it right */
471 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
472 getname((u_char
*)&addr
),
474 EXTRACT_24BITS(pptr
+1)>>4,
475 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
477 return 4 + (plen
+ 7) / 8;
481 bgp_vpn_rd_print (const u_char
*pptr
) {
483 /* allocate space for the following string
484 * xxx.xxx.xxx.xxx:xxxxx
485 * 21 bytes plus one termination byte */
489 /* ok lets load the RD format */
490 switch (EXTRACT_16BITS(pptr
)) {
491 /* AS:IP-address fmt*/
493 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u.%u.%u.%u",
494 EXTRACT_16BITS(pptr
+2), *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
496 /* IP-address:AS fmt*/
498 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
499 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
502 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
511 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
516 plen
= pptr
[0]; /* get prefix length */
518 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
523 memset(&addr
, 0, sizeof(addr
));
524 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
526 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
527 ((0xff00 >> (plen
% 8)) & 0xff);
529 /* the label may get offsetted by 4 bits so lets shift it right */
530 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
531 bgp_vpn_rd_print(pptr
+4),
532 getname((u_char
*)&addr
),
534 EXTRACT_24BITS(pptr
+1)>>4,
535 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
537 return 12 + (plen
+ 7) / 8;
541 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
543 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
544 plen
=EXTRACT_16BITS(pptr
);
547 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
548 bgp_vpn_rd_print(pptr
),
549 EXTRACT_16BITS(pptr
+8),
550 EXTRACT_16BITS(pptr
+10),
551 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
555 /* ok now the variable part - lets read out TLVs*/
558 tlv_len
=EXTRACT_16BITS(pptr
);
564 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
567 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
569 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "%02x",*pptr
++);
574 snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tunknown TLV #%u, length: %u",
579 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it tright */
586 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
588 struct in6_addr addr
;
595 memset(&addr
, 0, sizeof(addr
));
596 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
598 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
599 ((0xff00 >> (plen
% 8)) & 0xff);
601 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
602 return 1 + (plen
+ 7) / 8;
606 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
608 struct in6_addr addr
;
611 plen
= pptr
[0]; /* get prefix length */
612 plen
-=24; /* adjust prefixlen - labellength */
617 memset(&addr
, 0, sizeof(addr
));
618 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
620 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
621 ((0xff00 >> (plen
% 8)) & 0xff);
623 /* the label may get offsetted by 4 bits so lets shift it right */
624 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
625 getname6((u_char
*)&addr
),
627 EXTRACT_24BITS(pptr
+1)>>4,
628 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
630 return 4 + (plen
+ 7) / 8;
634 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
636 struct in6_addr addr
;
639 plen
= pptr
[0]; /* get prefix length */
641 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
646 memset(&addr
, 0, sizeof(addr
));
647 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
649 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
650 ((0xff00 >> (plen
% 8)) & 0xff);
652 /* the label may get offsetted by 4 bits so lets shift it right */
653 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
654 bgp_vpn_rd_print(pptr
+4),
655 getname6((u_char
*)&addr
),
657 EXTRACT_24BITS(pptr
+1)>>4,
658 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
660 return 12 + (plen
+ 7) / 8;
665 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
670 union { /* copy buffer for bandwidth values */
677 char buf
[MAXHOSTNAMELEN
+ 100];
682 switch (attr
->bgpa_type
) {
685 printf("invalid len");
687 printf("%s", tok2str(bgp_origin_values
, "Unknown Origin Typecode", tptr
[0]));
689 case BGPTYPE_AS_PATH
:
691 printf("invalid len");
698 while (tptr
< pptr
+ len
) {
700 * under RFC1965, p[0] means:
701 * 1: AS_SET 2: AS_SEQUENCE
702 * 3: AS_CONFED_SET 4: AS_CONFED_SEQUENCE
704 if (tptr
[0] == 3 || tptr
[0] == 4)
706 printf("%s", (tptr
[0] & 1) ? "{" : "");
707 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
708 printf("%s%u", i
== 0 ? "" : " ",
709 EXTRACT_16BITS(&tptr
[2 + i
]));
711 printf("%s", (tptr
[0] & 1) ? "}" : "");
712 tptr
+= 2 + tptr
[1] * 2;
715 case BGPTYPE_NEXT_HOP
:
717 printf("invalid len");
719 printf("%s", getname(tptr
));
721 case BGPTYPE_MULTI_EXIT_DISC
:
722 case BGPTYPE_LOCAL_PREF
:
724 printf("invalid len");
726 printf("%u", EXTRACT_32BITS(tptr
));
728 case BGPTYPE_ATOMIC_AGGREGATE
:
730 printf("invalid len");
732 case BGPTYPE_AGGREGATOR
:
734 printf("invalid len");
737 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
740 case BGPTYPE_COMMUNITIES
:
742 printf("invalid len");
747 comm
= EXTRACT_32BITS(tptr
);
749 case BGP_COMMUNITY_NO_EXPORT
:
750 printf(" NO_EXPORT");
752 case BGP_COMMUNITY_NO_ADVERT
:
753 printf(" NO_ADVERTISE");
755 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
756 printf(" NO_EXPORT_SUBCONFED");
760 (comm
>> 16) & 0xffff,
762 (tlen
>4) ? ", " : "");
769 case BGPTYPE_ORIGINATOR_ID
:
771 printf("invalid len");
774 printf("%s",getname(tptr
));
776 case BGPTYPE_CLUSTER_LIST
:
780 (tlen
>4) ? ", " : "");
785 case BGPTYPE_MP_REACH_NLRI
:
786 af
= EXTRACT_16BITS(tptr
);
789 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
790 tok2str(bgp_afi_values
, "Unknown AFI", af
),
792 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
793 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
796 if (af
== AFNUM_INET
|| af
==AFNUM_L2VPN
)
799 else if (af
== AFNUM_INET6
)
803 printf("\n\t no AFI %u decoder",af
);
805 print_unknown_data(tptr
,"\n\t ",tlen
);
815 printf("\n\t nexthop: ");
821 case SAFNUM_MULTICAST
:
822 case SAFNUM_UNIMULTICAST
:
823 case SAFNUM_LABUNICAST
:
824 printf("%s",getname(tptr
));
825 tlen
-= sizeof(struct in_addr
);
826 tptr
+= sizeof(struct in_addr
);
828 case SAFNUM_VPNUNICAST
:
829 case SAFNUM_VPNMULTICAST
:
830 case SAFNUM_VPNUNIMULTICAST
:
832 bgp_vpn_rd_print(tptr
),
833 getname(tptr
+BGP_VPN_RD_LEN
));
834 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
835 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
838 printf("no SAFI %u decoder",safi
);
840 print_unknown_data(tptr
,"\n\t ",tlen
);
848 case SAFNUM_MULTICAST
:
849 case SAFNUM_UNIMULTICAST
:
850 case SAFNUM_LABUNICAST
:
851 printf("%s", getname6(tptr
));
852 tlen
-= sizeof(struct in6_addr
);
853 tptr
+= sizeof(struct in6_addr
);
855 case SAFNUM_VPNUNICAST
:
856 case SAFNUM_VPNMULTICAST
:
857 case SAFNUM_VPNUNIMULTICAST
:
859 bgp_vpn_rd_print(tptr
),
860 getname6(tptr
+BGP_VPN_RD_LEN
));
861 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
862 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
865 printf("no SAFI %u decoder",safi
);
867 print_unknown_data(tptr
,"\n\t ",tlen
);
874 case SAFNUM_VPNUNICAST
:
875 case SAFNUM_VPNMULTICAST
:
876 case SAFNUM_VPNUNIMULTICAST
:
877 printf("%s", getname(tptr
));
878 tlen
-= (sizeof(struct in_addr
));
879 tptr
+= (sizeof(struct in_addr
));
882 printf("no SAFI %u decoder",safi
);
884 print_unknown_data(tptr
,"\n\t ",tlen
);
890 printf("no AFI %u decoder",af
);
892 print_unknown_data(tptr
,"\n\t ",tlen
);
903 printf("\n\t %u SNPA", snpa
);
904 for (/*nothing*/; snpa
> 0; snpa
--) {
905 printf("\n\t %d bytes", tptr
[0]);
912 while (len
- (tptr
- pptr
) > 0) {
917 case SAFNUM_MULTICAST
:
918 case SAFNUM_UNIMULTICAST
:
919 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
921 printf("\n\t %s", buf
);
923 printf("\n\t (illegal prefix length)");
925 case SAFNUM_LABUNICAST
:
926 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
927 printf("\n\t %s", buf
);
929 case SAFNUM_VPNUNICAST
:
930 case SAFNUM_VPNMULTICAST
:
931 case SAFNUM_VPNUNIMULTICAST
:
932 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
933 printf("\n\t %s", buf
);
936 printf("\n\t no SAFI %u decoder",safi
);
938 print_unknown_data(tptr
-3,"\n\t ",tlen
);
948 case SAFNUM_MULTICAST
:
949 case SAFNUM_UNIMULTICAST
:
950 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
951 printf("\n\t %s", buf
);
953 case SAFNUM_LABUNICAST
:
954 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
955 printf("\n\t %s", buf
);
957 case SAFNUM_VPNUNICAST
:
958 case SAFNUM_VPNMULTICAST
:
959 case SAFNUM_VPNUNIMULTICAST
:
960 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
961 printf("\n\t %s", buf
);
964 printf("\n\t no SAFI %u decoder ",safi
);
966 print_unknown_data(tptr
-3,"\n\t ",tlen
);
975 case SAFNUM_VPNUNICAST
:
976 case SAFNUM_VPNMULTICAST
:
977 case SAFNUM_VPNUNIMULTICAST
:
978 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
979 printf("\n\t %s", buf
);
982 printf("no SAFI %u decoder",safi
);
984 print_unknown_data(tptr
,"\n\t ",tlen
);
993 printf("\n\t no AFI %u decoder ",af
);
995 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1004 case BGPTYPE_MP_UNREACH_NLRI
:
1005 af
= EXTRACT_16BITS(tptr
);
1008 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1009 tok2str(bgp_afi_values
, "Unknown AFI", af
),
1011 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1012 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1017 while (len
- (tptr
- pptr
) > 0) {
1021 case SAFNUM_UNICAST
:
1022 case SAFNUM_MULTICAST
:
1023 case SAFNUM_UNIMULTICAST
:
1024 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1026 printf("\n\t %s", buf
);
1028 printf("\n\t (illegal prefix length)");
1030 case SAFNUM_LABUNICAST
:
1031 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1032 printf("\n\t %s", buf
);
1034 case SAFNUM_VPNUNICAST
:
1035 case SAFNUM_VPNMULTICAST
:
1036 case SAFNUM_VPNUNIMULTICAST
:
1037 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1038 printf("\n\t %s", buf
);
1041 printf("\n\t no SAFI %u decoder",safi
);
1043 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1053 case SAFNUM_UNICAST
:
1054 case SAFNUM_MULTICAST
:
1055 case SAFNUM_UNIMULTICAST
:
1056 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1057 printf("\n\t %s", buf
);
1059 case SAFNUM_LABUNICAST
:
1060 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1061 printf("\n\t %s", buf
);
1063 case SAFNUM_VPNUNICAST
:
1064 case SAFNUM_VPNMULTICAST
:
1065 case SAFNUM_VPNUNIMULTICAST
:
1066 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1067 printf("\n\t %s", buf
);
1070 printf("\n\t no SAFI %u decoder",safi
);
1072 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1082 case SAFNUM_VPNUNICAST
:
1083 case SAFNUM_VPNMULTICAST
:
1084 case SAFNUM_VPNUNIMULTICAST
:
1085 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1086 printf("\n\t %s", buf
);
1089 printf("no SAFI %u decoder",safi
);
1091 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1099 printf("\n\t no AFI %u decoder",af
);
1101 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1110 case BGPTYPE_EXTD_COMMUNITIES
:
1112 printf("invalid len");
1116 u_int16_t extd_comm
;
1117 extd_comm
=EXTRACT_16BITS(tptr
);
1119 printf("\n\t %s (0x%04x), Flags [%s]",
1120 tok2str(bgp_extd_comm_subtype_values
, "unknown extd community typecode", extd_comm
),
1122 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1125 case BGP_EXT_COM_RT_0
:
1126 case BGP_EXT_COM_RO_0
:
1128 EXTRACT_16BITS(tptr
+2),
1131 case BGP_EXT_COM_RT_1
:
1132 case BGP_EXT_COM_RO_1
:
1135 EXTRACT_16BITS(tptr
+6));
1137 case BGP_EXT_COM_RT_2
:
1138 case BGP_EXT_COM_RO_2
:
1140 EXTRACT_32BITS(tptr
+2),
1141 EXTRACT_16BITS(tptr
+6));
1143 case BGP_EXT_COM_LINKBAND
:
1144 bw
.i
= EXTRACT_32BITS(tptr
+2);
1145 printf(": bandwidth: %.3f Mbps",
1148 case BGP_EXT_COM_VPN_ORIGIN
:
1149 case BGP_EXT_COM_VPN_ORIGIN2
:
1150 case BGP_EXT_COM_VPN_ORIGIN3
:
1151 case BGP_EXT_COM_VPN_ORIGIN4
:
1152 case BGP_EXT_COM_OSPF_RID
:
1153 case BGP_EXT_COM_OSPF_RID2
:
1154 printf("%s", getname(tptr
+2));
1156 case BGP_EXT_COM_OSPF_RTYPE
:
1157 case BGP_EXT_COM_OSPF_RTYPE2
:
1158 printf(": area:%s, router-type:%s, metric-type:%s%s",
1160 tok2str(bgp_extd_comm_ospf_rtype_values
,
1163 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1164 (*(tptr
+6) == (BGP_OSPF_RTYPE_EXT
||BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1166 case BGP_EXT_COM_L2INFO
:
1167 printf(": %s Control Flags [0x%02x]:MTU %u",
1168 tok2str(bgp_l2vpn_encaps_values
,
1172 EXTRACT_16BITS(tptr
+4));
1175 print_unknown_data(tptr
,"\n\t ",8);
1184 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1186 print_unknown_data(pptr
,"\n\t ",len
);
1189 if (vflag
> 1 && len
) /* omit zero length attributes*/
1190 print_unknown_data(pptr
,"\n\t ",len
);
1194 bgp_open_print(const u_char
*dat
, int length
)
1196 struct bgp_open bgpo
;
1197 struct bgp_opt bgpopt
;
1200 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
1202 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1203 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1204 hlen
= ntohs(bgpo
.bgpo_len
);
1206 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1207 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1208 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1209 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1210 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1212 /* some little sanity checking */
1213 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
1217 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1221 while (i
< bgpo
.bgpo_optlen
) {
1222 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1223 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1224 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1225 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1229 printf("\n\t Option %s (%u), length: %u",
1230 tok2str(bgp_opt_values
,"Unknown", bgpopt
.bgpopt_type
),
1234 /* now lets decode the options we know*/
1235 switch(bgpopt
.bgpopt_type
) {
1237 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1238 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1240 printf("\n\t %s, length: %u",
1241 tok2str(bgp_capcode_values
,"Unknown", cap_type
),
1244 case BGP_CAPCODE_MP
:
1245 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1246 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)),
1247 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1248 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+5]),
1249 opt
[i
+BGP_OPT_SIZE
+5]);
1251 case BGP_CAPCODE_RESTART
:
1252 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
1253 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
1254 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
1257 while(tcap_len
>=4) {
1258 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1259 tok2str(bgp_afi_values
,"Unknown", EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
)),
1260 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1261 tok2str(bgp_safi_values
,"Unknown", opt
[i
+BGP_OPT_SIZE
+cap_offset
+2]),
1262 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1263 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
1268 case BGP_CAPCODE_RR
:
1269 case BGP_CAPCODE_RR_CISCO
:
1272 printf("\n\t\tno decoder for Capability %u",
1275 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1279 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1283 printf("\n\t no decoder for option %u",
1284 bgpopt
.bgpopt_type
);
1288 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1296 bgp_update_print(const u_char
*dat
, int length
)
1299 struct bgp_attr bgpa
;
1305 TCHECK2(dat
[0], BGP_SIZE
);
1306 memcpy(&bgp
, dat
, BGP_SIZE
);
1307 hlen
= ntohs(bgp
.bgp_len
);
1308 p
= dat
+ BGP_SIZE
; /*XXX*/
1310 /* Unfeasible routes */
1311 len
= EXTRACT_16BITS(p
);
1314 * Without keeping state from the original NLRI message,
1315 * it's not possible to tell if this a v4 or v6 route,
1316 * so only try to decode it if we're not v6 enabled.
1319 printf("\n\t Withdrawn routes: %d bytes", len
);
1321 char buf
[MAXHOSTNAMELEN
+ 100];
1327 printf("\n\t Withdrawn routes:");
1329 while(i
< 2 + len
) {
1330 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1333 printf("\n\t %s", buf
);
1335 printf("\n\t (illegal prefix length)");
1344 len
= EXTRACT_16BITS(p
);
1346 /* do something more useful!*/
1348 while (i
< 2 + len
) {
1351 TCHECK2(p
[i
], sizeof(bgpa
));
1352 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
1353 alen
= bgp_attr_len(&bgpa
);
1354 aoff
= bgp_attr_off(&bgpa
);
1356 printf("\n\t %s (%u), length: %u",
1357 tok2str(bgp_attr_values
, "Unknown Attribute", bgpa
.bgpa_type
),
1361 if (bgpa
.bgpa_flags
) {
1362 printf(", Flags [%s%s%s%s",
1363 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1364 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1365 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1366 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1367 if (bgpa
.bgpa_flags
& 0xf)
1368 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1371 bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
);
1377 if (dat
+ length
> p
) {
1378 printf("\n\t Updated routes:");
1379 while (dat
+ length
> p
) {
1380 char buf
[MAXHOSTNAMELEN
+ 100];
1381 i
= decode_prefix4(p
, buf
, sizeof(buf
));
1383 printf("\n\t %s", buf
);
1386 printf("\n\t (illegal prefix length)");
1397 bgp_notification_print(const u_char
*dat
, int length
)
1399 struct bgp_notification bgpn
;
1403 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1404 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1405 hlen
= ntohs(bgpn
.bgpn_len
);
1407 /* some little sanity checking */
1408 if (length
<BGP_NOTIFICATION_SIZE
)
1412 tok2str(bgp_notify_major_values
, "Unknown Error", bgpn
.bgpn_major
),
1415 switch (bgpn
.bgpn_major
) {
1417 case BGP_NOTIFY_MAJOR_MSG
:
1418 printf(", subcode %s (%u)",
1419 tok2str(bgp_notify_minor_msg_values
, "Unknown", bgpn
.bgpn_minor
),
1422 case BGP_NOTIFY_MAJOR_OPEN
:
1423 printf(", subcode %s (%u)",
1424 tok2str(bgp_notify_minor_open_values
, "Unknown", bgpn
.bgpn_minor
),
1427 case BGP_NOTIFY_MAJOR_UPDATE
:
1428 printf(", subcode %s (%u)",
1429 tok2str(bgp_notify_minor_update_values
, "Unknown", bgpn
.bgpn_minor
),
1432 case BGP_NOTIFY_MAJOR_CAP
:
1433 printf(" subcode %s (%u)",
1434 tok2str(bgp_notify_minor_cap_values
, "Unknown", bgpn
.bgpn_minor
),
1436 case BGP_NOTIFY_MAJOR_CEASE
:
1437 printf(", subcode %s (%u)",
1438 tok2str(bgp_notify_minor_cease_values
, "Unknown", bgpn
.bgpn_minor
),
1441 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
1442 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
1444 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
1445 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
1447 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
1448 tok2str(bgp_afi_values
, "Unknown", EXTRACT_16BITS(tptr
)),
1449 EXTRACT_16BITS(tptr
),
1450 tok2str(bgp_safi_values
, "Unknown", *(tptr
+2)),
1452 EXTRACT_32BITS(tptr
+3));
1465 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1467 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1468 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
1470 printf("\n\t AFI %s (%u), SAFI %s (%u)",
1471 tok2str(bgp_afi_values
,"Unknown",
1472 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
)), /* this stinks but the compiler pads the structure weird */
1473 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1474 tok2str(bgp_safi_values
,"Unknown",
1475 bgp_route_refresh_header
->safi
),
1476 bgp_route_refresh_header
->safi
);
1479 print_unknown_data(pptr
,"\n\t ", len
);
1485 bgp_header_print(const u_char
*dat
, int length
)
1489 TCHECK2(dat
[0], BGP_SIZE
);
1490 memcpy(&bgp
, dat
, BGP_SIZE
);
1491 printf("\n\t%s Message (%u), length: %u",
1492 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
1496 switch (bgp
.bgp_type
) {
1498 bgp_open_print(dat
, length
);
1501 bgp_update_print(dat
, length
);
1503 case BGP_NOTIFICATION
:
1504 bgp_notification_print(dat
, length
);
1508 case BGP_ROUTE_REFRESH
:
1509 bgp_route_refresh_print(dat
, length
);
1512 /* we have no decoder for the BGP message */
1513 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
1514 print_unknown_data(dat
,"\n\t ",length
);
1523 bgp_print(const u_char
*dat
, int length
)
1527 const u_char
*start
;
1528 const u_char marker
[] = {
1529 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1530 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1536 if (snapend
< dat
+ length
)
1539 printf(": BGP, length: %u",length
);
1541 if (vflag
< 1) /* lets be less chatty */
1546 while (p
< snapend
) {
1547 if (!TTEST2(p
[0], 1))
1554 if (!TTEST2(p
[0], sizeof(marker
)))
1556 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
1561 /* found BGP header */
1562 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
1563 memcpy(&bgp
, p
, BGP_SIZE
);
1568 hlen
= ntohs(bgp
.bgp_len
);
1569 if (hlen
< BGP_SIZE
) {
1570 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
1575 if (TTEST2(p
[0], hlen
)) {
1576 bgp_header_print(p
, hlen
);
1580 printf("\n[|BGP %s]", tok2str(bgp_msg_values
, "Unknown Message Type",bgp
.bgp_type
));