2 * Copyright (C) 1999 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Extensively modified by Hannes Gredler (hannes@juniper.net) for more
30 * complete BGP support.
38 static const char rcsid
[] _U_
=
39 "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.91.2.10 2006-10-06 06:26:40 hannes Exp $";
42 #include <tcpdump-stdinc.h>
47 #include "interface.h"
48 #include "decode_prefix.h"
49 #include "addrtoname.h"
55 u_int8_t bgp_marker
[16];
59 #define BGP_SIZE 19 /* unaligned */
63 #define BGP_NOTIFICATION 3
64 #define BGP_KEEPALIVE 4
65 #define BGP_ROUTE_REFRESH 5
67 static struct tok bgp_msg_values
[] = {
69 { BGP_UPDATE
, "Update"},
70 { BGP_NOTIFICATION
, "Notification"},
71 { BGP_KEEPALIVE
, "Keepalive"},
72 { BGP_ROUTE_REFRESH
, "Route Refresh"},
77 u_int8_t bgpo_marker
[16];
80 u_int8_t bgpo_version
;
82 u_int16_t bgpo_holdtime
;
85 /* options should follow */
87 #define BGP_OPEN_SIZE 29 /* unaligned */
94 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
96 #define BGP_UPDATE_MINSIZE 23
98 struct bgp_notification
{
99 u_int8_t bgpn_marker
[16];
105 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
107 struct bgp_route_refresh
{
108 u_int8_t bgp_marker
[16];
111 u_int8_t afi
[2]; /* the compiler messes this structure up */
112 u_int8_t res
; /* when doing misaligned sequences of int8 and int16 */
113 u_int8_t safi
; /* afi should be int16 - so we have to access it using */
114 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
115 #define BGP_ROUTE_REFRESH_SIZE 23
124 #define bgp_attr_len(p) \
125 (((p)->bgpa_flags & 0x10) ? \
126 EXTRACT_16BITS(&(p)->bgpa_len.elen) : (p)->bgpa_len.len)
127 #define bgp_attr_off(p) \
128 (((p)->bgpa_flags & 0x10) ? 4 : 3)
131 #define BGPTYPE_ORIGIN 1
132 #define BGPTYPE_AS_PATH 2
133 #define BGPTYPE_NEXT_HOP 3
134 #define BGPTYPE_MULTI_EXIT_DISC 4
135 #define BGPTYPE_LOCAL_PREF 5
136 #define BGPTYPE_ATOMIC_AGGREGATE 6
137 #define BGPTYPE_AGGREGATOR 7
138 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
139 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
140 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
141 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
142 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
143 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
144 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
145 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
146 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
147 #define BGPTYPE_ATTR_SET 128 /* draft-marques-ppvpn-ibgp */
149 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
151 static struct tok bgp_attr_values
[] = {
152 { BGPTYPE_ORIGIN
, "Origin"},
153 { BGPTYPE_AS_PATH
, "AS Path"},
154 { BGPTYPE_NEXT_HOP
, "Next Hop"},
155 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
156 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
157 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
158 { BGPTYPE_AGGREGATOR
, "Aggregator"},
159 { BGPTYPE_COMMUNITIES
, "Community"},
160 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
161 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
162 { BGPTYPE_DPA
, "DPA"},
163 { BGPTYPE_ADVERTISERS
, "Advertisers"},
164 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
165 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
166 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
167 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
168 { BGPTYPE_ATTR_SET
, "Attribute Set"},
169 { 255, "Reserved for development"},
174 #define BGP_AS_SEQUENCE 2
175 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
176 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
178 static struct tok bgp_as_path_segment_open_values
[] = {
179 { BGP_AS_SEQUENCE
, ""},
181 { BGP_CONFED_AS_SEQUENCE
, "( "},
182 { BGP_CONFED_AS_SET
, "({ "},
186 static struct tok bgp_as_path_segment_close_values
[] = {
187 { BGP_AS_SEQUENCE
, ""},
189 { BGP_CONFED_AS_SEQUENCE
, ")"},
190 { BGP_CONFED_AS_SET
, "})"},
194 #define BGP_OPT_AUTH 1
195 #define BGP_OPT_CAP 2
198 static struct tok bgp_opt_values
[] = {
199 { BGP_OPT_AUTH
, "Authentication Information"},
200 { BGP_OPT_CAP
, "Capabilities Advertisement"},
204 #define BGP_CAPCODE_MP 1
205 #define BGP_CAPCODE_RR 2
206 #define BGP_CAPCODE_ORF 3 /* XXX */
207 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
208 #define BGP_CAPCODE_AS_NEW 65 /* XXX */
209 #define BGP_CAPCODE_DYN_CAP 67 /* XXX */
210 #define BGP_CAPCODE_RR_CISCO 128
212 static struct tok bgp_capcode_values
[] = {
213 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
214 { BGP_CAPCODE_RR
, "Route Refresh"},
215 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
216 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
217 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
218 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
219 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
223 #define BGP_NOTIFY_MAJOR_MSG 1
224 #define BGP_NOTIFY_MAJOR_OPEN 2
225 #define BGP_NOTIFY_MAJOR_UPDATE 3
226 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
227 #define BGP_NOTIFY_MAJOR_FSM 5
228 #define BGP_NOTIFY_MAJOR_CEASE 6
229 #define BGP_NOTIFY_MAJOR_CAP 7
231 static struct tok bgp_notify_major_values
[] = {
232 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
233 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
234 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
235 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
236 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
237 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
238 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
242 /* draft-ietf-idr-cease-subcode-02 */
243 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
244 static struct tok bgp_notify_minor_cease_values
[] = {
245 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
246 { 2, "Administratively Shutdown"},
247 { 3, "Peer Unconfigured"},
248 { 4, "Administratively Reset"},
249 { 5, "Connection Rejected"},
250 { 6, "Other Configuration Change"},
251 { 7, "Connection Collision Resolution"},
255 static struct tok bgp_notify_minor_msg_values
[] = {
256 { 1, "Connection Not Synchronized"},
257 { 2, "Bad Message Length"},
258 { 3, "Bad Message Type"},
262 static struct tok bgp_notify_minor_open_values
[] = {
263 { 1, "Unsupported Version Number"},
265 { 3, "Bad BGP Identifier"},
266 { 4, "Unsupported Optional Parameter"},
267 { 5, "Authentication Failure"},
268 { 6, "Unacceptable Hold Time"},
272 static struct tok bgp_notify_minor_update_values
[] = {
273 { 1, "Malformed Attribute List"},
274 { 2, "Unrecognized Well-known Attribute"},
275 { 3, "Missing Well-known Attribute"},
276 { 4, "Attribute Flags Error"},
277 { 5, "Attribute Length Error"},
278 { 6, "Invalid ORIGIN Attribute"},
279 { 7, "AS Routing Loop"},
280 { 8, "Invalid NEXT_HOP Attribute"},
281 { 9, "Optional Attribute Error"},
282 { 10, "Invalid Network Field"},
283 { 11, "Malformed AS_PATH"},
287 static struct tok bgp_notify_minor_cap_values
[] = {
288 { 1, "Invalid Action Value" },
289 { 2, "Invalid Capability Length" },
290 { 3, "Malformed Capability Value" },
291 { 4, "Unsupported Capability Code" },
295 static struct tok bgp_origin_values
[] = {
302 /* Subsequent address family identifier, RFC2283 section 7 */
304 #define SAFNUM_UNICAST 1
305 #define SAFNUM_MULTICAST 2
306 #define SAFNUM_UNIMULTICAST 3
307 /* labeled BGP RFC3107 */
308 #define SAFNUM_LABUNICAST 4
309 #define SAFNUM_TUNNEL 64 /* XXX */
310 #define SAFNUM_VPLS 65 /* XXX */
311 #define SAFNUM_MDT 66 /* XXX */
312 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
313 #define SAFNUM_VPNUNICAST 128
314 #define SAFNUM_VPNMULTICAST 129
315 #define SAFNUM_VPNUNIMULTICAST 130
316 /* draft-marques-ppvpn-rt-constrain-01.txt */
317 #define SAFNUM_RT_ROUTING_INFO 132
319 #define BGP_VPN_RD_LEN 8
321 static struct tok bgp_safi_values
[] = {
322 { SAFNUM_RES
, "Reserved"},
323 { SAFNUM_UNICAST
, "Unicast"},
324 { SAFNUM_MULTICAST
, "Multicast"},
325 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
326 { SAFNUM_LABUNICAST
, "labeled Unicast"},
327 { SAFNUM_TUNNEL
, "Tunnel"},
328 { SAFNUM_VPLS
, "VPLS"},
329 { SAFNUM_MDT
, "MDT"},
330 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
331 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
332 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
333 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"}, /* draft-marques-ppvpn-rt-constrain-01.txt */
337 /* well-known community */
338 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
339 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
340 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
342 /* RFC1700 address family numbers */
344 #define AFNUM_INET6 2
347 #define AFNUM_BBN1822 5
352 #define AFNUM_X121 10
354 #define AFNUM_ATALK 12
355 #define AFNUM_DECNET 13
356 #define AFNUM_BANYAN 14
357 #define AFNUM_E164NSAP 15
358 #define AFNUM_VPLS 25
359 /* draft-kompella-ppvpn-l2vpn */
360 #define AFNUM_L2VPN 196 /* still to be approved by IANA */
362 static struct tok bgp_afi_values
[] = {
364 { AFNUM_INET
, "IPv4"},
365 { AFNUM_INET6
, "IPv6"},
366 { AFNUM_NSAP
, "NSAP"},
367 { AFNUM_HDLC
, "HDLC"},
368 { AFNUM_BBN1822
, "BBN 1822"},
370 { AFNUM_E163
, "E.163"},
371 { AFNUM_E164
, "E.164"},
372 { AFNUM_F69
, "F.69"},
373 { AFNUM_X121
, "X.121"},
374 { AFNUM_IPX
, "Novell IPX"},
375 { AFNUM_ATALK
, "Appletalk"},
376 { AFNUM_DECNET
, "Decnet IV"},
377 { AFNUM_BANYAN
, "Banyan Vines"},
378 { AFNUM_E164NSAP
, "E.164 with NSAP subaddress"},
379 { AFNUM_L2VPN
, "Layer-2 VPN"},
380 { AFNUM_VPLS
, "VPLS"},
384 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
385 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
386 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
387 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
388 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
389 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
390 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
391 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
392 /* rfc2547 bgp-mpls-vpns */
393 #define BGP_EXT_COM_CISCO_MCAST 0x0009 /* cisco proprietary */
395 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
396 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
397 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
398 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
400 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
401 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
403 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
404 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
406 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
408 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
409 #define BGP_EXT_COM_EIGRP_GEN 0x8800
410 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
411 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
412 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
413 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
414 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
416 static struct tok bgp_extd_comm_flag_values
[] = {
417 { 0x8000, "vendor-specific"},
418 { 0x4000, "non-transitive"},
422 static struct tok bgp_extd_comm_subtype_values
[] = {
423 { BGP_EXT_COM_RT_0
, "target"},
424 { BGP_EXT_COM_RT_1
, "target"},
425 { BGP_EXT_COM_RT_2
, "target"},
426 { BGP_EXT_COM_RO_0
, "origin"},
427 { BGP_EXT_COM_RO_1
, "origin"},
428 { BGP_EXT_COM_RO_2
, "origin"},
429 { BGP_EXT_COM_LINKBAND
, "link-BW"},
430 { BGP_EXT_COM_CISCO_MCAST
, "mdt-group"},
431 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
432 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
433 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
434 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
435 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
436 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
437 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
438 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
439 { BGP_EXT_COM_L2INFO
, "layer2-info"},
440 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
441 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
442 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
443 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
444 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
445 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
449 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
450 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
451 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
452 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
453 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
454 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
455 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
456 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
458 static struct tok bgp_extd_comm_ospf_rtype_values
[] = {
459 { BGP_OSPF_RTYPE_RTR
, "Router" },
460 { BGP_OSPF_RTYPE_NET
, "Network" },
461 { BGP_OSPF_RTYPE_SUM
, "Summary" },
462 { BGP_OSPF_RTYPE_EXT
, "External" },
463 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
464 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
469 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
479 memset(&addr
, 0, sizeof(addr
));
480 TCHECK2(pptr
[1], (plen
+ 7) / 8);
481 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
483 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
484 ((0xff00 >> (plen
% 8)) & 0xff);
486 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
487 return 1 + (plen
+ 7) / 8;
494 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
500 plen
= pptr
[0]; /* get prefix length */
502 /* this is one of the weirdnesses of rfc3107
503 the label length (actually the label + COS bits)
504 is added to the prefix length;
505 we also do only read out just one label -
506 there is no real application for advertisement of
507 stacked labels in a a single BGP message
513 plen
-=24; /* adjust prefixlen - labellength */
518 memset(&addr
, 0, sizeof(addr
));
519 TCHECK2(pptr
[4], (plen
+ 7) / 8);
520 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
522 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
523 ((0xff00 >> (plen
% 8)) & 0xff);
525 /* the label may get offsetted by 4 bits so lets shift it right */
526 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
527 getname((u_char
*)&addr
),
529 EXTRACT_24BITS(pptr
+1)>>4,
530 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
532 return 4 + (plen
+ 7) / 8;
538 /* RDs and RTs share the same semantics
539 * we use bgp_vpn_rd_print for
540 * printing route targets inside a NLRI */
542 bgp_vpn_rd_print (const u_char
*pptr
) {
544 /* allocate space for the largest possible string */
545 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
548 /* ok lets load the RD format */
549 switch (EXTRACT_16BITS(pptr
)) {
551 /* AS:IP-address fmt*/
553 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u.%u.%u.%u",
554 EXTRACT_16BITS(pptr
+2), *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
556 /* IP-address:AS fmt*/
559 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
560 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
563 /* 4-byte-AS:number fmt*/
565 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (%u.%u.%u.%u:%u)",
566 EXTRACT_32BITS(pptr
+2), EXTRACT_16BITS(pptr
+6),
567 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
570 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
579 decode_rt_routing_info(const u_char
*pptr
, char *buf
, u_int buflen
)
581 u_int8_t route_target
[8];
585 plen
= pptr
[0]; /* get prefix length */
588 return 1; /* default route target */
593 plen
-=32; /* adjust prefix length */
598 memset(&route_target
, 0, sizeof(route_target
));
599 TCHECK2(pptr
[1], (plen
+ 7) / 8);
600 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
602 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
603 ((0xff00 >> (plen
% 8)) & 0xff);
605 snprintf(buf
, buflen
, "origin AS: %u, route target %s",
606 EXTRACT_32BITS(pptr
+1),
607 bgp_vpn_rd_print((u_char
*)&route_target
));
609 return 5 + (plen
+ 7) / 8;
616 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
622 plen
= pptr
[0]; /* get prefix length */
627 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
632 memset(&addr
, 0, sizeof(addr
));
633 TCHECK2(pptr
[12], (plen
+ 7) / 8);
634 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
636 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
637 ((0xff00 >> (plen
% 8)) & 0xff);
639 /* the label may get offsetted by 4 bits so lets shift it right */
640 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
641 bgp_vpn_rd_print(pptr
+4),
642 getname((u_char
*)&addr
),
644 EXTRACT_24BITS(pptr
+1)>>4,
645 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
647 return 12 + (plen
+ 7) / 8;
654 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
656 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
659 plen
=EXTRACT_16BITS(pptr
);
663 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
664 bgp_vpn_rd_print(pptr
),
665 EXTRACT_16BITS(pptr
+8),
666 EXTRACT_16BITS(pptr
+10),
667 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
671 /* ok now the variable part - lets read out TLVs*/
677 tlv_len
=EXTRACT_16BITS(pptr
);
683 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
686 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
689 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "%02x",*pptr
++);
694 snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tunknown TLV #%u, length: %u",
699 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it tright */
709 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
711 struct in6_addr addr
;
719 memset(&addr
, 0, sizeof(addr
));
720 TCHECK2(pd
[1], (plen
+ 7) / 8);
721 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
723 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
724 ((0xff00 >> (plen
% 8)) & 0xff);
726 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
727 return 1 + (plen
+ 7) / 8;
734 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
736 struct in6_addr addr
;
740 plen
= pptr
[0]; /* get prefix length */
745 plen
-=24; /* adjust prefixlen - labellength */
750 memset(&addr
, 0, sizeof(addr
));
751 TCHECK2(pptr
[4], (plen
+ 7) / 8);
752 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
754 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
755 ((0xff00 >> (plen
% 8)) & 0xff);
757 /* the label may get offsetted by 4 bits so lets shift it right */
758 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
759 getname6((u_char
*)&addr
),
761 EXTRACT_24BITS(pptr
+1)>>4,
762 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
764 return 4 + (plen
+ 7) / 8;
771 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
773 struct in6_addr addr
;
777 plen
= pptr
[0]; /* get prefix length */
782 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
787 memset(&addr
, 0, sizeof(addr
));
788 TCHECK2(pptr
[12], (plen
+ 7) / 8);
789 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
791 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
792 ((0xff00 >> (plen
% 8)) & 0xff);
794 /* the label may get offsetted by 4 bits so lets shift it right */
795 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
796 bgp_vpn_rd_print(pptr
+4),
797 getname6((u_char
*)&addr
),
799 EXTRACT_24BITS(pptr
+1)>>4,
800 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
802 return 12 + (plen
+ 7) / 8;
810 decode_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
816 plen
= pptr
[0]; /* get prefix length */
821 memset(&addr
, 0, sizeof(addr
));
822 TCHECK2(pptr
[4], (plen
+ 7) / 8);
823 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
825 addr
[(plen
+ 7) / 8 - 1] &=
826 ((0xff00 >> (plen
% 8)) & 0xff);
828 snprintf(buf
, buflen
, "%s/%d",
829 isonsap_string(addr
,(plen
+ 7) / 8),
832 return 1 + (plen
+ 7) / 8;
839 decode_labeled_vpn_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
845 plen
= pptr
[0]; /* get prefix length */
850 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
855 memset(&addr
, 0, sizeof(addr
));
856 TCHECK2(pptr
[12], (plen
+ 7) / 8);
857 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
859 addr
[(plen
+ 7) / 8 - 1] &=
860 ((0xff00 >> (plen
% 8)) & 0xff);
862 /* the label may get offsetted by 4 bits so lets shift it right */
863 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
864 bgp_vpn_rd_print(pptr
+4),
865 isonsap_string(addr
,(plen
+ 7) / 8),
867 EXTRACT_24BITS(pptr
+1)>>4,
868 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
870 return 12 + (plen
+ 7) / 8;
877 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
881 u_int8_t safi
, snpa
, nhlen
;
882 union { /* copy buffer for bandwidth values */
889 char buf
[MAXHOSTNAMELEN
+ 100];
890 char tokbuf
[TOKBUFSIZE
];
895 switch (attr
->bgpa_type
) {
898 printf("invalid len");
901 printf("%s", tok2strbuf(bgp_origin_values
,
902 "Unknown Origin Typecode",
904 tokbuf
, sizeof(tokbuf
)));
908 case BGPTYPE_AS_PATH
:
910 printf("invalid len");
918 while (tptr
< pptr
+ len
) {
920 printf("%s", tok2strbuf(bgp_as_path_segment_open_values
,
922 tokbuf
, sizeof(tokbuf
)));
923 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
924 TCHECK2(tptr
[2 + i
], 2);
925 printf("%u ", EXTRACT_16BITS(&tptr
[2 + i
]));
928 printf("%s", tok2strbuf(bgp_as_path_segment_close_values
,
930 tokbuf
, sizeof(tokbuf
)));
932 tptr
+= 2 + tptr
[1] * 2;
935 case BGPTYPE_NEXT_HOP
:
937 printf("invalid len");
940 printf("%s", getname(tptr
));
943 case BGPTYPE_MULTI_EXIT_DISC
:
944 case BGPTYPE_LOCAL_PREF
:
946 printf("invalid len");
949 printf("%u", EXTRACT_32BITS(tptr
));
952 case BGPTYPE_ATOMIC_AGGREGATE
:
954 printf("invalid len");
956 case BGPTYPE_AGGREGATOR
:
958 printf("invalid len");
962 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
965 case BGPTYPE_COMMUNITIES
:
967 printf("invalid len");
973 comm
= EXTRACT_32BITS(tptr
);
975 case BGP_COMMUNITY_NO_EXPORT
:
976 printf(" NO_EXPORT");
978 case BGP_COMMUNITY_NO_ADVERT
:
979 printf(" NO_ADVERTISE");
981 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
982 printf(" NO_EXPORT_SUBCONFED");
986 (comm
>> 16) & 0xffff,
988 (tlen
>4) ? ", " : "");
995 case BGPTYPE_ORIGINATOR_ID
:
997 printf("invalid len");
1000 TCHECK2(tptr
[0], 4);
1001 printf("%s",getname(tptr
));
1003 case BGPTYPE_CLUSTER_LIST
:
1005 printf("invalid len");
1009 TCHECK2(tptr
[0], 4);
1012 (tlen
>4) ? ", " : "");
1017 case BGPTYPE_MP_REACH_NLRI
:
1018 TCHECK2(tptr
[0], 3);
1019 af
= EXTRACT_16BITS(tptr
);
1022 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1023 tok2strbuf(bgp_afi_values
, "Unknown AFI", af
,
1024 tokbuf
, sizeof(tokbuf
)),
1026 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1027 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1028 tokbuf
, sizeof(tokbuf
)),
1031 switch(af
<<8 | safi
) {
1032 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1033 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1034 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1035 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1036 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1037 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1038 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1039 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1041 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1042 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1043 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1044 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1045 case (AFNUM_INET6
<<8 | SAFNUM_RT_ROUTING_INFO
):
1046 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1047 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1048 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1050 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1051 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1052 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1053 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1054 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1055 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1056 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1057 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1058 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1059 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1062 TCHECK2(tptr
[0], tlen
);
1063 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1065 print_unknown_data(tptr
,"\n\t ",tlen
);
1078 printf("\n\t nexthop: ");
1080 switch(af
<<8 | safi
) {
1081 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1082 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1083 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1084 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1085 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1086 if (tlen
< (int)sizeof(struct in_addr
)) {
1087 printf("invalid len");
1090 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1091 printf("%s",getname(tptr
));
1092 tlen
-= sizeof(struct in_addr
);
1093 tptr
+= sizeof(struct in_addr
);
1096 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1097 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1098 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1099 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1100 printf("invalid len");
1103 TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1104 printf("RD: %s, %s",
1105 bgp_vpn_rd_print(tptr
),
1106 getname(tptr
+BGP_VPN_RD_LEN
));
1107 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1108 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1112 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1113 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1114 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1115 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1116 case (AFNUM_INET6
<<8 | SAFNUM_RT_ROUTING_INFO
):
1117 if (tlen
< (int)sizeof(struct in6_addr
)) {
1118 printf("invalid len");
1121 TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1122 printf("%s", getname6(tptr
));
1123 tlen
-= sizeof(struct in6_addr
);
1124 tptr
+= sizeof(struct in6_addr
);
1127 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1128 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1129 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1130 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1131 printf("invalid len");
1134 TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1135 printf("RD: %s, %s",
1136 bgp_vpn_rd_print(tptr
),
1137 getname6(tptr
+BGP_VPN_RD_LEN
));
1138 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1139 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1143 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1144 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1145 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1146 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1147 if (tlen
< (int)sizeof(struct in_addr
)) {
1148 printf("invalid len");
1151 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1152 printf("%s", getname(tptr
));
1153 tlen
-= (sizeof(struct in_addr
));
1154 tptr
+= (sizeof(struct in_addr
));
1157 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1158 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1159 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1160 TCHECK2(tptr
[0], tlen
);
1161 printf("%s",isonsap_string(tptr
,tlen
));
1166 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1167 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1168 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1169 if (tlen
< BGP_VPN_RD_LEN
+1) {
1170 printf("invalid len");
1173 TCHECK2(tptr
[0], tlen
);
1174 printf("RD: %s, %s",
1175 bgp_vpn_rd_print(tptr
),
1176 isonsap_string(tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
));
1177 /* rfc986 mapped IPv4 address ? */
1178 if (EXTRACT_32BITS(tptr
+BGP_VPN_RD_LEN
) == 0x47000601)
1179 printf(" = %s", getname(tptr
+BGP_VPN_RD_LEN
+4));
1181 /* rfc1888 mapped IPv6 address ? */
1182 else if (EXTRACT_24BITS(tptr
+BGP_VPN_RD_LEN
) == 0x350000)
1183 printf(" = %s", getname6(tptr
+BGP_VPN_RD_LEN
+3));
1190 TCHECK2(tptr
[0], tlen
);
1191 printf("no AFI %u/SAFI %u decoder",af
,safi
);
1193 print_unknown_data(tptr
,"\n\t ",tlen
);
1201 printf(", nh-length: %u", nhlen
);
1209 printf("\n\t %u SNPA", snpa
);
1210 for (/*nothing*/; snpa
> 0; snpa
--) {
1212 printf("\n\t %d bytes", tptr
[0]);
1213 tptr
+= tptr
[0] + 1;
1216 printf(", no SNPA");
1219 while (len
- (tptr
- pptr
) > 0) {
1220 switch (af
<<8 | safi
) {
1221 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1222 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1223 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1224 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1226 printf("\n\t (illegal prefix length)");
1227 else if (advance
== -2)
1230 printf("\n\t %s", buf
);
1232 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1233 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1235 printf("\n\t (illegal prefix length)");
1236 else if (advance
== -2)
1239 printf("\n\t %s", buf
);
1241 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1242 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1243 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1244 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1246 printf("\n\t (illegal prefix length)");
1247 else if (advance
== -2)
1250 printf("\n\t %s", buf
);
1252 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1253 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1255 printf("\n\t (illegal prefix length)");
1256 else if (advance
== -2)
1259 printf("\n\t %s", buf
);
1262 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1263 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1264 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1265 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1267 printf("\n\t (illegal prefix length)");
1268 else if (advance
== -2)
1271 printf("\n\t %s", buf
);
1273 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1274 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1276 printf("\n\t (illegal prefix length)");
1277 else if (advance
== -2)
1280 printf("\n\t %s", buf
);
1282 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1283 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1284 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1285 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1287 printf("\n\t (illegal prefix length)");
1288 else if (advance
== -2)
1291 printf("\n\t %s", buf
);
1293 case (AFNUM_INET6
<<8 | SAFNUM_RT_ROUTING_INFO
):
1294 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1296 printf("\n\t (illegal prefix length)");
1297 else if (advance
== -2)
1300 printf("\n\t %s", buf
);
1303 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1304 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1305 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1306 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1307 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1309 printf("\n\t (illegal length)");
1310 else if (advance
== -2)
1313 printf("\n\t %s", buf
);
1315 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1316 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1317 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1318 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1320 printf("\n\t (illegal prefix length)");
1321 else if (advance
== -2)
1324 printf("\n\t %s", buf
);
1326 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1327 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1328 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1329 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1331 printf("\n\t (illegal prefix length)");
1332 else if (advance
== -2)
1335 printf("\n\t %s", buf
);
1338 TCHECK2(*tptr
,tlen
);
1339 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1341 print_unknown_data(tptr
,"\n\t ",tlen
);
1353 case BGPTYPE_MP_UNREACH_NLRI
:
1354 TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1355 af
= EXTRACT_16BITS(tptr
);
1358 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1359 tok2strbuf(bgp_afi_values
, "Unknown AFI", af
,
1360 tokbuf
, sizeof(tokbuf
)),
1362 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1363 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1364 tokbuf
, sizeof(tokbuf
)),
1367 if (len
== BGP_MP_NLRI_MINSIZE
)
1368 printf("\n\t End-of-Rib Marker (empty NLRI)");
1372 while (len
- (tptr
- pptr
) > 0) {
1373 switch (af
<<8 | safi
) {
1374 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1375 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1376 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1377 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1379 printf("\n\t (illegal prefix length)");
1380 else if (advance
== -2)
1383 printf("\n\t %s", buf
);
1385 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1386 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1388 printf("\n\t (illegal prefix length)");
1389 else if (advance
== -2)
1392 printf("\n\t %s", buf
);
1394 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1395 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1396 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1397 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1399 printf("\n\t (illegal prefix length)");
1400 else if (advance
== -2)
1403 printf("\n\t %s", buf
);
1406 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1407 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1408 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1409 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1411 printf("\n\t (illegal prefix length)");
1412 else if (advance
== -2)
1415 printf("\n\t %s", buf
);
1417 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1418 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1420 printf("\n\t (illegal prefix length)");
1421 else if (advance
== -2)
1424 printf("\n\t %s", buf
);
1426 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1427 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1428 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1429 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1431 printf("\n\t (illegal prefix length)");
1432 else if (advance
== -2)
1435 printf("\n\t %s", buf
);
1438 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1439 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1440 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1441 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1442 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1444 printf("\n\t (illegal length)");
1445 else if (advance
== -2)
1448 printf("\n\t %s", buf
);
1450 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1451 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1452 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1453 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1455 printf("\n\t (illegal prefix length)");
1456 else if (advance
== -2)
1459 printf("\n\t %s", buf
);
1461 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1462 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1463 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1464 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1466 printf("\n\t (illegal prefix length)");
1467 else if (advance
== -2)
1470 printf("\n\t %s", buf
);
1473 TCHECK2(*(tptr
-3),tlen
);
1474 printf("no AFI %u / SAFI %u decoder",af
,safi
);
1476 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1486 case BGPTYPE_EXTD_COMMUNITIES
:
1488 printf("invalid len");
1492 u_int16_t extd_comm
;
1494 TCHECK2(tptr
[0], 2);
1495 extd_comm
=EXTRACT_16BITS(tptr
);
1497 printf("\n\t %s (0x%04x), Flags [%s]",
1498 tok2strbuf(bgp_extd_comm_subtype_values
,
1499 "unknown extd community typecode",
1500 extd_comm
, tokbuf
, sizeof(tokbuf
)),
1502 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1504 TCHECK2(*(tptr
+2), 6);
1506 case BGP_EXT_COM_RT_0
:
1507 case BGP_EXT_COM_RO_0
:
1509 EXTRACT_16BITS(tptr
+2),
1512 case BGP_EXT_COM_RT_1
:
1513 case BGP_EXT_COM_RO_1
:
1516 EXTRACT_16BITS(tptr
+6));
1518 case BGP_EXT_COM_RT_2
:
1519 case BGP_EXT_COM_RO_2
:
1521 EXTRACT_32BITS(tptr
+2),
1522 EXTRACT_16BITS(tptr
+6));
1524 case BGP_EXT_COM_LINKBAND
:
1525 bw
.i
= EXTRACT_32BITS(tptr
+2);
1526 printf(": bandwidth: %.3f Mbps",
1529 case BGP_EXT_COM_CISCO_MCAST
:
1530 printf(": AS %u, group %s",
1531 EXTRACT_16BITS(tptr
+2),
1534 case BGP_EXT_COM_VPN_ORIGIN
:
1535 case BGP_EXT_COM_VPN_ORIGIN2
:
1536 case BGP_EXT_COM_VPN_ORIGIN3
:
1537 case BGP_EXT_COM_VPN_ORIGIN4
:
1538 case BGP_EXT_COM_OSPF_RID
:
1539 case BGP_EXT_COM_OSPF_RID2
:
1540 printf("%s", getname(tptr
+2));
1542 case BGP_EXT_COM_OSPF_RTYPE
:
1543 case BGP_EXT_COM_OSPF_RTYPE2
:
1544 printf(": area:%s, router-type:%s, metric-type:%s%s",
1546 tok2strbuf(bgp_extd_comm_ospf_rtype_values
,
1549 tokbuf
, sizeof(tokbuf
)),
1550 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1551 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1553 case BGP_EXT_COM_L2INFO
:
1554 printf(": %s Control Flags [0x%02x]:MTU %u",
1555 tok2strbuf(l2vpn_encaps_values
,
1558 tokbuf
, sizeof(tokbuf
)),
1560 EXTRACT_16BITS(tptr
+4));
1564 print_unknown_data(tptr
,"\n\t ",8);
1572 case BGPTYPE_ATTR_SET
:
1573 TCHECK2(tptr
[0], 4);
1574 printf("\n\t Origin AS: %u", EXTRACT_32BITS(tptr
));
1580 struct bgp_attr bgpa
;
1582 TCHECK2(tptr
[0], sizeof(bgpa
));
1583 memcpy(&bgpa
, tptr
, sizeof(bgpa
));
1584 alen
= bgp_attr_len(&bgpa
);
1585 tptr
+= bgp_attr_off(&bgpa
);
1586 len
-= bgp_attr_off(&bgpa
);
1588 printf("\n\t %s (%u), length: %u",
1589 tok2strbuf(bgp_attr_values
,
1590 "Unknown Attribute", bgpa
.bgpa_type
,
1591 tokbuf
, sizeof(tokbuf
)),
1595 if (bgpa
.bgpa_flags
) {
1596 printf(", Flags [%s%s%s%s",
1597 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1598 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1599 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1600 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1601 if (bgpa
.bgpa_flags
& 0xf)
1602 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1605 /* FIXME check for recursion */
1606 if (!bgp_attr_print(&bgpa
, tptr
, alen
))
1616 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1618 print_unknown_data(pptr
,"\n\t ",len
);
1621 if (vflag
> 1 && len
) { /* omit zero length attributes*/
1623 print_unknown_data(pptr
,"\n\t ",len
);
1632 bgp_open_print(const u_char
*dat
, int length
)
1634 struct bgp_open bgpo
;
1635 struct bgp_opt bgpopt
;
1637 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
1638 char tokbuf
[TOKBUFSIZE
];
1639 char tokbuf2
[TOKBUFSIZE
];
1641 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1642 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1644 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1645 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1646 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1647 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1648 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1650 /* some little sanity checking */
1651 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
1655 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1659 while (i
< bgpo
.bgpo_optlen
) {
1660 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1661 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1662 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1663 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1667 printf("\n\t Option %s (%u), length: %u",
1668 tok2strbuf(bgp_opt_values
,"Unknown",
1670 tokbuf
, sizeof(tokbuf
)),
1674 /* now lets decode the options we know*/
1675 switch(bgpopt
.bgpopt_type
) {
1677 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1678 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1680 printf("\n\t %s (%u), length: %u",
1681 tok2strbuf(bgp_capcode_values
, "Unknown",
1682 cap_type
, tokbuf
, sizeof(tokbuf
)),
1686 case BGP_CAPCODE_MP
:
1687 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1688 tok2strbuf(bgp_afi_values
, "Unknown",
1689 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1690 tokbuf
, sizeof(tokbuf
)),
1691 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1692 tok2strbuf(bgp_safi_values
, "Unknown",
1693 opt
[i
+BGP_OPT_SIZE
+5],
1694 tokbuf
, sizeof(tokbuf
)),
1695 opt
[i
+BGP_OPT_SIZE
+5]);
1697 case BGP_CAPCODE_RESTART
:
1698 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
1699 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
1700 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
1703 while(tcap_len
>=4) {
1704 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1705 tok2strbuf(bgp_afi_values
,"Unknown",
1706 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1707 tokbuf
, sizeof(tokbuf
)),
1708 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1709 tok2strbuf(bgp_safi_values
,"Unknown",
1710 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1711 tokbuf2
, sizeof(tokbuf2
)),
1712 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1713 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
1718 case BGP_CAPCODE_RR
:
1719 case BGP_CAPCODE_RR_CISCO
:
1722 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
1723 printf("\n\t\tno decoder for Capability %u",
1726 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1730 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
1731 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1736 printf("\n\t no decoder for option %u",
1737 bgpopt
.bgpopt_type
);
1741 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1749 bgp_update_print(const u_char
*dat
, int length
)
1752 struct bgp_attr bgpa
;
1756 char tokbuf
[TOKBUFSIZE
];
1758 TCHECK2(dat
[0], BGP_SIZE
);
1759 memcpy(&bgp
, dat
, BGP_SIZE
);
1760 p
= dat
+ BGP_SIZE
; /*XXX*/
1762 /* Unfeasible routes */
1763 len
= EXTRACT_16BITS(p
);
1766 * Without keeping state from the original NLRI message,
1767 * it's not possible to tell if this a v4 or v6 route,
1768 * so only try to decode it if we're not v6 enabled.
1771 printf("\n\t Withdrawn routes: %d bytes", len
);
1773 char buf
[MAXHOSTNAMELEN
+ 100];
1779 printf("\n\t Withdrawn routes:");
1781 while(i
< 2 + len
) {
1782 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1784 printf("\n\t (illegal prefix length)");
1786 } else if (wpfx
== -2)
1790 printf("\n\t %s", buf
);
1798 len
= EXTRACT_16BITS(p
);
1800 if (len
== 0 && length
== BGP_UPDATE_MINSIZE
) {
1801 printf("\n\t End-of-Rib Marker (empty NLRI)");
1806 /* do something more useful!*/
1808 while (i
< 2 + len
) {
1811 TCHECK2(p
[i
], sizeof(bgpa
));
1812 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
1813 alen
= bgp_attr_len(&bgpa
);
1814 aoff
= bgp_attr_off(&bgpa
);
1816 printf("\n\t %s (%u), length: %u",
1817 tok2strbuf(bgp_attr_values
, "Unknown Attribute",
1819 tokbuf
, sizeof(tokbuf
)),
1823 if (bgpa
.bgpa_flags
) {
1824 printf(", Flags [%s%s%s%s",
1825 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1826 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1827 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1828 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1829 if (bgpa
.bgpa_flags
& 0xf)
1830 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1833 if (!bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
))
1840 if (dat
+ length
> p
) {
1841 printf("\n\t Updated routes:");
1842 while (dat
+ length
> p
) {
1843 char buf
[MAXHOSTNAMELEN
+ 100];
1844 i
= decode_prefix4(p
, buf
, sizeof(buf
));
1846 printf("\n\t (illegal prefix length)");
1851 printf("\n\t %s", buf
);
1862 bgp_notification_print(const u_char
*dat
, int length
)
1864 struct bgp_notification bgpn
;
1866 char tokbuf
[TOKBUFSIZE
];
1867 char tokbuf2
[TOKBUFSIZE
];
1869 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1870 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1872 /* some little sanity checking */
1873 if (length
<BGP_NOTIFICATION_SIZE
)
1877 tok2strbuf(bgp_notify_major_values
, "Unknown Error",
1878 bgpn
.bgpn_major
, tokbuf
, sizeof(tokbuf
)),
1881 switch (bgpn
.bgpn_major
) {
1883 case BGP_NOTIFY_MAJOR_MSG
:
1884 printf(", subcode %s (%u)",
1885 tok2strbuf(bgp_notify_minor_msg_values
, "Unknown",
1886 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
1889 case BGP_NOTIFY_MAJOR_OPEN
:
1890 printf(", subcode %s (%u)",
1891 tok2strbuf(bgp_notify_minor_open_values
, "Unknown",
1892 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
1895 case BGP_NOTIFY_MAJOR_UPDATE
:
1896 printf(", subcode %s (%u)",
1897 tok2strbuf(bgp_notify_minor_update_values
, "Unknown",
1898 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
1901 case BGP_NOTIFY_MAJOR_CAP
:
1902 printf(" subcode %s (%u)",
1903 tok2strbuf(bgp_notify_minor_cap_values
, "Unknown",
1904 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
1906 case BGP_NOTIFY_MAJOR_CEASE
:
1907 printf(", subcode %s (%u)",
1908 tok2strbuf(bgp_notify_minor_cease_values
, "Unknown",
1909 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
1912 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
1913 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
1915 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
1916 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
1918 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
1919 tok2strbuf(bgp_afi_values
, "Unknown",
1920 EXTRACT_16BITS(tptr
), tokbuf
, sizeof(tokbuf
)),
1921 EXTRACT_16BITS(tptr
),
1922 tok2strbuf(bgp_safi_values
, "Unknown", *(tptr
+2),
1923 tokbuf2
, sizeof(tokbuf
)),
1925 EXTRACT_32BITS(tptr
+3));
1938 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
1940 const struct bgp_route_refresh
*bgp_route_refresh_header
;
1941 char tokbuf
[TOKBUFSIZE
];
1942 char tokbuf2
[TOKBUFSIZE
];
1944 TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
1946 /* some little sanity checking */
1947 if (len
<BGP_ROUTE_REFRESH_SIZE
)
1950 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
1952 printf("\n\t AFI %s (%u), SAFI %s (%u)",
1953 tok2strbuf(bgp_afi_values
,"Unknown",
1954 /* this stinks but the compiler pads the structure
1956 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1957 tokbuf
, sizeof(tokbuf
)),
1958 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
1959 tok2strbuf(bgp_safi_values
,"Unknown",
1960 bgp_route_refresh_header
->safi
,
1961 tokbuf2
, sizeof(tokbuf2
)),
1962 bgp_route_refresh_header
->safi
);
1965 TCHECK2(*pptr
, len
);
1966 print_unknown_data(pptr
,"\n\t ", len
);
1975 bgp_header_print(const u_char
*dat
, int length
)
1978 char tokbuf
[TOKBUFSIZE
];
1980 TCHECK2(dat
[0], BGP_SIZE
);
1981 memcpy(&bgp
, dat
, BGP_SIZE
);
1982 printf("\n\t%s Message (%u), length: %u",
1983 tok2strbuf(bgp_msg_values
, "Unknown", bgp
.bgp_type
,
1984 tokbuf
, sizeof(tokbuf
)),
1988 switch (bgp
.bgp_type
) {
1990 bgp_open_print(dat
, length
);
1993 bgp_update_print(dat
, length
);
1995 case BGP_NOTIFICATION
:
1996 bgp_notification_print(dat
, length
);
2000 case BGP_ROUTE_REFRESH
:
2001 bgp_route_refresh_print(dat
, length
);
2004 /* we have no decoder for the BGP message */
2005 TCHECK2(*dat
, length
);
2006 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
2007 print_unknown_data(dat
,"\n\t ",length
);
2017 bgp_print(const u_char
*dat
, int length
)
2021 const u_char
*start
;
2022 const u_char marker
[] = {
2023 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2024 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2028 char tokbuf
[TOKBUFSIZE
];
2031 if (snapend
< dat
+ length
)
2034 printf(": BGP, length: %u",length
);
2036 if (vflag
< 1) /* lets be less chatty */
2042 if (!TTEST2(p
[0], 1))
2049 if (!TTEST2(p
[0], sizeof(marker
)))
2051 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2056 /* found BGP header */
2057 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2058 memcpy(&bgp
, p
, BGP_SIZE
);
2063 hlen
= ntohs(bgp
.bgp_len
);
2064 if (hlen
< BGP_SIZE
) {
2065 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
2070 if (TTEST2(p
[0], hlen
)) {
2071 if (!bgp_header_print(p
, hlen
))
2076 printf("\n[|BGP %s]",
2077 tok2strbuf(bgp_msg_values
,
2078 "Unknown Message Type",
2080 tokbuf
, sizeof(tokbuf
)));