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.105 2007-05-16 14:02:51 hannes Exp $";
42 #include <tcpdump-stdinc.h>
47 #include "interface.h"
48 #include "decode_prefix.h"
49 #include "addrtoname.h"
56 u_int8_t bgp_marker
[16];
60 #define BGP_SIZE 19 /* unaligned */
64 #define BGP_NOTIFICATION 3
65 #define BGP_KEEPALIVE 4
66 #define BGP_ROUTE_REFRESH 5
68 static struct tok bgp_msg_values
[] = {
70 { BGP_UPDATE
, "Update"},
71 { BGP_NOTIFICATION
, "Notification"},
72 { BGP_KEEPALIVE
, "Keepalive"},
73 { BGP_ROUTE_REFRESH
, "Route Refresh"},
78 u_int8_t bgpo_marker
[16];
81 u_int8_t bgpo_version
;
83 u_int16_t bgpo_holdtime
;
86 /* options should follow */
88 #define BGP_OPEN_SIZE 29 /* unaligned */
95 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
97 #define BGP_UPDATE_MINSIZE 23
99 struct bgp_notification
{
100 u_int8_t bgpn_marker
[16];
106 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
108 struct bgp_route_refresh
{
109 u_int8_t bgp_marker
[16];
112 u_int8_t afi
[2]; /* the compiler messes this structure up */
113 u_int8_t res
; /* when doing misaligned sequences of int8 and int16 */
114 u_int8_t safi
; /* afi should be int16 - so we have to access it using */
115 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
116 #define BGP_ROUTE_REFRESH_SIZE 23
125 #define bgp_attr_len(p) \
126 (((p)->bgpa_flags & 0x10) ? \
127 EXTRACT_16BITS(&(p)->bgpa_len.elen) : (p)->bgpa_len.len)
128 #define bgp_attr_off(p) \
129 (((p)->bgpa_flags & 0x10) ? 4 : 3)
132 #define BGPTYPE_ORIGIN 1
133 #define BGPTYPE_AS_PATH 2
134 #define BGPTYPE_NEXT_HOP 3
135 #define BGPTYPE_MULTI_EXIT_DISC 4
136 #define BGPTYPE_LOCAL_PREF 5
137 #define BGPTYPE_ATOMIC_AGGREGATE 6
138 #define BGPTYPE_AGGREGATOR 7
139 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
140 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
141 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
142 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
143 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
144 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
145 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
146 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
147 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
148 #define BGPTYPE_PMSI_TUNNEL 17 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
149 #define BGPTYPE_ATTR_SET 128 /* draft-marques-ppvpn-ibgp */
151 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
153 static struct tok bgp_attr_values
[] = {
154 { BGPTYPE_ORIGIN
, "Origin"},
155 { BGPTYPE_AS_PATH
, "AS Path"},
156 { BGPTYPE_NEXT_HOP
, "Next Hop"},
157 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
158 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
159 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
160 { BGPTYPE_AGGREGATOR
, "Aggregator"},
161 { BGPTYPE_COMMUNITIES
, "Community"},
162 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
163 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
164 { BGPTYPE_DPA
, "DPA"},
165 { BGPTYPE_ADVERTISERS
, "Advertisers"},
166 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
167 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
168 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
169 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
170 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
171 { BGPTYPE_ATTR_SET
, "Attribute Set"},
172 { 255, "Reserved for development"},
177 #define BGP_AS_SEQUENCE 2
178 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
179 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
181 static struct tok bgp_as_path_segment_open_values
[] = {
182 { BGP_AS_SEQUENCE
, ""},
184 { BGP_CONFED_AS_SEQUENCE
, "( "},
185 { BGP_CONFED_AS_SET
, "({ "},
189 static struct tok bgp_as_path_segment_close_values
[] = {
190 { BGP_AS_SEQUENCE
, ""},
192 { BGP_CONFED_AS_SEQUENCE
, ")"},
193 { BGP_CONFED_AS_SET
, "})"},
197 #define BGP_OPT_AUTH 1
198 #define BGP_OPT_CAP 2
201 static struct tok bgp_opt_values
[] = {
202 { BGP_OPT_AUTH
, "Authentication Information"},
203 { BGP_OPT_CAP
, "Capabilities Advertisement"},
207 #define BGP_CAPCODE_MP 1
208 #define BGP_CAPCODE_RR 2
209 #define BGP_CAPCODE_ORF 3 /* XXX */
210 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
211 #define BGP_CAPCODE_AS_NEW 65 /* XXX */
212 #define BGP_CAPCODE_DYN_CAP 67 /* XXX */
213 #define BGP_CAPCODE_RR_CISCO 128
215 static struct tok bgp_capcode_values
[] = {
216 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
217 { BGP_CAPCODE_RR
, "Route Refresh"},
218 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
219 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
220 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
221 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
222 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
226 #define BGP_NOTIFY_MAJOR_MSG 1
227 #define BGP_NOTIFY_MAJOR_OPEN 2
228 #define BGP_NOTIFY_MAJOR_UPDATE 3
229 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
230 #define BGP_NOTIFY_MAJOR_FSM 5
231 #define BGP_NOTIFY_MAJOR_CEASE 6
232 #define BGP_NOTIFY_MAJOR_CAP 7
234 static struct tok bgp_notify_major_values
[] = {
235 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
236 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
237 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
238 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
239 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
240 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
241 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
245 /* draft-ietf-idr-cease-subcode-02 */
246 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
247 static struct tok bgp_notify_minor_cease_values
[] = {
248 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
249 { 2, "Administratively Shutdown"},
250 { 3, "Peer Unconfigured"},
251 { 4, "Administratively Reset"},
252 { 5, "Connection Rejected"},
253 { 6, "Other Configuration Change"},
254 { 7, "Connection Collision Resolution"},
258 static struct tok bgp_notify_minor_msg_values
[] = {
259 { 1, "Connection Not Synchronized"},
260 { 2, "Bad Message Length"},
261 { 3, "Bad Message Type"},
265 static struct tok bgp_notify_minor_open_values
[] = {
266 { 1, "Unsupported Version Number"},
268 { 3, "Bad BGP Identifier"},
269 { 4, "Unsupported Optional Parameter"},
270 { 5, "Authentication Failure"},
271 { 6, "Unacceptable Hold Time"},
272 { 7, "Capability Message Error"},
276 static struct tok bgp_notify_minor_update_values
[] = {
277 { 1, "Malformed Attribute List"},
278 { 2, "Unrecognized Well-known Attribute"},
279 { 3, "Missing Well-known Attribute"},
280 { 4, "Attribute Flags Error"},
281 { 5, "Attribute Length Error"},
282 { 6, "Invalid ORIGIN Attribute"},
283 { 7, "AS Routing Loop"},
284 { 8, "Invalid NEXT_HOP Attribute"},
285 { 9, "Optional Attribute Error"},
286 { 10, "Invalid Network Field"},
287 { 11, "Malformed AS_PATH"},
291 static struct tok bgp_notify_minor_cap_values
[] = {
292 { 1, "Invalid Action Value" },
293 { 2, "Invalid Capability Length" },
294 { 3, "Malformed Capability Value" },
295 { 4, "Unsupported Capability Code" },
299 static struct tok bgp_origin_values
[] = {
306 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
307 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
308 #define BGP_PMSI_TUNNEL_PIM_SSM 3
309 #define BGP_PMSI_TUNNEL_PIM_SM 4
310 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
311 #define BGP_PMSI_TUNNEL_INGRESS 6
312 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
314 static struct tok bgp_pmsi_tunnel_values
[] = {
315 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
316 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
317 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
318 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
319 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
320 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
321 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
325 static struct tok bgp_pmsi_flag_values
[] = {
326 { 0x01, "Leaf Information required"},
331 /* Subsequent address family identifier, RFC2283 section 7 */
333 #define SAFNUM_UNICAST 1
334 #define SAFNUM_MULTICAST 2
335 #define SAFNUM_UNIMULTICAST 3
336 /* labeled BGP RFC3107 */
337 #define SAFNUM_LABUNICAST 4
338 #define SAFNUM_TUNNEL 64 /* XXX */
339 #define SAFNUM_VPLS 65 /* XXX */
340 #define SAFNUM_MDT 66 /* XXX */
341 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
342 #define SAFNUM_VPNUNICAST 128
343 #define SAFNUM_VPNMULTICAST 129
344 #define SAFNUM_VPNUNIMULTICAST 130
345 /* draft-marques-ppvpn-rt-constrain-01.txt */
346 #define SAFNUM_RT_ROUTING_INFO 132
347 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
348 #define SAFNUM_MULTICAST_VPN 139
350 #define BGP_VPN_RD_LEN 8
352 static struct tok bgp_safi_values
[] = {
353 { SAFNUM_RES
, "Reserved"},
354 { SAFNUM_UNICAST
, "Unicast"},
355 { SAFNUM_MULTICAST
, "Multicast"},
356 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
357 { SAFNUM_LABUNICAST
, "labeled Unicast"},
358 { SAFNUM_TUNNEL
, "Tunnel"},
359 { SAFNUM_VPLS
, "VPLS"},
360 { SAFNUM_MDT
, "MDT"},
361 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
362 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
363 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
364 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
365 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
369 /* well-known community */
370 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
371 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
372 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
374 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
375 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
376 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
377 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
378 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
379 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
380 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
381 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
382 /* rfc2547 bgp-mpls-vpns */
383 #define BGP_EXT_COM_CISCO_MCAST 0x0009 /* cisco proprietary */
385 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
386 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
387 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
388 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
390 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
391 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
393 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
394 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
396 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
398 #define BGP_EXT_COM_SOURCE_AS 0x0010 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
399 #define BGP_EXT_COM_VRF_RT_IMP 0x0108 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
401 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
402 #define BGP_EXT_COM_EIGRP_GEN 0x8800
403 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
404 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
405 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
406 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
407 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
409 static struct tok bgp_extd_comm_flag_values
[] = {
410 { 0x8000, "vendor-specific"},
411 { 0x4000, "non-transitive"},
415 static struct tok bgp_extd_comm_subtype_values
[] = {
416 { BGP_EXT_COM_RT_0
, "target"},
417 { BGP_EXT_COM_RT_1
, "target"},
418 { BGP_EXT_COM_RT_2
, "target"},
419 { BGP_EXT_COM_RO_0
, "origin"},
420 { BGP_EXT_COM_RO_1
, "origin"},
421 { BGP_EXT_COM_RO_2
, "origin"},
422 { BGP_EXT_COM_LINKBAND
, "link-BW"},
423 { BGP_EXT_COM_CISCO_MCAST
, "mdt-group"},
424 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
425 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
426 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
427 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
428 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
429 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
430 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
431 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
432 { BGP_EXT_COM_L2INFO
, "layer2-info"},
433 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
434 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
435 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
436 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
437 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
438 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
439 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
440 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
444 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
445 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
446 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
447 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
448 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
449 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
450 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
451 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
453 static struct tok bgp_extd_comm_ospf_rtype_values
[] = {
454 { BGP_OSPF_RTYPE_RTR
, "Router" },
455 { BGP_OSPF_RTYPE_NET
, "Network" },
456 { BGP_OSPF_RTYPE_SUM
, "Summary" },
457 { BGP_OSPF_RTYPE_EXT
, "External" },
458 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
459 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
464 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
474 memset(&addr
, 0, sizeof(addr
));
475 TCHECK2(pptr
[1], (plen
+ 7) / 8);
476 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
478 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
479 ((0xff00 >> (plen
% 8)) & 0xff);
481 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
482 return 1 + (plen
+ 7) / 8;
489 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
495 plen
= pptr
[0]; /* get prefix length */
497 /* this is one of the weirdnesses of rfc3107
498 the label length (actually the label + COS bits)
499 is added to the prefix length;
500 we also do only read out just one label -
501 there is no real application for advertisement of
502 stacked labels in a a single BGP message
508 plen
-=24; /* adjust prefixlen - labellength */
513 memset(&addr
, 0, sizeof(addr
));
514 TCHECK2(pptr
[4], (plen
+ 7) / 8);
515 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
517 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
518 ((0xff00 >> (plen
% 8)) & 0xff);
520 /* the label may get offsetted by 4 bits so lets shift it right */
521 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
522 getname((u_char
*)&addr
),
524 EXTRACT_24BITS(pptr
+1)>>4,
525 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
527 return 4 + (plen
+ 7) / 8;
533 /* RDs and RTs share the same semantics
534 * we use bgp_vpn_rd_print for
535 * printing route targets inside a NLRI */
537 bgp_vpn_rd_print (const u_char
*pptr
) {
539 /* allocate space for the largest possible string */
540 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
543 /* ok lets load the RD format */
544 switch (EXTRACT_16BITS(pptr
)) {
546 /* AS:IP-address fmt*/
548 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u.%u.%u.%u",
549 EXTRACT_16BITS(pptr
+2), *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
551 /* IP-address:AS fmt*/
554 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
555 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
558 /* 4-byte-AS:number fmt*/
560 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (%u.%u.%u.%u:%u)",
561 EXTRACT_32BITS(pptr
+2), EXTRACT_16BITS(pptr
+6),
562 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
565 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
574 decode_rt_routing_info(const u_char
*pptr
, char *buf
, u_int buflen
)
576 u_int8_t route_target
[8];
580 plen
= pptr
[0]; /* get prefix length */
583 return 1; /* default route target */
588 plen
-=32; /* adjust prefix length */
593 memset(&route_target
, 0, sizeof(route_target
));
594 TCHECK2(pptr
[1], (plen
+ 7) / 8);
595 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
597 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
598 ((0xff00 >> (plen
% 8)) & 0xff);
600 snprintf(buf
, buflen
, "origin AS: %u, route target %s",
601 EXTRACT_32BITS(pptr
+1),
602 bgp_vpn_rd_print((u_char
*)&route_target
));
604 return 5 + (plen
+ 7) / 8;
611 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
617 plen
= pptr
[0]; /* get prefix length */
622 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
627 memset(&addr
, 0, sizeof(addr
));
628 TCHECK2(pptr
[12], (plen
+ 7) / 8);
629 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
631 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
632 ((0xff00 >> (plen
% 8)) & 0xff);
634 /* the label may get offsetted by 4 bits so lets shift it right */
635 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
636 bgp_vpn_rd_print(pptr
+4),
637 getname((u_char
*)&addr
),
639 EXTRACT_24BITS(pptr
+1)>>4,
640 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
642 return 12 + (plen
+ 7) / 8;
648 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
649 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
650 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
651 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
652 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
653 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
654 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
656 static struct tok bgp_multicast_vpn_route_type_values
[] = {
657 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
658 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
659 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
660 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
661 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
662 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
663 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
667 decode_multicast_vpn(const u_char
*pptr
, char *buf
, u_int buflen
)
669 u_int8_t route_type
, route_length
;
672 route_type
= *pptr
++;
673 route_length
= *pptr
++;
675 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
676 tok2str(bgp_multicast_vpn_route_type_values
, "Unknown", route_type
),
677 route_type
, route_length
);
682 * no per route-type printing yet.
684 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
685 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
686 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
687 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
688 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
689 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
:
690 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
695 return route_length
+ 2;
702 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
704 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
707 plen
=EXTRACT_16BITS(pptr
);
711 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
712 bgp_vpn_rd_print(pptr
),
713 EXTRACT_16BITS(pptr
+8),
714 EXTRACT_16BITS(pptr
+10),
715 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
719 /* ok now the variable part - lets read out TLVs*/
725 tlv_len
=EXTRACT_16BITS(pptr
);
731 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
734 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
737 strlen
+=snprintf(buf
+strlen
,buflen
-strlen
, "%02x",*pptr
++);
742 snprintf(buf
+strlen
,buflen
-strlen
, "\n\t\tunknown TLV #%u, length: %u",
747 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it tright */
757 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
759 struct in6_addr addr
;
767 memset(&addr
, 0, sizeof(addr
));
768 TCHECK2(pd
[1], (plen
+ 7) / 8);
769 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
771 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
772 ((0xff00 >> (plen
% 8)) & 0xff);
774 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
775 return 1 + (plen
+ 7) / 8;
782 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
784 struct in6_addr addr
;
788 plen
= pptr
[0]; /* get prefix length */
793 plen
-=24; /* adjust prefixlen - labellength */
798 memset(&addr
, 0, sizeof(addr
));
799 TCHECK2(pptr
[4], (plen
+ 7) / 8);
800 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
802 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
803 ((0xff00 >> (plen
% 8)) & 0xff);
805 /* the label may get offsetted by 4 bits so lets shift it right */
806 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
807 getname6((u_char
*)&addr
),
809 EXTRACT_24BITS(pptr
+1)>>4,
810 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
812 return 4 + (plen
+ 7) / 8;
819 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
821 struct in6_addr addr
;
825 plen
= pptr
[0]; /* get prefix length */
830 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
835 memset(&addr
, 0, sizeof(addr
));
836 TCHECK2(pptr
[12], (plen
+ 7) / 8);
837 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
839 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
840 ((0xff00 >> (plen
% 8)) & 0xff);
842 /* the label may get offsetted by 4 bits so lets shift it right */
843 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
844 bgp_vpn_rd_print(pptr
+4),
845 getname6((u_char
*)&addr
),
847 EXTRACT_24BITS(pptr
+1)>>4,
848 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
850 return 12 + (plen
+ 7) / 8;
858 decode_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
864 plen
= pptr
[0]; /* get prefix length */
869 memset(&addr
, 0, sizeof(addr
));
870 TCHECK2(pptr
[4], (plen
+ 7) / 8);
871 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
873 addr
[(plen
+ 7) / 8 - 1] &=
874 ((0xff00 >> (plen
% 8)) & 0xff);
876 snprintf(buf
, buflen
, "%s/%d",
877 isonsap_string(addr
,(plen
+ 7) / 8),
880 return 1 + (plen
+ 7) / 8;
887 decode_labeled_vpn_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
893 plen
= pptr
[0]; /* get prefix length */
898 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
903 memset(&addr
, 0, sizeof(addr
));
904 TCHECK2(pptr
[12], (plen
+ 7) / 8);
905 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
907 addr
[(plen
+ 7) / 8 - 1] &=
908 ((0xff00 >> (plen
% 8)) & 0xff);
910 /* the label may get offsetted by 4 bits so lets shift it right */
911 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
912 bgp_vpn_rd_print(pptr
+4),
913 isonsap_string(addr
,(plen
+ 7) / 8),
915 EXTRACT_24BITS(pptr
+1)>>4,
916 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
918 return 12 + (plen
+ 7) / 8;
925 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
929 u_int8_t safi
, snpa
, nhlen
;
930 union { /* copy buffer for bandwidth values */
937 char buf
[MAXHOSTNAMELEN
+ 100];
938 char tokbuf
[TOKBUFSIZE
];
943 switch (attr
->bgpa_type
) {
946 printf("invalid len");
949 printf("%s", tok2strbuf(bgp_origin_values
,
950 "Unknown Origin Typecode",
952 tokbuf
, sizeof(tokbuf
)));
956 case BGPTYPE_AS_PATH
:
958 printf("invalid len");
966 while (tptr
< pptr
+ len
) {
968 printf("%s", tok2strbuf(bgp_as_path_segment_open_values
,
970 tokbuf
, sizeof(tokbuf
)));
971 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
972 TCHECK2(tptr
[2 + i
], 2);
973 printf("%u ", EXTRACT_16BITS(&tptr
[2 + i
]));
976 printf("%s", tok2strbuf(bgp_as_path_segment_close_values
,
978 tokbuf
, sizeof(tokbuf
)));
980 tptr
+= 2 + tptr
[1] * 2;
983 case BGPTYPE_NEXT_HOP
:
985 printf("invalid len");
988 printf("%s", getname(tptr
));
991 case BGPTYPE_MULTI_EXIT_DISC
:
992 case BGPTYPE_LOCAL_PREF
:
994 printf("invalid len");
997 printf("%u", EXTRACT_32BITS(tptr
));
1000 case BGPTYPE_ATOMIC_AGGREGATE
:
1002 printf("invalid len");
1004 case BGPTYPE_AGGREGATOR
:
1006 printf("invalid len");
1009 TCHECK2(tptr
[0], 6);
1010 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
1013 case BGPTYPE_COMMUNITIES
:
1015 printf("invalid len");
1020 TCHECK2(tptr
[0], 4);
1021 comm
= EXTRACT_32BITS(tptr
);
1023 case BGP_COMMUNITY_NO_EXPORT
:
1024 printf(" NO_EXPORT");
1026 case BGP_COMMUNITY_NO_ADVERT
:
1027 printf(" NO_ADVERTISE");
1029 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1030 printf(" NO_EXPORT_SUBCONFED");
1034 (comm
>> 16) & 0xffff,
1036 (tlen
>4) ? ", " : "");
1043 case BGPTYPE_ORIGINATOR_ID
:
1045 printf("invalid len");
1048 TCHECK2(tptr
[0], 4);
1049 printf("%s",getname(tptr
));
1051 case BGPTYPE_CLUSTER_LIST
:
1053 printf("invalid len");
1057 TCHECK2(tptr
[0], 4);
1060 (tlen
>4) ? ", " : "");
1065 case BGPTYPE_MP_REACH_NLRI
:
1066 TCHECK2(tptr
[0], 3);
1067 af
= EXTRACT_16BITS(tptr
);
1070 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1071 tok2strbuf(af_values
, "Unknown AFI", af
,
1072 tokbuf
, sizeof(tokbuf
)),
1074 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1075 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1076 tokbuf
, sizeof(tokbuf
)),
1079 switch(af
<<8 | safi
) {
1080 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1081 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1082 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1083 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1084 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1085 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1086 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1087 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1088 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1090 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1091 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1092 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1093 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1094 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1095 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1096 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1098 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1099 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1100 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1101 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1102 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1103 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1104 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1105 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1106 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1107 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1110 TCHECK2(tptr
[0], tlen
);
1111 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1113 print_unknown_data(tptr
,"\n\t ",tlen
);
1126 printf("\n\t nexthop: ");
1128 switch(af
<<8 | safi
) {
1129 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1130 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1131 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1132 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1133 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1134 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1135 if (tlen
< (int)sizeof(struct in_addr
)) {
1136 printf("invalid len");
1139 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1140 printf("%s",getname(tptr
));
1141 tlen
-= sizeof(struct in_addr
);
1142 tptr
+= sizeof(struct in_addr
);
1145 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1146 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1147 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1148 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1149 printf("invalid len");
1152 TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1153 printf("RD: %s, %s",
1154 bgp_vpn_rd_print(tptr
),
1155 getname(tptr
+BGP_VPN_RD_LEN
));
1156 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1157 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1161 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1162 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1163 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1164 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1165 if (tlen
< (int)sizeof(struct in6_addr
)) {
1166 printf("invalid len");
1169 TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1170 printf("%s", getname6(tptr
));
1171 tlen
-= sizeof(struct in6_addr
);
1172 tptr
+= sizeof(struct in6_addr
);
1175 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1176 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1177 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1178 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1179 printf("invalid len");
1182 TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1183 printf("RD: %s, %s",
1184 bgp_vpn_rd_print(tptr
),
1185 getname6(tptr
+BGP_VPN_RD_LEN
));
1186 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1187 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1191 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1192 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1193 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1194 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1195 if (tlen
< (int)sizeof(struct in_addr
)) {
1196 printf("invalid len");
1199 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1200 printf("%s", getname(tptr
));
1201 tlen
-= (sizeof(struct in_addr
));
1202 tptr
+= (sizeof(struct in_addr
));
1205 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1206 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1207 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1208 TCHECK2(tptr
[0], tlen
);
1209 printf("%s",isonsap_string(tptr
,tlen
));
1214 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1215 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1216 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1217 if (tlen
< BGP_VPN_RD_LEN
+1) {
1218 printf("invalid len");
1221 TCHECK2(tptr
[0], tlen
);
1222 printf("RD: %s, %s",
1223 bgp_vpn_rd_print(tptr
),
1224 isonsap_string(tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
));
1225 /* rfc986 mapped IPv4 address ? */
1226 if (EXTRACT_32BITS(tptr
+BGP_VPN_RD_LEN
) == 0x47000601)
1227 printf(" = %s", getname(tptr
+BGP_VPN_RD_LEN
+4));
1229 /* rfc1888 mapped IPv6 address ? */
1230 else if (EXTRACT_24BITS(tptr
+BGP_VPN_RD_LEN
) == 0x350000)
1231 printf(" = %s", getname6(tptr
+BGP_VPN_RD_LEN
+3));
1238 TCHECK2(tptr
[0], tlen
);
1239 printf("no AFI %u/SAFI %u decoder",af
,safi
);
1241 print_unknown_data(tptr
,"\n\t ",tlen
);
1249 printf(", nh-length: %u", nhlen
);
1257 printf("\n\t %u SNPA", snpa
);
1258 for (/*nothing*/; snpa
> 0; snpa
--) {
1260 printf("\n\t %d bytes", tptr
[0]);
1261 tptr
+= tptr
[0] + 1;
1264 printf(", no SNPA");
1267 while (len
- (tptr
- pptr
) > 0) {
1268 switch (af
<<8 | safi
) {
1269 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1270 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1271 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1272 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1274 printf("\n\t (illegal prefix length)");
1275 else if (advance
== -2)
1278 printf("\n\t %s", buf
);
1280 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1281 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1283 printf("\n\t (illegal prefix length)");
1284 else if (advance
== -2)
1287 printf("\n\t %s", buf
);
1289 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1290 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1291 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1292 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1294 printf("\n\t (illegal prefix length)");
1295 else if (advance
== -2)
1298 printf("\n\t %s", buf
);
1300 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1301 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1303 printf("\n\t (illegal prefix length)");
1304 else if (advance
== -2)
1307 printf("\n\t %s", buf
);
1309 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1310 advance
= decode_multicast_vpn(tptr
, buf
, sizeof(buf
));
1312 printf("\n\t (illegal prefix length)");
1313 else if (advance
== -2)
1316 printf("\n\t %s", buf
);
1319 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1320 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1321 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1322 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1324 printf("\n\t (illegal prefix length)");
1325 else if (advance
== -2)
1328 printf("\n\t %s", buf
);
1330 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1331 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1333 printf("\n\t (illegal prefix length)");
1334 else if (advance
== -2)
1337 printf("\n\t %s", buf
);
1339 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1340 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1341 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1342 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1344 printf("\n\t (illegal prefix length)");
1345 else if (advance
== -2)
1348 printf("\n\t %s", buf
);
1351 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1352 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1353 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1354 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1355 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1357 printf("\n\t (illegal length)");
1358 else if (advance
== -2)
1361 printf("\n\t %s", buf
);
1363 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1364 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1365 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1366 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1368 printf("\n\t (illegal prefix length)");
1369 else if (advance
== -2)
1372 printf("\n\t %s", buf
);
1374 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1375 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1376 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1377 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1379 printf("\n\t (illegal prefix length)");
1380 else if (advance
== -2)
1383 printf("\n\t %s", buf
);
1386 TCHECK2(*tptr
,tlen
);
1387 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1389 print_unknown_data(tptr
,"\n\t ",tlen
);
1401 case BGPTYPE_MP_UNREACH_NLRI
:
1402 TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1403 af
= EXTRACT_16BITS(tptr
);
1406 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1407 tok2strbuf(af_values
, "Unknown AFI", af
,
1408 tokbuf
, sizeof(tokbuf
)),
1410 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1411 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1412 tokbuf
, sizeof(tokbuf
)),
1415 if (len
== BGP_MP_NLRI_MINSIZE
)
1416 printf("\n\t End-of-Rib Marker (empty NLRI)");
1420 while (len
- (tptr
- pptr
) > 0) {
1421 switch (af
<<8 | safi
) {
1422 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1423 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1424 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1425 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1427 printf("\n\t (illegal prefix length)");
1428 else if (advance
== -2)
1431 printf("\n\t %s", buf
);
1433 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1434 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1436 printf("\n\t (illegal prefix length)");
1437 else if (advance
== -2)
1440 printf("\n\t %s", buf
);
1442 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1443 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1444 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1445 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1447 printf("\n\t (illegal prefix length)");
1448 else if (advance
== -2)
1451 printf("\n\t %s", buf
);
1454 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1455 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1456 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1457 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1459 printf("\n\t (illegal prefix length)");
1460 else if (advance
== -2)
1463 printf("\n\t %s", buf
);
1465 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1466 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1468 printf("\n\t (illegal prefix length)");
1469 else if (advance
== -2)
1472 printf("\n\t %s", buf
);
1474 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1475 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1476 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1477 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1479 printf("\n\t (illegal prefix length)");
1480 else if (advance
== -2)
1483 printf("\n\t %s", buf
);
1486 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1487 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1488 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1489 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1490 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1492 printf("\n\t (illegal length)");
1493 else if (advance
== -2)
1496 printf("\n\t %s", buf
);
1498 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1499 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1500 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1501 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1503 printf("\n\t (illegal prefix length)");
1504 else if (advance
== -2)
1507 printf("\n\t %s", buf
);
1509 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1510 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1511 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1512 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1514 printf("\n\t (illegal prefix length)");
1515 else if (advance
== -2)
1518 printf("\n\t %s", buf
);
1521 TCHECK2(*(tptr
-3),tlen
);
1522 printf("no AFI %u / SAFI %u decoder",af
,safi
);
1524 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1534 case BGPTYPE_EXTD_COMMUNITIES
:
1536 printf("invalid len");
1540 u_int16_t extd_comm
;
1542 TCHECK2(tptr
[0], 2);
1543 extd_comm
=EXTRACT_16BITS(tptr
);
1545 printf("\n\t %s (0x%04x), Flags [%s]",
1546 tok2strbuf(bgp_extd_comm_subtype_values
,
1547 "unknown extd community typecode",
1548 extd_comm
, tokbuf
, sizeof(tokbuf
)),
1550 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1552 TCHECK2(*(tptr
+2), 6);
1554 case BGP_EXT_COM_RT_0
:
1555 case BGP_EXT_COM_RO_0
:
1557 EXTRACT_16BITS(tptr
+2),
1560 case BGP_EXT_COM_RT_1
:
1561 case BGP_EXT_COM_RO_1
:
1562 case BGP_EXT_COM_VRF_RT_IMP
:
1565 EXTRACT_16BITS(tptr
+6));
1567 case BGP_EXT_COM_RT_2
:
1568 case BGP_EXT_COM_RO_2
:
1570 EXTRACT_32BITS(tptr
+2),
1571 EXTRACT_16BITS(tptr
+6));
1573 case BGP_EXT_COM_LINKBAND
:
1574 bw
.i
= EXTRACT_32BITS(tptr
+2);
1575 printf(": bandwidth: %.3f Mbps",
1578 case BGP_EXT_COM_CISCO_MCAST
:
1579 printf(": AS %u, group %s",
1580 EXTRACT_16BITS(tptr
+2),
1583 case BGP_EXT_COM_VPN_ORIGIN
:
1584 case BGP_EXT_COM_VPN_ORIGIN2
:
1585 case BGP_EXT_COM_VPN_ORIGIN3
:
1586 case BGP_EXT_COM_VPN_ORIGIN4
:
1587 case BGP_EXT_COM_OSPF_RID
:
1588 case BGP_EXT_COM_OSPF_RID2
:
1589 printf("%s", getname(tptr
+2));
1591 case BGP_EXT_COM_OSPF_RTYPE
:
1592 case BGP_EXT_COM_OSPF_RTYPE2
:
1593 printf(": area:%s, router-type:%s, metric-type:%s%s",
1595 tok2strbuf(bgp_extd_comm_ospf_rtype_values
,
1598 tokbuf
, sizeof(tokbuf
)),
1599 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1600 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1602 case BGP_EXT_COM_L2INFO
:
1603 printf(": %s Control Flags [0x%02x]:MTU %u",
1604 tok2strbuf(l2vpn_encaps_values
,
1607 tokbuf
, sizeof(tokbuf
)),
1609 EXTRACT_16BITS(tptr
+4));
1611 case BGP_EXT_COM_SOURCE_AS
:
1612 printf(": AS %u", EXTRACT_16BITS(tptr
+2));
1616 print_unknown_data(tptr
,"\n\t ",8);
1624 case BGPTYPE_PMSI_TUNNEL
:
1626 u_int8_t tunnel_type
, flags
;
1628 tunnel_type
= *(tptr
+1);
1632 TCHECK2(tptr
[0], 5);
1633 printf("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
1634 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
1636 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
1637 EXTRACT_24BITS(tptr
+2)>>4);
1642 switch (tunnel_type
) {
1643 case BGP_PMSI_TUNNEL_PIM_SSM
:
1644 TCHECK2(tptr
[0], 8);
1645 printf("\n\t P-Root-Node %s, P-Group %s",
1646 ipaddr_string(tptr
),
1647 ipaddr_string(tptr
+4));
1651 * no Tunnel-ID printing, just hexdumping for now
1652 * you are welcome to contribute code ;-)
1654 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
1655 case BGP_PMSI_TUNNEL_LDP_P2MP
:
1656 case BGP_PMSI_TUNNEL_PIM_SM
:
1657 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
1658 case BGP_PMSI_TUNNEL_INGRESS
:
1659 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
1662 print_unknown_data(tptr
,"\n\t ",tlen
);
1667 case BGPTYPE_ATTR_SET
:
1668 TCHECK2(tptr
[0], 4);
1669 printf("\n\t Origin AS: %u", EXTRACT_32BITS(tptr
));
1675 struct bgp_attr bgpa
;
1677 TCHECK2(tptr
[0], sizeof(bgpa
));
1678 memcpy(&bgpa
, tptr
, sizeof(bgpa
));
1679 alen
= bgp_attr_len(&bgpa
);
1680 tptr
+= bgp_attr_off(&bgpa
);
1681 len
-= bgp_attr_off(&bgpa
);
1683 printf("\n\t %s (%u), length: %u",
1684 tok2strbuf(bgp_attr_values
,
1685 "Unknown Attribute", bgpa
.bgpa_type
,
1686 tokbuf
, sizeof(tokbuf
)),
1690 if (bgpa
.bgpa_flags
) {
1691 printf(", Flags [%s%s%s%s",
1692 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1693 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1694 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1695 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1696 if (bgpa
.bgpa_flags
& 0xf)
1697 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1700 /* FIXME check for recursion */
1701 if (!bgp_attr_print(&bgpa
, tptr
, alen
))
1711 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1713 print_unknown_data(pptr
,"\n\t ",len
);
1716 if (vflag
> 1 && len
) { /* omit zero length attributes*/
1718 print_unknown_data(pptr
,"\n\t ",len
);
1727 bgp_open_print(const u_char
*dat
, int length
)
1729 struct bgp_open bgpo
;
1730 struct bgp_opt bgpopt
;
1732 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
1733 char tokbuf
[TOKBUFSIZE
];
1734 char tokbuf2
[TOKBUFSIZE
];
1736 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1737 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1739 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1740 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1741 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1742 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1743 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1745 /* some little sanity checking */
1746 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
1750 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1754 while (i
< bgpo
.bgpo_optlen
) {
1755 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1756 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1757 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1758 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1762 printf("\n\t Option %s (%u), length: %u",
1763 tok2strbuf(bgp_opt_values
,"Unknown",
1765 tokbuf
, sizeof(tokbuf
)),
1769 /* now lets decode the options we know*/
1770 switch(bgpopt
.bgpopt_type
) {
1772 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1773 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1775 printf("\n\t %s (%u), length: %u",
1776 tok2strbuf(bgp_capcode_values
, "Unknown",
1777 cap_type
, tokbuf
, sizeof(tokbuf
)),
1781 case BGP_CAPCODE_MP
:
1782 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1783 tok2strbuf(af_values
, "Unknown",
1784 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1785 tokbuf
, sizeof(tokbuf
)),
1786 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1787 tok2strbuf(bgp_safi_values
, "Unknown",
1788 opt
[i
+BGP_OPT_SIZE
+5],
1789 tokbuf
, sizeof(tokbuf
)),
1790 opt
[i
+BGP_OPT_SIZE
+5]);
1792 case BGP_CAPCODE_RESTART
:
1793 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
1794 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
1795 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
1798 while(tcap_len
>=4) {
1799 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1800 tok2strbuf(af_values
,"Unknown",
1801 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1802 tokbuf
, sizeof(tokbuf
)),
1803 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1804 tok2strbuf(bgp_safi_values
,"Unknown",
1805 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1806 tokbuf2
, sizeof(tokbuf2
)),
1807 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1808 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
1813 case BGP_CAPCODE_RR
:
1814 case BGP_CAPCODE_RR_CISCO
:
1817 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
1818 printf("\n\t\tno decoder for Capability %u",
1821 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1825 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
1826 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
1831 printf("\n\t no decoder for option %u",
1832 bgpopt
.bgpopt_type
);
1836 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
1844 bgp_update_print(const u_char
*dat
, int length
)
1847 struct bgp_attr bgpa
;
1851 char tokbuf
[TOKBUFSIZE
];
1853 TCHECK2(dat
[0], BGP_SIZE
);
1854 memcpy(&bgp
, dat
, BGP_SIZE
);
1855 p
= dat
+ BGP_SIZE
; /*XXX*/
1857 /* Unfeasible routes */
1858 len
= EXTRACT_16BITS(p
);
1861 * Without keeping state from the original NLRI message,
1862 * it's not possible to tell if this a v4 or v6 route,
1863 * so only try to decode it if we're not v6 enabled.
1866 printf("\n\t Withdrawn routes: %d bytes", len
);
1868 char buf
[MAXHOSTNAMELEN
+ 100];
1874 printf("\n\t Withdrawn routes:");
1876 while(i
< 2 + len
) {
1877 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
1879 printf("\n\t (illegal prefix length)");
1881 } else if (wpfx
== -2)
1885 printf("\n\t %s", buf
);
1893 len
= EXTRACT_16BITS(p
);
1895 if (len
== 0 && length
== BGP_UPDATE_MINSIZE
) {
1896 printf("\n\t End-of-Rib Marker (empty NLRI)");
1901 /* do something more useful!*/
1903 while (i
< 2 + len
) {
1906 TCHECK2(p
[i
], sizeof(bgpa
));
1907 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
1908 alen
= bgp_attr_len(&bgpa
);
1909 aoff
= bgp_attr_off(&bgpa
);
1911 printf("\n\t %s (%u), length: %u",
1912 tok2strbuf(bgp_attr_values
, "Unknown Attribute",
1914 tokbuf
, sizeof(tokbuf
)),
1918 if (bgpa
.bgpa_flags
) {
1919 printf(", Flags [%s%s%s%s",
1920 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1921 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1922 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1923 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1924 if (bgpa
.bgpa_flags
& 0xf)
1925 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1928 if (!bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
))
1935 if (dat
+ length
> p
) {
1936 printf("\n\t Updated routes:");
1937 while (dat
+ length
> p
) {
1938 char buf
[MAXHOSTNAMELEN
+ 100];
1939 i
= decode_prefix4(p
, buf
, sizeof(buf
));
1941 printf("\n\t (illegal prefix length)");
1946 printf("\n\t %s", buf
);
1957 bgp_notification_print(const u_char
*dat
, int length
)
1959 struct bgp_notification bgpn
;
1961 char tokbuf
[TOKBUFSIZE
];
1962 char tokbuf2
[TOKBUFSIZE
];
1964 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
1965 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
1967 /* some little sanity checking */
1968 if (length
<BGP_NOTIFICATION_SIZE
)
1972 tok2strbuf(bgp_notify_major_values
, "Unknown Error",
1973 bgpn
.bgpn_major
, tokbuf
, sizeof(tokbuf
)),
1976 switch (bgpn
.bgpn_major
) {
1978 case BGP_NOTIFY_MAJOR_MSG
:
1979 printf(", subcode %s (%u)",
1980 tok2strbuf(bgp_notify_minor_msg_values
, "Unknown",
1981 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
1984 case BGP_NOTIFY_MAJOR_OPEN
:
1985 printf(", subcode %s (%u)",
1986 tok2strbuf(bgp_notify_minor_open_values
, "Unknown",
1987 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
1990 case BGP_NOTIFY_MAJOR_UPDATE
:
1991 printf(", subcode %s (%u)",
1992 tok2strbuf(bgp_notify_minor_update_values
, "Unknown",
1993 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
1996 case BGP_NOTIFY_MAJOR_CAP
:
1997 printf(" subcode %s (%u)",
1998 tok2strbuf(bgp_notify_minor_cap_values
, "Unknown",
1999 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2001 case BGP_NOTIFY_MAJOR_CEASE
:
2002 printf(", subcode %s (%u)",
2003 tok2strbuf(bgp_notify_minor_cease_values
, "Unknown",
2004 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2007 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2008 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2010 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2011 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2013 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2014 tok2strbuf(af_values
, "Unknown",
2015 EXTRACT_16BITS(tptr
), tokbuf
, sizeof(tokbuf
)),
2016 EXTRACT_16BITS(tptr
),
2017 tok2strbuf(bgp_safi_values
, "Unknown", *(tptr
+2),
2018 tokbuf2
, sizeof(tokbuf
)),
2020 EXTRACT_32BITS(tptr
+3));
2033 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
2035 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2036 char tokbuf
[TOKBUFSIZE
];
2037 char tokbuf2
[TOKBUFSIZE
];
2039 TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
2041 /* some little sanity checking */
2042 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2045 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2047 printf("\n\t AFI %s (%u), SAFI %s (%u)",
2048 tok2strbuf(af_values
,"Unknown",
2049 /* this stinks but the compiler pads the structure
2051 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2052 tokbuf
, sizeof(tokbuf
)),
2053 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2054 tok2strbuf(bgp_safi_values
,"Unknown",
2055 bgp_route_refresh_header
->safi
,
2056 tokbuf2
, sizeof(tokbuf2
)),
2057 bgp_route_refresh_header
->safi
);
2060 TCHECK2(*pptr
, len
);
2061 print_unknown_data(pptr
,"\n\t ", len
);
2070 bgp_header_print(const u_char
*dat
, int length
)
2073 char tokbuf
[TOKBUFSIZE
];
2075 TCHECK2(dat
[0], BGP_SIZE
);
2076 memcpy(&bgp
, dat
, BGP_SIZE
);
2077 printf("\n\t%s Message (%u), length: %u",
2078 tok2strbuf(bgp_msg_values
, "Unknown", bgp
.bgp_type
,
2079 tokbuf
, sizeof(tokbuf
)),
2083 switch (bgp
.bgp_type
) {
2085 bgp_open_print(dat
, length
);
2088 bgp_update_print(dat
, length
);
2090 case BGP_NOTIFICATION
:
2091 bgp_notification_print(dat
, length
);
2095 case BGP_ROUTE_REFRESH
:
2096 bgp_route_refresh_print(dat
, length
);
2099 /* we have no decoder for the BGP message */
2100 TCHECK2(*dat
, length
);
2101 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
2102 print_unknown_data(dat
,"\n\t ",length
);
2112 bgp_print(const u_char
*dat
, int length
)
2116 const u_char
*start
;
2117 const u_char marker
[] = {
2118 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2119 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2123 char tokbuf
[TOKBUFSIZE
];
2126 if (snapend
< dat
+ length
)
2129 printf(": BGP, length: %u",length
);
2131 if (vflag
< 1) /* lets be less chatty */
2137 if (!TTEST2(p
[0], 1))
2144 if (!TTEST2(p
[0], sizeof(marker
)))
2146 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2151 /* found BGP header */
2152 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2153 memcpy(&bgp
, p
, BGP_SIZE
);
2158 hlen
= ntohs(bgp
.bgp_len
);
2159 if (hlen
< BGP_SIZE
) {
2160 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
2165 if (TTEST2(p
[0], hlen
)) {
2166 if (!bgp_header_print(p
, hlen
))
2171 printf("\n[|BGP %s]",
2172 tok2strbuf(bgp_msg_values
,
2173 "Unknown Message Type",
2175 tokbuf
, sizeof(tokbuf
)));