4 * Copyright (C) 1999 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Extensively modified by Hannes Gredler (hannes@juniper.net) for more
32 * complete BGP support.
39 #include <sys/cdefs.h>
42 static const char rcsid
[] _U_
=
43 "@(#) Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.91.2.12 2007/07/14 22:26:35 guy Exp";
45 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
49 #include <tcpdump-stdinc.h>
54 #include "interface.h"
55 #include "decode_prefix.h"
56 #include "addrtoname.h"
63 u_int8_t bgp_marker
[16];
67 #define BGP_SIZE 19 /* unaligned */
71 #define BGP_NOTIFICATION 3
72 #define BGP_KEEPALIVE 4
73 #define BGP_ROUTE_REFRESH 5
75 static struct tok bgp_msg_values
[] = {
77 { BGP_UPDATE
, "Update"},
78 { BGP_NOTIFICATION
, "Notification"},
79 { BGP_KEEPALIVE
, "Keepalive"},
80 { BGP_ROUTE_REFRESH
, "Route Refresh"},
85 u_int8_t bgpo_marker
[16];
88 u_int8_t bgpo_version
;
90 u_int16_t bgpo_holdtime
;
93 /* options should follow */
95 #define BGP_OPEN_SIZE 29 /* unaligned */
100 /* variable length */
102 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
104 #define BGP_UPDATE_MINSIZE 23
106 struct bgp_notification
{
107 u_int8_t bgpn_marker
[16];
113 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
115 struct bgp_route_refresh
{
116 u_int8_t bgp_marker
[16];
119 u_int8_t afi
[2]; /* the compiler messes this structure up */
120 u_int8_t res
; /* when doing misaligned sequences of int8 and int16 */
121 u_int8_t safi
; /* afi should be int16 - so we have to access it using */
122 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
123 #define BGP_ROUTE_REFRESH_SIZE 23
132 #define bgp_attr_len(p) \
133 (((p)->bgpa_flags & 0x10) ? \
134 EXTRACT_16BITS(&(p)->bgpa_len.elen) : (p)->bgpa_len.len)
135 #define bgp_attr_off(p) \
136 (((p)->bgpa_flags & 0x10) ? 4 : 3)
139 #define BGPTYPE_ORIGIN 1
140 #define BGPTYPE_AS_PATH 2
141 #define BGPTYPE_NEXT_HOP 3
142 #define BGPTYPE_MULTI_EXIT_DISC 4
143 #define BGPTYPE_LOCAL_PREF 5
144 #define BGPTYPE_ATOMIC_AGGREGATE 6
145 #define BGPTYPE_AGGREGATOR 7
146 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
147 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
148 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
149 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
150 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
151 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
152 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
153 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
154 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
155 #define BGPTYPE_ATTR_SET 128 /* draft-marques-ppvpn-ibgp */
157 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
159 static struct tok bgp_attr_values
[] = {
160 { BGPTYPE_ORIGIN
, "Origin"},
161 { BGPTYPE_AS_PATH
, "AS Path"},
162 { BGPTYPE_NEXT_HOP
, "Next Hop"},
163 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
164 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
165 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
166 { BGPTYPE_AGGREGATOR
, "Aggregator"},
167 { BGPTYPE_COMMUNITIES
, "Community"},
168 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
169 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
170 { BGPTYPE_DPA
, "DPA"},
171 { BGPTYPE_ADVERTISERS
, "Advertisers"},
172 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
173 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
174 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
175 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
176 { BGPTYPE_ATTR_SET
, "Attribute Set"},
177 { 255, "Reserved for development"},
182 #define BGP_AS_SEQUENCE 2
183 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
184 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
186 static struct tok bgp_as_path_segment_open_values
[] = {
187 { BGP_AS_SEQUENCE
, ""},
189 { BGP_CONFED_AS_SEQUENCE
, "( "},
190 { BGP_CONFED_AS_SET
, "({ "},
194 static struct tok bgp_as_path_segment_close_values
[] = {
195 { BGP_AS_SEQUENCE
, ""},
197 { BGP_CONFED_AS_SEQUENCE
, ")"},
198 { BGP_CONFED_AS_SET
, "})"},
202 #define BGP_OPT_AUTH 1
203 #define BGP_OPT_CAP 2
206 static struct tok bgp_opt_values
[] = {
207 { BGP_OPT_AUTH
, "Authentication Information"},
208 { BGP_OPT_CAP
, "Capabilities Advertisement"},
212 #define BGP_CAPCODE_MP 1
213 #define BGP_CAPCODE_RR 2
214 #define BGP_CAPCODE_ORF 3 /* XXX */
215 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
216 #define BGP_CAPCODE_AS_NEW 65 /* XXX */
217 #define BGP_CAPCODE_DYN_CAP 67 /* XXX */
218 #define BGP_CAPCODE_RR_CISCO 128
220 static struct tok bgp_capcode_values
[] = {
221 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
222 { BGP_CAPCODE_RR
, "Route Refresh"},
223 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
224 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
225 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
226 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
227 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
231 #define BGP_NOTIFY_MAJOR_MSG 1
232 #define BGP_NOTIFY_MAJOR_OPEN 2
233 #define BGP_NOTIFY_MAJOR_UPDATE 3
234 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
235 #define BGP_NOTIFY_MAJOR_FSM 5
236 #define BGP_NOTIFY_MAJOR_CEASE 6
237 #define BGP_NOTIFY_MAJOR_CAP 7
239 static struct tok bgp_notify_major_values
[] = {
240 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
241 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
242 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
243 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
244 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
245 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
246 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
250 /* draft-ietf-idr-cease-subcode-02 */
251 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
252 static struct tok bgp_notify_minor_cease_values
[] = {
253 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
254 { 2, "Administratively Shutdown"},
255 { 3, "Peer Unconfigured"},
256 { 4, "Administratively Reset"},
257 { 5, "Connection Rejected"},
258 { 6, "Other Configuration Change"},
259 { 7, "Connection Collision Resolution"},
263 static struct tok bgp_notify_minor_msg_values
[] = {
264 { 1, "Connection Not Synchronized"},
265 { 2, "Bad Message Length"},
266 { 3, "Bad Message Type"},
270 static struct tok bgp_notify_minor_open_values
[] = {
271 { 1, "Unsupported Version Number"},
273 { 3, "Bad BGP Identifier"},
274 { 4, "Unsupported Optional Parameter"},
275 { 5, "Authentication Failure"},
276 { 6, "Unacceptable Hold Time"},
280 static struct tok bgp_notify_minor_update_values
[] = {
281 { 1, "Malformed Attribute List"},
282 { 2, "Unrecognized Well-known Attribute"},
283 { 3, "Missing Well-known Attribute"},
284 { 4, "Attribute Flags Error"},
285 { 5, "Attribute Length Error"},
286 { 6, "Invalid ORIGIN Attribute"},
287 { 7, "AS Routing Loop"},
288 { 8, "Invalid NEXT_HOP Attribute"},
289 { 9, "Optional Attribute Error"},
290 { 10, "Invalid Network Field"},
291 { 11, "Malformed AS_PATH"},
295 static struct tok bgp_notify_minor_cap_values
[] = {
296 { 1, "Invalid Action Value" },
297 { 2, "Invalid Capability Length" },
298 { 3, "Malformed Capability Value" },
299 { 4, "Unsupported Capability Code" },
303 static struct tok bgp_origin_values
[] = {
310 /* Subsequent address family identifier, RFC2283 section 7 */
312 #define SAFNUM_UNICAST 1
313 #define SAFNUM_MULTICAST 2
314 #define SAFNUM_UNIMULTICAST 3
315 /* labeled BGP RFC3107 */
316 #define SAFNUM_LABUNICAST 4
317 #define SAFNUM_TUNNEL 64 /* XXX */
318 #define SAFNUM_VPLS 65 /* XXX */
319 #define SAFNUM_MDT 66 /* XXX */
320 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
321 #define SAFNUM_VPNUNICAST 128
322 #define SAFNUM_VPNMULTICAST 129
323 #define SAFNUM_VPNUNIMULTICAST 130
324 /* draft-marques-ppvpn-rt-constrain-01.txt */
325 #define SAFNUM_RT_ROUTING_INFO 132
327 #define BGP_VPN_RD_LEN 8
329 static struct tok bgp_safi_values
[] = {
330 { SAFNUM_RES
, "Reserved"},
331 { SAFNUM_UNICAST
, "Unicast"},
332 { SAFNUM_MULTICAST
, "Multicast"},
333 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
334 { SAFNUM_LABUNICAST
, "labeled Unicast"},
335 { SAFNUM_TUNNEL
, "Tunnel"},
336 { SAFNUM_VPLS
, "VPLS"},
337 { SAFNUM_MDT
, "MDT"},
338 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
339 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
340 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
341 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"}, /* draft-marques-ppvpn-rt-constrain-01.txt */
345 /* well-known community */
346 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
347 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
348 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
350 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
351 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
352 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
353 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
354 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
355 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
356 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
357 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
358 /* rfc2547 bgp-mpls-vpns */
359 #define BGP_EXT_COM_CISCO_MCAST 0x0009 /* cisco proprietary */
361 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
362 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
363 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
364 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
366 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
367 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
369 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
370 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
372 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
374 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
375 #define BGP_EXT_COM_EIGRP_GEN 0x8800
376 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
377 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
378 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
379 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
380 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
382 static struct tok bgp_extd_comm_flag_values
[] = {
383 { 0x8000, "vendor-specific"},
384 { 0x4000, "non-transitive"},
388 static struct tok bgp_extd_comm_subtype_values
[] = {
389 { BGP_EXT_COM_RT_0
, "target"},
390 { BGP_EXT_COM_RT_1
, "target"},
391 { BGP_EXT_COM_RT_2
, "target"},
392 { BGP_EXT_COM_RO_0
, "origin"},
393 { BGP_EXT_COM_RO_1
, "origin"},
394 { BGP_EXT_COM_RO_2
, "origin"},
395 { BGP_EXT_COM_LINKBAND
, "link-BW"},
396 { BGP_EXT_COM_CISCO_MCAST
, "mdt-group"},
397 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
398 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
399 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
400 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
401 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
402 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
403 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
404 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
405 { BGP_EXT_COM_L2INFO
, "layer2-info"},
406 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
407 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
408 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
409 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
410 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
411 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
415 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
416 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
417 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
418 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
419 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
420 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
421 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
422 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
424 static struct tok bgp_extd_comm_ospf_rtype_values
[] = {
425 { BGP_OSPF_RTYPE_RTR
, "Router" },
426 { BGP_OSPF_RTYPE_NET
, "Network" },
427 { BGP_OSPF_RTYPE_SUM
, "Summary" },
428 { BGP_OSPF_RTYPE_EXT
, "External" },
429 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
430 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
435 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
445 memset(&addr
, 0, sizeof(addr
));
446 TCHECK2(pptr
[1], (plen
+ 7) / 8);
447 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
449 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
450 ((0xff00 >> (plen
% 8)) & 0xff);
452 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
453 return 1 + (plen
+ 7) / 8;
460 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
466 plen
= pptr
[0]; /* get prefix length */
468 /* this is one of the weirdnesses of rfc3107
469 the label length (actually the label + COS bits)
470 is added to the prefix length;
471 we also do only read out just one label -
472 there is no real application for advertisement of
473 stacked labels in a a single BGP message
479 plen
-=24; /* adjust prefixlen - labellength */
484 memset(&addr
, 0, sizeof(addr
));
485 TCHECK2(pptr
[4], (plen
+ 7) / 8);
486 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
488 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
489 ((0xff00 >> (plen
% 8)) & 0xff);
491 /* the label may get offsetted by 4 bits so lets shift it right */
492 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
493 getname((u_char
*)&addr
),
495 EXTRACT_24BITS(pptr
+1)>>4,
496 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
498 return 4 + (plen
+ 7) / 8;
504 /* RDs and RTs share the same semantics
505 * we use bgp_vpn_rd_print for
506 * printing route targets inside a NLRI */
508 bgp_vpn_rd_print (const u_char
*pptr
) {
510 /* allocate space for the largest possible string */
511 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
514 /* ok lets load the RD format */
515 switch (EXTRACT_16BITS(pptr
)) {
517 /* AS:IP-address fmt*/
519 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u.%u.%u.%u",
520 EXTRACT_16BITS(pptr
+2), *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
522 /* IP-address:AS fmt*/
525 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
526 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
529 /* 4-byte-AS:number fmt*/
531 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (%u.%u.%u.%u:%u)",
532 EXTRACT_32BITS(pptr
+2), EXTRACT_16BITS(pptr
+6),
533 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
536 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
545 decode_rt_routing_info(const u_char
*pptr
, char *buf
, u_int buflen
)
547 u_int8_t route_target
[8];
551 plen
= pptr
[0]; /* get prefix length */
554 return 1; /* default route target */
559 plen
-=32; /* adjust prefix length */
564 memset(&route_target
, 0, sizeof(route_target
));
565 TCHECK2(pptr
[1], (plen
+ 7) / 8);
566 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
568 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
569 ((0xff00 >> (plen
% 8)) & 0xff);
571 snprintf(buf
, buflen
, "origin AS: %u, route target %s",
572 EXTRACT_32BITS(pptr
+1),
573 bgp_vpn_rd_print((u_char
*)&route_target
));
575 return 5 + (plen
+ 7) / 8;
582 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
588 plen
= pptr
[0]; /* get prefix length */
593 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
598 memset(&addr
, 0, sizeof(addr
));
599 TCHECK2(pptr
[12], (plen
+ 7) / 8);
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;
620 * As I remember, some versions of systems have an snprintf() that
621 * returns -1 if the buffer would have overflowed. If the return
622 * value is negative, set buflen to 0, to indicate that we've filled
625 * If the return value is greater than buflen, that means that
626 * the buffer would have overflowed; again, set buflen to 0 in
629 #define UPDATE_BUF_BUFLEN(buf, buflen, strlen) \
632 else if ((u_int)strlen>buflen) \
640 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
642 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
645 plen
=EXTRACT_16BITS(pptr
);
650 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
651 bgp_vpn_rd_print(pptr
),
652 EXTRACT_16BITS(pptr
+8),
653 EXTRACT_16BITS(pptr
+10),
654 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
655 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
659 /* ok now the variable part - lets read out TLVs*/
665 tlv_len
=EXTRACT_16BITS(pptr
);
672 strlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
675 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
677 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
681 strlen
=snprintf(buf
,buflen
, "%02x",*pptr
++);
682 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
689 strlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
692 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
696 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
706 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
708 struct in6_addr addr
;
716 memset(&addr
, 0, sizeof(addr
));
717 TCHECK2(pd
[1], (plen
+ 7) / 8);
718 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
720 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
721 ((0xff00 >> (plen
% 8)) & 0xff);
723 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
724 return 1 + (plen
+ 7) / 8;
731 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
733 struct in6_addr addr
;
737 plen
= pptr
[0]; /* get prefix length */
742 plen
-=24; /* adjust prefixlen - labellength */
747 memset(&addr
, 0, sizeof(addr
));
748 TCHECK2(pptr
[4], (plen
+ 7) / 8);
749 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
751 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
752 ((0xff00 >> (plen
% 8)) & 0xff);
754 /* the label may get offsetted by 4 bits so lets shift it right */
755 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
756 getname6((u_char
*)&addr
),
758 EXTRACT_24BITS(pptr
+1)>>4,
759 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
761 return 4 + (plen
+ 7) / 8;
768 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
770 struct in6_addr addr
;
774 plen
= pptr
[0]; /* get prefix length */
779 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
784 memset(&addr
, 0, sizeof(addr
));
785 TCHECK2(pptr
[12], (plen
+ 7) / 8);
786 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
788 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
789 ((0xff00 >> (plen
% 8)) & 0xff);
791 /* the label may get offsetted by 4 bits so lets shift it right */
792 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
793 bgp_vpn_rd_print(pptr
+4),
794 getname6((u_char
*)&addr
),
796 EXTRACT_24BITS(pptr
+1)>>4,
797 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
799 return 12 + (plen
+ 7) / 8;
807 decode_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
813 plen
= pptr
[0]; /* get prefix length */
818 memset(&addr
, 0, sizeof(addr
));
819 TCHECK2(pptr
[4], (plen
+ 7) / 8);
820 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
822 addr
[(plen
+ 7) / 8 - 1] &=
823 ((0xff00 >> (plen
% 8)) & 0xff);
825 snprintf(buf
, buflen
, "%s/%d",
826 isonsap_string(addr
,(plen
+ 7) / 8),
829 return 1 + (plen
+ 7) / 8;
836 decode_labeled_vpn_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
842 plen
= pptr
[0]; /* get prefix length */
847 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
852 memset(&addr
, 0, sizeof(addr
));
853 TCHECK2(pptr
[12], (plen
+ 7) / 8);
854 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
856 addr
[(plen
+ 7) / 8 - 1] &=
857 ((0xff00 >> (plen
% 8)) & 0xff);
859 /* the label may get offsetted by 4 bits so lets shift it right */
860 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
861 bgp_vpn_rd_print(pptr
+4),
862 isonsap_string(addr
,(plen
+ 7) / 8),
864 EXTRACT_24BITS(pptr
+1)>>4,
865 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
867 return 12 + (plen
+ 7) / 8;
874 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
878 u_int8_t safi
, snpa
, nhlen
;
879 union { /* copy buffer for bandwidth values */
886 char buf
[MAXHOSTNAMELEN
+ 100];
887 char tokbuf
[TOKBUFSIZE
];
892 switch (attr
->bgpa_type
) {
895 printf("invalid len");
898 printf("%s", tok2strbuf(bgp_origin_values
,
899 "Unknown Origin Typecode",
901 tokbuf
, sizeof(tokbuf
)));
905 case BGPTYPE_AS_PATH
:
907 printf("invalid len");
915 while (tptr
< pptr
+ len
) {
917 printf("%s", tok2strbuf(bgp_as_path_segment_open_values
,
919 tokbuf
, sizeof(tokbuf
)));
920 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
921 TCHECK2(tptr
[2 + i
], 2);
922 printf("%u ", EXTRACT_16BITS(&tptr
[2 + i
]));
925 printf("%s", tok2strbuf(bgp_as_path_segment_close_values
,
927 tokbuf
, sizeof(tokbuf
)));
929 tptr
+= 2 + tptr
[1] * 2;
932 case BGPTYPE_NEXT_HOP
:
934 printf("invalid len");
937 printf("%s", getname(tptr
));
940 case BGPTYPE_MULTI_EXIT_DISC
:
941 case BGPTYPE_LOCAL_PREF
:
943 printf("invalid len");
946 printf("%u", EXTRACT_32BITS(tptr
));
949 case BGPTYPE_ATOMIC_AGGREGATE
:
951 printf("invalid len");
953 case BGPTYPE_AGGREGATOR
:
955 printf("invalid len");
959 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
962 case BGPTYPE_COMMUNITIES
:
964 printf("invalid len");
970 comm
= EXTRACT_32BITS(tptr
);
972 case BGP_COMMUNITY_NO_EXPORT
:
973 printf(" NO_EXPORT");
975 case BGP_COMMUNITY_NO_ADVERT
:
976 printf(" NO_ADVERTISE");
978 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
979 printf(" NO_EXPORT_SUBCONFED");
983 (comm
>> 16) & 0xffff,
985 (tlen
>4) ? ", " : "");
992 case BGPTYPE_ORIGINATOR_ID
:
994 printf("invalid len");
998 printf("%s",getname(tptr
));
1000 case BGPTYPE_CLUSTER_LIST
:
1002 printf("invalid len");
1006 TCHECK2(tptr
[0], 4);
1009 (tlen
>4) ? ", " : "");
1014 case BGPTYPE_MP_REACH_NLRI
:
1015 TCHECK2(tptr
[0], 3);
1016 af
= EXTRACT_16BITS(tptr
);
1019 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1020 tok2strbuf(af_values
, "Unknown AFI", af
,
1021 tokbuf
, sizeof(tokbuf
)),
1023 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1024 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1025 tokbuf
, sizeof(tokbuf
)),
1028 switch(af
<<8 | safi
) {
1029 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1030 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1031 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1032 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1033 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1034 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1035 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1036 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1038 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1039 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1040 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1041 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1042 case (AFNUM_INET6
<<8 | SAFNUM_RT_ROUTING_INFO
):
1043 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1044 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1045 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1047 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1048 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1049 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1050 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1051 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1052 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1053 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1054 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1055 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1056 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1059 TCHECK2(tptr
[0], tlen
);
1060 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1062 print_unknown_data(tptr
,"\n\t ",tlen
);
1075 printf("\n\t nexthop: ");
1077 switch(af
<<8 | safi
) {
1078 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1079 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1080 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1081 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1082 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1083 if (tlen
< (int)sizeof(struct in_addr
)) {
1084 printf("invalid len");
1087 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1088 printf("%s",getname(tptr
));
1089 tlen
-= sizeof(struct in_addr
);
1090 tptr
+= sizeof(struct in_addr
);
1093 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1094 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1095 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1096 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1097 printf("invalid len");
1100 TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1101 printf("RD: %s, %s",
1102 bgp_vpn_rd_print(tptr
),
1103 getname(tptr
+BGP_VPN_RD_LEN
));
1104 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1105 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1109 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1110 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1111 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1112 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1113 case (AFNUM_INET6
<<8 | SAFNUM_RT_ROUTING_INFO
):
1114 if (tlen
< (int)sizeof(struct in6_addr
)) {
1115 printf("invalid len");
1118 TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1119 printf("%s", getname6(tptr
));
1120 tlen
-= sizeof(struct in6_addr
);
1121 tptr
+= sizeof(struct in6_addr
);
1124 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1125 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1126 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1127 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1128 printf("invalid len");
1131 TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1132 printf("RD: %s, %s",
1133 bgp_vpn_rd_print(tptr
),
1134 getname6(tptr
+BGP_VPN_RD_LEN
));
1135 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1136 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1140 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1141 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1142 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1143 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1144 if (tlen
< (int)sizeof(struct in_addr
)) {
1145 printf("invalid len");
1148 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1149 printf("%s", getname(tptr
));
1150 tlen
-= (sizeof(struct in_addr
));
1151 tptr
+= (sizeof(struct in_addr
));
1154 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1155 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1156 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1157 TCHECK2(tptr
[0], tlen
);
1158 printf("%s",isonsap_string(tptr
,tlen
));
1163 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1164 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1165 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1166 if (tlen
< BGP_VPN_RD_LEN
+1) {
1167 printf("invalid len");
1170 TCHECK2(tptr
[0], tlen
);
1171 printf("RD: %s, %s",
1172 bgp_vpn_rd_print(tptr
),
1173 isonsap_string(tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
));
1174 /* rfc986 mapped IPv4 address ? */
1175 if (EXTRACT_32BITS(tptr
+BGP_VPN_RD_LEN
) == 0x47000601)
1176 printf(" = %s", getname(tptr
+BGP_VPN_RD_LEN
+4));
1178 /* rfc1888 mapped IPv6 address ? */
1179 else if (EXTRACT_24BITS(tptr
+BGP_VPN_RD_LEN
) == 0x350000)
1180 printf(" = %s", getname6(tptr
+BGP_VPN_RD_LEN
+3));
1187 TCHECK2(tptr
[0], tlen
);
1188 printf("no AFI %u/SAFI %u decoder",af
,safi
);
1190 print_unknown_data(tptr
,"\n\t ",tlen
);
1198 printf(", nh-length: %u", nhlen
);
1206 printf("\n\t %u SNPA", snpa
);
1207 for (/*nothing*/; snpa
> 0; snpa
--) {
1209 printf("\n\t %d bytes", tptr
[0]);
1210 tptr
+= tptr
[0] + 1;
1213 printf(", no SNPA");
1216 while (len
- (tptr
- pptr
) > 0) {
1217 switch (af
<<8 | safi
) {
1218 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1219 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1220 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1221 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1223 printf("\n\t (illegal prefix length)");
1224 else if (advance
== -2)
1227 printf("\n\t %s", buf
);
1229 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1230 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1232 printf("\n\t (illegal prefix length)");
1233 else if (advance
== -2)
1236 printf("\n\t %s", buf
);
1238 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1239 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1240 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1241 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1243 printf("\n\t (illegal prefix length)");
1244 else if (advance
== -2)
1247 printf("\n\t %s", buf
);
1249 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1250 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1252 printf("\n\t (illegal prefix length)");
1253 else if (advance
== -2)
1256 printf("\n\t %s", buf
);
1259 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1260 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1261 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1262 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1264 printf("\n\t (illegal prefix length)");
1265 else if (advance
== -2)
1268 printf("\n\t %s", buf
);
1270 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1271 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1273 printf("\n\t (illegal prefix length)");
1274 else if (advance
== -2)
1277 printf("\n\t %s", buf
);
1279 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1280 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1281 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1282 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1284 printf("\n\t (illegal prefix length)");
1285 else if (advance
== -2)
1288 printf("\n\t %s", buf
);
1290 case (AFNUM_INET6
<<8 | SAFNUM_RT_ROUTING_INFO
):
1291 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1293 printf("\n\t (illegal prefix length)");
1294 else if (advance
== -2)
1297 printf("\n\t %s", buf
);
1300 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1301 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1302 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1303 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1304 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1306 printf("\n\t (illegal length)");
1307 else if (advance
== -2)
1310 printf("\n\t %s", buf
);
1312 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1313 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1314 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1315 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1317 printf("\n\t (illegal prefix length)");
1318 else if (advance
== -2)
1321 printf("\n\t %s", buf
);
1323 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1324 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1325 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1326 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1328 printf("\n\t (illegal prefix length)");
1329 else if (advance
== -2)
1332 printf("\n\t %s", buf
);
1335 TCHECK2(*tptr
,tlen
);
1336 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1338 print_unknown_data(tptr
,"\n\t ",tlen
);
1350 case BGPTYPE_MP_UNREACH_NLRI
:
1351 TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1352 af
= EXTRACT_16BITS(tptr
);
1355 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1356 tok2strbuf(af_values
, "Unknown AFI", af
,
1357 tokbuf
, sizeof(tokbuf
)),
1359 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1360 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1361 tokbuf
, sizeof(tokbuf
)),
1364 if (len
== BGP_MP_NLRI_MINSIZE
)
1365 printf("\n\t End-of-Rib Marker (empty NLRI)");
1369 while (len
- (tptr
- pptr
) > 0) {
1370 switch (af
<<8 | safi
) {
1371 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1372 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1373 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1374 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1376 printf("\n\t (illegal prefix length)");
1377 else if (advance
== -2)
1380 printf("\n\t %s", buf
);
1382 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1383 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1385 printf("\n\t (illegal prefix length)");
1386 else if (advance
== -2)
1389 printf("\n\t %s", buf
);
1391 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1392 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1393 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1394 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1396 printf("\n\t (illegal prefix length)");
1397 else if (advance
== -2)
1400 printf("\n\t %s", buf
);
1403 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1404 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1405 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1406 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1408 printf("\n\t (illegal prefix length)");
1409 else if (advance
== -2)
1412 printf("\n\t %s", buf
);
1414 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1415 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1417 printf("\n\t (illegal prefix length)");
1418 else if (advance
== -2)
1421 printf("\n\t %s", buf
);
1423 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1424 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1425 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1426 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1428 printf("\n\t (illegal prefix length)");
1429 else if (advance
== -2)
1432 printf("\n\t %s", buf
);
1435 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1436 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1437 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1438 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1439 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1441 printf("\n\t (illegal length)");
1442 else if (advance
== -2)
1445 printf("\n\t %s", buf
);
1447 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1448 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1449 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1450 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1452 printf("\n\t (illegal prefix length)");
1453 else if (advance
== -2)
1456 printf("\n\t %s", buf
);
1458 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1459 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1460 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1461 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1463 printf("\n\t (illegal prefix length)");
1464 else if (advance
== -2)
1467 printf("\n\t %s", buf
);
1470 TCHECK2(*(tptr
-3),tlen
);
1471 printf("no AFI %u / SAFI %u decoder",af
,safi
);
1473 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1483 case BGPTYPE_EXTD_COMMUNITIES
:
1485 printf("invalid len");
1489 u_int16_t extd_comm
;
1491 TCHECK2(tptr
[0], 2);
1492 extd_comm
=EXTRACT_16BITS(tptr
);
1494 printf("\n\t %s (0x%04x), Flags [%s]",
1495 tok2strbuf(bgp_extd_comm_subtype_values
,
1496 "unknown extd community typecode",
1497 extd_comm
, tokbuf
, sizeof(tokbuf
)),
1499 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1501 TCHECK2(*(tptr
+2), 6);
1503 case BGP_EXT_COM_RT_0
:
1504 case BGP_EXT_COM_RO_0
:
1506 EXTRACT_16BITS(tptr
+2),
1509 case BGP_EXT_COM_RT_1
:
1510 case BGP_EXT_COM_RO_1
:
1513 EXTRACT_16BITS(tptr
+6));
1515 case BGP_EXT_COM_RT_2
:
1516 case BGP_EXT_COM_RO_2
:
1518 EXTRACT_32BITS(tptr
+2),
1519 EXTRACT_16BITS(tptr
+6));
1521 case BGP_EXT_COM_LINKBAND
:
1522 bw
.i
= EXTRACT_32BITS(tptr
+2);
1523 printf(": bandwidth: %.3f Mbps",
1526 case BGP_EXT_COM_CISCO_MCAST
:
1527 printf(": AS %u, group %s",
1528 EXTRACT_16BITS(tptr
+2),
1531 case BGP_EXT_COM_VPN_ORIGIN
:
1532 case BGP_EXT_COM_VPN_ORIGIN2
:
1533 case BGP_EXT_COM_VPN_ORIGIN3
:
1534 case BGP_EXT_COM_VPN_ORIGIN4
:
1535 case BGP_EXT_COM_OSPF_RID
:
1536 case BGP_EXT_COM_OSPF_RID2
:
1537 printf("%s", getname(tptr
+2));
1539 case BGP_EXT_COM_OSPF_RTYPE
:
1540 case BGP_EXT_COM_OSPF_RTYPE2
:
1541 printf(": area:%s, router-type:%s, metric-type:%s%s",
1543 tok2strbuf(bgp_extd_comm_ospf_rtype_values
,
1546 tokbuf
, sizeof(tokbuf
)),
1547 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1548 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1550 case BGP_EXT_COM_L2INFO
:
1551 printf(": %s Control Flags [0x%02x]:MTU %u",
1552 tok2strbuf(l2vpn_encaps_values
,
1555 tokbuf
, sizeof(tokbuf
)),
1557 EXTRACT_16BITS(tptr
+4));
1561 print_unknown_data(tptr
,"\n\t ",8);
1569 case BGPTYPE_ATTR_SET
:
1570 TCHECK2(tptr
[0], 4);
1571 printf("\n\t Origin AS: %u", EXTRACT_32BITS(tptr
));
1577 struct bgp_attr bgpa
;
1579 TCHECK2(tptr
[0], sizeof(bgpa
));
1580 memcpy(&bgpa
, tptr
, sizeof(bgpa
));
1581 alen
= bgp_attr_len(&bgpa
);
1582 tptr
+= bgp_attr_off(&bgpa
);
1583 len
-= bgp_attr_off(&bgpa
);
1585 printf("\n\t %s (%u), length: %u",
1586 tok2strbuf(bgp_attr_values
,
1587 "Unknown Attribute", bgpa
.bgpa_type
,
1588 tokbuf
, sizeof(tokbuf
)),
1592 if (bgpa
.bgpa_flags
) {
1593 printf(", Flags [%s%s%s%s",
1594 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1595 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1596 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1597 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1598 if (bgpa
.bgpa_flags
& 0xf)
1599 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1602 /* FIXME check for recursion */
1603 if (!bgp_attr_print(&bgpa
, tptr
, alen
))
1613 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1615 print_unknown_data(pptr
,"\n\t ",len
);
1618 if (vflag
> 1 && len
) { /* omit zero length attributes*/
1620 print_unknown_data(pptr
,"\n\t ",len
);
1629 bgp_open_print(const u_char
*dat
, int length
)
1631 struct bgp_open bgpo
;
1632 struct bgp_opt bgpopt
;
1634 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
1635 char tokbuf
[TOKBUFSIZE
];
1636 char tokbuf2
[TOKBUFSIZE
];
1638 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1639 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1641 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1642 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1643 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1644 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1645 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1647 /* some little sanity checking */
1648 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
1652 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1656 while (i
< bgpo
.bgpo_optlen
) {
1657 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1658 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1659 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1660 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1664 printf("\n\t Option %s (%u), length: %u",
1665 tok2strbuf(bgp_opt_values
,"Unknown",
1667 tokbuf
, sizeof(tokbuf
)),
1671 /* now lets decode the options we know*/
1672 switch(bgpopt
.bgpopt_type
) {
1674 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1675 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1677 printf("\n\t %s (%u), length: %u",
1678 tok2strbuf(bgp_capcode_values
, "Unknown",
1679 cap_type
, tokbuf
, sizeof(tokbuf
)),
1683 case BGP_CAPCODE_MP
:
1684 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1685 tok2strbuf(af_values
, "Unknown",
1686 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1687 tokbuf
, sizeof(tokbuf
)),
1688 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1689 tok2strbuf(bgp_safi_values
, "Unknown",
1690 opt
[i
+BGP_OPT_SIZE
+5],
1691 tokbuf
, sizeof(tokbuf
)),
1692 opt
[i
+BGP_OPT_SIZE
+5]);
1694 case BGP_CAPCODE_RESTART
:
1695 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
1696 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
1697 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
1700 while(tcap_len
>=4) {
1701 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1702 tok2strbuf(af_values
,"Unknown",
1703 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1704 tokbuf
, sizeof(tokbuf
)),
1705 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1706 tok2strbuf(bgp_safi_values
,"Unknown",
1707 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1708 tokbuf2
, sizeof(tokbuf2
)),
1709 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1710 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
1715 case BGP_CAPCODE_RR
:
1716 case BGP_CAPCODE_RR_CISCO
:
1719 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
1720 printf("\n\t\tno decoder for Capability %u",
1723 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1727 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
1728 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1733 printf("\n\t no decoder for option %u",
1734 bgpopt
.bgpopt_type
);
1738 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1746 bgp_update_print(const u_char
*dat
, int length
)
1749 struct bgp_attr bgpa
;
1753 char tokbuf
[TOKBUFSIZE
];
1755 TCHECK2(dat
[0], BGP_SIZE
);
1756 memcpy(&bgp
, dat
, BGP_SIZE
);
1757 p
= dat
+ BGP_SIZE
; /*XXX*/
1759 /* Unfeasible routes */
1760 len
= EXTRACT_16BITS(p
);
1763 * Without keeping state from the original NLRI message,
1764 * it's not possible to tell if this a v4 or v6 route,
1765 * so only try to decode it if we're not v6 enabled.
1768 printf("\n\t Withdrawn routes: %d bytes", len
);
1770 char buf
[MAXHOSTNAMELEN
+ 100];
1776 printf("\n\t Withdrawn routes:");
1778 while(i
< 2 + len
) {
1779 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1781 printf("\n\t (illegal prefix length)");
1783 } else if (wpfx
== -2)
1787 printf("\n\t %s", buf
);
1795 len
= EXTRACT_16BITS(p
);
1797 if (len
== 0 && length
== BGP_UPDATE_MINSIZE
) {
1798 printf("\n\t End-of-Rib Marker (empty NLRI)");
1803 /* do something more useful!*/
1805 while (i
< 2 + len
) {
1808 TCHECK2(p
[i
], sizeof(bgpa
));
1809 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
1810 alen
= bgp_attr_len(&bgpa
);
1811 aoff
= bgp_attr_off(&bgpa
);
1813 printf("\n\t %s (%u), length: %u",
1814 tok2strbuf(bgp_attr_values
, "Unknown Attribute",
1816 tokbuf
, sizeof(tokbuf
)),
1820 if (bgpa
.bgpa_flags
) {
1821 printf(", Flags [%s%s%s%s",
1822 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1823 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1824 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1825 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1826 if (bgpa
.bgpa_flags
& 0xf)
1827 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1830 if (!bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
))
1837 if (dat
+ length
> p
) {
1838 printf("\n\t Updated routes:");
1839 while (dat
+ length
> p
) {
1840 char buf
[MAXHOSTNAMELEN
+ 100];
1841 i
= decode_prefix4(p
, buf
, sizeof(buf
));
1843 printf("\n\t (illegal prefix length)");
1848 printf("\n\t %s", buf
);
1859 bgp_notification_print(const u_char
*dat
, int length
)
1861 struct bgp_notification bgpn
;
1863 char tokbuf
[TOKBUFSIZE
];
1864 char tokbuf2
[TOKBUFSIZE
];
1866 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1867 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1869 /* some little sanity checking */
1870 if (length
<BGP_NOTIFICATION_SIZE
)
1874 tok2strbuf(bgp_notify_major_values
, "Unknown Error",
1875 bgpn
.bgpn_major
, tokbuf
, sizeof(tokbuf
)),
1878 switch (bgpn
.bgpn_major
) {
1880 case BGP_NOTIFY_MAJOR_MSG
:
1881 printf(", subcode %s (%u)",
1882 tok2strbuf(bgp_notify_minor_msg_values
, "Unknown",
1883 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
1886 case BGP_NOTIFY_MAJOR_OPEN
:
1887 printf(", subcode %s (%u)",
1888 tok2strbuf(bgp_notify_minor_open_values
, "Unknown",
1889 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
1892 case BGP_NOTIFY_MAJOR_UPDATE
:
1893 printf(", subcode %s (%u)",
1894 tok2strbuf(bgp_notify_minor_update_values
, "Unknown",
1895 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
1898 case BGP_NOTIFY_MAJOR_CAP
:
1899 printf(" subcode %s (%u)",
1900 tok2strbuf(bgp_notify_minor_cap_values
, "Unknown",
1901 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
1903 case BGP_NOTIFY_MAJOR_CEASE
:
1904 printf(", subcode %s (%u)",
1905 tok2strbuf(bgp_notify_minor_cease_values
, "Unknown",
1906 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
1909 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
1910 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
1912 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
1913 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
1915 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
1916 tok2strbuf(af_values
, "Unknown",
1917 EXTRACT_16BITS(tptr
), tokbuf
, sizeof(tokbuf
)),
1918 EXTRACT_16BITS(tptr
),
1919 tok2strbuf(bgp_safi_values
, "Unknown", *(tptr
+2),
1920 tokbuf2
, sizeof(tokbuf
)),
1922 EXTRACT_32BITS(tptr
+3));
1935 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1937 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1938 char tokbuf
[TOKBUFSIZE
];
1939 char tokbuf2
[TOKBUFSIZE
];
1941 TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
1943 /* some little sanity checking */
1944 if (len
<BGP_ROUTE_REFRESH_SIZE
)
1947 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
1949 printf("\n\t AFI %s (%u), SAFI %s (%u)",
1950 tok2strbuf(af_values
,"Unknown",
1951 /* this stinks but the compiler pads the structure
1953 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1954 tokbuf
, sizeof(tokbuf
)),
1955 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1956 tok2strbuf(bgp_safi_values
,"Unknown",
1957 bgp_route_refresh_header
->safi
,
1958 tokbuf2
, sizeof(tokbuf2
)),
1959 bgp_route_refresh_header
->safi
);
1962 TCHECK2(*pptr
, len
);
1963 print_unknown_data(pptr
,"\n\t ", len
);
1972 bgp_header_print(const u_char
*dat
, int length
)
1975 char tokbuf
[TOKBUFSIZE
];
1977 TCHECK2(dat
[0], BGP_SIZE
);
1978 memcpy(&bgp
, dat
, BGP_SIZE
);
1979 printf("\n\t%s Message (%u), length: %u",
1980 tok2strbuf(bgp_msg_values
, "Unknown", bgp
.bgp_type
,
1981 tokbuf
, sizeof(tokbuf
)),
1985 switch (bgp
.bgp_type
) {
1987 bgp_open_print(dat
, length
);
1990 bgp_update_print(dat
, length
);
1992 case BGP_NOTIFICATION
:
1993 bgp_notification_print(dat
, length
);
1997 case BGP_ROUTE_REFRESH
:
1998 bgp_route_refresh_print(dat
, length
);
2001 /* we have no decoder for the BGP message */
2002 TCHECK2(*dat
, length
);
2003 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
2004 print_unknown_data(dat
,"\n\t ",length
);
2014 bgp_print(const u_char
*dat
, int length
)
2018 const u_char
*start
;
2019 const u_char marker
[] = {
2020 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2021 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2025 char tokbuf
[TOKBUFSIZE
];
2028 if (snapend
< dat
+ length
)
2031 printf(": BGP, length: %u",length
);
2033 if (vflag
< 1) /* lets be less chatty */
2039 if (!TTEST2(p
[0], 1))
2046 if (!TTEST2(p
[0], sizeof(marker
)))
2048 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2053 /* found BGP header */
2054 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2055 memcpy(&bgp
, p
, BGP_SIZE
);
2060 hlen
= ntohs(bgp
.bgp_len
);
2061 if (hlen
< BGP_SIZE
) {
2062 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
2067 if (TTEST2(p
[0], hlen
)) {
2068 if (!bgp_header_print(p
, hlen
))
2073 printf("\n[|BGP %s]",
2074 tok2strbuf(bgp_msg_values
,
2075 "Unknown Message Type",
2077 tokbuf
, sizeof(tokbuf
)));