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.116 2007-07-24 13:16:48 hannes Exp $";
42 #include <tcpdump-stdinc.h>
47 #include "interface.h"
48 #include "decode_prefix.h"
49 #include "addrtoname.h"
56 u_int8_t bgp_marker
[16];
60 #define BGP_SIZE 19 /* unaligned */
64 #define BGP_NOTIFICATION 3
65 #define BGP_KEEPALIVE 4
66 #define BGP_ROUTE_REFRESH 5
68 static struct tok bgp_msg_values
[] = {
70 { BGP_UPDATE
, "Update"},
71 { BGP_NOTIFICATION
, "Notification"},
72 { BGP_KEEPALIVE
, "Keepalive"},
73 { BGP_ROUTE_REFRESH
, "Route Refresh"},
78 u_int8_t bgpo_marker
[16];
81 u_int8_t bgpo_version
;
83 u_int16_t bgpo_holdtime
;
86 /* options should follow */
88 #define BGP_OPEN_SIZE 29 /* unaligned */
95 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
97 #define BGP_UPDATE_MINSIZE 23
99 struct bgp_notification
{
100 u_int8_t bgpn_marker
[16];
106 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
108 struct bgp_route_refresh
{
109 u_int8_t bgp_marker
[16];
112 u_int8_t afi
[2]; /* the compiler messes this structure up */
113 u_int8_t res
; /* when doing misaligned sequences of int8 and int16 */
114 u_int8_t safi
; /* afi should be int16 - so we have to access it using */
115 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
116 #define BGP_ROUTE_REFRESH_SIZE 23
125 #define bgp_attr_len(p) \
126 (((p)->bgpa_flags & 0x10) ? \
127 EXTRACT_16BITS(&(p)->bgpa_len.elen) : (p)->bgpa_len.len)
128 #define bgp_attr_off(p) \
129 (((p)->bgpa_flags & 0x10) ? 4 : 3)
132 #define BGPTYPE_ORIGIN 1
133 #define BGPTYPE_AS_PATH 2
134 #define BGPTYPE_NEXT_HOP 3
135 #define BGPTYPE_MULTI_EXIT_DISC 4
136 #define BGPTYPE_LOCAL_PREF 5
137 #define BGPTYPE_ATOMIC_AGGREGATE 6
138 #define BGPTYPE_AGGREGATOR 7
139 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
140 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
141 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
142 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
143 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
144 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
145 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
146 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
147 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
148 #define BGPTYPE_PMSI_TUNNEL 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 struct tok bgp_as_path_segment_open_values
[] = {
182 { BGP_AS_SEQUENCE
, ""},
184 { BGP_CONFED_AS_SEQUENCE
, "( "},
185 { BGP_CONFED_AS_SET
, "({ "},
189 static struct tok bgp_as_path_segment_close_values
[] = {
190 { BGP_AS_SEQUENCE
, ""},
192 { BGP_CONFED_AS_SEQUENCE
, ")"},
193 { BGP_CONFED_AS_SET
, "})"},
197 #define BGP_OPT_AUTH 1
198 #define BGP_OPT_CAP 2
201 static struct tok bgp_opt_values
[] = {
202 { BGP_OPT_AUTH
, "Authentication Information"},
203 { BGP_OPT_CAP
, "Capabilities Advertisement"},
207 #define BGP_CAPCODE_MP 1
208 #define BGP_CAPCODE_RR 2
209 #define BGP_CAPCODE_ORF 3 /* XXX */
210 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
211 #define BGP_CAPCODE_AS_NEW 65 /* XXX */
212 #define BGP_CAPCODE_DYN_CAP 67 /* XXX */
213 #define BGP_CAPCODE_RR_CISCO 128
215 static struct tok bgp_capcode_values
[] = {
216 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
217 { BGP_CAPCODE_RR
, "Route Refresh"},
218 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
219 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
220 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
221 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
222 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
226 #define BGP_NOTIFY_MAJOR_MSG 1
227 #define BGP_NOTIFY_MAJOR_OPEN 2
228 #define BGP_NOTIFY_MAJOR_UPDATE 3
229 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
230 #define BGP_NOTIFY_MAJOR_FSM 5
231 #define BGP_NOTIFY_MAJOR_CEASE 6
232 #define BGP_NOTIFY_MAJOR_CAP 7
234 static struct tok bgp_notify_major_values
[] = {
235 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
236 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
237 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
238 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
239 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
240 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
241 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
245 /* draft-ietf-idr-cease-subcode-02 */
246 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
247 static struct tok bgp_notify_minor_cease_values
[] = {
248 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
249 { 2, "Administratively Shutdown"},
250 { 3, "Peer Unconfigured"},
251 { 4, "Administratively Reset"},
252 { 5, "Connection Rejected"},
253 { 6, "Other Configuration Change"},
254 { 7, "Connection Collision Resolution"},
258 static struct tok bgp_notify_minor_msg_values
[] = {
259 { 1, "Connection Not Synchronized"},
260 { 2, "Bad Message Length"},
261 { 3, "Bad Message Type"},
265 static struct tok bgp_notify_minor_open_values
[] = {
266 { 1, "Unsupported Version Number"},
268 { 3, "Bad BGP Identifier"},
269 { 4, "Unsupported Optional Parameter"},
270 { 5, "Authentication Failure"},
271 { 6, "Unacceptable Hold Time"},
272 { 7, "Capability Message Error"},
276 static struct tok bgp_notify_minor_update_values
[] = {
277 { 1, "Malformed Attribute List"},
278 { 2, "Unrecognized Well-known Attribute"},
279 { 3, "Missing Well-known Attribute"},
280 { 4, "Attribute Flags Error"},
281 { 5, "Attribute Length Error"},
282 { 6, "Invalid ORIGIN Attribute"},
283 { 7, "AS Routing Loop"},
284 { 8, "Invalid NEXT_HOP Attribute"},
285 { 9, "Optional Attribute Error"},
286 { 10, "Invalid Network Field"},
287 { 11, "Malformed AS_PATH"},
291 static struct tok bgp_notify_minor_cap_values
[] = {
292 { 1, "Invalid Action Value" },
293 { 2, "Invalid Capability Length" },
294 { 3, "Malformed Capability Value" },
295 { 4, "Unsupported Capability Code" },
299 static struct tok bgp_origin_values
[] = {
306 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
307 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
308 #define BGP_PMSI_TUNNEL_PIM_SSM 3
309 #define BGP_PMSI_TUNNEL_PIM_SM 4
310 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
311 #define BGP_PMSI_TUNNEL_INGRESS 6
312 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
314 static struct tok bgp_pmsi_tunnel_values
[] = {
315 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
316 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
317 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
318 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
319 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
320 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
321 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
325 static struct tok bgp_pmsi_flag_values
[] = {
326 { 0x01, "Leaf Information required"},
331 /* Subsequent address family identifier, RFC2283 section 7 */
333 #define SAFNUM_UNICAST 1
334 #define SAFNUM_MULTICAST 2
335 #define SAFNUM_UNIMULTICAST 3
336 /* labeled BGP RFC3107 */
337 #define SAFNUM_LABUNICAST 4
338 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
339 #define SAFNUM_MULTICAST_VPN 5
340 #define SAFNUM_TUNNEL 64 /* XXX */
341 #define SAFNUM_VPLS 65 /* XXX */
342 #define SAFNUM_MDT 66 /* XXX */
343 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
344 #define SAFNUM_VPNUNICAST 128
345 #define SAFNUM_VPNMULTICAST 129
346 #define SAFNUM_VPNUNIMULTICAST 130
347 /* draft-marques-ppvpn-rt-constrain-01.txt */
348 #define SAFNUM_RT_ROUTING_INFO 132
350 #define BGP_VPN_RD_LEN 8
352 static struct tok bgp_safi_values
[] = {
353 { SAFNUM_RES
, "Reserved"},
354 { SAFNUM_UNICAST
, "Unicast"},
355 { SAFNUM_MULTICAST
, "Multicast"},
356 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
357 { SAFNUM_LABUNICAST
, "labeled Unicast"},
358 { SAFNUM_TUNNEL
, "Tunnel"},
359 { SAFNUM_VPLS
, "VPLS"},
360 { SAFNUM_MDT
, "MDT"},
361 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
362 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
363 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
364 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
365 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
369 /* well-known community */
370 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
371 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
372 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
374 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
375 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
376 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
377 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
378 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
379 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
380 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
381 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
382 /* rfc2547 bgp-mpls-vpns */
383 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
384 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
385 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
386 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
388 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
389 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
391 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
392 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
394 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
396 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
397 #define BGP_EXT_COM_VRF_RT_IMP 0x010a /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
399 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
400 #define BGP_EXT_COM_EIGRP_GEN 0x8800
401 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
402 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
403 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
404 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
405 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
407 static struct tok bgp_extd_comm_flag_values
[] = {
408 { 0x8000, "vendor-specific"},
409 { 0x4000, "non-transitive"},
413 static struct tok bgp_extd_comm_subtype_values
[] = {
414 { BGP_EXT_COM_RT_0
, "target"},
415 { BGP_EXT_COM_RT_1
, "target"},
416 { BGP_EXT_COM_RT_2
, "target"},
417 { BGP_EXT_COM_RO_0
, "origin"},
418 { BGP_EXT_COM_RO_1
, "origin"},
419 { BGP_EXT_COM_RO_2
, "origin"},
420 { BGP_EXT_COM_LINKBAND
, "link-BW"},
421 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
422 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
423 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
424 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
425 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
426 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
427 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
428 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
429 { BGP_EXT_COM_L2INFO
, "layer2-info"},
430 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
431 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
432 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
433 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
434 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
435 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
436 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
437 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
441 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
442 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
443 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
444 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
445 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
446 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
447 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
448 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
450 static struct tok bgp_extd_comm_ospf_rtype_values
[] = {
451 { BGP_OSPF_RTYPE_RTR
, "Router" },
452 { BGP_OSPF_RTYPE_NET
, "Network" },
453 { BGP_OSPF_RTYPE_SUM
, "Summary" },
454 { BGP_OSPF_RTYPE_EXT
, "External" },
455 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
456 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
461 decode_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
471 memset(&addr
, 0, sizeof(addr
));
472 TCHECK2(pptr
[1], (plen
+ 7) / 8);
473 memcpy(&addr
, &pptr
[1], (plen
+ 7) / 8);
475 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
476 ((0xff00 >> (plen
% 8)) & 0xff);
478 snprintf(buf
, buflen
, "%s/%d", getname((u_char
*)&addr
), plen
);
479 return 1 + (plen
+ 7) / 8;
486 decode_labeled_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
492 plen
= pptr
[0]; /* get prefix length */
494 /* this is one of the weirdnesses of rfc3107
495 the label length (actually the label + COS bits)
496 is added to the prefix length;
497 we also do only read out just one label -
498 there is no real application for advertisement of
499 stacked labels in a a single BGP message
505 plen
-=24; /* adjust prefixlen - labellength */
510 memset(&addr
, 0, sizeof(addr
));
511 TCHECK2(pptr
[4], (plen
+ 7) / 8);
512 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
514 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
515 ((0xff00 >> (plen
% 8)) & 0xff);
517 /* the label may get offsetted by 4 bits so lets shift it right */
518 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
519 getname((u_char
*)&addr
),
521 EXTRACT_24BITS(pptr
+1)>>4,
522 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
524 return 4 + (plen
+ 7) / 8;
533 * print an ipv4 or ipv6 address into a buffer dependend on address length.
536 bgp_vpn_ip_print (const u_char
*pptr
, u_int addr_length
) {
538 /* worst case string is s fully formatted v6 address */
539 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
542 switch(addr_length
) {
543 case (sizeof(struct in_addr
) << 3): /* 32 */
544 TCHECK2(pptr
[0], sizeof(struct in_addr
));
545 snprintf(pos
, sizeof(addr
), "%s", ipaddr_string(pptr
));
548 case (sizeof(struct in6_addr
) << 3): /* 128 */
549 TCHECK2(pptr
[0], sizeof(struct in6_addr
));
550 snprintf(pos
, sizeof(addr
), "%s", ip6addr_string(pptr
));
554 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
567 * print an multicast s,g entry into a buffer.
568 * the s,g entry is encoded like this.
570 * +-----------------------------------+
571 * | Multicast Source Length (1 octet) |
572 * +-----------------------------------+
573 * | Multicast Source (Variable) |
574 * +-----------------------------------+
575 * | Multicast Group Length (1 octet) |
576 * +-----------------------------------+
577 * | Multicast Group (Variable) |
578 * +-----------------------------------+
580 * return the number of bytes read from the wire.
583 bgp_vpn_sg_print (const u_char
*pptr
, char *buf
, u_int buflen
) {
585 u_int8_t addr_length
;
586 u_int total_length
, offset
;
590 /* Source address length, encoded in bits */
592 addr_length
= *pptr
++;
595 TCHECK2(pptr
[0], (addr_length
>> 3));
596 total_length
+= (addr_length
>> 3) + 1;
597 offset
= strlen(buf
);
599 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
600 bgp_vpn_ip_print(pptr
, addr_length
));
601 pptr
+= (addr_length
>> 3);
604 /* Group address length, encoded in bits */
606 addr_length
= *pptr
++;
609 TCHECK2(pptr
[0], (addr_length
>> 3));
610 total_length
+= (addr_length
>> 3) + 1;
611 offset
= strlen(buf
);
613 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
614 bgp_vpn_ip_print(pptr
, addr_length
));
615 pptr
+= (addr_length
>> 3);
619 return (total_length
);
623 /* RDs and RTs share the same semantics
624 * we use bgp_vpn_rd_print for
625 * printing route targets inside a NLRI */
627 bgp_vpn_rd_print (const u_char
*pptr
) {
629 /* allocate space for the largest possible string */
630 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
633 /* ok lets load the RD format */
634 switch (EXTRACT_16BITS(pptr
)) {
636 /* 2-byte-AS:number fmt*/
638 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
639 EXTRACT_16BITS(pptr
+2),
640 EXTRACT_32BITS(pptr
+4),
641 *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
643 /* IP-address:AS fmt*/
646 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
647 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
650 /* 4-byte-AS:number fmt*/
652 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (%u.%u.%u.%u:%u)",
653 EXTRACT_32BITS(pptr
+2), EXTRACT_16BITS(pptr
+6),
654 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
657 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
666 decode_rt_routing_info(const u_char
*pptr
, char *buf
, u_int buflen
)
668 u_int8_t route_target
[8];
672 plen
= pptr
[0]; /* get prefix length */
675 return 1; /* default route target */
680 plen
-=32; /* adjust prefix length */
685 memset(&route_target
, 0, sizeof(route_target
));
686 TCHECK2(pptr
[1], (plen
+ 7) / 8);
687 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
689 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
690 ((0xff00 >> (plen
% 8)) & 0xff);
692 snprintf(buf
, buflen
, "origin AS: %u, route target %s",
693 EXTRACT_32BITS(pptr
+1),
694 bgp_vpn_rd_print((u_char
*)&route_target
));
696 return 5 + (plen
+ 7) / 8;
703 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
709 plen
= pptr
[0]; /* get prefix length */
714 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
719 memset(&addr
, 0, sizeof(addr
));
720 TCHECK2(pptr
[12], (plen
+ 7) / 8);
721 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
723 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
724 ((0xff00 >> (plen
% 8)) & 0xff);
726 /* the label may get offsetted by 4 bits so lets shift it right */
727 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
728 bgp_vpn_rd_print(pptr
+4),
729 getname((u_char
*)&addr
),
731 EXTRACT_24BITS(pptr
+1)>>4,
732 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
734 return 12 + (plen
+ 7) / 8;
740 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
741 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
742 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
743 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
744 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
745 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
746 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
748 static struct tok bgp_multicast_vpn_route_type_values
[] = {
749 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
750 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
751 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
752 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
753 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
754 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
755 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
759 decode_multicast_vpn(const u_char
*pptr
, char *buf
, u_int buflen
)
761 u_int8_t route_type
, route_length
, addr_length
, sg_length
;
765 route_type
= *pptr
++;
766 route_length
= *pptr
++;
768 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
769 tok2str(bgp_multicast_vpn_route_type_values
,
770 "Unknown", route_type
),
771 route_type
, route_length
);
774 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
775 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
776 offset
= strlen(buf
);
777 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
778 bgp_vpn_rd_print(pptr
),
779 bgp_vpn_ip_print(pptr
+ BGP_VPN_RD_LEN
,
780 (route_length
- BGP_VPN_RD_LEN
) << 3));
782 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
783 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
+ 4);
784 offset
= strlen(buf
);
785 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %u",
786 bgp_vpn_rd_print(pptr
),
787 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
));
790 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
791 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
792 offset
= strlen(buf
);
793 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
794 bgp_vpn_rd_print(pptr
));
795 pptr
+= BGP_VPN_RD_LEN
;
797 sg_length
= bgp_vpn_sg_print(pptr
, buf
, buflen
);
798 addr_length
= route_length
- sg_length
;
800 TCHECK2(pptr
[0], addr_length
);
801 offset
= strlen(buf
);
802 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
803 bgp_vpn_ip_print(pptr
, addr_length
<< 3));
806 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
807 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
808 offset
= strlen(buf
);
809 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
810 bgp_vpn_rd_print(pptr
));
811 pptr
+= BGP_VPN_RD_LEN
;
813 bgp_vpn_sg_print(pptr
, buf
, buflen
);
816 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
817 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
818 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
819 offset
= strlen(buf
);
820 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %u",
821 bgp_vpn_rd_print(pptr
),
822 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
));
823 pptr
+= BGP_VPN_RD_LEN
;
825 bgp_vpn_sg_print(pptr
, buf
, buflen
);
829 * no per route-type printing yet.
831 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
836 return route_length
+ 2;
843 * As I remember, some versions of systems have an snprintf() that
844 * returns -1 if the buffer would have overflowed. If the return
845 * value is negative, set buflen to 0, to indicate that we've filled
848 * If the return value is greater than buflen, that means that
849 * the buffer would have overflowed; again, set buflen to 0 in
852 #define UPDATE_BUF_BUFLEN(buf, buflen, strlen) \
855 else if ((u_int)strlen>buflen) \
863 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
865 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
868 plen
=EXTRACT_16BITS(pptr
);
873 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
874 bgp_vpn_rd_print(pptr
),
875 EXTRACT_16BITS(pptr
+8),
876 EXTRACT_16BITS(pptr
+10),
877 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
878 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
882 /* ok now the variable part - lets read out TLVs*/
888 tlv_len
=EXTRACT_16BITS(pptr
);
895 strlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
898 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
900 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
904 strlen
=snprintf(buf
,buflen
, "%02x",*pptr
++);
905 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
912 strlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
915 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
919 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
929 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
931 struct in6_addr addr
;
939 memset(&addr
, 0, sizeof(addr
));
940 TCHECK2(pd
[1], (plen
+ 7) / 8);
941 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
943 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
944 ((0xff00 >> (plen
% 8)) & 0xff);
946 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
947 return 1 + (plen
+ 7) / 8;
954 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
956 struct in6_addr addr
;
960 plen
= pptr
[0]; /* get prefix length */
965 plen
-=24; /* adjust prefixlen - labellength */
970 memset(&addr
, 0, sizeof(addr
));
971 TCHECK2(pptr
[4], (plen
+ 7) / 8);
972 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
974 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
975 ((0xff00 >> (plen
% 8)) & 0xff);
977 /* the label may get offsetted by 4 bits so lets shift it right */
978 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
979 getname6((u_char
*)&addr
),
981 EXTRACT_24BITS(pptr
+1)>>4,
982 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
984 return 4 + (plen
+ 7) / 8;
991 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
993 struct in6_addr addr
;
997 plen
= pptr
[0]; /* get prefix length */
1002 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1007 memset(&addr
, 0, sizeof(addr
));
1008 TCHECK2(pptr
[12], (plen
+ 7) / 8);
1009 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1011 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1012 ((0xff00 >> (plen
% 8)) & 0xff);
1014 /* the label may get offsetted by 4 bits so lets shift it right */
1015 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1016 bgp_vpn_rd_print(pptr
+4),
1017 getname6((u_char
*)&addr
),
1019 EXTRACT_24BITS(pptr
+1)>>4,
1020 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1022 return 12 + (plen
+ 7) / 8;
1030 decode_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
1036 plen
= pptr
[0]; /* get prefix length */
1041 memset(&addr
, 0, sizeof(addr
));
1042 TCHECK2(pptr
[4], (plen
+ 7) / 8);
1043 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
1045 addr
[(plen
+ 7) / 8 - 1] &=
1046 ((0xff00 >> (plen
% 8)) & 0xff);
1048 snprintf(buf
, buflen
, "%s/%d",
1049 isonsap_string(addr
,(plen
+ 7) / 8),
1052 return 1 + (plen
+ 7) / 8;
1059 decode_labeled_vpn_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
1065 plen
= pptr
[0]; /* get prefix length */
1070 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1075 memset(&addr
, 0, sizeof(addr
));
1076 TCHECK2(pptr
[12], (plen
+ 7) / 8);
1077 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1079 addr
[(plen
+ 7) / 8 - 1] &=
1080 ((0xff00 >> (plen
% 8)) & 0xff);
1082 /* the label may get offsetted by 4 bits so lets shift it right */
1083 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1084 bgp_vpn_rd_print(pptr
+4),
1085 isonsap_string(addr
,(plen
+ 7) / 8),
1087 EXTRACT_24BITS(pptr
+1)>>4,
1088 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1090 return 12 + (plen
+ 7) / 8;
1097 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
1101 u_int8_t safi
, snpa
, nhlen
;
1102 union { /* copy buffer for bandwidth values */
1109 char buf
[MAXHOSTNAMELEN
+ 100];
1110 char tokbuf
[TOKBUFSIZE
];
1115 switch (attr
->bgpa_type
) {
1116 case BGPTYPE_ORIGIN
:
1118 printf("invalid len");
1121 printf("%s", tok2strbuf(bgp_origin_values
,
1122 "Unknown Origin Typecode",
1124 tokbuf
, sizeof(tokbuf
)));
1128 case BGPTYPE_AS_PATH
:
1130 printf("invalid len");
1138 while (tptr
< pptr
+ len
) {
1140 printf("%s", tok2strbuf(bgp_as_path_segment_open_values
,
1142 tokbuf
, sizeof(tokbuf
)));
1143 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
1144 TCHECK2(tptr
[2 + i
], 2);
1145 printf("%u ", EXTRACT_16BITS(&tptr
[2 + i
]));
1148 printf("%s", tok2strbuf(bgp_as_path_segment_close_values
,
1150 tokbuf
, sizeof(tokbuf
)));
1152 tptr
+= 2 + tptr
[1] * 2;
1155 case BGPTYPE_NEXT_HOP
:
1157 printf("invalid len");
1159 TCHECK2(tptr
[0], 4);
1160 printf("%s", getname(tptr
));
1163 case BGPTYPE_MULTI_EXIT_DISC
:
1164 case BGPTYPE_LOCAL_PREF
:
1166 printf("invalid len");
1168 TCHECK2(tptr
[0], 4);
1169 printf("%u", EXTRACT_32BITS(tptr
));
1172 case BGPTYPE_ATOMIC_AGGREGATE
:
1174 printf("invalid len");
1176 case BGPTYPE_AGGREGATOR
:
1178 printf("invalid len");
1181 TCHECK2(tptr
[0], 6);
1182 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
1185 case BGPTYPE_COMMUNITIES
:
1187 printf("invalid len");
1192 TCHECK2(tptr
[0], 4);
1193 comm
= EXTRACT_32BITS(tptr
);
1195 case BGP_COMMUNITY_NO_EXPORT
:
1196 printf(" NO_EXPORT");
1198 case BGP_COMMUNITY_NO_ADVERT
:
1199 printf(" NO_ADVERTISE");
1201 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1202 printf(" NO_EXPORT_SUBCONFED");
1206 (comm
>> 16) & 0xffff,
1208 (tlen
>4) ? ", " : "");
1215 case BGPTYPE_ORIGINATOR_ID
:
1217 printf("invalid len");
1220 TCHECK2(tptr
[0], 4);
1221 printf("%s",getname(tptr
));
1223 case BGPTYPE_CLUSTER_LIST
:
1225 printf("invalid len");
1229 TCHECK2(tptr
[0], 4);
1232 (tlen
>4) ? ", " : "");
1237 case BGPTYPE_MP_REACH_NLRI
:
1238 TCHECK2(tptr
[0], 3);
1239 af
= EXTRACT_16BITS(tptr
);
1242 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1243 tok2strbuf(af_values
, "Unknown AFI", af
,
1244 tokbuf
, sizeof(tokbuf
)),
1246 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1247 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1248 tokbuf
, sizeof(tokbuf
)),
1251 switch(af
<<8 | safi
) {
1252 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1253 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1254 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1255 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1256 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1257 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1258 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1259 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1260 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1262 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1263 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1264 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1265 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1266 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1267 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1268 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1270 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1271 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1272 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1273 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1274 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1275 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1276 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1277 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1278 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1279 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1282 TCHECK2(tptr
[0], tlen
);
1283 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1285 print_unknown_data(tptr
,"\n\t ",tlen
);
1298 printf("\n\t nexthop: ");
1300 switch(af
<<8 | safi
) {
1301 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1302 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1303 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1304 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1305 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1306 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1307 if (tlen
< (int)sizeof(struct in_addr
)) {
1308 printf("invalid len");
1311 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1312 printf("%s",getname(tptr
));
1313 tlen
-= sizeof(struct in_addr
);
1314 tptr
+= sizeof(struct in_addr
);
1317 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1318 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1319 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1320 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1321 printf("invalid len");
1324 TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1325 printf("RD: %s, %s",
1326 bgp_vpn_rd_print(tptr
),
1327 getname(tptr
+BGP_VPN_RD_LEN
));
1328 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1329 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1333 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1334 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1335 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1336 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1337 if (tlen
< (int)sizeof(struct in6_addr
)) {
1338 printf("invalid len");
1341 TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1342 printf("%s", getname6(tptr
));
1343 tlen
-= sizeof(struct in6_addr
);
1344 tptr
+= sizeof(struct in6_addr
);
1347 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1348 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1349 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1350 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1351 printf("invalid len");
1354 TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1355 printf("RD: %s, %s",
1356 bgp_vpn_rd_print(tptr
),
1357 getname6(tptr
+BGP_VPN_RD_LEN
));
1358 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1359 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1363 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1364 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1365 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1366 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1367 if (tlen
< (int)sizeof(struct in_addr
)) {
1368 printf("invalid len");
1371 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1372 printf("%s", getname(tptr
));
1373 tlen
-= (sizeof(struct in_addr
));
1374 tptr
+= (sizeof(struct in_addr
));
1377 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1378 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1379 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1380 TCHECK2(tptr
[0], tlen
);
1381 printf("%s",isonsap_string(tptr
,tlen
));
1386 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1387 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1388 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1389 if (tlen
< BGP_VPN_RD_LEN
+1) {
1390 printf("invalid len");
1393 TCHECK2(tptr
[0], tlen
);
1394 printf("RD: %s, %s",
1395 bgp_vpn_rd_print(tptr
),
1396 isonsap_string(tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
));
1397 /* rfc986 mapped IPv4 address ? */
1398 if (EXTRACT_32BITS(tptr
+BGP_VPN_RD_LEN
) == 0x47000601)
1399 printf(" = %s", getname(tptr
+BGP_VPN_RD_LEN
+4));
1401 /* rfc1888 mapped IPv6 address ? */
1402 else if (EXTRACT_24BITS(tptr
+BGP_VPN_RD_LEN
) == 0x350000)
1403 printf(" = %s", getname6(tptr
+BGP_VPN_RD_LEN
+3));
1410 TCHECK2(tptr
[0], tlen
);
1411 printf("no AFI %u/SAFI %u decoder",af
,safi
);
1413 print_unknown_data(tptr
,"\n\t ",tlen
);
1421 printf(", nh-length: %u", nhlen
);
1429 printf("\n\t %u SNPA", snpa
);
1430 for (/*nothing*/; snpa
> 0; snpa
--) {
1432 printf("\n\t %d bytes", tptr
[0]);
1433 tptr
+= tptr
[0] + 1;
1436 printf(", no SNPA");
1439 while (len
- (tptr
- pptr
) > 0) {
1440 switch (af
<<8 | safi
) {
1441 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1442 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1443 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1444 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1446 printf("\n\t (illegal prefix length)");
1447 else if (advance
== -2)
1450 printf("\n\t %s", buf
);
1452 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1453 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1455 printf("\n\t (illegal prefix length)");
1456 else if (advance
== -2)
1459 printf("\n\t %s", buf
);
1461 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1462 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1463 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1464 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1466 printf("\n\t (illegal prefix length)");
1467 else if (advance
== -2)
1470 printf("\n\t %s", buf
);
1472 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1473 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1475 printf("\n\t (illegal prefix length)");
1476 else if (advance
== -2)
1479 printf("\n\t %s", buf
);
1481 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1482 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1483 advance
= decode_multicast_vpn(tptr
, buf
, sizeof(buf
));
1485 printf("\n\t (illegal prefix length)");
1486 else if (advance
== -2)
1489 printf("\n\t %s", buf
);
1492 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1493 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1494 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1495 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1497 printf("\n\t (illegal prefix length)");
1498 else if (advance
== -2)
1501 printf("\n\t %s", buf
);
1503 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1504 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1506 printf("\n\t (illegal prefix length)");
1507 else if (advance
== -2)
1510 printf("\n\t %s", buf
);
1512 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1513 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1514 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1515 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1517 printf("\n\t (illegal prefix length)");
1518 else if (advance
== -2)
1521 printf("\n\t %s", buf
);
1524 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1525 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1526 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1527 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1528 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1530 printf("\n\t (illegal length)");
1531 else if (advance
== -2)
1534 printf("\n\t %s", buf
);
1536 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1537 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1538 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1539 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1541 printf("\n\t (illegal prefix length)");
1542 else if (advance
== -2)
1545 printf("\n\t %s", buf
);
1547 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1548 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1549 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1550 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1552 printf("\n\t (illegal prefix length)");
1553 else if (advance
== -2)
1556 printf("\n\t %s", buf
);
1559 TCHECK2(*tptr
,tlen
);
1560 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1562 print_unknown_data(tptr
,"\n\t ",tlen
);
1574 case BGPTYPE_MP_UNREACH_NLRI
:
1575 TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1576 af
= EXTRACT_16BITS(tptr
);
1579 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1580 tok2strbuf(af_values
, "Unknown AFI", af
,
1581 tokbuf
, sizeof(tokbuf
)),
1583 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1584 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1585 tokbuf
, sizeof(tokbuf
)),
1588 if (len
== BGP_MP_NLRI_MINSIZE
)
1589 printf("\n\t End-of-Rib Marker (empty NLRI)");
1593 while (len
- (tptr
- pptr
) > 0) {
1594 switch (af
<<8 | safi
) {
1595 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1596 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1597 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1598 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1600 printf("\n\t (illegal prefix length)");
1601 else if (advance
== -2)
1604 printf("\n\t %s", buf
);
1606 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1607 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1609 printf("\n\t (illegal prefix length)");
1610 else if (advance
== -2)
1613 printf("\n\t %s", buf
);
1615 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1616 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1617 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1618 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1620 printf("\n\t (illegal prefix length)");
1621 else if (advance
== -2)
1624 printf("\n\t %s", buf
);
1627 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1628 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1629 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1630 advance
= decode_prefix6(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_INET6
<<8 | SAFNUM_LABUNICAST
):
1639 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1641 printf("\n\t (illegal prefix length)");
1642 else if (advance
== -2)
1645 printf("\n\t %s", buf
);
1647 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1648 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1649 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1650 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1652 printf("\n\t (illegal prefix length)");
1653 else if (advance
== -2)
1656 printf("\n\t %s", buf
);
1659 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1660 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1661 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1662 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1663 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1665 printf("\n\t (illegal length)");
1666 else if (advance
== -2)
1669 printf("\n\t %s", buf
);
1671 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1672 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1673 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1674 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1676 printf("\n\t (illegal prefix length)");
1677 else if (advance
== -2)
1680 printf("\n\t %s", buf
);
1682 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1683 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1684 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1685 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1687 printf("\n\t (illegal prefix length)");
1688 else if (advance
== -2)
1691 printf("\n\t %s", buf
);
1693 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1694 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1695 advance
= decode_multicast_vpn(tptr
, buf
, sizeof(buf
));
1697 printf("\n\t (illegal prefix length)");
1698 else if (advance
== -2)
1701 printf("\n\t %s", buf
);
1704 TCHECK2(*(tptr
-3),tlen
);
1705 printf("no AFI %u / SAFI %u decoder",af
,safi
);
1707 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1717 case BGPTYPE_EXTD_COMMUNITIES
:
1719 printf("invalid len");
1723 u_int16_t extd_comm
;
1725 TCHECK2(tptr
[0], 2);
1726 extd_comm
=EXTRACT_16BITS(tptr
);
1728 printf("\n\t %s (0x%04x), Flags [%s]",
1729 tok2strbuf(bgp_extd_comm_subtype_values
,
1730 "unknown extd community typecode",
1731 extd_comm
, tokbuf
, sizeof(tokbuf
)),
1733 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1735 TCHECK2(*(tptr
+2), 6);
1737 case BGP_EXT_COM_RT_0
:
1738 case BGP_EXT_COM_RO_0
:
1739 printf(": %u:%u (= %s)",
1740 EXTRACT_16BITS(tptr
+2),
1741 EXTRACT_32BITS(tptr
+4),
1744 case BGP_EXT_COM_RT_1
:
1745 case BGP_EXT_COM_RO_1
:
1746 case BGP_EXT_COM_VRF_RT_IMP
:
1749 EXTRACT_16BITS(tptr
+6));
1751 case BGP_EXT_COM_RT_2
:
1752 case BGP_EXT_COM_RO_2
:
1754 EXTRACT_32BITS(tptr
+2),
1755 EXTRACT_16BITS(tptr
+6));
1757 case BGP_EXT_COM_LINKBAND
:
1758 bw
.i
= EXTRACT_32BITS(tptr
+2);
1759 printf(": bandwidth: %.3f Mbps",
1762 case BGP_EXT_COM_VPN_ORIGIN
:
1763 case BGP_EXT_COM_VPN_ORIGIN2
:
1764 case BGP_EXT_COM_VPN_ORIGIN3
:
1765 case BGP_EXT_COM_VPN_ORIGIN4
:
1766 case BGP_EXT_COM_OSPF_RID
:
1767 case BGP_EXT_COM_OSPF_RID2
:
1768 printf("%s", getname(tptr
+2));
1770 case BGP_EXT_COM_OSPF_RTYPE
:
1771 case BGP_EXT_COM_OSPF_RTYPE2
:
1772 printf(": area:%s, router-type:%s, metric-type:%s%s",
1774 tok2strbuf(bgp_extd_comm_ospf_rtype_values
,
1777 tokbuf
, sizeof(tokbuf
)),
1778 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1779 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1781 case BGP_EXT_COM_L2INFO
:
1782 printf(": %s Control Flags [0x%02x]:MTU %u",
1783 tok2strbuf(l2vpn_encaps_values
,
1786 tokbuf
, sizeof(tokbuf
)),
1788 EXTRACT_16BITS(tptr
+4));
1790 case BGP_EXT_COM_SOURCE_AS
:
1791 printf(": AS %u", EXTRACT_16BITS(tptr
+2));
1795 print_unknown_data(tptr
,"\n\t ",8);
1803 case BGPTYPE_PMSI_TUNNEL
:
1805 u_int8_t tunnel_type
, flags
;
1807 tunnel_type
= *(tptr
+1);
1811 TCHECK2(tptr
[0], 5);
1812 printf("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
1813 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
1815 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
1816 EXTRACT_24BITS(tptr
+2)>>4);
1821 switch (tunnel_type
) {
1822 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
1823 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
1824 TCHECK2(tptr
[0], 8);
1825 printf("\n\t Sender %s, P-Group %s",
1826 ipaddr_string(tptr
),
1827 ipaddr_string(tptr
+4));
1830 case BGP_PMSI_TUNNEL_PIM_SSM
:
1831 TCHECK2(tptr
[0], 8);
1832 printf("\n\t Root-Node %s, P-Group %s",
1833 ipaddr_string(tptr
),
1834 ipaddr_string(tptr
+4));
1836 case BGP_PMSI_TUNNEL_INGRESS
:
1837 TCHECK2(tptr
[0], 4);
1838 printf("\n\t Tunnel-Endpoint %s",
1839 ipaddr_string(tptr
));
1841 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
1842 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
1843 TCHECK2(tptr
[0], 8);
1844 printf("\n\t Root-Node %s, LSP-ID 0x%08x",
1845 ipaddr_string(tptr
),
1846 EXTRACT_32BITS(tptr
+4));
1848 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
1849 TCHECK2(tptr
[0], 8);
1850 printf("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
1851 ipaddr_string(tptr
),
1852 EXTRACT_32BITS(tptr
+4));
1856 print_unknown_data(tptr
,"\n\t ",tlen
);
1861 case BGPTYPE_ATTR_SET
:
1862 TCHECK2(tptr
[0], 4);
1863 printf("\n\t Origin AS: %u", EXTRACT_32BITS(tptr
));
1869 struct bgp_attr bgpa
;
1871 TCHECK2(tptr
[0], sizeof(bgpa
));
1872 memcpy(&bgpa
, tptr
, sizeof(bgpa
));
1873 alen
= bgp_attr_len(&bgpa
);
1874 tptr
+= bgp_attr_off(&bgpa
);
1875 len
-= bgp_attr_off(&bgpa
);
1877 printf("\n\t %s (%u), length: %u",
1878 tok2strbuf(bgp_attr_values
,
1879 "Unknown Attribute", bgpa
.bgpa_type
,
1880 tokbuf
, sizeof(tokbuf
)),
1884 if (bgpa
.bgpa_flags
) {
1885 printf(", Flags [%s%s%s%s",
1886 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1887 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1888 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1889 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1890 if (bgpa
.bgpa_flags
& 0xf)
1891 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1894 /* FIXME check for recursion */
1895 if (!bgp_attr_print(&bgpa
, tptr
, alen
))
1905 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1907 print_unknown_data(pptr
,"\n\t ",len
);
1910 if (vflag
> 1 && len
) { /* omit zero length attributes*/
1912 print_unknown_data(pptr
,"\n\t ",len
);
1921 bgp_open_print(const u_char
*dat
, int length
)
1923 struct bgp_open bgpo
;
1924 struct bgp_opt bgpopt
;
1926 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
1927 char tokbuf
[TOKBUFSIZE
];
1928 char tokbuf2
[TOKBUFSIZE
];
1930 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1931 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1933 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1934 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1935 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1936 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1937 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1939 /* some little sanity checking */
1940 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
1944 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1948 while (i
< bgpo
.bgpo_optlen
) {
1949 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1950 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1951 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1952 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1956 printf("\n\t Option %s (%u), length: %u",
1957 tok2strbuf(bgp_opt_values
,"Unknown",
1959 tokbuf
, sizeof(tokbuf
)),
1963 /* now lets decode the options we know*/
1964 switch(bgpopt
.bgpopt_type
) {
1966 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1967 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1969 printf("\n\t %s (%u), length: %u",
1970 tok2strbuf(bgp_capcode_values
, "Unknown",
1971 cap_type
, tokbuf
, sizeof(tokbuf
)),
1975 case BGP_CAPCODE_MP
:
1976 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1977 tok2strbuf(af_values
, "Unknown",
1978 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1979 tokbuf
, sizeof(tokbuf
)),
1980 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1981 tok2strbuf(bgp_safi_values
, "Unknown",
1982 opt
[i
+BGP_OPT_SIZE
+5],
1983 tokbuf
, sizeof(tokbuf
)),
1984 opt
[i
+BGP_OPT_SIZE
+5]);
1986 case BGP_CAPCODE_RESTART
:
1987 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
1988 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
1989 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
1992 while(tcap_len
>=4) {
1993 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1994 tok2strbuf(af_values
,"Unknown",
1995 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1996 tokbuf
, sizeof(tokbuf
)),
1997 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1998 tok2strbuf(bgp_safi_values
,"Unknown",
1999 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
2000 tokbuf2
, sizeof(tokbuf2
)),
2001 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
2002 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
2007 case BGP_CAPCODE_RR
:
2008 case BGP_CAPCODE_RR_CISCO
:
2011 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
2012 printf("\n\t\tno decoder for Capability %u",
2015 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
2019 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
2020 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
2025 printf("\n\t no decoder for option %u",
2026 bgpopt
.bgpopt_type
);
2030 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
2038 bgp_update_print(const u_char
*dat
, int length
)
2041 struct bgp_attr bgpa
;
2045 char tokbuf
[TOKBUFSIZE
];
2047 TCHECK2(dat
[0], BGP_SIZE
);
2048 memcpy(&bgp
, dat
, BGP_SIZE
);
2049 p
= dat
+ BGP_SIZE
; /*XXX*/
2051 /* Unfeasible routes */
2052 len
= EXTRACT_16BITS(p
);
2055 * Without keeping state from the original NLRI message,
2056 * it's not possible to tell if this a v4 or v6 route,
2057 * so only try to decode it if we're not v6 enabled.
2060 printf("\n\t Withdrawn routes: %d bytes", len
);
2062 char buf
[MAXHOSTNAMELEN
+ 100];
2068 printf("\n\t Withdrawn routes:");
2070 while(i
< 2 + len
) {
2071 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
2073 printf("\n\t (illegal prefix length)");
2075 } else if (wpfx
== -2)
2079 printf("\n\t %s", buf
);
2087 len
= EXTRACT_16BITS(p
);
2089 if (len
== 0 && length
== BGP_UPDATE_MINSIZE
) {
2090 printf("\n\t End-of-Rib Marker (empty NLRI)");
2095 /* do something more useful!*/
2097 while (i
< 2 + len
) {
2100 TCHECK2(p
[i
], sizeof(bgpa
));
2101 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
2102 alen
= bgp_attr_len(&bgpa
);
2103 aoff
= bgp_attr_off(&bgpa
);
2105 printf("\n\t %s (%u), length: %u",
2106 tok2strbuf(bgp_attr_values
, "Unknown Attribute",
2108 tokbuf
, sizeof(tokbuf
)),
2112 if (bgpa
.bgpa_flags
) {
2113 printf(", Flags [%s%s%s%s",
2114 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
2115 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
2116 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
2117 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
2118 if (bgpa
.bgpa_flags
& 0xf)
2119 printf("+%x", bgpa
.bgpa_flags
& 0xf);
2122 if (!bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
))
2129 if (dat
+ length
> p
) {
2130 printf("\n\t Updated routes:");
2131 while (dat
+ length
> p
) {
2132 char buf
[MAXHOSTNAMELEN
+ 100];
2133 i
= decode_prefix4(p
, buf
, sizeof(buf
));
2135 printf("\n\t (illegal prefix length)");
2140 printf("\n\t %s", buf
);
2151 bgp_notification_print(const u_char
*dat
, int length
)
2153 struct bgp_notification bgpn
;
2155 char tokbuf
[TOKBUFSIZE
];
2156 char tokbuf2
[TOKBUFSIZE
];
2158 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
2159 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
2161 /* some little sanity checking */
2162 if (length
<BGP_NOTIFICATION_SIZE
)
2166 tok2strbuf(bgp_notify_major_values
, "Unknown Error",
2167 bgpn
.bgpn_major
, tokbuf
, sizeof(tokbuf
)),
2170 switch (bgpn
.bgpn_major
) {
2172 case BGP_NOTIFY_MAJOR_MSG
:
2173 printf(", subcode %s (%u)",
2174 tok2strbuf(bgp_notify_minor_msg_values
, "Unknown",
2175 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2178 case BGP_NOTIFY_MAJOR_OPEN
:
2179 printf(", subcode %s (%u)",
2180 tok2strbuf(bgp_notify_minor_open_values
, "Unknown",
2181 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2184 case BGP_NOTIFY_MAJOR_UPDATE
:
2185 printf(", subcode %s (%u)",
2186 tok2strbuf(bgp_notify_minor_update_values
, "Unknown",
2187 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2190 case BGP_NOTIFY_MAJOR_CAP
:
2191 printf(" subcode %s (%u)",
2192 tok2strbuf(bgp_notify_minor_cap_values
, "Unknown",
2193 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2195 case BGP_NOTIFY_MAJOR_CEASE
:
2196 printf(", subcode %s (%u)",
2197 tok2strbuf(bgp_notify_minor_cease_values
, "Unknown",
2198 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2201 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2202 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2204 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2205 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2207 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2208 tok2strbuf(af_values
, "Unknown",
2209 EXTRACT_16BITS(tptr
), tokbuf
, sizeof(tokbuf
)),
2210 EXTRACT_16BITS(tptr
),
2211 tok2strbuf(bgp_safi_values
, "Unknown", *(tptr
+2),
2212 tokbuf2
, sizeof(tokbuf
)),
2214 EXTRACT_32BITS(tptr
+3));
2227 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
2229 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2230 char tokbuf
[TOKBUFSIZE
];
2231 char tokbuf2
[TOKBUFSIZE
];
2233 TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
2235 /* some little sanity checking */
2236 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2239 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2241 printf("\n\t AFI %s (%u), SAFI %s (%u)",
2242 tok2strbuf(af_values
,"Unknown",
2243 /* this stinks but the compiler pads the structure
2245 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2246 tokbuf
, sizeof(tokbuf
)),
2247 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2248 tok2strbuf(bgp_safi_values
,"Unknown",
2249 bgp_route_refresh_header
->safi
,
2250 tokbuf2
, sizeof(tokbuf2
)),
2251 bgp_route_refresh_header
->safi
);
2254 TCHECK2(*pptr
, len
);
2255 print_unknown_data(pptr
,"\n\t ", len
);
2264 bgp_header_print(const u_char
*dat
, int length
)
2267 char tokbuf
[TOKBUFSIZE
];
2269 TCHECK2(dat
[0], BGP_SIZE
);
2270 memcpy(&bgp
, dat
, BGP_SIZE
);
2271 printf("\n\t%s Message (%u), length: %u",
2272 tok2strbuf(bgp_msg_values
, "Unknown", bgp
.bgp_type
,
2273 tokbuf
, sizeof(tokbuf
)),
2277 switch (bgp
.bgp_type
) {
2279 bgp_open_print(dat
, length
);
2282 bgp_update_print(dat
, length
);
2284 case BGP_NOTIFICATION
:
2285 bgp_notification_print(dat
, length
);
2289 case BGP_ROUTE_REFRESH
:
2290 bgp_route_refresh_print(dat
, length
);
2293 /* we have no decoder for the BGP message */
2294 TCHECK2(*dat
, length
);
2295 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
2296 print_unknown_data(dat
,"\n\t ",length
);
2306 bgp_print(const u_char
*dat
, int length
)
2310 const u_char
*start
;
2311 const u_char marker
[] = {
2312 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2313 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2317 char tokbuf
[TOKBUFSIZE
];
2320 if (snapend
< dat
+ length
)
2323 printf(": BGP, length: %u",length
);
2325 if (vflag
< 1) /* lets be less chatty */
2331 if (!TTEST2(p
[0], 1))
2338 if (!TTEST2(p
[0], sizeof(marker
)))
2340 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2345 /* found BGP header */
2346 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2347 memcpy(&bgp
, p
, BGP_SIZE
);
2352 hlen
= ntohs(bgp
.bgp_len
);
2353 if (hlen
< BGP_SIZE
) {
2354 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
2359 if (TTEST2(p
[0], hlen
)) {
2360 if (!bgp_header_print(p
, hlen
))
2365 printf("\n[|BGP %s]",
2366 tok2strbuf(bgp_msg_values
,
2367 "Unknown Message Type",
2369 tokbuf
, sizeof(tokbuf
)));
2382 * c-style: whitesmith