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.117.2.1 2007-12-08 10:08:07 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 #define SAFNUM_MDT 66 /* XXX */
350 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
351 #define SAFNUM_VPNUNICAST 128
352 #define SAFNUM_VPNMULTICAST 129
353 #define SAFNUM_VPNUNIMULTICAST 130
354 /* draft-marques-ppvpn-rt-constrain-01.txt */
355 #define SAFNUM_RT_ROUTING_INFO 132
357 #define BGP_VPN_RD_LEN 8
359 static struct tok bgp_safi_values
[] = {
360 { SAFNUM_RES
, "Reserved"},
361 { SAFNUM_UNICAST
, "Unicast"},
362 { SAFNUM_MULTICAST
, "Multicast"},
363 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
364 { SAFNUM_LABUNICAST
, "labeled Unicast"},
365 { SAFNUM_TUNNEL
, "Tunnel"},
366 { SAFNUM_VPLS
, "VPLS"},
367 { SAFNUM_MDT
, "MDT"},
368 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
369 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
370 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
371 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
372 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
376 /* well-known community */
377 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
378 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
379 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
381 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
382 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
383 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
384 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
385 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
386 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
387 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
388 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
389 /* rfc2547 bgp-mpls-vpns */
390 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
391 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
392 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
393 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
395 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
396 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
398 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
399 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
401 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
403 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
404 #define BGP_EXT_COM_VRF_RT_IMP 0x010a /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
406 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
407 #define BGP_EXT_COM_EIGRP_GEN 0x8800
408 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
409 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
410 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
411 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
412 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
414 static struct tok bgp_extd_comm_flag_values
[] = {
415 { 0x8000, "vendor-specific"},
416 { 0x4000, "non-transitive"},
420 static struct tok bgp_extd_comm_subtype_values
[] = {
421 { BGP_EXT_COM_RT_0
, "target"},
422 { BGP_EXT_COM_RT_1
, "target"},
423 { BGP_EXT_COM_RT_2
, "target"},
424 { BGP_EXT_COM_RO_0
, "origin"},
425 { BGP_EXT_COM_RO_1
, "origin"},
426 { BGP_EXT_COM_RO_2
, "origin"},
427 { BGP_EXT_COM_LINKBAND
, "link-BW"},
428 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
429 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
430 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
431 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
432 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
433 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
434 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
435 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
436 { BGP_EXT_COM_L2INFO
, "layer2-info"},
437 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
438 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
439 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
440 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
441 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
442 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
443 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
444 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
448 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
449 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
450 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
451 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
452 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
453 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
454 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
455 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
457 static struct tok bgp_extd_comm_ospf_rtype_values
[] = {
458 { BGP_OSPF_RTYPE_RTR
, "Router" },
459 { BGP_OSPF_RTYPE_NET
, "Network" },
460 { BGP_OSPF_RTYPE_SUM
, "Summary" },
461 { BGP_OSPF_RTYPE_EXT
, "External" },
462 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
463 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
468 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
478 memset(&addr
, 0, sizeof(addr
));
479 TCHECK2(pptr
[1], (plen
+ 7) / 8);
480 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
482 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
483 ((0xff00 >> (plen
% 8)) & 0xff);
485 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
486 return 1 + (plen
+ 7) / 8;
493 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
499 plen
= pptr
[0]; /* get prefix length */
501 /* this is one of the weirdnesses of rfc3107
502 the label length (actually the label + COS bits)
503 is added to the prefix length;
504 we also do only read out just one label -
505 there is no real application for advertisement of
506 stacked labels in a a single BGP message
512 plen
-=24; /* adjust prefixlen - labellength */
517 memset(&addr
, 0, sizeof(addr
));
518 TCHECK2(pptr
[4], (plen
+ 7) / 8);
519 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
521 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
522 ((0xff00 >> (plen
% 8)) & 0xff);
524 /* the label may get offsetted by 4 bits so lets shift it right */
525 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
526 getname((u_char
*)&addr
),
528 EXTRACT_24BITS(pptr
+1)>>4,
529 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
531 return 4 + (plen
+ 7) / 8;
540 * print an ipv4 or ipv6 address into a buffer dependend on address length.
543 bgp_vpn_ip_print (const u_char
*pptr
, u_int addr_length
) {
545 /* worst case string is s fully formatted v6 address */
546 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
549 switch(addr_length
) {
550 case (sizeof(struct in_addr
) << 3): /* 32 */
551 TCHECK2(pptr
[0], sizeof(struct in_addr
));
552 snprintf(pos
, sizeof(addr
), "%s", ipaddr_string(pptr
));
555 case (sizeof(struct in6_addr
) << 3): /* 128 */
556 TCHECK2(pptr
[0], sizeof(struct in6_addr
));
557 snprintf(pos
, sizeof(addr
), "%s", ip6addr_string(pptr
));
561 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
574 * print an multicast s,g entry into a buffer.
575 * the s,g entry is encoded like this.
577 * +-----------------------------------+
578 * | Multicast Source Length (1 octet) |
579 * +-----------------------------------+
580 * | Multicast Source (Variable) |
581 * +-----------------------------------+
582 * | Multicast Group Length (1 octet) |
583 * +-----------------------------------+
584 * | Multicast Group (Variable) |
585 * +-----------------------------------+
587 * return the number of bytes read from the wire.
590 bgp_vpn_sg_print (const u_char
*pptr
, char *buf
, u_int buflen
) {
592 u_int8_t addr_length
;
593 u_int total_length
, offset
;
597 /* Source address length, encoded in bits */
599 addr_length
= *pptr
++;
602 TCHECK2(pptr
[0], (addr_length
>> 3));
603 total_length
+= (addr_length
>> 3) + 1;
604 offset
= strlen(buf
);
606 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
607 bgp_vpn_ip_print(pptr
, addr_length
));
608 pptr
+= (addr_length
>> 3);
611 /* Group address length, encoded in bits */
613 addr_length
= *pptr
++;
616 TCHECK2(pptr
[0], (addr_length
>> 3));
617 total_length
+= (addr_length
>> 3) + 1;
618 offset
= strlen(buf
);
620 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
621 bgp_vpn_ip_print(pptr
, addr_length
));
622 pptr
+= (addr_length
>> 3);
626 return (total_length
);
630 /* RDs and RTs share the same semantics
631 * we use bgp_vpn_rd_print for
632 * printing route targets inside a NLRI */
634 bgp_vpn_rd_print (const u_char
*pptr
) {
636 /* allocate space for the largest possible string */
637 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
640 /* ok lets load the RD format */
641 switch (EXTRACT_16BITS(pptr
)) {
643 /* 2-byte-AS:number fmt*/
645 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
646 EXTRACT_16BITS(pptr
+2),
647 EXTRACT_32BITS(pptr
+4),
648 *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
650 /* IP-address:AS fmt*/
653 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
654 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
657 /* 4-byte-AS:number fmt*/
659 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (%u.%u.%u.%u:%u)",
660 EXTRACT_32BITS(pptr
+2), EXTRACT_16BITS(pptr
+6),
661 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
664 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
673 decode_rt_routing_info(const u_char
*pptr
, char *buf
, u_int buflen
)
675 u_int8_t route_target
[8];
679 plen
= pptr
[0]; /* get prefix length */
682 return 1; /* default route target */
687 plen
-=32; /* adjust prefix length */
692 memset(&route_target
, 0, sizeof(route_target
));
693 TCHECK2(pptr
[1], (plen
+ 7) / 8);
694 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
696 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
697 ((0xff00 >> (plen
% 8)) & 0xff);
699 snprintf(buf
, buflen
, "origin AS: %u, route target %s",
700 EXTRACT_32BITS(pptr
+1),
701 bgp_vpn_rd_print((u_char
*)&route_target
));
703 return 5 + (plen
+ 7) / 8;
710 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
716 plen
= pptr
[0]; /* get prefix length */
721 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
726 memset(&addr
, 0, sizeof(addr
));
727 TCHECK2(pptr
[12], (plen
+ 7) / 8);
728 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
730 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
731 ((0xff00 >> (plen
% 8)) & 0xff);
733 /* the label may get offsetted by 4 bits so lets shift it right */
734 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
735 bgp_vpn_rd_print(pptr
+4),
736 getname((u_char
*)&addr
),
738 EXTRACT_24BITS(pptr
+1)>>4,
739 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
741 return 12 + (plen
+ 7) / 8;
747 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
748 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
749 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
750 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
751 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
752 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
753 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
755 static struct tok bgp_multicast_vpn_route_type_values
[] = {
756 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
757 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
758 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
759 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
760 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
761 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
762 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
766 decode_multicast_vpn(const u_char
*pptr
, char *buf
, u_int buflen
)
768 u_int8_t route_type
, route_length
, addr_length
, sg_length
;
772 route_type
= *pptr
++;
773 route_length
= *pptr
++;
775 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
776 tok2str(bgp_multicast_vpn_route_type_values
,
777 "Unknown", route_type
),
778 route_type
, route_length
);
781 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
782 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
783 offset
= strlen(buf
);
784 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
785 bgp_vpn_rd_print(pptr
),
786 bgp_vpn_ip_print(pptr
+ BGP_VPN_RD_LEN
,
787 (route_length
- BGP_VPN_RD_LEN
) << 3));
789 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
790 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
+ 4);
791 offset
= strlen(buf
);
792 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %u",
793 bgp_vpn_rd_print(pptr
),
794 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
));
797 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
798 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
799 offset
= strlen(buf
);
800 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
801 bgp_vpn_rd_print(pptr
));
802 pptr
+= BGP_VPN_RD_LEN
;
804 sg_length
= bgp_vpn_sg_print(pptr
, buf
, buflen
);
805 addr_length
= route_length
- sg_length
;
807 TCHECK2(pptr
[0], addr_length
);
808 offset
= strlen(buf
);
809 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
810 bgp_vpn_ip_print(pptr
, addr_length
<< 3));
813 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
814 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
815 offset
= strlen(buf
);
816 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
817 bgp_vpn_rd_print(pptr
));
818 pptr
+= BGP_VPN_RD_LEN
;
820 bgp_vpn_sg_print(pptr
, buf
, buflen
);
823 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
824 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
825 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
826 offset
= strlen(buf
);
827 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %u",
828 bgp_vpn_rd_print(pptr
),
829 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
));
830 pptr
+= BGP_VPN_RD_LEN
;
832 bgp_vpn_sg_print(pptr
, buf
, buflen
);
836 * no per route-type printing yet.
838 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
843 return route_length
+ 2;
850 * As I remember, some versions of systems have an snprintf() that
851 * returns -1 if the buffer would have overflowed. If the return
852 * value is negative, set buflen to 0, to indicate that we've filled
855 * If the return value is greater than buflen, that means that
856 * the buffer would have overflowed; again, set buflen to 0 in
859 #define UPDATE_BUF_BUFLEN(buf, buflen, strlen) \
862 else if ((u_int)strlen>buflen) \
870 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
872 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
875 plen
=EXTRACT_16BITS(pptr
);
880 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
881 bgp_vpn_rd_print(pptr
),
882 EXTRACT_16BITS(pptr
+8),
883 EXTRACT_16BITS(pptr
+10),
884 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
885 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
889 /* ok now the variable part - lets read out TLVs*/
895 tlv_len
=EXTRACT_16BITS(pptr
);
902 strlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
905 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
907 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
911 strlen
=snprintf(buf
,buflen
, "%02x",*pptr
++);
912 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
919 strlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
922 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
926 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
936 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
938 struct in6_addr addr
;
946 memset(&addr
, 0, sizeof(addr
));
947 TCHECK2(pd
[1], (plen
+ 7) / 8);
948 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
950 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
951 ((0xff00 >> (plen
% 8)) & 0xff);
953 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
954 return 1 + (plen
+ 7) / 8;
961 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
963 struct in6_addr addr
;
967 plen
= pptr
[0]; /* get prefix length */
972 plen
-=24; /* adjust prefixlen - labellength */
977 memset(&addr
, 0, sizeof(addr
));
978 TCHECK2(pptr
[4], (plen
+ 7) / 8);
979 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
981 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
982 ((0xff00 >> (plen
% 8)) & 0xff);
984 /* the label may get offsetted by 4 bits so lets shift it right */
985 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
986 getname6((u_char
*)&addr
),
988 EXTRACT_24BITS(pptr
+1)>>4,
989 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
991 return 4 + (plen
+ 7) / 8;
998 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
1000 struct in6_addr addr
;
1004 plen
= pptr
[0]; /* get prefix length */
1009 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1014 memset(&addr
, 0, sizeof(addr
));
1015 TCHECK2(pptr
[12], (plen
+ 7) / 8);
1016 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1018 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1019 ((0xff00 >> (plen
% 8)) & 0xff);
1021 /* the label may get offsetted by 4 bits so lets shift it right */
1022 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1023 bgp_vpn_rd_print(pptr
+4),
1024 getname6((u_char
*)&addr
),
1026 EXTRACT_24BITS(pptr
+1)>>4,
1027 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1029 return 12 + (plen
+ 7) / 8;
1037 decode_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
1043 plen
= pptr
[0]; /* get prefix length */
1048 memset(&addr
, 0, sizeof(addr
));
1049 TCHECK2(pptr
[4], (plen
+ 7) / 8);
1050 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
1052 addr
[(plen
+ 7) / 8 - 1] &=
1053 ((0xff00 >> (plen
% 8)) & 0xff);
1055 snprintf(buf
, buflen
, "%s/%d",
1056 isonsap_string(addr
,(plen
+ 7) / 8),
1059 return 1 + (plen
+ 7) / 8;
1066 decode_labeled_vpn_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
1072 plen
= pptr
[0]; /* get prefix length */
1077 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1082 memset(&addr
, 0, sizeof(addr
));
1083 TCHECK2(pptr
[12], (plen
+ 7) / 8);
1084 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1086 addr
[(plen
+ 7) / 8 - 1] &=
1087 ((0xff00 >> (plen
% 8)) & 0xff);
1089 /* the label may get offsetted by 4 bits so lets shift it right */
1090 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1091 bgp_vpn_rd_print(pptr
+4),
1092 isonsap_string(addr
,(plen
+ 7) / 8),
1094 EXTRACT_24BITS(pptr
+1)>>4,
1095 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1097 return 12 + (plen
+ 7) / 8;
1104 * bgp_attr_get_as_size
1106 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1107 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1108 * support, exchange AS-Path with the same path-attribute type value 0x02.
1111 bgp_attr_get_as_size (u_int8_t bgpa_type
, const u_char
*pptr
, int len
)
1113 const u_char
*tptr
= pptr
;
1116 * If the path attribute is the optional AS4 path type, then we already
1117 * know, that ASs must be encoded in 4 byte format.
1119 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1124 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1125 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1128 while (tptr
< pptr
+ len
) {
1132 * If we do not find a valid segment type, our guess might be wrong.
1134 if (tptr
[0] < BGP_AS_SEG_TYPE_MIN
|| tptr
[0] > BGP_AS_SEG_TYPE_MAX
) {
1138 tptr
+= 2 + tptr
[1] * 2;
1142 * If we correctly reached end of the AS path attribute data content,
1143 * then most likely ASs were indeed encoded as 2 bytes.
1145 if (tptr
== pptr
+ len
) {
1152 * We can come here, either we did not have enough data, or if we
1153 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1154 * so that calller can try to decode each AS as of 4 bytes. If indeed
1155 * there was not enough data, it will crib and end the parse anyways.
1161 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
1165 u_int8_t safi
, snpa
, nhlen
;
1166 union { /* copy buffer for bandwidth values */
1173 char buf
[MAXHOSTNAMELEN
+ 100];
1174 char tokbuf
[TOKBUFSIZE
];
1180 switch (attr
->bgpa_type
) {
1181 case BGPTYPE_ORIGIN
:
1183 printf("invalid len");
1186 printf("%s", tok2strbuf(bgp_origin_values
,
1187 "Unknown Origin Typecode",
1189 tokbuf
, sizeof(tokbuf
)));
1195 * Process AS4 byte path and AS2 byte path attributes here.
1197 case BGPTYPE_AS4_PATH
:
1198 case BGPTYPE_AS_PATH
:
1200 printf("invalid len");
1209 * BGP updates exchanged between New speakers that support 4
1210 * byte AS, ASs are always encoded in 4 bytes. There is no
1211 * definitive way to find this, just by the packet's
1212 * contents. So, check for packet's TLV's sanity assuming
1213 * 2 bytes first, and it does not pass, assume that ASs are
1214 * encoded in 4 bytes format and move on.
1216 as_size
= bgp_attr_get_as_size(attr
->bgpa_type
, pptr
, len
);
1218 while (tptr
< pptr
+ len
) {
1220 printf("%s", tok2strbuf(bgp_as_path_segment_open_values
,
1222 tokbuf
, sizeof(tokbuf
)));
1223 for (i
= 0; i
< tptr
[1] * as_size
; i
+= as_size
) {
1224 TCHECK2(tptr
[2 + i
], as_size
);
1226 as_size
== 2 ? EXTRACT_16BITS(&tptr
[2 + i
]) :
1227 EXTRACT_32BITS(&tptr
[2 + i
]));
1230 printf("%s", tok2strbuf(bgp_as_path_segment_close_values
,
1232 tokbuf
, sizeof(tokbuf
)));
1234 tptr
+= 2 + tptr
[1] * as_size
;
1237 case BGPTYPE_NEXT_HOP
:
1239 printf("invalid len");
1241 TCHECK2(tptr
[0], 4);
1242 printf("%s", getname(tptr
));
1245 case BGPTYPE_MULTI_EXIT_DISC
:
1246 case BGPTYPE_LOCAL_PREF
:
1248 printf("invalid len");
1250 TCHECK2(tptr
[0], 4);
1251 printf("%u", EXTRACT_32BITS(tptr
));
1254 case BGPTYPE_ATOMIC_AGGREGATE
:
1256 printf("invalid len");
1258 case BGPTYPE_AGGREGATOR
:
1260 printf("invalid len");
1263 TCHECK2(tptr
[0], 6);
1264 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
1267 case BGPTYPE_AGGREGATOR4
:
1269 printf("invalid len");
1272 TCHECK2(tptr
[0], 8);
1273 printf(" AS #%u, origin %s", EXTRACT_32BITS(tptr
),
1276 case BGPTYPE_COMMUNITIES
:
1278 printf("invalid len");
1283 TCHECK2(tptr
[0], 4);
1284 comm
= EXTRACT_32BITS(tptr
);
1286 case BGP_COMMUNITY_NO_EXPORT
:
1287 printf(" NO_EXPORT");
1289 case BGP_COMMUNITY_NO_ADVERT
:
1290 printf(" NO_ADVERTISE");
1292 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1293 printf(" NO_EXPORT_SUBCONFED");
1297 (comm
>> 16) & 0xffff,
1299 (tlen
>4) ? ", " : "");
1306 case BGPTYPE_ORIGINATOR_ID
:
1308 printf("invalid len");
1311 TCHECK2(tptr
[0], 4);
1312 printf("%s",getname(tptr
));
1314 case BGPTYPE_CLUSTER_LIST
:
1316 printf("invalid len");
1320 TCHECK2(tptr
[0], 4);
1323 (tlen
>4) ? ", " : "");
1328 case BGPTYPE_MP_REACH_NLRI
:
1329 TCHECK2(tptr
[0], 3);
1330 af
= EXTRACT_16BITS(tptr
);
1333 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1334 tok2strbuf(af_values
, "Unknown AFI", af
,
1335 tokbuf
, sizeof(tokbuf
)),
1337 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1338 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1339 tokbuf
, sizeof(tokbuf
)),
1342 switch(af
<<8 | safi
) {
1343 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1344 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1345 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1346 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1347 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1348 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1349 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1350 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1351 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1353 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1354 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1355 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1356 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1357 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1358 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1359 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1361 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1362 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1363 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1364 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1365 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1366 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1367 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1368 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1369 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1370 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1373 TCHECK2(tptr
[0], tlen
);
1374 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1376 print_unknown_data(tptr
,"\n\t ",tlen
);
1389 printf("\n\t nexthop: ");
1391 switch(af
<<8 | safi
) {
1392 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1393 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1394 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1395 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1396 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1397 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1398 if (tlen
< (int)sizeof(struct in_addr
)) {
1399 printf("invalid len");
1402 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1403 printf("%s",getname(tptr
));
1404 tlen
-= sizeof(struct in_addr
);
1405 tptr
+= sizeof(struct in_addr
);
1408 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1409 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1410 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1411 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1412 printf("invalid len");
1415 TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1416 printf("RD: %s, %s",
1417 bgp_vpn_rd_print(tptr
),
1418 getname(tptr
+BGP_VPN_RD_LEN
));
1419 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1420 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1424 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1425 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1426 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1427 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1428 if (tlen
< (int)sizeof(struct in6_addr
)) {
1429 printf("invalid len");
1432 TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1433 printf("%s", getname6(tptr
));
1434 tlen
-= sizeof(struct in6_addr
);
1435 tptr
+= sizeof(struct in6_addr
);
1438 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1439 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1440 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1441 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1442 printf("invalid len");
1445 TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1446 printf("RD: %s, %s",
1447 bgp_vpn_rd_print(tptr
),
1448 getname6(tptr
+BGP_VPN_RD_LEN
));
1449 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1450 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1454 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1455 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1456 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1457 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1458 if (tlen
< (int)sizeof(struct in_addr
)) {
1459 printf("invalid len");
1462 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1463 printf("%s", getname(tptr
));
1464 tlen
-= (sizeof(struct in_addr
));
1465 tptr
+= (sizeof(struct in_addr
));
1468 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1469 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1470 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1471 TCHECK2(tptr
[0], tlen
);
1472 printf("%s",isonsap_string(tptr
,tlen
));
1477 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1478 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1479 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1480 if (tlen
< BGP_VPN_RD_LEN
+1) {
1481 printf("invalid len");
1484 TCHECK2(tptr
[0], tlen
);
1485 printf("RD: %s, %s",
1486 bgp_vpn_rd_print(tptr
),
1487 isonsap_string(tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
));
1488 /* rfc986 mapped IPv4 address ? */
1489 if (EXTRACT_32BITS(tptr
+BGP_VPN_RD_LEN
) == 0x47000601)
1490 printf(" = %s", getname(tptr
+BGP_VPN_RD_LEN
+4));
1492 /* rfc1888 mapped IPv6 address ? */
1493 else if (EXTRACT_24BITS(tptr
+BGP_VPN_RD_LEN
) == 0x350000)
1494 printf(" = %s", getname6(tptr
+BGP_VPN_RD_LEN
+3));
1501 TCHECK2(tptr
[0], tlen
);
1502 printf("no AFI %u/SAFI %u decoder",af
,safi
);
1504 print_unknown_data(tptr
,"\n\t ",tlen
);
1512 printf(", nh-length: %u", nhlen
);
1520 printf("\n\t %u SNPA", snpa
);
1521 for (/*nothing*/; snpa
> 0; snpa
--) {
1523 printf("\n\t %d bytes", tptr
[0]);
1524 tptr
+= tptr
[0] + 1;
1527 printf(", no SNPA");
1530 while (len
- (tptr
- pptr
) > 0) {
1531 switch (af
<<8 | safi
) {
1532 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1533 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1534 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1535 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1537 printf("\n\t (illegal prefix length)");
1538 else if (advance
== -2)
1541 printf("\n\t %s", buf
);
1543 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1544 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1546 printf("\n\t (illegal prefix length)");
1547 else if (advance
== -2)
1550 printf("\n\t %s", buf
);
1552 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1553 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1554 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1555 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1557 printf("\n\t (illegal prefix length)");
1558 else if (advance
== -2)
1561 printf("\n\t %s", buf
);
1563 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1564 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1566 printf("\n\t (illegal prefix length)");
1567 else if (advance
== -2)
1570 printf("\n\t %s", buf
);
1572 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1573 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1574 advance
= decode_multicast_vpn(tptr
, buf
, sizeof(buf
));
1576 printf("\n\t (illegal prefix length)");
1577 else if (advance
== -2)
1580 printf("\n\t %s", buf
);
1583 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1584 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1585 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1586 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1588 printf("\n\t (illegal prefix length)");
1589 else if (advance
== -2)
1592 printf("\n\t %s", buf
);
1594 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1595 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1597 printf("\n\t (illegal prefix length)");
1598 else if (advance
== -2)
1601 printf("\n\t %s", buf
);
1603 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1604 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1605 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1606 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1608 printf("\n\t (illegal prefix length)");
1609 else if (advance
== -2)
1612 printf("\n\t %s", buf
);
1615 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1616 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1617 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1618 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1619 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1621 printf("\n\t (illegal length)");
1622 else if (advance
== -2)
1625 printf("\n\t %s", buf
);
1627 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1628 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1629 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1630 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1632 printf("\n\t (illegal prefix length)");
1633 else if (advance
== -2)
1636 printf("\n\t %s", buf
);
1638 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1639 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1640 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1641 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1643 printf("\n\t (illegal prefix length)");
1644 else if (advance
== -2)
1647 printf("\n\t %s", buf
);
1650 TCHECK2(*tptr
,tlen
);
1651 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1653 print_unknown_data(tptr
,"\n\t ",tlen
);
1665 case BGPTYPE_MP_UNREACH_NLRI
:
1666 TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1667 af
= EXTRACT_16BITS(tptr
);
1670 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1671 tok2strbuf(af_values
, "Unknown AFI", af
,
1672 tokbuf
, sizeof(tokbuf
)),
1674 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1675 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1676 tokbuf
, sizeof(tokbuf
)),
1679 if (len
== BGP_MP_NLRI_MINSIZE
)
1680 printf("\n\t End-of-Rib Marker (empty NLRI)");
1684 while (len
- (tptr
- pptr
) > 0) {
1685 switch (af
<<8 | safi
) {
1686 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1687 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1688 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1689 advance
= decode_prefix4(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_INET
<<8 | SAFNUM_LABUNICAST
):
1698 advance
= decode_labeled_prefix4(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_INET
<<8 | SAFNUM_VPNUNICAST
):
1707 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1708 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1709 advance
= decode_labeled_vpn_prefix4(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_INET6
<<8 | SAFNUM_UNICAST
):
1719 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1720 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1721 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1723 printf("\n\t (illegal prefix length)");
1724 else if (advance
== -2)
1727 printf("\n\t %s", buf
);
1729 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1730 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1732 printf("\n\t (illegal prefix length)");
1733 else if (advance
== -2)
1736 printf("\n\t %s", buf
);
1738 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1739 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1740 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1741 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1743 printf("\n\t (illegal prefix length)");
1744 else if (advance
== -2)
1747 printf("\n\t %s", buf
);
1750 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1751 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1752 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1753 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1754 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1756 printf("\n\t (illegal length)");
1757 else if (advance
== -2)
1760 printf("\n\t %s", buf
);
1762 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1763 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1764 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1765 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1767 printf("\n\t (illegal prefix length)");
1768 else if (advance
== -2)
1771 printf("\n\t %s", buf
);
1773 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1774 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1775 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1776 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1778 printf("\n\t (illegal prefix length)");
1779 else if (advance
== -2)
1782 printf("\n\t %s", buf
);
1784 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1785 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1786 advance
= decode_multicast_vpn(tptr
, buf
, sizeof(buf
));
1788 printf("\n\t (illegal prefix length)");
1789 else if (advance
== -2)
1792 printf("\n\t %s", buf
);
1795 TCHECK2(*(tptr
-3),tlen
);
1796 printf("no AFI %u / SAFI %u decoder",af
,safi
);
1798 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1808 case BGPTYPE_EXTD_COMMUNITIES
:
1810 printf("invalid len");
1814 u_int16_t extd_comm
;
1816 TCHECK2(tptr
[0], 2);
1817 extd_comm
=EXTRACT_16BITS(tptr
);
1819 printf("\n\t %s (0x%04x), Flags [%s]",
1820 tok2strbuf(bgp_extd_comm_subtype_values
,
1821 "unknown extd community typecode",
1822 extd_comm
, tokbuf
, sizeof(tokbuf
)),
1824 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1826 TCHECK2(*(tptr
+2), 6);
1828 case BGP_EXT_COM_RT_0
:
1829 case BGP_EXT_COM_RO_0
:
1830 printf(": %u:%u (= %s)",
1831 EXTRACT_16BITS(tptr
+2),
1832 EXTRACT_32BITS(tptr
+4),
1835 case BGP_EXT_COM_RT_1
:
1836 case BGP_EXT_COM_RO_1
:
1837 case BGP_EXT_COM_VRF_RT_IMP
:
1840 EXTRACT_16BITS(tptr
+6));
1842 case BGP_EXT_COM_RT_2
:
1843 case BGP_EXT_COM_RO_2
:
1845 EXTRACT_32BITS(tptr
+2),
1846 EXTRACT_16BITS(tptr
+6));
1848 case BGP_EXT_COM_LINKBAND
:
1849 bw
.i
= EXTRACT_32BITS(tptr
+2);
1850 printf(": bandwidth: %.3f Mbps",
1853 case BGP_EXT_COM_VPN_ORIGIN
:
1854 case BGP_EXT_COM_VPN_ORIGIN2
:
1855 case BGP_EXT_COM_VPN_ORIGIN3
:
1856 case BGP_EXT_COM_VPN_ORIGIN4
:
1857 case BGP_EXT_COM_OSPF_RID
:
1858 case BGP_EXT_COM_OSPF_RID2
:
1859 printf("%s", getname(tptr
+2));
1861 case BGP_EXT_COM_OSPF_RTYPE
:
1862 case BGP_EXT_COM_OSPF_RTYPE2
:
1863 printf(": area:%s, router-type:%s, metric-type:%s%s",
1865 tok2strbuf(bgp_extd_comm_ospf_rtype_values
,
1868 tokbuf
, sizeof(tokbuf
)),
1869 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1870 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1872 case BGP_EXT_COM_L2INFO
:
1873 printf(": %s Control Flags [0x%02x]:MTU %u",
1874 tok2strbuf(l2vpn_encaps_values
,
1877 tokbuf
, sizeof(tokbuf
)),
1879 EXTRACT_16BITS(tptr
+4));
1881 case BGP_EXT_COM_SOURCE_AS
:
1882 printf(": AS %u", EXTRACT_16BITS(tptr
+2));
1886 print_unknown_data(tptr
,"\n\t ",8);
1894 case BGPTYPE_PMSI_TUNNEL
:
1896 u_int8_t tunnel_type
, flags
;
1898 tunnel_type
= *(tptr
+1);
1902 TCHECK2(tptr
[0], 5);
1903 printf("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
1904 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
1906 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
1907 EXTRACT_24BITS(tptr
+2)>>4);
1912 switch (tunnel_type
) {
1913 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
1914 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
1915 TCHECK2(tptr
[0], 8);
1916 printf("\n\t Sender %s, P-Group %s",
1917 ipaddr_string(tptr
),
1918 ipaddr_string(tptr
+4));
1921 case BGP_PMSI_TUNNEL_PIM_SSM
:
1922 TCHECK2(tptr
[0], 8);
1923 printf("\n\t Root-Node %s, P-Group %s",
1924 ipaddr_string(tptr
),
1925 ipaddr_string(tptr
+4));
1927 case BGP_PMSI_TUNNEL_INGRESS
:
1928 TCHECK2(tptr
[0], 4);
1929 printf("\n\t Tunnel-Endpoint %s",
1930 ipaddr_string(tptr
));
1932 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
1933 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
1934 TCHECK2(tptr
[0], 8);
1935 printf("\n\t Root-Node %s, LSP-ID 0x%08x",
1936 ipaddr_string(tptr
),
1937 EXTRACT_32BITS(tptr
+4));
1939 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
1940 TCHECK2(tptr
[0], 8);
1941 printf("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
1942 ipaddr_string(tptr
),
1943 EXTRACT_32BITS(tptr
+4));
1947 print_unknown_data(tptr
,"\n\t ",tlen
);
1952 case BGPTYPE_ATTR_SET
:
1953 TCHECK2(tptr
[0], 4);
1954 printf("\n\t Origin AS: %u", EXTRACT_32BITS(tptr
));
1960 struct bgp_attr bgpa
;
1962 TCHECK2(tptr
[0], sizeof(bgpa
));
1963 memcpy(&bgpa
, tptr
, sizeof(bgpa
));
1964 alen
= bgp_attr_len(&bgpa
);
1965 tptr
+= bgp_attr_off(&bgpa
);
1966 len
-= bgp_attr_off(&bgpa
);
1968 printf("\n\t %s (%u), length: %u",
1969 tok2strbuf(bgp_attr_values
,
1970 "Unknown Attribute", bgpa
.bgpa_type
,
1971 tokbuf
, sizeof(tokbuf
)),
1975 if (bgpa
.bgpa_flags
) {
1976 printf(", Flags [%s%s%s%s",
1977 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1978 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1979 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1980 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1981 if (bgpa
.bgpa_flags
& 0xf)
1982 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1985 /* FIXME check for recursion */
1986 if (!bgp_attr_print(&bgpa
, tptr
, alen
))
1996 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1998 print_unknown_data(pptr
,"\n\t ",len
);
2001 if (vflag
> 1 && len
) { /* omit zero length attributes*/
2003 print_unknown_data(pptr
,"\n\t ",len
);
2012 bgp_open_print(const u_char
*dat
, int length
)
2014 struct bgp_open bgpo
;
2015 struct bgp_opt bgpopt
;
2017 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
2018 char tokbuf
[TOKBUFSIZE
];
2019 char tokbuf2
[TOKBUFSIZE
];
2021 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
2022 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
2024 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
2025 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
2026 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
2027 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
2028 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
2030 /* some little sanity checking */
2031 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
2035 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
2039 while (i
< bgpo
.bgpo_optlen
) {
2040 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
2041 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
2042 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
2043 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
2047 printf("\n\t Option %s (%u), length: %u",
2048 tok2strbuf(bgp_opt_values
,"Unknown",
2050 tokbuf
, sizeof(tokbuf
)),
2054 /* now lets decode the options we know*/
2055 switch(bgpopt
.bgpopt_type
) {
2057 cap_type
=opt
[i
+BGP_OPT_SIZE
];
2058 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
2060 printf("\n\t %s (%u), length: %u",
2061 tok2strbuf(bgp_capcode_values
, "Unknown",
2062 cap_type
, tokbuf
, sizeof(tokbuf
)),
2066 case BGP_CAPCODE_MP
:
2067 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
2068 tok2strbuf(af_values
, "Unknown",
2069 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
2070 tokbuf
, sizeof(tokbuf
)),
2071 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
2072 tok2strbuf(bgp_safi_values
, "Unknown",
2073 opt
[i
+BGP_OPT_SIZE
+5],
2074 tokbuf
, sizeof(tokbuf
)),
2075 opt
[i
+BGP_OPT_SIZE
+5]);
2077 case BGP_CAPCODE_RESTART
:
2078 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
2079 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
2080 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
2083 while(tcap_len
>=4) {
2084 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2085 tok2strbuf(af_values
,"Unknown",
2086 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
2087 tokbuf
, sizeof(tokbuf
)),
2088 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
2089 tok2strbuf(bgp_safi_values
,"Unknown",
2090 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
2091 tokbuf2
, sizeof(tokbuf2
)),
2092 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
2093 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
2098 case BGP_CAPCODE_RR
:
2099 case BGP_CAPCODE_RR_CISCO
:
2102 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
2103 printf("\n\t\tno decoder for Capability %u",
2106 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
2110 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
2111 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
2116 printf("\n\t no decoder for option %u",
2117 bgpopt
.bgpopt_type
);
2121 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
2129 bgp_update_print(const u_char
*dat
, int length
)
2132 struct bgp_attr bgpa
;
2136 char tokbuf
[TOKBUFSIZE
];
2138 TCHECK2(dat
[0], BGP_SIZE
);
2139 memcpy(&bgp
, dat
, BGP_SIZE
);
2140 p
= dat
+ BGP_SIZE
; /*XXX*/
2142 /* Unfeasible routes */
2143 len
= EXTRACT_16BITS(p
);
2146 * Without keeping state from the original NLRI message,
2147 * it's not possible to tell if this a v4 or v6 route,
2148 * so only try to decode it if we're not v6 enabled.
2151 printf("\n\t Withdrawn routes: %d bytes", len
);
2153 char buf
[MAXHOSTNAMELEN
+ 100];
2159 printf("\n\t Withdrawn routes:");
2161 while(i
< 2 + len
) {
2162 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
2164 printf("\n\t (illegal prefix length)");
2166 } else if (wpfx
== -2)
2170 printf("\n\t %s", buf
);
2178 len
= EXTRACT_16BITS(p
);
2180 if (len
== 0 && length
== BGP_UPDATE_MINSIZE
) {
2181 printf("\n\t End-of-Rib Marker (empty NLRI)");
2186 /* do something more useful!*/
2188 while (i
< 2 + len
) {
2191 TCHECK2(p
[i
], sizeof(bgpa
));
2192 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
2193 alen
= bgp_attr_len(&bgpa
);
2194 aoff
= bgp_attr_off(&bgpa
);
2196 printf("\n\t %s (%u), length: %u",
2197 tok2strbuf(bgp_attr_values
, "Unknown Attribute",
2199 tokbuf
, sizeof(tokbuf
)),
2203 if (bgpa
.bgpa_flags
) {
2204 printf(", Flags [%s%s%s%s",
2205 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
2206 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
2207 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
2208 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
2209 if (bgpa
.bgpa_flags
& 0xf)
2210 printf("+%x", bgpa
.bgpa_flags
& 0xf);
2213 if (!bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
))
2220 if (dat
+ length
> p
) {
2221 printf("\n\t Updated routes:");
2222 while (dat
+ length
> p
) {
2223 char buf
[MAXHOSTNAMELEN
+ 100];
2224 i
= decode_prefix4(p
, buf
, sizeof(buf
));
2226 printf("\n\t (illegal prefix length)");
2231 printf("\n\t %s", buf
);
2242 bgp_notification_print(const u_char
*dat
, int length
)
2244 struct bgp_notification bgpn
;
2246 char tokbuf
[TOKBUFSIZE
];
2247 char tokbuf2
[TOKBUFSIZE
];
2249 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
2250 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
2252 /* some little sanity checking */
2253 if (length
<BGP_NOTIFICATION_SIZE
)
2257 tok2strbuf(bgp_notify_major_values
, "Unknown Error",
2258 bgpn
.bgpn_major
, tokbuf
, sizeof(tokbuf
)),
2261 switch (bgpn
.bgpn_major
) {
2263 case BGP_NOTIFY_MAJOR_MSG
:
2264 printf(", subcode %s (%u)",
2265 tok2strbuf(bgp_notify_minor_msg_values
, "Unknown",
2266 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2269 case BGP_NOTIFY_MAJOR_OPEN
:
2270 printf(", subcode %s (%u)",
2271 tok2strbuf(bgp_notify_minor_open_values
, "Unknown",
2272 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2275 case BGP_NOTIFY_MAJOR_UPDATE
:
2276 printf(", subcode %s (%u)",
2277 tok2strbuf(bgp_notify_minor_update_values
, "Unknown",
2278 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2281 case BGP_NOTIFY_MAJOR_CAP
:
2282 printf(" subcode %s (%u)",
2283 tok2strbuf(bgp_notify_minor_cap_values
, "Unknown",
2284 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2286 case BGP_NOTIFY_MAJOR_CEASE
:
2287 printf(", subcode %s (%u)",
2288 tok2strbuf(bgp_notify_minor_cease_values
, "Unknown",
2289 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2292 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2293 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2295 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2296 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2298 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2299 tok2strbuf(af_values
, "Unknown",
2300 EXTRACT_16BITS(tptr
), tokbuf
, sizeof(tokbuf
)),
2301 EXTRACT_16BITS(tptr
),
2302 tok2strbuf(bgp_safi_values
, "Unknown", *(tptr
+2),
2303 tokbuf2
, sizeof(tokbuf
)),
2305 EXTRACT_32BITS(tptr
+3));
2318 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
2320 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2321 char tokbuf
[TOKBUFSIZE
];
2322 char tokbuf2
[TOKBUFSIZE
];
2324 TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
2326 /* some little sanity checking */
2327 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2330 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2332 printf("\n\t AFI %s (%u), SAFI %s (%u)",
2333 tok2strbuf(af_values
,"Unknown",
2334 /* this stinks but the compiler pads the structure
2336 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2337 tokbuf
, sizeof(tokbuf
)),
2338 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2339 tok2strbuf(bgp_safi_values
,"Unknown",
2340 bgp_route_refresh_header
->safi
,
2341 tokbuf2
, sizeof(tokbuf2
)),
2342 bgp_route_refresh_header
->safi
);
2345 TCHECK2(*pptr
, len
);
2346 print_unknown_data(pptr
,"\n\t ", len
);
2355 bgp_header_print(const u_char
*dat
, int length
)
2358 char tokbuf
[TOKBUFSIZE
];
2360 TCHECK2(dat
[0], BGP_SIZE
);
2361 memcpy(&bgp
, dat
, BGP_SIZE
);
2362 printf("\n\t%s Message (%u), length: %u",
2363 tok2strbuf(bgp_msg_values
, "Unknown", bgp
.bgp_type
,
2364 tokbuf
, sizeof(tokbuf
)),
2368 switch (bgp
.bgp_type
) {
2370 bgp_open_print(dat
, length
);
2373 bgp_update_print(dat
, length
);
2375 case BGP_NOTIFICATION
:
2376 bgp_notification_print(dat
, length
);
2380 case BGP_ROUTE_REFRESH
:
2381 bgp_route_refresh_print(dat
, length
);
2384 /* we have no decoder for the BGP message */
2385 TCHECK2(*dat
, length
);
2386 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
2387 print_unknown_data(dat
,"\n\t ",length
);
2397 bgp_print(const u_char
*dat
, int length
)
2401 const u_char
*start
;
2402 const u_char marker
[] = {
2403 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2404 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2408 char tokbuf
[TOKBUFSIZE
];
2411 if (snapend
< dat
+ length
)
2414 printf(": BGP, length: %u",length
);
2416 if (vflag
< 1) /* lets be less chatty */
2422 if (!TTEST2(p
[0], 1))
2429 if (!TTEST2(p
[0], sizeof(marker
)))
2431 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2436 /* found BGP header */
2437 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2438 memcpy(&bgp
, p
, BGP_SIZE
);
2443 hlen
= ntohs(bgp
.bgp_len
);
2444 if (hlen
< BGP_SIZE
) {
2445 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
2450 if (TTEST2(p
[0], hlen
)) {
2451 if (!bgp_header_print(p
, hlen
))
2456 printf("\n[|BGP %s]",
2457 tok2strbuf(bgp_msg_values
,
2458 "Unknown Message Type",
2460 tokbuf
, sizeof(tokbuf
)));
2473 * c-style: whitesmith