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 2007-10-05 02:00:11 guy Exp $";
42 #include <tcpdump-stdinc.h>
47 #include "interface.h"
48 #include "decode_prefix.h"
49 #include "addrtoname.h"
56 u_int8_t bgp_marker
[16];
60 #define BGP_SIZE 19 /* unaligned */
64 #define BGP_NOTIFICATION 3
65 #define BGP_KEEPALIVE 4
66 #define BGP_ROUTE_REFRESH 5
68 static struct tok bgp_msg_values
[] = {
70 { BGP_UPDATE
, "Update"},
71 { BGP_NOTIFICATION
, "Notification"},
72 { BGP_KEEPALIVE
, "Keepalive"},
73 { BGP_ROUTE_REFRESH
, "Route Refresh"},
78 u_int8_t bgpo_marker
[16];
81 u_int8_t bgpo_version
;
83 u_int16_t bgpo_holdtime
;
86 /* options should follow */
88 #define BGP_OPEN_SIZE 29 /* unaligned */
95 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
97 #define BGP_UPDATE_MINSIZE 23
99 struct bgp_notification
{
100 u_int8_t bgpn_marker
[16];
106 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
108 struct bgp_route_refresh
{
109 u_int8_t bgp_marker
[16];
112 u_int8_t afi
[2]; /* the compiler messes this structure up */
113 u_int8_t res
; /* when doing misaligned sequences of int8 and int16 */
114 u_int8_t safi
; /* afi should be int16 - so we have to access it using */
115 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
116 #define BGP_ROUTE_REFRESH_SIZE 23
125 #define bgp_attr_len(p) \
126 (((p)->bgpa_flags & 0x10) ? \
127 EXTRACT_16BITS(&(p)->bgpa_len.elen) : (p)->bgpa_len.len)
128 #define bgp_attr_off(p) \
129 (((p)->bgpa_flags & 0x10) ? 4 : 3)
132 #define BGPTYPE_ORIGIN 1
133 #define BGPTYPE_AS_PATH 2
134 #define BGPTYPE_NEXT_HOP 3
135 #define BGPTYPE_MULTI_EXIT_DISC 4
136 #define BGPTYPE_LOCAL_PREF 5
137 #define BGPTYPE_ATOMIC_AGGREGATE 6
138 #define BGPTYPE_AGGREGATOR 7
139 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
140 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
141 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
142 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
143 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
144 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
145 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
146 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
147 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
148 #define BGPTYPE_PMSI_TUNNEL 22 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
149 #define BGPTYPE_ATTR_SET 128 /* draft-marques-ppvpn-ibgp */
151 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
153 static struct tok bgp_attr_values
[] = {
154 { BGPTYPE_ORIGIN
, "Origin"},
155 { BGPTYPE_AS_PATH
, "AS Path"},
156 { BGPTYPE_NEXT_HOP
, "Next Hop"},
157 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
158 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
159 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
160 { BGPTYPE_AGGREGATOR
, "Aggregator"},
161 { BGPTYPE_COMMUNITIES
, "Community"},
162 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
163 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
164 { BGPTYPE_DPA
, "DPA"},
165 { BGPTYPE_ADVERTISERS
, "Advertisers"},
166 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
167 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
168 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
169 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
170 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
171 { BGPTYPE_ATTR_SET
, "Attribute Set"},
172 { 255, "Reserved for development"},
177 #define BGP_AS_SEQUENCE 2
178 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
179 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
181 static int bgp_as_path_segment_known
[] = {
184 BGP_CONFED_AS_SEQUENCE
,
189 static struct tok bgp_as_path_segment_open_values
[] = {
190 { BGP_AS_SEQUENCE
, ""},
192 { BGP_CONFED_AS_SEQUENCE
, "( "},
193 { BGP_CONFED_AS_SET
, "({ "},
197 static struct tok bgp_as_path_segment_close_values
[] = {
198 { BGP_AS_SEQUENCE
, ""},
200 { BGP_CONFED_AS_SEQUENCE
, ")"},
201 { BGP_CONFED_AS_SET
, "})"},
205 #define BGP_OPT_AUTH 1
206 #define BGP_OPT_CAP 2
209 static struct tok bgp_opt_values
[] = {
210 { BGP_OPT_AUTH
, "Authentication Information"},
211 { BGP_OPT_CAP
, "Capabilities Advertisement"},
215 #define BGP_CAPCODE_MP 1
216 #define BGP_CAPCODE_RR 2
217 #define BGP_CAPCODE_ORF 3 /* XXX */
218 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
219 #define BGP_CAPCODE_AS_NEW 65 /* XXX */
220 #define BGP_CAPCODE_DYN_CAP 67 /* XXX */
221 #define BGP_CAPCODE_RR_CISCO 128
223 static struct tok bgp_capcode_values
[] = {
224 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
225 { BGP_CAPCODE_RR
, "Route Refresh"},
226 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
227 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
228 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
229 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
230 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
234 #define BGP_NOTIFY_MAJOR_MSG 1
235 #define BGP_NOTIFY_MAJOR_OPEN 2
236 #define BGP_NOTIFY_MAJOR_UPDATE 3
237 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
238 #define BGP_NOTIFY_MAJOR_FSM 5
239 #define BGP_NOTIFY_MAJOR_CEASE 6
240 #define BGP_NOTIFY_MAJOR_CAP 7
242 static struct tok bgp_notify_major_values
[] = {
243 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
244 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
245 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
246 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
247 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
248 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
249 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
253 /* draft-ietf-idr-cease-subcode-02 */
254 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
255 static struct tok bgp_notify_minor_cease_values
[] = {
256 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
257 { 2, "Administratively Shutdown"},
258 { 3, "Peer Unconfigured"},
259 { 4, "Administratively Reset"},
260 { 5, "Connection Rejected"},
261 { 6, "Other Configuration Change"},
262 { 7, "Connection Collision Resolution"},
266 static struct tok bgp_notify_minor_msg_values
[] = {
267 { 1, "Connection Not Synchronized"},
268 { 2, "Bad Message Length"},
269 { 3, "Bad Message Type"},
273 static struct tok bgp_notify_minor_open_values
[] = {
274 { 1, "Unsupported Version Number"},
276 { 3, "Bad BGP Identifier"},
277 { 4, "Unsupported Optional Parameter"},
278 { 5, "Authentication Failure"},
279 { 6, "Unacceptable Hold Time"},
280 { 7, "Capability Message Error"},
284 static struct tok bgp_notify_minor_update_values
[] = {
285 { 1, "Malformed Attribute List"},
286 { 2, "Unrecognized Well-known Attribute"},
287 { 3, "Missing Well-known Attribute"},
288 { 4, "Attribute Flags Error"},
289 { 5, "Attribute Length Error"},
290 { 6, "Invalid ORIGIN Attribute"},
291 { 7, "AS Routing Loop"},
292 { 8, "Invalid NEXT_HOP Attribute"},
293 { 9, "Optional Attribute Error"},
294 { 10, "Invalid Network Field"},
295 { 11, "Malformed AS_PATH"},
299 static struct tok bgp_notify_minor_cap_values
[] = {
300 { 1, "Invalid Action Value" },
301 { 2, "Invalid Capability Length" },
302 { 3, "Malformed Capability Value" },
303 { 4, "Unsupported Capability Code" },
307 static struct tok bgp_origin_values
[] = {
314 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
315 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
316 #define BGP_PMSI_TUNNEL_PIM_SSM 3
317 #define BGP_PMSI_TUNNEL_PIM_SM 4
318 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
319 #define BGP_PMSI_TUNNEL_INGRESS 6
320 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
322 static struct tok bgp_pmsi_tunnel_values
[] = {
323 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
324 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
325 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
326 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
327 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
328 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
329 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
333 static struct tok bgp_pmsi_flag_values
[] = {
334 { 0x01, "Leaf Information required"},
339 /* Subsequent address family identifier, RFC2283 section 7 */
341 #define SAFNUM_UNICAST 1
342 #define SAFNUM_MULTICAST 2
343 #define SAFNUM_UNIMULTICAST 3
344 /* labeled BGP RFC3107 */
345 #define SAFNUM_LABUNICAST 4
346 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
347 #define SAFNUM_MULTICAST_VPN 5
348 #define SAFNUM_TUNNEL 64 /* XXX */
349 #define SAFNUM_VPLS 65 /* XXX */
350 #define SAFNUM_MDT 66 /* XXX */
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" },
469 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
479 memset(&addr
, 0, sizeof(addr
));
480 TCHECK2(pptr
[1], (plen
+ 7) / 8);
481 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
483 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
484 ((0xff00 >> (plen
% 8)) & 0xff);
486 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
487 return 1 + (plen
+ 7) / 8;
494 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
500 plen
= pptr
[0]; /* get prefix length */
502 /* this is one of the weirdnesses of rfc3107
503 the label length (actually the label + COS bits)
504 is added to the prefix length;
505 we also do only read out just one label -
506 there is no real application for advertisement of
507 stacked labels in a a single BGP message
513 plen
-=24; /* adjust prefixlen - labellength */
518 memset(&addr
, 0, sizeof(addr
));
519 TCHECK2(pptr
[4], (plen
+ 7) / 8);
520 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
522 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
523 ((0xff00 >> (plen
% 8)) & 0xff);
525 /* the label may get offsetted by 4 bits so lets shift it right */
526 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
527 getname((u_char
*)&addr
),
529 EXTRACT_24BITS(pptr
+1)>>4,
530 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
532 return 4 + (plen
+ 7) / 8;
541 * print an ipv4 or ipv6 address into a buffer dependend on address length.
544 bgp_vpn_ip_print (const u_char
*pptr
, u_int addr_length
) {
546 /* worst case string is s fully formatted v6 address */
547 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
550 switch(addr_length
) {
551 case (sizeof(struct in_addr
) << 3): /* 32 */
552 TCHECK2(pptr
[0], sizeof(struct in_addr
));
553 snprintf(pos
, sizeof(addr
), "%s", ipaddr_string(pptr
));
556 case (sizeof(struct in6_addr
) << 3): /* 128 */
557 TCHECK2(pptr
[0], sizeof(struct in6_addr
));
558 snprintf(pos
, sizeof(addr
), "%s", ip6addr_string(pptr
));
562 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
575 * print an multicast s,g entry into a buffer.
576 * the s,g entry is encoded like this.
578 * +-----------------------------------+
579 * | Multicast Source Length (1 octet) |
580 * +-----------------------------------+
581 * | Multicast Source (Variable) |
582 * +-----------------------------------+
583 * | Multicast Group Length (1 octet) |
584 * +-----------------------------------+
585 * | Multicast Group (Variable) |
586 * +-----------------------------------+
588 * return the number of bytes read from the wire.
591 bgp_vpn_sg_print (const u_char
*pptr
, char *buf
, u_int buflen
) {
593 u_int8_t addr_length
;
594 u_int total_length
, offset
;
598 /* Source address length, encoded in bits */
600 addr_length
= *pptr
++;
603 TCHECK2(pptr
[0], (addr_length
>> 3));
604 total_length
+= (addr_length
>> 3) + 1;
605 offset
= strlen(buf
);
607 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
608 bgp_vpn_ip_print(pptr
, addr_length
));
609 pptr
+= (addr_length
>> 3);
612 /* Group address length, encoded in bits */
614 addr_length
= *pptr
++;
617 TCHECK2(pptr
[0], (addr_length
>> 3));
618 total_length
+= (addr_length
>> 3) + 1;
619 offset
= strlen(buf
);
621 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
622 bgp_vpn_ip_print(pptr
, addr_length
));
623 pptr
+= (addr_length
>> 3);
627 return (total_length
);
631 /* RDs and RTs share the same semantics
632 * we use bgp_vpn_rd_print for
633 * printing route targets inside a NLRI */
635 bgp_vpn_rd_print (const u_char
*pptr
) {
637 /* allocate space for the largest possible string */
638 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
641 /* ok lets load the RD format */
642 switch (EXTRACT_16BITS(pptr
)) {
644 /* 2-byte-AS:number fmt*/
646 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
647 EXTRACT_16BITS(pptr
+2),
648 EXTRACT_32BITS(pptr
+4),
649 *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
651 /* IP-address:AS fmt*/
654 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
655 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
658 /* 4-byte-AS:number fmt*/
660 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (%u.%u.%u.%u:%u)",
661 EXTRACT_32BITS(pptr
+2), EXTRACT_16BITS(pptr
+6),
662 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
665 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
674 decode_rt_routing_info(const u_char
*pptr
, char *buf
, u_int buflen
)
676 u_int8_t route_target
[8];
680 plen
= pptr
[0]; /* get prefix length */
683 return 1; /* default route target */
688 plen
-=32; /* adjust prefix length */
693 memset(&route_target
, 0, sizeof(route_target
));
694 TCHECK2(pptr
[1], (plen
+ 7) / 8);
695 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
697 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
698 ((0xff00 >> (plen
% 8)) & 0xff);
700 snprintf(buf
, buflen
, "origin AS: %u, route target %s",
701 EXTRACT_32BITS(pptr
+1),
702 bgp_vpn_rd_print((u_char
*)&route_target
));
704 return 5 + (plen
+ 7) / 8;
711 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
717 plen
= pptr
[0]; /* get prefix length */
722 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
727 memset(&addr
, 0, sizeof(addr
));
728 TCHECK2(pptr
[12], (plen
+ 7) / 8);
729 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
731 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
732 ((0xff00 >> (plen
% 8)) & 0xff);
734 /* the label may get offsetted by 4 bits so lets shift it right */
735 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
736 bgp_vpn_rd_print(pptr
+4),
737 getname((u_char
*)&addr
),
739 EXTRACT_24BITS(pptr
+1)>>4,
740 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
742 return 12 + (plen
+ 7) / 8;
748 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
749 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
750 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
751 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
752 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
753 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
754 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
756 static struct tok bgp_multicast_vpn_route_type_values
[] = {
757 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
758 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
759 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
760 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
761 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
762 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
763 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
767 decode_multicast_vpn(const u_char
*pptr
, char *buf
, u_int buflen
)
769 u_int8_t route_type
, route_length
, addr_length
, sg_length
;
773 route_type
= *pptr
++;
774 route_length
= *pptr
++;
776 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
777 tok2str(bgp_multicast_vpn_route_type_values
,
778 "Unknown", route_type
),
779 route_type
, route_length
);
782 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
783 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
784 offset
= strlen(buf
);
785 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
786 bgp_vpn_rd_print(pptr
),
787 bgp_vpn_ip_print(pptr
+ BGP_VPN_RD_LEN
,
788 (route_length
- BGP_VPN_RD_LEN
) << 3));
790 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
791 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
+ 4);
792 offset
= strlen(buf
);
793 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %u",
794 bgp_vpn_rd_print(pptr
),
795 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
));
798 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
799 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
800 offset
= strlen(buf
);
801 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
802 bgp_vpn_rd_print(pptr
));
803 pptr
+= BGP_VPN_RD_LEN
;
805 sg_length
= bgp_vpn_sg_print(pptr
, buf
, buflen
);
806 addr_length
= route_length
- sg_length
;
808 TCHECK2(pptr
[0], addr_length
);
809 offset
= strlen(buf
);
810 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
811 bgp_vpn_ip_print(pptr
, addr_length
<< 3));
814 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
815 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
816 offset
= strlen(buf
);
817 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
818 bgp_vpn_rd_print(pptr
));
819 pptr
+= BGP_VPN_RD_LEN
;
821 bgp_vpn_sg_print(pptr
, buf
, buflen
);
824 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
825 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
826 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
827 offset
= strlen(buf
);
828 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %u",
829 bgp_vpn_rd_print(pptr
),
830 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
));
831 pptr
+= BGP_VPN_RD_LEN
;
833 bgp_vpn_sg_print(pptr
, buf
, buflen
);
837 * no per route-type printing yet.
839 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
844 return route_length
+ 2;
851 * As I remember, some versions of systems have an snprintf() that
852 * returns -1 if the buffer would have overflowed. If the return
853 * value is negative, set buflen to 0, to indicate that we've filled
856 * If the return value is greater than buflen, that means that
857 * the buffer would have overflowed; again, set buflen to 0 in
860 #define UPDATE_BUF_BUFLEN(buf, buflen, strlen) \
863 else if ((u_int)strlen>buflen) \
871 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
873 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
876 plen
=EXTRACT_16BITS(pptr
);
881 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
882 bgp_vpn_rd_print(pptr
),
883 EXTRACT_16BITS(pptr
+8),
884 EXTRACT_16BITS(pptr
+10),
885 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
886 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
890 /* ok now the variable part - lets read out TLVs*/
896 tlv_len
=EXTRACT_16BITS(pptr
);
903 strlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
906 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
908 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
912 strlen
=snprintf(buf
,buflen
, "%02x",*pptr
++);
913 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
920 strlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
923 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
927 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
937 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
939 struct in6_addr addr
;
947 memset(&addr
, 0, sizeof(addr
));
948 TCHECK2(pd
[1], (plen
+ 7) / 8);
949 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
951 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
952 ((0xff00 >> (plen
% 8)) & 0xff);
954 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
955 return 1 + (plen
+ 7) / 8;
962 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
964 struct in6_addr addr
;
968 plen
= pptr
[0]; /* get prefix length */
973 plen
-=24; /* adjust prefixlen - labellength */
978 memset(&addr
, 0, sizeof(addr
));
979 TCHECK2(pptr
[4], (plen
+ 7) / 8);
980 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
982 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
983 ((0xff00 >> (plen
% 8)) & 0xff);
985 /* the label may get offsetted by 4 bits so lets shift it right */
986 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
987 getname6((u_char
*)&addr
),
989 EXTRACT_24BITS(pptr
+1)>>4,
990 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
992 return 4 + (plen
+ 7) / 8;
999 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
1001 struct in6_addr addr
;
1005 plen
= pptr
[0]; /* get prefix length */
1010 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1015 memset(&addr
, 0, sizeof(addr
));
1016 TCHECK2(pptr
[12], (plen
+ 7) / 8);
1017 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1019 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1020 ((0xff00 >> (plen
% 8)) & 0xff);
1022 /* the label may get offsetted by 4 bits so lets shift it right */
1023 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1024 bgp_vpn_rd_print(pptr
+4),
1025 getname6((u_char
*)&addr
),
1027 EXTRACT_24BITS(pptr
+1)>>4,
1028 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1030 return 12 + (plen
+ 7) / 8;
1038 decode_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
1044 plen
= pptr
[0]; /* get prefix length */
1049 memset(&addr
, 0, sizeof(addr
));
1050 TCHECK2(pptr
[4], (plen
+ 7) / 8);
1051 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
1053 addr
[(plen
+ 7) / 8 - 1] &=
1054 ((0xff00 >> (plen
% 8)) & 0xff);
1056 snprintf(buf
, buflen
, "%s/%d",
1057 isonsap_string(addr
,(plen
+ 7) / 8),
1060 return 1 + (plen
+ 7) / 8;
1067 decode_labeled_vpn_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
1073 plen
= pptr
[0]; /* get prefix length */
1078 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1083 memset(&addr
, 0, sizeof(addr
));
1084 TCHECK2(pptr
[12], (plen
+ 7) / 8);
1085 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1087 addr
[(plen
+ 7) / 8 - 1] &=
1088 ((0xff00 >> (plen
% 8)) & 0xff);
1090 /* the label may get offsetted by 4 bits so lets shift it right */
1091 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1092 bgp_vpn_rd_print(pptr
+4),
1093 isonsap_string(addr
,(plen
+ 7) / 8),
1095 EXTRACT_24BITS(pptr
+1)>>4,
1096 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1098 return 12 + (plen
+ 7) / 8;
1105 * Check for 4-byte ASN's, as per RFC 4893.
1108 check_asnbytes(const u_char
*tptr
, const u_char
*mptr
, int asnlen
)
1112 while (tptr
< mptr
) {
1114 kptr
= bgp_as_path_segment_known
;
1115 while (kptr
[0] != 0) {
1116 if (kptr
[0] == tptr
[0])
1123 tptr
+= 2 + tptr
[1] * asnlen
;
1133 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
1137 u_int8_t safi
, snpa
, nhlen
;
1138 union { /* copy buffer for bandwidth values */
1145 char buf
[MAXHOSTNAMELEN
+ 100];
1146 char tokbuf
[TOKBUFSIZE
];
1152 switch (attr
->bgpa_type
) {
1153 case BGPTYPE_ORIGIN
:
1155 printf("invalid len");
1158 printf("%s", tok2strbuf(bgp_origin_values
,
1159 "Unknown Origin Typecode",
1161 tokbuf
, sizeof(tokbuf
)));
1165 case BGPTYPE_AS_PATH
:
1167 printf("invalid len");
1176 if (!check_asnbytes(tptr
, pptr
+len
, 2) &&
1177 check_asnbytes(tptr
, pptr
+len
, 4))
1179 while (tptr
< pptr
+ len
) {
1181 printf("%s", tok2strbuf(bgp_as_path_segment_open_values
,
1183 tokbuf
, sizeof(tokbuf
)));
1185 if (asn4bytes
== 0) {
1186 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
1187 TCHECK2(tptr
[2 + i
], 2);
1188 printf("%u ", EXTRACT_16BITS(&tptr
[2 + i
]));
1191 for (i
= 0; i
< tptr
[1] * 4; i
+= 4) {
1192 TCHECK2(tptr
[2 + i
], 4);
1193 printf("%u.%u ", EXTRACT_16BITS(&tptr
[2 + i
]), EXTRACT_16BITS(&tptr
[4 + i
]));
1197 printf("%s", tok2strbuf(bgp_as_path_segment_close_values
,
1199 tokbuf
, sizeof(tokbuf
)));
1202 tptr
+= 2 + tptr
[1] * 2;
1204 tptr
+= 2 + tptr
[1] * 4;
1207 case BGPTYPE_NEXT_HOP
:
1209 printf("invalid len");
1211 TCHECK2(tptr
[0], 4);
1212 printf("%s", getname(tptr
));
1215 case BGPTYPE_MULTI_EXIT_DISC
:
1216 case BGPTYPE_LOCAL_PREF
:
1218 printf("invalid len");
1220 TCHECK2(tptr
[0], 4);
1221 printf("%u", EXTRACT_32BITS(tptr
));
1224 case BGPTYPE_ATOMIC_AGGREGATE
:
1226 printf("invalid len");
1228 case BGPTYPE_AGGREGATOR
:
1230 printf("invalid len");
1233 TCHECK2(tptr
[0], 6);
1234 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
1237 case BGPTYPE_COMMUNITIES
:
1239 printf("invalid len");
1244 TCHECK2(tptr
[0], 4);
1245 comm
= EXTRACT_32BITS(tptr
);
1247 case BGP_COMMUNITY_NO_EXPORT
:
1248 printf(" NO_EXPORT");
1250 case BGP_COMMUNITY_NO_ADVERT
:
1251 printf(" NO_ADVERTISE");
1253 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1254 printf(" NO_EXPORT_SUBCONFED");
1258 (comm
>> 16) & 0xffff,
1260 (tlen
>4) ? ", " : "");
1267 case BGPTYPE_ORIGINATOR_ID
:
1269 printf("invalid len");
1272 TCHECK2(tptr
[0], 4);
1273 printf("%s",getname(tptr
));
1275 case BGPTYPE_CLUSTER_LIST
:
1277 printf("invalid len");
1281 TCHECK2(tptr
[0], 4);
1284 (tlen
>4) ? ", " : "");
1289 case BGPTYPE_MP_REACH_NLRI
:
1290 TCHECK2(tptr
[0], 3);
1291 af
= EXTRACT_16BITS(tptr
);
1294 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1295 tok2strbuf(af_values
, "Unknown AFI", af
,
1296 tokbuf
, sizeof(tokbuf
)),
1298 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1299 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1300 tokbuf
, sizeof(tokbuf
)),
1303 switch(af
<<8 | safi
) {
1304 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1305 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1306 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1307 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1308 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1309 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1310 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1311 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1312 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1314 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1315 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1316 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1317 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1318 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1319 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1320 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1322 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1323 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1324 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1325 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1326 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1327 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1328 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1329 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1330 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1331 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1334 TCHECK2(tptr
[0], tlen
);
1335 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1337 print_unknown_data(tptr
,"\n\t ",tlen
);
1350 printf("\n\t nexthop: ");
1352 switch(af
<<8 | safi
) {
1353 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1354 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1355 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1356 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1357 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1358 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1359 if (tlen
< (int)sizeof(struct in_addr
)) {
1360 printf("invalid len");
1363 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1364 printf("%s",getname(tptr
));
1365 tlen
-= sizeof(struct in_addr
);
1366 tptr
+= sizeof(struct in_addr
);
1369 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1370 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1371 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1372 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1373 printf("invalid len");
1376 TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1377 printf("RD: %s, %s",
1378 bgp_vpn_rd_print(tptr
),
1379 getname(tptr
+BGP_VPN_RD_LEN
));
1380 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1381 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1385 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1386 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1387 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1388 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1389 if (tlen
< (int)sizeof(struct in6_addr
)) {
1390 printf("invalid len");
1393 TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1394 printf("%s", getname6(tptr
));
1395 tlen
-= sizeof(struct in6_addr
);
1396 tptr
+= sizeof(struct in6_addr
);
1399 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1400 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1401 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1402 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1403 printf("invalid len");
1406 TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1407 printf("RD: %s, %s",
1408 bgp_vpn_rd_print(tptr
),
1409 getname6(tptr
+BGP_VPN_RD_LEN
));
1410 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1411 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1415 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1416 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1417 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1418 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1419 if (tlen
< (int)sizeof(struct in_addr
)) {
1420 printf("invalid len");
1423 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1424 printf("%s", getname(tptr
));
1425 tlen
-= (sizeof(struct in_addr
));
1426 tptr
+= (sizeof(struct in_addr
));
1429 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1430 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1431 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1432 TCHECK2(tptr
[0], tlen
);
1433 printf("%s",isonsap_string(tptr
,tlen
));
1438 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1439 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1440 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1441 if (tlen
< BGP_VPN_RD_LEN
+1) {
1442 printf("invalid len");
1445 TCHECK2(tptr
[0], tlen
);
1446 printf("RD: %s, %s",
1447 bgp_vpn_rd_print(tptr
),
1448 isonsap_string(tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
));
1449 /* rfc986 mapped IPv4 address ? */
1450 if (EXTRACT_32BITS(tptr
+BGP_VPN_RD_LEN
) == 0x47000601)
1451 printf(" = %s", getname(tptr
+BGP_VPN_RD_LEN
+4));
1453 /* rfc1888 mapped IPv6 address ? */
1454 else if (EXTRACT_24BITS(tptr
+BGP_VPN_RD_LEN
) == 0x350000)
1455 printf(" = %s", getname6(tptr
+BGP_VPN_RD_LEN
+3));
1462 TCHECK2(tptr
[0], tlen
);
1463 printf("no AFI %u/SAFI %u decoder",af
,safi
);
1465 print_unknown_data(tptr
,"\n\t ",tlen
);
1473 printf(", nh-length: %u", nhlen
);
1481 printf("\n\t %u SNPA", snpa
);
1482 for (/*nothing*/; snpa
> 0; snpa
--) {
1484 printf("\n\t %d bytes", tptr
[0]);
1485 tptr
+= tptr
[0] + 1;
1488 printf(", no SNPA");
1491 while (len
- (tptr
- pptr
) > 0) {
1492 switch (af
<<8 | safi
) {
1493 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1494 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1495 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1496 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1498 printf("\n\t (illegal prefix length)");
1499 else if (advance
== -2)
1502 printf("\n\t %s", buf
);
1504 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1505 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1507 printf("\n\t (illegal prefix length)");
1508 else if (advance
== -2)
1511 printf("\n\t %s", buf
);
1513 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1514 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1515 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1516 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1518 printf("\n\t (illegal prefix length)");
1519 else if (advance
== -2)
1522 printf("\n\t %s", buf
);
1524 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1525 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1527 printf("\n\t (illegal prefix length)");
1528 else if (advance
== -2)
1531 printf("\n\t %s", buf
);
1533 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1534 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1535 advance
= decode_multicast_vpn(tptr
, buf
, sizeof(buf
));
1537 printf("\n\t (illegal prefix length)");
1538 else if (advance
== -2)
1541 printf("\n\t %s", buf
);
1544 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1545 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1546 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1547 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1549 printf("\n\t (illegal prefix length)");
1550 else if (advance
== -2)
1553 printf("\n\t %s", buf
);
1555 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1556 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1558 printf("\n\t (illegal prefix length)");
1559 else if (advance
== -2)
1562 printf("\n\t %s", buf
);
1564 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1565 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1566 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1567 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1569 printf("\n\t (illegal prefix length)");
1570 else if (advance
== -2)
1573 printf("\n\t %s", buf
);
1576 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1577 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1578 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1579 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1580 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1582 printf("\n\t (illegal length)");
1583 else if (advance
== -2)
1586 printf("\n\t %s", buf
);
1588 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1589 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1590 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1591 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1593 printf("\n\t (illegal prefix length)");
1594 else if (advance
== -2)
1597 printf("\n\t %s", buf
);
1599 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1600 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1601 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1602 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1604 printf("\n\t (illegal prefix length)");
1605 else if (advance
== -2)
1608 printf("\n\t %s", buf
);
1611 TCHECK2(*tptr
,tlen
);
1612 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1614 print_unknown_data(tptr
,"\n\t ",tlen
);
1626 case BGPTYPE_MP_UNREACH_NLRI
:
1627 TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1628 af
= EXTRACT_16BITS(tptr
);
1631 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1632 tok2strbuf(af_values
, "Unknown AFI", af
,
1633 tokbuf
, sizeof(tokbuf
)),
1635 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1636 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1637 tokbuf
, sizeof(tokbuf
)),
1640 if (len
== BGP_MP_NLRI_MINSIZE
)
1641 printf("\n\t End-of-Rib Marker (empty NLRI)");
1645 while (len
- (tptr
- pptr
) > 0) {
1646 switch (af
<<8 | safi
) {
1647 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1648 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1649 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1650 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1652 printf("\n\t (illegal prefix length)");
1653 else if (advance
== -2)
1656 printf("\n\t %s", buf
);
1658 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1659 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1661 printf("\n\t (illegal prefix length)");
1662 else if (advance
== -2)
1665 printf("\n\t %s", buf
);
1667 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1668 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1669 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1670 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1672 printf("\n\t (illegal prefix length)");
1673 else if (advance
== -2)
1676 printf("\n\t %s", buf
);
1679 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1680 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1681 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1682 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1684 printf("\n\t (illegal prefix length)");
1685 else if (advance
== -2)
1688 printf("\n\t %s", buf
);
1690 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1691 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1693 printf("\n\t (illegal prefix length)");
1694 else if (advance
== -2)
1697 printf("\n\t %s", buf
);
1699 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1700 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1701 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1702 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1704 printf("\n\t (illegal prefix length)");
1705 else if (advance
== -2)
1708 printf("\n\t %s", buf
);
1711 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1712 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1713 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1714 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1715 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1717 printf("\n\t (illegal length)");
1718 else if (advance
== -2)
1721 printf("\n\t %s", buf
);
1723 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1724 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1725 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1726 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1728 printf("\n\t (illegal prefix length)");
1729 else if (advance
== -2)
1732 printf("\n\t %s", buf
);
1734 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1735 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1736 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1737 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1739 printf("\n\t (illegal prefix length)");
1740 else if (advance
== -2)
1743 printf("\n\t %s", buf
);
1745 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1746 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1747 advance
= decode_multicast_vpn(tptr
, buf
, sizeof(buf
));
1749 printf("\n\t (illegal prefix length)");
1750 else if (advance
== -2)
1753 printf("\n\t %s", buf
);
1756 TCHECK2(*(tptr
-3),tlen
);
1757 printf("no AFI %u / SAFI %u decoder",af
,safi
);
1759 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1769 case BGPTYPE_EXTD_COMMUNITIES
:
1771 printf("invalid len");
1775 u_int16_t extd_comm
;
1777 TCHECK2(tptr
[0], 2);
1778 extd_comm
=EXTRACT_16BITS(tptr
);
1780 printf("\n\t %s (0x%04x), Flags [%s]",
1781 tok2strbuf(bgp_extd_comm_subtype_values
,
1782 "unknown extd community typecode",
1783 extd_comm
, tokbuf
, sizeof(tokbuf
)),
1785 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1787 TCHECK2(*(tptr
+2), 6);
1789 case BGP_EXT_COM_RT_0
:
1790 case BGP_EXT_COM_RO_0
:
1791 printf(": %u:%u (= %s)",
1792 EXTRACT_16BITS(tptr
+2),
1793 EXTRACT_32BITS(tptr
+4),
1796 case BGP_EXT_COM_RT_1
:
1797 case BGP_EXT_COM_RO_1
:
1798 case BGP_EXT_COM_VRF_RT_IMP
:
1801 EXTRACT_16BITS(tptr
+6));
1803 case BGP_EXT_COM_RT_2
:
1804 case BGP_EXT_COM_RO_2
:
1806 EXTRACT_32BITS(tptr
+2),
1807 EXTRACT_16BITS(tptr
+6));
1809 case BGP_EXT_COM_LINKBAND
:
1810 bw
.i
= EXTRACT_32BITS(tptr
+2);
1811 printf(": bandwidth: %.3f Mbps",
1814 case BGP_EXT_COM_VPN_ORIGIN
:
1815 case BGP_EXT_COM_VPN_ORIGIN2
:
1816 case BGP_EXT_COM_VPN_ORIGIN3
:
1817 case BGP_EXT_COM_VPN_ORIGIN4
:
1818 case BGP_EXT_COM_OSPF_RID
:
1819 case BGP_EXT_COM_OSPF_RID2
:
1820 printf("%s", getname(tptr
+2));
1822 case BGP_EXT_COM_OSPF_RTYPE
:
1823 case BGP_EXT_COM_OSPF_RTYPE2
:
1824 printf(": area:%s, router-type:%s, metric-type:%s%s",
1826 tok2strbuf(bgp_extd_comm_ospf_rtype_values
,
1829 tokbuf
, sizeof(tokbuf
)),
1830 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1831 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1833 case BGP_EXT_COM_L2INFO
:
1834 printf(": %s Control Flags [0x%02x]:MTU %u",
1835 tok2strbuf(l2vpn_encaps_values
,
1838 tokbuf
, sizeof(tokbuf
)),
1840 EXTRACT_16BITS(tptr
+4));
1842 case BGP_EXT_COM_SOURCE_AS
:
1843 printf(": AS %u", EXTRACT_16BITS(tptr
+2));
1847 print_unknown_data(tptr
,"\n\t ",8);
1855 case BGPTYPE_PMSI_TUNNEL
:
1857 u_int8_t tunnel_type
, flags
;
1859 tunnel_type
= *(tptr
+1);
1863 TCHECK2(tptr
[0], 5);
1864 printf("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
1865 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
1867 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
1868 EXTRACT_24BITS(tptr
+2)>>4);
1873 switch (tunnel_type
) {
1874 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
1875 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
1876 TCHECK2(tptr
[0], 8);
1877 printf("\n\t Sender %s, P-Group %s",
1878 ipaddr_string(tptr
),
1879 ipaddr_string(tptr
+4));
1882 case BGP_PMSI_TUNNEL_PIM_SSM
:
1883 TCHECK2(tptr
[0], 8);
1884 printf("\n\t Root-Node %s, P-Group %s",
1885 ipaddr_string(tptr
),
1886 ipaddr_string(tptr
+4));
1888 case BGP_PMSI_TUNNEL_INGRESS
:
1889 TCHECK2(tptr
[0], 4);
1890 printf("\n\t Tunnel-Endpoint %s",
1891 ipaddr_string(tptr
));
1893 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
1894 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
1895 TCHECK2(tptr
[0], 8);
1896 printf("\n\t Root-Node %s, LSP-ID 0x%08x",
1897 ipaddr_string(tptr
),
1898 EXTRACT_32BITS(tptr
+4));
1900 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
1901 TCHECK2(tptr
[0], 8);
1902 printf("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
1903 ipaddr_string(tptr
),
1904 EXTRACT_32BITS(tptr
+4));
1908 print_unknown_data(tptr
,"\n\t ",tlen
);
1913 case BGPTYPE_ATTR_SET
:
1914 TCHECK2(tptr
[0], 4);
1915 printf("\n\t Origin AS: %u", EXTRACT_32BITS(tptr
));
1921 struct bgp_attr bgpa
;
1923 TCHECK2(tptr
[0], sizeof(bgpa
));
1924 memcpy(&bgpa
, tptr
, sizeof(bgpa
));
1925 alen
= bgp_attr_len(&bgpa
);
1926 tptr
+= bgp_attr_off(&bgpa
);
1927 len
-= bgp_attr_off(&bgpa
);
1929 printf("\n\t %s (%u), length: %u",
1930 tok2strbuf(bgp_attr_values
,
1931 "Unknown Attribute", bgpa
.bgpa_type
,
1932 tokbuf
, sizeof(tokbuf
)),
1936 if (bgpa
.bgpa_flags
) {
1937 printf(", Flags [%s%s%s%s",
1938 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1939 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1940 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1941 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1942 if (bgpa
.bgpa_flags
& 0xf)
1943 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1946 /* FIXME check for recursion */
1947 if (!bgp_attr_print(&bgpa
, tptr
, alen
))
1957 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1959 print_unknown_data(pptr
,"\n\t ",len
);
1962 if (vflag
> 1 && len
) { /* omit zero length attributes*/
1964 print_unknown_data(pptr
,"\n\t ",len
);
1973 bgp_open_print(const u_char
*dat
, int length
)
1975 struct bgp_open bgpo
;
1976 struct bgp_opt bgpopt
;
1978 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
1979 char tokbuf
[TOKBUFSIZE
];
1980 char tokbuf2
[TOKBUFSIZE
];
1982 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1983 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1985 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1986 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1987 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1988 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1989 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1991 /* some little sanity checking */
1992 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
1996 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
2000 while (i
< bgpo
.bgpo_optlen
) {
2001 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
2002 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
2003 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
2004 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
2008 printf("\n\t Option %s (%u), length: %u",
2009 tok2strbuf(bgp_opt_values
,"Unknown",
2011 tokbuf
, sizeof(tokbuf
)),
2015 /* now lets decode the options we know*/
2016 switch(bgpopt
.bgpopt_type
) {
2018 cap_type
=opt
[i
+BGP_OPT_SIZE
];
2019 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
2021 printf("\n\t %s (%u), length: %u",
2022 tok2strbuf(bgp_capcode_values
, "Unknown",
2023 cap_type
, tokbuf
, sizeof(tokbuf
)),
2027 case BGP_CAPCODE_MP
:
2028 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
2029 tok2strbuf(af_values
, "Unknown",
2030 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
2031 tokbuf
, sizeof(tokbuf
)),
2032 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
2033 tok2strbuf(bgp_safi_values
, "Unknown",
2034 opt
[i
+BGP_OPT_SIZE
+5],
2035 tokbuf
, sizeof(tokbuf
)),
2036 opt
[i
+BGP_OPT_SIZE
+5]);
2038 case BGP_CAPCODE_RESTART
:
2039 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
2040 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
2041 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
2044 while(tcap_len
>=4) {
2045 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2046 tok2strbuf(af_values
,"Unknown",
2047 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
2048 tokbuf
, sizeof(tokbuf
)),
2049 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
2050 tok2strbuf(bgp_safi_values
,"Unknown",
2051 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
2052 tokbuf2
, sizeof(tokbuf2
)),
2053 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
2054 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
2059 case BGP_CAPCODE_RR
:
2060 case BGP_CAPCODE_RR_CISCO
:
2063 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
2064 printf("\n\t\tno decoder for Capability %u",
2067 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
2071 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
2072 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
2077 printf("\n\t no decoder for option %u",
2078 bgpopt
.bgpopt_type
);
2082 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
2090 bgp_update_print(const u_char
*dat
, int length
)
2093 struct bgp_attr bgpa
;
2097 char tokbuf
[TOKBUFSIZE
];
2099 TCHECK2(dat
[0], BGP_SIZE
);
2100 memcpy(&bgp
, dat
, BGP_SIZE
);
2101 p
= dat
+ BGP_SIZE
; /*XXX*/
2103 /* Unfeasible routes */
2104 len
= EXTRACT_16BITS(p
);
2107 * Without keeping state from the original NLRI message,
2108 * it's not possible to tell if this a v4 or v6 route,
2109 * so only try to decode it if we're not v6 enabled.
2112 printf("\n\t Withdrawn routes: %d bytes", len
);
2114 char buf
[MAXHOSTNAMELEN
+ 100];
2120 printf("\n\t Withdrawn routes:");
2122 while(i
< 2 + len
) {
2123 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
2125 printf("\n\t (illegal prefix length)");
2127 } else if (wpfx
== -2)
2131 printf("\n\t %s", buf
);
2139 len
= EXTRACT_16BITS(p
);
2141 if (len
== 0 && length
== BGP_UPDATE_MINSIZE
) {
2142 printf("\n\t End-of-Rib Marker (empty NLRI)");
2147 /* do something more useful!*/
2149 while (i
< 2 + len
) {
2152 TCHECK2(p
[i
], sizeof(bgpa
));
2153 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
2154 alen
= bgp_attr_len(&bgpa
);
2155 aoff
= bgp_attr_off(&bgpa
);
2157 printf("\n\t %s (%u), length: %u",
2158 tok2strbuf(bgp_attr_values
, "Unknown Attribute",
2160 tokbuf
, sizeof(tokbuf
)),
2164 if (bgpa
.bgpa_flags
) {
2165 printf(", Flags [%s%s%s%s",
2166 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
2167 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
2168 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
2169 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
2170 if (bgpa
.bgpa_flags
& 0xf)
2171 printf("+%x", bgpa
.bgpa_flags
& 0xf);
2174 if (!bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
))
2181 if (dat
+ length
> p
) {
2182 printf("\n\t Updated routes:");
2183 while (dat
+ length
> p
) {
2184 char buf
[MAXHOSTNAMELEN
+ 100];
2185 i
= decode_prefix4(p
, buf
, sizeof(buf
));
2187 printf("\n\t (illegal prefix length)");
2192 printf("\n\t %s", buf
);
2203 bgp_notification_print(const u_char
*dat
, int length
)
2205 struct bgp_notification bgpn
;
2207 char tokbuf
[TOKBUFSIZE
];
2208 char tokbuf2
[TOKBUFSIZE
];
2210 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
2211 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
2213 /* some little sanity checking */
2214 if (length
<BGP_NOTIFICATION_SIZE
)
2218 tok2strbuf(bgp_notify_major_values
, "Unknown Error",
2219 bgpn
.bgpn_major
, tokbuf
, sizeof(tokbuf
)),
2222 switch (bgpn
.bgpn_major
) {
2224 case BGP_NOTIFY_MAJOR_MSG
:
2225 printf(", subcode %s (%u)",
2226 tok2strbuf(bgp_notify_minor_msg_values
, "Unknown",
2227 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2230 case BGP_NOTIFY_MAJOR_OPEN
:
2231 printf(", subcode %s (%u)",
2232 tok2strbuf(bgp_notify_minor_open_values
, "Unknown",
2233 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2236 case BGP_NOTIFY_MAJOR_UPDATE
:
2237 printf(", subcode %s (%u)",
2238 tok2strbuf(bgp_notify_minor_update_values
, "Unknown",
2239 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2242 case BGP_NOTIFY_MAJOR_CAP
:
2243 printf(" subcode %s (%u)",
2244 tok2strbuf(bgp_notify_minor_cap_values
, "Unknown",
2245 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2247 case BGP_NOTIFY_MAJOR_CEASE
:
2248 printf(", subcode %s (%u)",
2249 tok2strbuf(bgp_notify_minor_cease_values
, "Unknown",
2250 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2253 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2254 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2256 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2257 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2259 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2260 tok2strbuf(af_values
, "Unknown",
2261 EXTRACT_16BITS(tptr
), tokbuf
, sizeof(tokbuf
)),
2262 EXTRACT_16BITS(tptr
),
2263 tok2strbuf(bgp_safi_values
, "Unknown", *(tptr
+2),
2264 tokbuf2
, sizeof(tokbuf
)),
2266 EXTRACT_32BITS(tptr
+3));
2279 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
2281 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2282 char tokbuf
[TOKBUFSIZE
];
2283 char tokbuf2
[TOKBUFSIZE
];
2285 TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
2287 /* some little sanity checking */
2288 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2291 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2293 printf("\n\t AFI %s (%u), SAFI %s (%u)",
2294 tok2strbuf(af_values
,"Unknown",
2295 /* this stinks but the compiler pads the structure
2297 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2298 tokbuf
, sizeof(tokbuf
)),
2299 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2300 tok2strbuf(bgp_safi_values
,"Unknown",
2301 bgp_route_refresh_header
->safi
,
2302 tokbuf2
, sizeof(tokbuf2
)),
2303 bgp_route_refresh_header
->safi
);
2306 TCHECK2(*pptr
, len
);
2307 print_unknown_data(pptr
,"\n\t ", len
);
2316 bgp_header_print(const u_char
*dat
, int length
)
2319 char tokbuf
[TOKBUFSIZE
];
2321 TCHECK2(dat
[0], BGP_SIZE
);
2322 memcpy(&bgp
, dat
, BGP_SIZE
);
2323 printf("\n\t%s Message (%u), length: %u",
2324 tok2strbuf(bgp_msg_values
, "Unknown", bgp
.bgp_type
,
2325 tokbuf
, sizeof(tokbuf
)),
2329 switch (bgp
.bgp_type
) {
2331 bgp_open_print(dat
, length
);
2334 bgp_update_print(dat
, length
);
2336 case BGP_NOTIFICATION
:
2337 bgp_notification_print(dat
, length
);
2341 case BGP_ROUTE_REFRESH
:
2342 bgp_route_refresh_print(dat
, length
);
2345 /* we have no decoder for the BGP message */
2346 TCHECK2(*dat
, length
);
2347 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
2348 print_unknown_data(dat
,"\n\t ",length
);
2358 bgp_print(const u_char
*dat
, int length
)
2362 const u_char
*start
;
2363 const u_char marker
[] = {
2364 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2365 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2369 char tokbuf
[TOKBUFSIZE
];
2372 if (snapend
< dat
+ length
)
2375 printf(": BGP, length: %u",length
);
2377 if (vflag
< 1) /* lets be less chatty */
2383 if (!TTEST2(p
[0], 1))
2390 if (!TTEST2(p
[0], sizeof(marker
)))
2392 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2397 /* found BGP header */
2398 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2399 memcpy(&bgp
, p
, BGP_SIZE
);
2404 hlen
= ntohs(bgp
.bgp_len
);
2405 if (hlen
< BGP_SIZE
) {
2406 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
2411 if (TTEST2(p
[0], hlen
)) {
2412 if (!bgp_header_print(p
, hlen
))
2417 printf("\n[|BGP %s]",
2418 tok2strbuf(bgp_msg_values
,
2419 "Unknown Message Type",
2421 tokbuf
, sizeof(tokbuf
)));
2434 * c-style: whitesmith