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.118 2007-12-07 15:54:52 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_AS4_PATH 17 /* RFC4893 */
149 #define BGPTYPE_AGGREGATOR4 18 /* RFC4893 */
150 #define BGPTYPE_PMSI_TUNNEL 22 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
151 #define BGPTYPE_ATTR_SET 128 /* draft-marques-ppvpn-ibgp */
153 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
155 static struct tok bgp_attr_values
[] = {
156 { BGPTYPE_ORIGIN
, "Origin"},
157 { BGPTYPE_AS_PATH
, "AS Path"},
158 { BGPTYPE_AS4_PATH
, "AS4 Path"},
159 { BGPTYPE_NEXT_HOP
, "Next Hop"},
160 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
161 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
162 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
163 { BGPTYPE_AGGREGATOR
, "Aggregator"},
164 { BGPTYPE_AGGREGATOR4
, "Aggregator4"},
165 { BGPTYPE_COMMUNITIES
, "Community"},
166 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
167 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
168 { BGPTYPE_DPA
, "DPA"},
169 { BGPTYPE_ADVERTISERS
, "Advertisers"},
170 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
171 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
172 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
173 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
174 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
175 { BGPTYPE_ATTR_SET
, "Attribute Set"},
176 { 255, "Reserved for development"},
181 #define BGP_AS_SEQUENCE 2
182 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
183 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
185 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
186 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
188 static struct tok bgp_as_path_segment_open_values
[] = {
189 { BGP_AS_SEQUENCE
, ""},
191 { BGP_CONFED_AS_SEQUENCE
, "( "},
192 { BGP_CONFED_AS_SET
, "({ "},
196 static struct tok bgp_as_path_segment_close_values
[] = {
197 { BGP_AS_SEQUENCE
, ""},
199 { BGP_CONFED_AS_SEQUENCE
, ")"},
200 { BGP_CONFED_AS_SET
, "})"},
204 #define BGP_OPT_AUTH 1
205 #define BGP_OPT_CAP 2
208 static struct tok bgp_opt_values
[] = {
209 { BGP_OPT_AUTH
, "Authentication Information"},
210 { BGP_OPT_CAP
, "Capabilities Advertisement"},
214 #define BGP_CAPCODE_MP 1
215 #define BGP_CAPCODE_RR 2
216 #define BGP_CAPCODE_ORF 3 /* XXX */
217 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
218 #define BGP_CAPCODE_AS_NEW 65 /* XXX */
219 #define BGP_CAPCODE_DYN_CAP 67 /* XXX */
220 #define BGP_CAPCODE_RR_CISCO 128
222 static struct tok bgp_capcode_values
[] = {
223 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
224 { BGP_CAPCODE_RR
, "Route Refresh"},
225 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
226 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
227 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
228 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
229 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
233 #define BGP_NOTIFY_MAJOR_MSG 1
234 #define BGP_NOTIFY_MAJOR_OPEN 2
235 #define BGP_NOTIFY_MAJOR_UPDATE 3
236 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
237 #define BGP_NOTIFY_MAJOR_FSM 5
238 #define BGP_NOTIFY_MAJOR_CEASE 6
239 #define BGP_NOTIFY_MAJOR_CAP 7
241 static struct tok bgp_notify_major_values
[] = {
242 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
243 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
244 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
245 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
246 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
247 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
248 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
252 /* draft-ietf-idr-cease-subcode-02 */
253 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
254 static struct tok bgp_notify_minor_cease_values
[] = {
255 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
256 { 2, "Administratively Shutdown"},
257 { 3, "Peer Unconfigured"},
258 { 4, "Administratively Reset"},
259 { 5, "Connection Rejected"},
260 { 6, "Other Configuration Change"},
261 { 7, "Connection Collision Resolution"},
265 static struct tok bgp_notify_minor_msg_values
[] = {
266 { 1, "Connection Not Synchronized"},
267 { 2, "Bad Message Length"},
268 { 3, "Bad Message Type"},
272 static struct tok bgp_notify_minor_open_values
[] = {
273 { 1, "Unsupported Version Number"},
275 { 3, "Bad BGP Identifier"},
276 { 4, "Unsupported Optional Parameter"},
277 { 5, "Authentication Failure"},
278 { 6, "Unacceptable Hold Time"},
279 { 7, "Capability Message Error"},
283 static struct tok bgp_notify_minor_update_values
[] = {
284 { 1, "Malformed Attribute List"},
285 { 2, "Unrecognized Well-known Attribute"},
286 { 3, "Missing Well-known Attribute"},
287 { 4, "Attribute Flags Error"},
288 { 5, "Attribute Length Error"},
289 { 6, "Invalid ORIGIN Attribute"},
290 { 7, "AS Routing Loop"},
291 { 8, "Invalid NEXT_HOP Attribute"},
292 { 9, "Optional Attribute Error"},
293 { 10, "Invalid Network Field"},
294 { 11, "Malformed AS_PATH"},
298 static struct tok bgp_notify_minor_cap_values
[] = {
299 { 1, "Invalid Action Value" },
300 { 2, "Invalid Capability Length" },
301 { 3, "Malformed Capability Value" },
302 { 4, "Unsupported Capability Code" },
306 static struct tok bgp_origin_values
[] = {
313 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
314 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
315 #define BGP_PMSI_TUNNEL_PIM_SSM 3
316 #define BGP_PMSI_TUNNEL_PIM_SM 4
317 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
318 #define BGP_PMSI_TUNNEL_INGRESS 6
319 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
321 static struct tok bgp_pmsi_tunnel_values
[] = {
322 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
323 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
324 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
325 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
326 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
327 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
328 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
332 static struct tok bgp_pmsi_flag_values
[] = {
333 { 0x01, "Leaf Information required"},
338 /* Subsequent address family identifier, RFC2283 section 7 */
340 #define SAFNUM_UNICAST 1
341 #define SAFNUM_MULTICAST 2
342 #define SAFNUM_UNIMULTICAST 3
343 /* labeled BGP RFC3107 */
344 #define SAFNUM_LABUNICAST 4
345 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
346 #define SAFNUM_MULTICAST_VPN 5
347 #define SAFNUM_TUNNEL 64 /* XXX */
348 #define SAFNUM_VPLS 65 /* XXX */
349 /* draft-nalawade-idr-mdt-safi-03 */
350 #define SAFNUM_MDT 66
351 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
352 #define SAFNUM_VPNUNICAST 128
353 #define SAFNUM_VPNMULTICAST 129
354 #define SAFNUM_VPNUNIMULTICAST 130
355 /* draft-marques-ppvpn-rt-constrain-01.txt */
356 #define SAFNUM_RT_ROUTING_INFO 132
358 #define BGP_VPN_RD_LEN 8
360 static struct tok bgp_safi_values
[] = {
361 { SAFNUM_RES
, "Reserved"},
362 { SAFNUM_UNICAST
, "Unicast"},
363 { SAFNUM_MULTICAST
, "Multicast"},
364 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
365 { SAFNUM_LABUNICAST
, "labeled Unicast"},
366 { SAFNUM_TUNNEL
, "Tunnel"},
367 { SAFNUM_VPLS
, "VPLS"},
368 { SAFNUM_MDT
, "MDT"},
369 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
370 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
371 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
372 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
373 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
377 /* well-known community */
378 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
379 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
380 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
382 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
383 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
384 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
385 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
386 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
387 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
388 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
389 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
390 /* rfc2547 bgp-mpls-vpns */
391 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
392 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
393 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
394 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
396 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
397 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
399 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
400 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
402 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
404 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
405 #define BGP_EXT_COM_VRF_RT_IMP 0x010a /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
407 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
408 #define BGP_EXT_COM_EIGRP_GEN 0x8800
409 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
410 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
411 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
412 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
413 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
415 static struct tok bgp_extd_comm_flag_values
[] = {
416 { 0x8000, "vendor-specific"},
417 { 0x4000, "non-transitive"},
421 static struct tok bgp_extd_comm_subtype_values
[] = {
422 { BGP_EXT_COM_RT_0
, "target"},
423 { BGP_EXT_COM_RT_1
, "target"},
424 { BGP_EXT_COM_RT_2
, "target"},
425 { BGP_EXT_COM_RO_0
, "origin"},
426 { BGP_EXT_COM_RO_1
, "origin"},
427 { BGP_EXT_COM_RO_2
, "origin"},
428 { BGP_EXT_COM_LINKBAND
, "link-BW"},
429 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
430 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
431 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
432 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
433 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
434 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
435 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
436 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
437 { BGP_EXT_COM_L2INFO
, "layer2-info"},
438 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
439 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
440 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
441 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
442 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
443 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
444 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
445 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
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" },
468 #define TOKBUFSIZE 128
469 static char astostr
[20];
474 * Convert an AS number into a string and return string pointer.
476 * Bepending on bflag is set or not, AS number is converted into ASDOT notation
477 * or plain number notation.
481 as_printf (char *str
, int size
, u_int asnum
)
483 if (!bflag
|| asnum
<= 0xFFFF) {
484 snprintf(str
, size
, "%u", asnum
);
486 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
492 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
502 memset(&addr
, 0, sizeof(addr
));
503 TCHECK2(pptr
[1], (plen
+ 7) / 8);
504 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
506 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
507 ((0xff00 >> (plen
% 8)) & 0xff);
509 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
510 return 1 + (plen
+ 7) / 8;
517 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
523 plen
= pptr
[0]; /* get prefix length */
525 /* this is one of the weirdnesses of rfc3107
526 the label length (actually the label + COS bits)
527 is added to the prefix length;
528 we also do only read out just one label -
529 there is no real application for advertisement of
530 stacked labels in a a single BGP message
536 plen
-=24; /* adjust prefixlen - labellength */
541 memset(&addr
, 0, sizeof(addr
));
542 TCHECK2(pptr
[4], (plen
+ 7) / 8);
543 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
545 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
546 ((0xff00 >> (plen
% 8)) & 0xff);
548 /* the label may get offsetted by 4 bits so lets shift it right */
549 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
550 getname((u_char
*)&addr
),
552 EXTRACT_24BITS(pptr
+1)>>4,
553 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
555 return 4 + (plen
+ 7) / 8;
564 * print an ipv4 or ipv6 address into a buffer dependend on address length.
567 bgp_vpn_ip_print (const u_char
*pptr
, u_int addr_length
) {
569 /* worst case string is s fully formatted v6 address */
570 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
573 switch(addr_length
) {
574 case (sizeof(struct in_addr
) << 3): /* 32 */
575 TCHECK2(pptr
[0], sizeof(struct in_addr
));
576 snprintf(pos
, sizeof(addr
), "%s", ipaddr_string(pptr
));
579 case (sizeof(struct in6_addr
) << 3): /* 128 */
580 TCHECK2(pptr
[0], sizeof(struct in6_addr
));
581 snprintf(pos
, sizeof(addr
), "%s", ip6addr_string(pptr
));
585 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
598 * print an multicast s,g entry into a buffer.
599 * the s,g entry is encoded like this.
601 * +-----------------------------------+
602 * | Multicast Source Length (1 octet) |
603 * +-----------------------------------+
604 * | Multicast Source (Variable) |
605 * +-----------------------------------+
606 * | Multicast Group Length (1 octet) |
607 * +-----------------------------------+
608 * | Multicast Group (Variable) |
609 * +-----------------------------------+
611 * return the number of bytes read from the wire.
614 bgp_vpn_sg_print (const u_char
*pptr
, char *buf
, u_int buflen
) {
616 u_int8_t addr_length
;
617 u_int total_length
, offset
;
621 /* Source address length, encoded in bits */
623 addr_length
= *pptr
++;
626 TCHECK2(pptr
[0], (addr_length
>> 3));
627 total_length
+= (addr_length
>> 3) + 1;
628 offset
= strlen(buf
);
630 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
631 bgp_vpn_ip_print(pptr
, addr_length
));
632 pptr
+= (addr_length
>> 3);
635 /* Group address length, encoded in bits */
637 addr_length
= *pptr
++;
640 TCHECK2(pptr
[0], (addr_length
>> 3));
641 total_length
+= (addr_length
>> 3) + 1;
642 offset
= strlen(buf
);
644 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
645 bgp_vpn_ip_print(pptr
, addr_length
));
646 pptr
+= (addr_length
>> 3);
650 return (total_length
);
654 /* RDs and RTs share the same semantics
655 * we use bgp_vpn_rd_print for
656 * printing route targets inside a NLRI */
658 bgp_vpn_rd_print (const u_char
*pptr
) {
660 /* allocate space for the largest possible string */
661 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
664 /* ok lets load the RD format */
665 switch (EXTRACT_16BITS(pptr
)) {
667 /* 2-byte-AS:number fmt*/
669 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
670 EXTRACT_16BITS(pptr
+2),
671 EXTRACT_32BITS(pptr
+4),
672 *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
674 /* IP-address:AS fmt*/
677 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
678 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
681 /* 4-byte-AS:number fmt*/
683 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
684 as_printf(astostr
, sizeof(astostr
), EXTRACT_32BITS(pptr
+2)),
685 EXTRACT_16BITS(pptr
+6), *(pptr
+2), *(pptr
+3), *(pptr
+4),
686 *(pptr
+5), EXTRACT_16BITS(pptr
+6));
689 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
698 decode_rt_routing_info(const u_char
*pptr
, char *buf
, u_int buflen
)
700 u_int8_t route_target
[8];
704 plen
= pptr
[0]; /* get prefix length */
707 return 1; /* default route target */
712 plen
-=32; /* adjust prefix length */
717 memset(&route_target
, 0, sizeof(route_target
));
718 TCHECK2(pptr
[1], (plen
+ 7) / 8);
719 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
721 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
722 ((0xff00 >> (plen
% 8)) & 0xff);
724 snprintf(buf
, buflen
, "origin AS: %s, route target %s",
725 as_printf(astostr
, sizeof(astostr
), EXTRACT_32BITS(pptr
+1)),
726 bgp_vpn_rd_print((u_char
*)&route_target
));
728 return 5 + (plen
+ 7) / 8;
735 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
741 plen
= pptr
[0]; /* get prefix length */
746 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
751 memset(&addr
, 0, sizeof(addr
));
752 TCHECK2(pptr
[12], (plen
+ 7) / 8);
753 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
755 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
756 ((0xff00 >> (plen
% 8)) & 0xff);
758 /* the label may get offsetted by 4 bits so lets shift it right */
759 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
760 bgp_vpn_rd_print(pptr
+4),
761 getname((u_char
*)&addr
),
763 EXTRACT_24BITS(pptr
+1)>>4,
764 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
766 return 12 + (plen
+ 7) / 8;
773 * +-------------------------------+
775 * | RD:IPv4-address (12 octets) |
777 * +-------------------------------+
778 * | MDT Group-address (4 octets) |
779 * +-------------------------------+
782 #define MDT_VPN_NLRI_LEN 16
785 decode_mdt_vpn_nlri(const u_char
*pptr
, char *buf
, u_int buflen
)
789 const u_char
*vpn_ip
;
793 /* if the NLRI is not predefined length, quit.*/
794 if (*pptr
!= MDT_VPN_NLRI_LEN
* NBBY
)
804 TCHECK2(pptr
[0], sizeof(struct in_addr
));
806 pptr
+=sizeof(struct in_addr
);
808 /* MDT Group Address */
809 TCHECK2(pptr
[0], sizeof(struct in_addr
));
811 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
812 bgp_vpn_rd_print(rd
), ipaddr_string(vpn_ip
), ipaddr_string(pptr
));
814 return MDT_VPN_NLRI_LEN
+ 1;
821 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
822 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
823 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
824 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
825 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
826 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
827 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
829 static struct tok bgp_multicast_vpn_route_type_values
[] = {
830 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
831 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
832 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
833 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
834 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
835 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
836 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
840 decode_multicast_vpn(const u_char
*pptr
, char *buf
, u_int buflen
)
842 u_int8_t route_type
, route_length
, addr_length
, sg_length
;
846 route_type
= *pptr
++;
847 route_length
= *pptr
++;
849 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
850 tok2str(bgp_multicast_vpn_route_type_values
,
851 "Unknown", route_type
),
852 route_type
, route_length
);
855 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
856 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
857 offset
= strlen(buf
);
858 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
859 bgp_vpn_rd_print(pptr
),
860 bgp_vpn_ip_print(pptr
+ BGP_VPN_RD_LEN
,
861 (route_length
- BGP_VPN_RD_LEN
) << 3));
863 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
864 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
+ 4);
865 offset
= strlen(buf
);
866 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
867 bgp_vpn_rd_print(pptr
),
868 as_printf(astostr
, sizeof(astostr
),
869 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
872 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
873 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
874 offset
= strlen(buf
);
875 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
876 bgp_vpn_rd_print(pptr
));
877 pptr
+= BGP_VPN_RD_LEN
;
879 sg_length
= bgp_vpn_sg_print(pptr
, buf
, buflen
);
880 addr_length
= route_length
- sg_length
;
882 TCHECK2(pptr
[0], addr_length
);
883 offset
= strlen(buf
);
884 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
885 bgp_vpn_ip_print(pptr
, addr_length
<< 3));
888 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
889 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
890 offset
= strlen(buf
);
891 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
892 bgp_vpn_rd_print(pptr
));
893 pptr
+= BGP_VPN_RD_LEN
;
895 bgp_vpn_sg_print(pptr
, buf
, buflen
);
898 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
899 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
900 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
901 offset
= strlen(buf
);
902 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
903 bgp_vpn_rd_print(pptr
),
904 as_printf(astostr
, sizeof(astostr
),
905 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
906 pptr
+= BGP_VPN_RD_LEN
;
908 bgp_vpn_sg_print(pptr
, buf
, buflen
);
912 * no per route-type printing yet.
914 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
919 return route_length
+ 2;
926 * As I remember, some versions of systems have an snprintf() that
927 * returns -1 if the buffer would have overflowed. If the return
928 * value is negative, set buflen to 0, to indicate that we've filled
931 * If the return value is greater than buflen, that means that
932 * the buffer would have overflowed; again, set buflen to 0 in
935 #define UPDATE_BUF_BUFLEN(buf, buflen, strlen) \
938 else if ((u_int)strlen>buflen) \
946 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
948 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
951 plen
=EXTRACT_16BITS(pptr
);
956 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
957 bgp_vpn_rd_print(pptr
),
958 EXTRACT_16BITS(pptr
+8),
959 EXTRACT_16BITS(pptr
+10),
960 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
961 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
965 /* ok now the variable part - lets read out TLVs*/
971 tlv_len
=EXTRACT_16BITS(pptr
);
978 strlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
981 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
983 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
987 strlen
=snprintf(buf
,buflen
, "%02x",*pptr
++);
988 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
995 strlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
998 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
1002 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
1012 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
1014 struct in6_addr addr
;
1022 memset(&addr
, 0, sizeof(addr
));
1023 TCHECK2(pd
[1], (plen
+ 7) / 8);
1024 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
1026 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1027 ((0xff00 >> (plen
% 8)) & 0xff);
1029 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
1030 return 1 + (plen
+ 7) / 8;
1037 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
1039 struct in6_addr addr
;
1043 plen
= pptr
[0]; /* get prefix length */
1048 plen
-=24; /* adjust prefixlen - labellength */
1053 memset(&addr
, 0, sizeof(addr
));
1054 TCHECK2(pptr
[4], (plen
+ 7) / 8);
1055 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
1057 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1058 ((0xff00 >> (plen
% 8)) & 0xff);
1060 /* the label may get offsetted by 4 bits so lets shift it right */
1061 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
1062 getname6((u_char
*)&addr
),
1064 EXTRACT_24BITS(pptr
+1)>>4,
1065 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1067 return 4 + (plen
+ 7) / 8;
1074 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
1076 struct in6_addr addr
;
1080 plen
= pptr
[0]; /* get prefix length */
1085 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1090 memset(&addr
, 0, sizeof(addr
));
1091 TCHECK2(pptr
[12], (plen
+ 7) / 8);
1092 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1094 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1095 ((0xff00 >> (plen
% 8)) & 0xff);
1097 /* the label may get offsetted by 4 bits so lets shift it right */
1098 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1099 bgp_vpn_rd_print(pptr
+4),
1100 getname6((u_char
*)&addr
),
1102 EXTRACT_24BITS(pptr
+1)>>4,
1103 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1105 return 12 + (plen
+ 7) / 8;
1113 decode_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
1119 plen
= pptr
[0]; /* get prefix length */
1124 memset(&addr
, 0, sizeof(addr
));
1125 TCHECK2(pptr
[4], (plen
+ 7) / 8);
1126 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
1128 addr
[(plen
+ 7) / 8 - 1] &=
1129 ((0xff00 >> (plen
% 8)) & 0xff);
1131 snprintf(buf
, buflen
, "%s/%d",
1132 isonsap_string(addr
,(plen
+ 7) / 8),
1135 return 1 + (plen
+ 7) / 8;
1142 decode_labeled_vpn_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
1148 plen
= pptr
[0]; /* get prefix length */
1153 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1158 memset(&addr
, 0, sizeof(addr
));
1159 TCHECK2(pptr
[12], (plen
+ 7) / 8);
1160 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1162 addr
[(plen
+ 7) / 8 - 1] &=
1163 ((0xff00 >> (plen
% 8)) & 0xff);
1165 /* the label may get offsetted by 4 bits so lets shift it right */
1166 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1167 bgp_vpn_rd_print(pptr
+4),
1168 isonsap_string(addr
,(plen
+ 7) / 8),
1170 EXTRACT_24BITS(pptr
+1)>>4,
1171 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1173 return 12 + (plen
+ 7) / 8;
1180 * bgp_attr_get_as_size
1182 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1183 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1184 * support, exchange AS-Path with the same path-attribute type value 0x02.
1187 bgp_attr_get_as_size (u_int8_t bgpa_type
, const u_char
*pptr
, int len
)
1189 const u_char
*tptr
= pptr
;
1192 * If the path attribute is the optional AS4 path type, then we already
1193 * know, that ASs must be encoded in 4 byte format.
1195 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1200 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1201 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1204 while (tptr
< pptr
+ len
) {
1208 * If we do not find a valid segment type, our guess might be wrong.
1210 if (tptr
[0] < BGP_AS_SEG_TYPE_MIN
|| tptr
[0] > BGP_AS_SEG_TYPE_MAX
) {
1214 tptr
+= 2 + tptr
[1] * 2;
1218 * If we correctly reached end of the AS path attribute data content,
1219 * then most likely ASs were indeed encoded as 2 bytes.
1221 if (tptr
== pptr
+ len
) {
1228 * We can come here, either we did not have enough data, or if we
1229 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1230 * so that calller can try to decode each AS as of 4 bytes. If indeed
1231 * there was not enough data, it will crib and end the parse anyways.
1237 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
1241 u_int8_t safi
, snpa
, nhlen
;
1242 union { /* copy buffer for bandwidth values */
1249 char buf
[MAXHOSTNAMELEN
+ 100];
1250 char tokbuf
[TOKBUFSIZE
];
1256 switch (attr
->bgpa_type
) {
1257 case BGPTYPE_ORIGIN
:
1259 printf("invalid len");
1262 printf("%s", tok2strbuf(bgp_origin_values
,
1263 "Unknown Origin Typecode",
1265 tokbuf
, sizeof(tokbuf
)));
1271 * Process AS4 byte path and AS2 byte path attributes here.
1273 case BGPTYPE_AS4_PATH
:
1274 case BGPTYPE_AS_PATH
:
1276 printf("invalid len");
1285 * BGP updates exchanged between New speakers that support 4
1286 * byte AS, ASs are always encoded in 4 bytes. There is no
1287 * definitive way to find this, just by the packet's
1288 * contents. So, check for packet's TLV's sanity assuming
1289 * 2 bytes first, and it does not pass, assume that ASs are
1290 * encoded in 4 bytes format and move on.
1292 as_size
= bgp_attr_get_as_size(attr
->bgpa_type
, pptr
, len
);
1294 while (tptr
< pptr
+ len
) {
1296 printf("%s", tok2strbuf(bgp_as_path_segment_open_values
,
1298 tokbuf
, sizeof(tokbuf
)));
1299 for (i
= 0; i
< tptr
[1] * as_size
; i
+= as_size
) {
1300 TCHECK2(tptr
[2 + i
], as_size
);
1302 as_printf(astostr
, sizeof(astostr
),
1304 EXTRACT_16BITS(&tptr
[2 + i
]) :
1305 EXTRACT_32BITS(&tptr
[2 + i
])));
1308 printf("%s", tok2strbuf(bgp_as_path_segment_close_values
,
1310 tokbuf
, sizeof(tokbuf
)));
1312 tptr
+= 2 + tptr
[1] * as_size
;
1315 case BGPTYPE_NEXT_HOP
:
1317 printf("invalid len");
1319 TCHECK2(tptr
[0], 4);
1320 printf("%s", getname(tptr
));
1323 case BGPTYPE_MULTI_EXIT_DISC
:
1324 case BGPTYPE_LOCAL_PREF
:
1326 printf("invalid len");
1328 TCHECK2(tptr
[0], 4);
1329 printf("%u", EXTRACT_32BITS(tptr
));
1332 case BGPTYPE_ATOMIC_AGGREGATE
:
1334 printf("invalid len");
1336 case BGPTYPE_AGGREGATOR
:
1339 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1340 * the length of this PA can be either 6 bytes or 8 bytes.
1342 if (len
!= 6 && len
!= 8) {
1343 printf("invalid len");
1346 TCHECK2(tptr
[0], len
);
1348 printf(" AS #%s, origin %s",
1349 as_printf(astostr
, sizeof(astostr
), EXTRACT_16BITS(tptr
)),
1352 printf(" AS #%s, origin %s",
1353 as_printf(astostr
, sizeof(astostr
),
1354 EXTRACT_32BITS(tptr
)), getname(tptr
+ 4));
1357 case BGPTYPE_AGGREGATOR4
:
1359 printf("invalid len");
1362 TCHECK2(tptr
[0], 8);
1363 printf(" AS #%s, origin %s",
1364 as_printf(astostr
, sizeof(astostr
), EXTRACT_32BITS(tptr
)),
1367 case BGPTYPE_COMMUNITIES
:
1369 printf("invalid len");
1374 TCHECK2(tptr
[0], 4);
1375 comm
= EXTRACT_32BITS(tptr
);
1377 case BGP_COMMUNITY_NO_EXPORT
:
1378 printf(" NO_EXPORT");
1380 case BGP_COMMUNITY_NO_ADVERT
:
1381 printf(" NO_ADVERTISE");
1383 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1384 printf(" NO_EXPORT_SUBCONFED");
1388 (comm
>> 16) & 0xffff,
1390 (tlen
>4) ? ", " : "");
1397 case BGPTYPE_ORIGINATOR_ID
:
1399 printf("invalid len");
1402 TCHECK2(tptr
[0], 4);
1403 printf("%s",getname(tptr
));
1405 case BGPTYPE_CLUSTER_LIST
:
1407 printf("invalid len");
1411 TCHECK2(tptr
[0], 4);
1414 (tlen
>4) ? ", " : "");
1419 case BGPTYPE_MP_REACH_NLRI
:
1420 TCHECK2(tptr
[0], 3);
1421 af
= EXTRACT_16BITS(tptr
);
1424 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1425 tok2strbuf(af_values
, "Unknown AFI", af
,
1426 tokbuf
, sizeof(tokbuf
)),
1428 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1429 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1430 tokbuf
, sizeof(tokbuf
)),
1433 switch(af
<<8 | safi
) {
1434 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1435 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1436 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1437 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1438 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1439 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1440 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1441 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1442 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1443 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1445 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1446 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1447 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1448 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1449 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1450 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1451 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1453 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1454 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1455 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1456 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1457 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1458 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1459 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1460 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1461 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1462 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1465 TCHECK2(tptr
[0], tlen
);
1466 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1468 print_unknown_data(tptr
,"\n\t ",tlen
);
1481 printf("\n\t nexthop: ");
1483 switch(af
<<8 | safi
) {
1484 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1485 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1486 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1487 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1488 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1489 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1490 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1491 if (tlen
< (int)sizeof(struct in_addr
)) {
1492 printf("invalid len");
1495 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1496 printf("%s",getname(tptr
));
1497 tlen
-= sizeof(struct in_addr
);
1498 tptr
+= sizeof(struct in_addr
);
1501 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1502 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1503 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1504 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1505 printf("invalid len");
1508 TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1509 printf("RD: %s, %s",
1510 bgp_vpn_rd_print(tptr
),
1511 getname(tptr
+BGP_VPN_RD_LEN
));
1512 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1513 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1517 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1518 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1519 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1520 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1521 if (tlen
< (int)sizeof(struct in6_addr
)) {
1522 printf("invalid len");
1525 TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1526 printf("%s", getname6(tptr
));
1527 tlen
-= sizeof(struct in6_addr
);
1528 tptr
+= sizeof(struct in6_addr
);
1531 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1532 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1533 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1534 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1535 printf("invalid len");
1538 TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1539 printf("RD: %s, %s",
1540 bgp_vpn_rd_print(tptr
),
1541 getname6(tptr
+BGP_VPN_RD_LEN
));
1542 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1543 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1547 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1548 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1549 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1550 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1551 if (tlen
< (int)sizeof(struct in_addr
)) {
1552 printf("invalid len");
1555 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1556 printf("%s", getname(tptr
));
1557 tlen
-= (sizeof(struct in_addr
));
1558 tptr
+= (sizeof(struct in_addr
));
1561 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1562 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1563 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1564 TCHECK2(tptr
[0], tlen
);
1565 printf("%s",isonsap_string(tptr
,tlen
));
1570 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1571 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1572 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1573 if (tlen
< BGP_VPN_RD_LEN
+1) {
1574 printf("invalid len");
1577 TCHECK2(tptr
[0], tlen
);
1578 printf("RD: %s, %s",
1579 bgp_vpn_rd_print(tptr
),
1580 isonsap_string(tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
));
1581 /* rfc986 mapped IPv4 address ? */
1582 if (EXTRACT_32BITS(tptr
+BGP_VPN_RD_LEN
) == 0x47000601)
1583 printf(" = %s", getname(tptr
+BGP_VPN_RD_LEN
+4));
1585 /* rfc1888 mapped IPv6 address ? */
1586 else if (EXTRACT_24BITS(tptr
+BGP_VPN_RD_LEN
) == 0x350000)
1587 printf(" = %s", getname6(tptr
+BGP_VPN_RD_LEN
+3));
1594 TCHECK2(tptr
[0], tlen
);
1595 printf("no AFI %u/SAFI %u decoder",af
,safi
);
1597 print_unknown_data(tptr
,"\n\t ",tlen
);
1605 printf(", nh-length: %u", nhlen
);
1613 printf("\n\t %u SNPA", snpa
);
1614 for (/*nothing*/; snpa
> 0; snpa
--) {
1616 printf("\n\t %d bytes", tptr
[0]);
1617 tptr
+= tptr
[0] + 1;
1620 printf(", no SNPA");
1623 while (len
- (tptr
- pptr
) > 0) {
1624 switch (af
<<8 | safi
) {
1625 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1626 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1627 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1628 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1630 printf("\n\t (illegal prefix length)");
1631 else if (advance
== -2)
1634 printf("\n\t %s", buf
);
1636 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1637 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1639 printf("\n\t (illegal prefix length)");
1640 else if (advance
== -2)
1643 printf("\n\t %s", buf
);
1645 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1646 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1647 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1648 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1650 printf("\n\t (illegal prefix length)");
1651 else if (advance
== -2)
1654 printf("\n\t %s", buf
);
1656 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1657 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1659 printf("\n\t (illegal prefix length)");
1660 else if (advance
== -2)
1663 printf("\n\t %s", buf
);
1665 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1666 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1667 advance
= decode_multicast_vpn(tptr
, buf
, sizeof(buf
));
1669 printf("\n\t (illegal prefix length)");
1670 else if (advance
== -2)
1673 printf("\n\t %s", buf
);
1676 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1677 advance
= decode_mdt_vpn_nlri(tptr
, buf
, sizeof(buf
));
1679 printf("\n\t (illegal prefix length)");
1680 else if (advance
== -2)
1683 printf("\n\t %s", buf
);
1686 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1687 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1688 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1689 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1691 printf("\n\t (illegal prefix length)");
1692 else if (advance
== -2)
1695 printf("\n\t %s", buf
);
1697 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1698 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1700 printf("\n\t (illegal prefix length)");
1701 else if (advance
== -2)
1704 printf("\n\t %s", buf
);
1706 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1707 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1708 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1709 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1711 printf("\n\t (illegal prefix length)");
1712 else if (advance
== -2)
1715 printf("\n\t %s", buf
);
1718 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1719 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1720 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1721 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1722 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1724 printf("\n\t (illegal length)");
1725 else if (advance
== -2)
1728 printf("\n\t %s", buf
);
1730 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1731 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1732 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1733 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1735 printf("\n\t (illegal prefix length)");
1736 else if (advance
== -2)
1739 printf("\n\t %s", buf
);
1741 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1742 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1743 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1744 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1746 printf("\n\t (illegal prefix length)");
1747 else if (advance
== -2)
1750 printf("\n\t %s", buf
);
1753 TCHECK2(*tptr
,tlen
);
1754 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1756 print_unknown_data(tptr
,"\n\t ",tlen
);
1768 case BGPTYPE_MP_UNREACH_NLRI
:
1769 TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1770 af
= EXTRACT_16BITS(tptr
);
1773 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1774 tok2strbuf(af_values
, "Unknown AFI", af
,
1775 tokbuf
, sizeof(tokbuf
)),
1777 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1778 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1779 tokbuf
, sizeof(tokbuf
)),
1782 if (len
== BGP_MP_NLRI_MINSIZE
)
1783 printf("\n\t End-of-Rib Marker (empty NLRI)");
1787 while (len
- (tptr
- pptr
) > 0) {
1788 switch (af
<<8 | safi
) {
1789 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1790 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1791 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1792 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1794 printf("\n\t (illegal prefix length)");
1795 else if (advance
== -2)
1798 printf("\n\t %s", buf
);
1800 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1801 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1803 printf("\n\t (illegal prefix length)");
1804 else if (advance
== -2)
1807 printf("\n\t %s", buf
);
1809 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1810 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1811 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1812 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1814 printf("\n\t (illegal prefix length)");
1815 else if (advance
== -2)
1818 printf("\n\t %s", buf
);
1821 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1822 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1823 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1824 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1826 printf("\n\t (illegal prefix length)");
1827 else if (advance
== -2)
1830 printf("\n\t %s", buf
);
1832 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1833 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1835 printf("\n\t (illegal prefix length)");
1836 else if (advance
== -2)
1839 printf("\n\t %s", buf
);
1841 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1842 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1843 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1844 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1846 printf("\n\t (illegal prefix length)");
1847 else if (advance
== -2)
1850 printf("\n\t %s", buf
);
1853 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1854 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1855 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1856 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1857 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1859 printf("\n\t (illegal length)");
1860 else if (advance
== -2)
1863 printf("\n\t %s", buf
);
1865 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1866 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1867 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1868 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1870 printf("\n\t (illegal prefix length)");
1871 else if (advance
== -2)
1874 printf("\n\t %s", buf
);
1876 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1877 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1878 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1879 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1881 printf("\n\t (illegal prefix length)");
1882 else if (advance
== -2)
1885 printf("\n\t %s", buf
);
1887 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1888 advance
= decode_mdt_vpn_nlri(tptr
, buf
, sizeof(buf
));
1890 printf("\n\t (illegal prefix length)");
1891 else if (advance
== -2)
1894 printf("\n\t %s", buf
);
1896 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1897 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1898 advance
= decode_multicast_vpn(tptr
, buf
, sizeof(buf
));
1900 printf("\n\t (illegal prefix length)");
1901 else if (advance
== -2)
1904 printf("\n\t %s", buf
);
1907 TCHECK2(*(tptr
-3),tlen
);
1908 printf("no AFI %u / SAFI %u decoder",af
,safi
);
1910 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1920 case BGPTYPE_EXTD_COMMUNITIES
:
1922 printf("invalid len");
1926 u_int16_t extd_comm
;
1928 TCHECK2(tptr
[0], 2);
1929 extd_comm
=EXTRACT_16BITS(tptr
);
1931 printf("\n\t %s (0x%04x), Flags [%s]",
1932 tok2strbuf(bgp_extd_comm_subtype_values
,
1933 "unknown extd community typecode",
1934 extd_comm
, tokbuf
, sizeof(tokbuf
)),
1936 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1938 TCHECK2(*(tptr
+2), 6);
1940 case BGP_EXT_COM_RT_0
:
1941 case BGP_EXT_COM_RO_0
:
1942 printf(": %u:%u (= %s)",
1943 EXTRACT_16BITS(tptr
+2),
1944 EXTRACT_32BITS(tptr
+4),
1947 case BGP_EXT_COM_RT_1
:
1948 case BGP_EXT_COM_RO_1
:
1949 case BGP_EXT_COM_VRF_RT_IMP
:
1952 EXTRACT_16BITS(tptr
+6));
1954 case BGP_EXT_COM_RT_2
:
1955 case BGP_EXT_COM_RO_2
:
1957 as_printf(astostr
, sizeof(astostr
),
1958 EXTRACT_32BITS(tptr
+2)), EXTRACT_16BITS(tptr
+6));
1960 case BGP_EXT_COM_LINKBAND
:
1961 bw
.i
= EXTRACT_32BITS(tptr
+2);
1962 printf(": bandwidth: %.3f Mbps",
1965 case BGP_EXT_COM_VPN_ORIGIN
:
1966 case BGP_EXT_COM_VPN_ORIGIN2
:
1967 case BGP_EXT_COM_VPN_ORIGIN3
:
1968 case BGP_EXT_COM_VPN_ORIGIN4
:
1969 case BGP_EXT_COM_OSPF_RID
:
1970 case BGP_EXT_COM_OSPF_RID2
:
1971 printf("%s", getname(tptr
+2));
1973 case BGP_EXT_COM_OSPF_RTYPE
:
1974 case BGP_EXT_COM_OSPF_RTYPE2
:
1975 printf(": area:%s, router-type:%s, metric-type:%s%s",
1977 tok2strbuf(bgp_extd_comm_ospf_rtype_values
,
1980 tokbuf
, sizeof(tokbuf
)),
1981 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1982 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1984 case BGP_EXT_COM_L2INFO
:
1985 printf(": %s Control Flags [0x%02x]:MTU %u",
1986 tok2strbuf(l2vpn_encaps_values
,
1989 tokbuf
, sizeof(tokbuf
)),
1991 EXTRACT_16BITS(tptr
+4));
1993 case BGP_EXT_COM_SOURCE_AS
:
1994 printf(": AS %u", EXTRACT_16BITS(tptr
+2));
1998 print_unknown_data(tptr
,"\n\t ",8);
2006 case BGPTYPE_PMSI_TUNNEL
:
2008 u_int8_t tunnel_type
, flags
;
2010 tunnel_type
= *(tptr
+1);
2014 TCHECK2(tptr
[0], 5);
2015 printf("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2016 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2018 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2019 EXTRACT_24BITS(tptr
+2)>>4);
2024 switch (tunnel_type
) {
2025 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2026 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2027 TCHECK2(tptr
[0], 8);
2028 printf("\n\t Sender %s, P-Group %s",
2029 ipaddr_string(tptr
),
2030 ipaddr_string(tptr
+4));
2033 case BGP_PMSI_TUNNEL_PIM_SSM
:
2034 TCHECK2(tptr
[0], 8);
2035 printf("\n\t Root-Node %s, P-Group %s",
2036 ipaddr_string(tptr
),
2037 ipaddr_string(tptr
+4));
2039 case BGP_PMSI_TUNNEL_INGRESS
:
2040 TCHECK2(tptr
[0], 4);
2041 printf("\n\t Tunnel-Endpoint %s",
2042 ipaddr_string(tptr
));
2044 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2045 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2046 TCHECK2(tptr
[0], 8);
2047 printf("\n\t Root-Node %s, LSP-ID 0x%08x",
2048 ipaddr_string(tptr
),
2049 EXTRACT_32BITS(tptr
+4));
2051 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2052 TCHECK2(tptr
[0], 8);
2053 printf("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2054 ipaddr_string(tptr
),
2055 EXTRACT_32BITS(tptr
+4));
2059 print_unknown_data(tptr
,"\n\t ",tlen
);
2064 case BGPTYPE_ATTR_SET
:
2065 TCHECK2(tptr
[0], 4);
2066 printf("\n\t Origin AS: %s",
2067 as_printf(astostr
, sizeof(astostr
), EXTRACT_32BITS(tptr
)));
2073 struct bgp_attr bgpa
;
2075 TCHECK2(tptr
[0], sizeof(bgpa
));
2076 memcpy(&bgpa
, tptr
, sizeof(bgpa
));
2077 alen
= bgp_attr_len(&bgpa
);
2078 tptr
+= bgp_attr_off(&bgpa
);
2079 len
-= bgp_attr_off(&bgpa
);
2081 printf("\n\t %s (%u), length: %u",
2082 tok2strbuf(bgp_attr_values
,
2083 "Unknown Attribute", bgpa
.bgpa_type
,
2084 tokbuf
, sizeof(tokbuf
)),
2088 if (bgpa
.bgpa_flags
) {
2089 printf(", Flags [%s%s%s%s",
2090 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
2091 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
2092 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
2093 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
2094 if (bgpa
.bgpa_flags
& 0xf)
2095 printf("+%x", bgpa
.bgpa_flags
& 0xf);
2098 /* FIXME check for recursion */
2099 if (!bgp_attr_print(&bgpa
, tptr
, alen
))
2109 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
2111 print_unknown_data(pptr
,"\n\t ",len
);
2114 if (vflag
> 1 && len
) { /* omit zero length attributes*/
2116 print_unknown_data(pptr
,"\n\t ",len
);
2125 bgp_open_print(const u_char
*dat
, int length
)
2127 struct bgp_open bgpo
;
2128 struct bgp_opt bgpopt
;
2130 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
2131 char tokbuf
[TOKBUFSIZE
];
2132 char tokbuf2
[TOKBUFSIZE
];
2134 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
2135 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
2137 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
2138 printf("my AS %s, ",
2139 as_printf(astostr
, sizeof(astostr
), ntohs(bgpo
.bgpo_myas
)));
2140 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
2141 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
2142 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
2144 /* some little sanity checking */
2145 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
2149 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
2153 while (i
< bgpo
.bgpo_optlen
) {
2154 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
2155 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
2156 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
2157 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
2161 printf("\n\t Option %s (%u), length: %u",
2162 tok2strbuf(bgp_opt_values
,"Unknown",
2164 tokbuf
, sizeof(tokbuf
)),
2168 /* now lets decode the options we know*/
2169 switch(bgpopt
.bgpopt_type
) {
2171 cap_type
=opt
[i
+BGP_OPT_SIZE
];
2172 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
2174 printf("\n\t %s (%u), length: %u",
2175 tok2strbuf(bgp_capcode_values
, "Unknown",
2176 cap_type
, tokbuf
, sizeof(tokbuf
)),
2180 case BGP_CAPCODE_MP
:
2181 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
2182 tok2strbuf(af_values
, "Unknown",
2183 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
2184 tokbuf
, sizeof(tokbuf
)),
2185 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
2186 tok2strbuf(bgp_safi_values
, "Unknown",
2187 opt
[i
+BGP_OPT_SIZE
+5],
2188 tokbuf
, sizeof(tokbuf
)),
2189 opt
[i
+BGP_OPT_SIZE
+5]);
2191 case BGP_CAPCODE_RESTART
:
2192 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
2193 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
2194 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
2197 while(tcap_len
>=4) {
2198 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2199 tok2strbuf(af_values
,"Unknown",
2200 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
2201 tokbuf
, sizeof(tokbuf
)),
2202 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
2203 tok2strbuf(bgp_safi_values
,"Unknown",
2204 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
2205 tokbuf2
, sizeof(tokbuf2
)),
2206 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
2207 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
2212 case BGP_CAPCODE_RR
:
2213 case BGP_CAPCODE_RR_CISCO
:
2215 case BGP_CAPCODE_AS_NEW
:
2218 * Extract the 4 byte AS number encoded.
2220 TCHECK2(opt
[i
+ BGP_OPT_SIZE
+ 2], cap_len
);
2222 printf("\n\t\t 4 Byte AS %s",
2223 as_printf(astostr
, sizeof(astostr
),
2224 EXTRACT_32BITS(opt
+ i
+ BGP_OPT_SIZE
+ 2)));
2228 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
2229 printf("\n\t\tno decoder for Capability %u",
2232 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
2236 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
2237 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
2242 printf("\n\t no decoder for option %u",
2243 bgpopt
.bgpopt_type
);
2247 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
2255 bgp_update_print(const u_char
*dat
, int length
)
2258 struct bgp_attr bgpa
;
2262 char tokbuf
[TOKBUFSIZE
];
2264 TCHECK2(dat
[0], BGP_SIZE
);
2265 memcpy(&bgp
, dat
, BGP_SIZE
);
2266 p
= dat
+ BGP_SIZE
; /*XXX*/
2268 /* Unfeasible routes */
2269 len
= EXTRACT_16BITS(p
);
2272 * Without keeping state from the original NLRI message,
2273 * it's not possible to tell if this a v4 or v6 route,
2274 * so only try to decode it if we're not v6 enabled.
2277 printf("\n\t Withdrawn routes: %d bytes", len
);
2279 char buf
[MAXHOSTNAMELEN
+ 100];
2285 printf("\n\t Withdrawn routes:");
2287 while(i
< 2 + len
) {
2288 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
2290 printf("\n\t (illegal prefix length)");
2292 } else if (wpfx
== -2)
2296 printf("\n\t %s", buf
);
2304 len
= EXTRACT_16BITS(p
);
2306 if (len
== 0 && length
== BGP_UPDATE_MINSIZE
) {
2307 printf("\n\t End-of-Rib Marker (empty NLRI)");
2312 /* do something more useful!*/
2314 while (i
< 2 + len
) {
2317 TCHECK2(p
[i
], sizeof(bgpa
));
2318 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
2319 alen
= bgp_attr_len(&bgpa
);
2320 aoff
= bgp_attr_off(&bgpa
);
2322 printf("\n\t %s (%u), length: %u",
2323 tok2strbuf(bgp_attr_values
, "Unknown Attribute",
2325 tokbuf
, sizeof(tokbuf
)),
2329 if (bgpa
.bgpa_flags
) {
2330 printf(", Flags [%s%s%s%s",
2331 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
2332 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
2333 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
2334 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
2335 if (bgpa
.bgpa_flags
& 0xf)
2336 printf("+%x", bgpa
.bgpa_flags
& 0xf);
2339 if (!bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
))
2346 if (dat
+ length
> p
) {
2347 printf("\n\t Updated routes:");
2348 while (dat
+ length
> p
) {
2349 char buf
[MAXHOSTNAMELEN
+ 100];
2350 i
= decode_prefix4(p
, buf
, sizeof(buf
));
2352 printf("\n\t (illegal prefix length)");
2357 printf("\n\t %s", buf
);
2368 bgp_notification_print(const u_char
*dat
, int length
)
2370 struct bgp_notification bgpn
;
2372 char tokbuf
[TOKBUFSIZE
];
2373 char tokbuf2
[TOKBUFSIZE
];
2375 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
2376 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
2378 /* some little sanity checking */
2379 if (length
<BGP_NOTIFICATION_SIZE
)
2383 tok2strbuf(bgp_notify_major_values
, "Unknown Error",
2384 bgpn
.bgpn_major
, tokbuf
, sizeof(tokbuf
)),
2387 switch (bgpn
.bgpn_major
) {
2389 case BGP_NOTIFY_MAJOR_MSG
:
2390 printf(", subcode %s (%u)",
2391 tok2strbuf(bgp_notify_minor_msg_values
, "Unknown",
2392 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2395 case BGP_NOTIFY_MAJOR_OPEN
:
2396 printf(", subcode %s (%u)",
2397 tok2strbuf(bgp_notify_minor_open_values
, "Unknown",
2398 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2401 case BGP_NOTIFY_MAJOR_UPDATE
:
2402 printf(", subcode %s (%u)",
2403 tok2strbuf(bgp_notify_minor_update_values
, "Unknown",
2404 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2407 case BGP_NOTIFY_MAJOR_CAP
:
2408 printf(" subcode %s (%u)",
2409 tok2strbuf(bgp_notify_minor_cap_values
, "Unknown",
2410 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2412 case BGP_NOTIFY_MAJOR_CEASE
:
2413 printf(", subcode %s (%u)",
2414 tok2strbuf(bgp_notify_minor_cease_values
, "Unknown",
2415 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2418 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2419 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2421 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2422 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2424 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2425 tok2strbuf(af_values
, "Unknown",
2426 EXTRACT_16BITS(tptr
), tokbuf
, sizeof(tokbuf
)),
2427 EXTRACT_16BITS(tptr
),
2428 tok2strbuf(bgp_safi_values
, "Unknown", *(tptr
+2),
2429 tokbuf2
, sizeof(tokbuf
)),
2431 EXTRACT_32BITS(tptr
+3));
2444 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
2446 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2447 char tokbuf
[TOKBUFSIZE
];
2448 char tokbuf2
[TOKBUFSIZE
];
2450 TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
2452 /* some little sanity checking */
2453 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2456 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2458 printf("\n\t AFI %s (%u), SAFI %s (%u)",
2459 tok2strbuf(af_values
,"Unknown",
2460 /* this stinks but the compiler pads the structure
2462 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2463 tokbuf
, sizeof(tokbuf
)),
2464 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2465 tok2strbuf(bgp_safi_values
,"Unknown",
2466 bgp_route_refresh_header
->safi
,
2467 tokbuf2
, sizeof(tokbuf2
)),
2468 bgp_route_refresh_header
->safi
);
2471 TCHECK2(*pptr
, len
);
2472 print_unknown_data(pptr
,"\n\t ", len
);
2481 bgp_header_print(const u_char
*dat
, int length
)
2484 char tokbuf
[TOKBUFSIZE
];
2486 TCHECK2(dat
[0], BGP_SIZE
);
2487 memcpy(&bgp
, dat
, BGP_SIZE
);
2488 printf("\n\t%s Message (%u), length: %u",
2489 tok2strbuf(bgp_msg_values
, "Unknown", bgp
.bgp_type
,
2490 tokbuf
, sizeof(tokbuf
)),
2494 switch (bgp
.bgp_type
) {
2496 bgp_open_print(dat
, length
);
2499 bgp_update_print(dat
, length
);
2501 case BGP_NOTIFICATION
:
2502 bgp_notification_print(dat
, length
);
2506 case BGP_ROUTE_REFRESH
:
2507 bgp_route_refresh_print(dat
, length
);
2510 /* we have no decoder for the BGP message */
2511 TCHECK2(*dat
, length
);
2512 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
2513 print_unknown_data(dat
,"\n\t ",length
);
2523 bgp_print(const u_char
*dat
, int length
)
2527 const u_char
*start
;
2528 const u_char marker
[] = {
2529 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2530 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2534 char tokbuf
[TOKBUFSIZE
];
2537 if (snapend
< dat
+ length
)
2540 printf(": BGP, length: %u",length
);
2542 if (vflag
< 1) /* lets be less chatty */
2548 if (!TTEST2(p
[0], 1))
2555 if (!TTEST2(p
[0], sizeof(marker
)))
2557 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2562 /* found BGP header */
2563 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2564 memcpy(&bgp
, p
, BGP_SIZE
);
2569 hlen
= ntohs(bgp
.bgp_len
);
2570 if (hlen
< BGP_SIZE
) {
2571 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
2576 if (TTEST2(p
[0], hlen
)) {
2577 if (!bgp_header_print(p
, hlen
))
2582 printf("\n[|BGP %s]",
2583 tok2strbuf(bgp_msg_values
,
2584 "Unknown Message Type",
2586 tokbuf
, sizeof(tokbuf
)));
2599 * c-style: whitesmith