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.114 2007-07-14 22:24:54 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 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
));
547 case (sizeof(struct in6_addr
) << 3): /* 128 */
548 TCHECK2(pptr
[0], sizeof(struct in6_addr
));
549 snprintf(pos
, sizeof(addr
), "%s", ip6addr_string(pptr
));
552 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
565 * print an multicast s,g entry into a buffer.
566 * the s,g entry is encoded like this.
568 * +-----------------------------------+
569 * | Multicast Source Length (1 octet) |
570 * +-----------------------------------+
571 * | Multicast Source (Variable) |
572 * +-----------------------------------+
573 * | Multicast Group Length (1 octet) |
574 * +-----------------------------------+
575 * | Multicast Group (Variable) |
576 * +-----------------------------------+
578 * return the number of bytes read from the wire.
581 bgp_vpn_sg_print (const u_char
*pptr
, char *buf
, u_int buflen
) {
583 u_int8_t addr_length
;
584 u_int total_length
, offset
;
588 /* Source address length, encoded in bits */
590 addr_length
= *pptr
++;
593 TCHECK2(pptr
[0], (addr_length
>> 3));
594 total_length
+= (addr_length
>> 3) + 1;
595 offset
= strlen(buf
);
597 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
598 bgp_vpn_ip_print(pptr
, addr_length
));
599 pptr
+= (addr_length
>> 3);
602 /* Group address length, encoded in bits */
604 addr_length
= *pptr
++;
607 TCHECK2(pptr
[0], (addr_length
>> 3));
608 total_length
+= (addr_length
>> 3) + 1;
609 offset
= strlen(buf
);
611 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
612 bgp_vpn_ip_print(pptr
, addr_length
));
613 pptr
+= (addr_length
>> 3);
617 return (total_length
);
621 /* RDs and RTs share the same semantics
622 * we use bgp_vpn_rd_print for
623 * printing route targets inside a NLRI */
625 bgp_vpn_rd_print (const u_char
*pptr
) {
627 /* allocate space for the largest possible string */
628 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
631 /* ok lets load the RD format */
632 switch (EXTRACT_16BITS(pptr
)) {
634 /* AS:IP-address fmt*/
636 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u.%u.%u.%u",
637 EXTRACT_16BITS(pptr
+2), *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
639 /* IP-address:AS fmt*/
642 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
643 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
646 /* 4-byte-AS:number fmt*/
648 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (%u.%u.%u.%u:%u)",
649 EXTRACT_32BITS(pptr
+2), EXTRACT_16BITS(pptr
+6),
650 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
653 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
662 decode_rt_routing_info(const u_char
*pptr
, char *buf
, u_int buflen
)
664 u_int8_t route_target
[8];
668 plen
= pptr
[0]; /* get prefix length */
671 return 1; /* default route target */
676 plen
-=32; /* adjust prefix length */
681 memset(&route_target
, 0, sizeof(route_target
));
682 TCHECK2(pptr
[1], (plen
+ 7) / 8);
683 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
685 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
686 ((0xff00 >> (plen
% 8)) & 0xff);
688 snprintf(buf
, buflen
, "origin AS: %u, route target %s",
689 EXTRACT_32BITS(pptr
+1),
690 bgp_vpn_rd_print((u_char
*)&route_target
));
692 return 5 + (plen
+ 7) / 8;
699 decode_labeled_vpn_prefix4(const u_char
*pptr
, char *buf
, u_int buflen
)
705 plen
= pptr
[0]; /* get prefix length */
710 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
715 memset(&addr
, 0, sizeof(addr
));
716 TCHECK2(pptr
[12], (plen
+ 7) / 8);
717 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
719 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
720 ((0xff00 >> (plen
% 8)) & 0xff);
722 /* the label may get offsetted by 4 bits so lets shift it right */
723 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
724 bgp_vpn_rd_print(pptr
+4),
725 getname((u_char
*)&addr
),
727 EXTRACT_24BITS(pptr
+1)>>4,
728 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
730 return 12 + (plen
+ 7) / 8;
736 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
737 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
738 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
739 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
740 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
741 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
742 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
744 static struct tok bgp_multicast_vpn_route_type_values
[] = {
745 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
746 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
747 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
748 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
749 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
750 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
751 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
755 decode_multicast_vpn(const u_char
*pptr
, char *buf
, u_int buflen
)
757 u_int8_t route_type
, route_length
, addr_length
, sg_length
;
761 route_type
= *pptr
++;
762 route_length
= *pptr
++;
764 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
765 tok2str(bgp_multicast_vpn_route_type_values
,
766 "Unknown", route_type
),
767 route_type
, route_length
);
770 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
771 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
772 offset
= strlen(buf
);
773 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
774 bgp_vpn_rd_print(pptr
),
775 bgp_vpn_ip_print(pptr
+ BGP_VPN_RD_LEN
,
776 (route_length
- BGP_VPN_RD_LEN
) << 3));
778 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
779 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
+ 4);
780 offset
= strlen(buf
);
781 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %u",
782 bgp_vpn_rd_print(pptr
),
783 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
));
786 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
787 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
788 offset
= strlen(buf
);
789 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
790 bgp_vpn_rd_print(pptr
));
791 pptr
+= BGP_VPN_RD_LEN
;
793 sg_length
= bgp_vpn_sg_print(pptr
, buf
, buflen
);
794 addr_length
= route_length
- sg_length
;
796 TCHECK2(pptr
[0], addr_length
);
797 offset
= strlen(buf
);
798 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
799 bgp_vpn_ip_print(pptr
, addr_length
<< 3));
802 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
803 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
804 offset
= strlen(buf
);
805 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
806 bgp_vpn_rd_print(pptr
));
807 pptr
+= BGP_VPN_RD_LEN
;
809 bgp_vpn_sg_print(pptr
, buf
, buflen
);
812 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
813 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
814 TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
815 offset
= strlen(buf
);
816 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %u",
817 bgp_vpn_rd_print(pptr
),
818 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
));
819 pptr
+= BGP_VPN_RD_LEN
;
821 bgp_vpn_sg_print(pptr
, buf
, buflen
);
825 * no per route-type printing yet.
827 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
832 return route_length
+ 2;
839 * As I remember, some versions of systems have an snprintf() that
840 * returns -1 if the buffer would have overflowed. If the return
841 * value is negative, set buflen to 0, to indicate that we've filled
844 * If the return value is greater than buflen, that means that
845 * the buffer would have overflowed; again, set buflen to 0 in
848 #define UPDATE_BUF_BUFLEN(buf, buflen, strlen) \
851 else if ((u_int)strlen>buflen) \
859 decode_labeled_vpn_l2(const u_char
*pptr
, char *buf
, u_int buflen
)
861 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
864 plen
=EXTRACT_16BITS(pptr
);
869 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
870 bgp_vpn_rd_print(pptr
),
871 EXTRACT_16BITS(pptr
+8),
872 EXTRACT_16BITS(pptr
+10),
873 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
874 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
878 /* ok now the variable part - lets read out TLVs*/
884 tlv_len
=EXTRACT_16BITS(pptr
);
891 strlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
894 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
896 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
900 strlen
=snprintf(buf
,buflen
, "%02x",*pptr
++);
901 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
908 strlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
911 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
915 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
925 decode_prefix6(const u_char
*pd
, char *buf
, u_int buflen
)
927 struct in6_addr addr
;
935 memset(&addr
, 0, sizeof(addr
));
936 TCHECK2(pd
[1], (plen
+ 7) / 8);
937 memcpy(&addr
, &pd
[1], (plen
+ 7) / 8);
939 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
940 ((0xff00 >> (plen
% 8)) & 0xff);
942 snprintf(buf
, buflen
, "%s/%d", getname6((u_char
*)&addr
), plen
);
943 return 1 + (plen
+ 7) / 8;
950 decode_labeled_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
952 struct in6_addr addr
;
956 plen
= pptr
[0]; /* get prefix length */
961 plen
-=24; /* adjust prefixlen - labellength */
966 memset(&addr
, 0, sizeof(addr
));
967 TCHECK2(pptr
[4], (plen
+ 7) / 8);
968 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
970 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
971 ((0xff00 >> (plen
% 8)) & 0xff);
973 /* the label may get offsetted by 4 bits so lets shift it right */
974 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
975 getname6((u_char
*)&addr
),
977 EXTRACT_24BITS(pptr
+1)>>4,
978 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
980 return 4 + (plen
+ 7) / 8;
987 decode_labeled_vpn_prefix6(const u_char
*pptr
, char *buf
, u_int buflen
)
989 struct in6_addr addr
;
993 plen
= pptr
[0]; /* get prefix length */
998 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1003 memset(&addr
, 0, sizeof(addr
));
1004 TCHECK2(pptr
[12], (plen
+ 7) / 8);
1005 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1007 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1008 ((0xff00 >> (plen
% 8)) & 0xff);
1010 /* the label may get offsetted by 4 bits so lets shift it right */
1011 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1012 bgp_vpn_rd_print(pptr
+4),
1013 getname6((u_char
*)&addr
),
1015 EXTRACT_24BITS(pptr
+1)>>4,
1016 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1018 return 12 + (plen
+ 7) / 8;
1026 decode_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
1032 plen
= pptr
[0]; /* get prefix length */
1037 memset(&addr
, 0, sizeof(addr
));
1038 TCHECK2(pptr
[4], (plen
+ 7) / 8);
1039 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
1041 addr
[(plen
+ 7) / 8 - 1] &=
1042 ((0xff00 >> (plen
% 8)) & 0xff);
1044 snprintf(buf
, buflen
, "%s/%d",
1045 isonsap_string(addr
,(plen
+ 7) / 8),
1048 return 1 + (plen
+ 7) / 8;
1055 decode_labeled_vpn_clnp_prefix(const u_char
*pptr
, char *buf
, u_int buflen
)
1061 plen
= pptr
[0]; /* get prefix length */
1066 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1071 memset(&addr
, 0, sizeof(addr
));
1072 TCHECK2(pptr
[12], (plen
+ 7) / 8);
1073 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1075 addr
[(plen
+ 7) / 8 - 1] &=
1076 ((0xff00 >> (plen
% 8)) & 0xff);
1078 /* the label may get offsetted by 4 bits so lets shift it right */
1079 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1080 bgp_vpn_rd_print(pptr
+4),
1081 isonsap_string(addr
,(plen
+ 7) / 8),
1083 EXTRACT_24BITS(pptr
+1)>>4,
1084 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1086 return 12 + (plen
+ 7) / 8;
1093 bgp_attr_print(const struct bgp_attr
*attr
, const u_char
*pptr
, int len
)
1097 u_int8_t safi
, snpa
, nhlen
;
1098 union { /* copy buffer for bandwidth values */
1105 char buf
[MAXHOSTNAMELEN
+ 100];
1106 char tokbuf
[TOKBUFSIZE
];
1111 switch (attr
->bgpa_type
) {
1112 case BGPTYPE_ORIGIN
:
1114 printf("invalid len");
1117 printf("%s", tok2strbuf(bgp_origin_values
,
1118 "Unknown Origin Typecode",
1120 tokbuf
, sizeof(tokbuf
)));
1124 case BGPTYPE_AS_PATH
:
1126 printf("invalid len");
1134 while (tptr
< pptr
+ len
) {
1136 printf("%s", tok2strbuf(bgp_as_path_segment_open_values
,
1138 tokbuf
, sizeof(tokbuf
)));
1139 for (i
= 0; i
< tptr
[1] * 2; i
+= 2) {
1140 TCHECK2(tptr
[2 + i
], 2);
1141 printf("%u ", EXTRACT_16BITS(&tptr
[2 + i
]));
1144 printf("%s", tok2strbuf(bgp_as_path_segment_close_values
,
1146 tokbuf
, sizeof(tokbuf
)));
1148 tptr
+= 2 + tptr
[1] * 2;
1151 case BGPTYPE_NEXT_HOP
:
1153 printf("invalid len");
1155 TCHECK2(tptr
[0], 4);
1156 printf("%s", getname(tptr
));
1159 case BGPTYPE_MULTI_EXIT_DISC
:
1160 case BGPTYPE_LOCAL_PREF
:
1162 printf("invalid len");
1164 TCHECK2(tptr
[0], 4);
1165 printf("%u", EXTRACT_32BITS(tptr
));
1168 case BGPTYPE_ATOMIC_AGGREGATE
:
1170 printf("invalid len");
1172 case BGPTYPE_AGGREGATOR
:
1174 printf("invalid len");
1177 TCHECK2(tptr
[0], 6);
1178 printf(" AS #%u, origin %s", EXTRACT_16BITS(tptr
),
1181 case BGPTYPE_COMMUNITIES
:
1183 printf("invalid len");
1188 TCHECK2(tptr
[0], 4);
1189 comm
= EXTRACT_32BITS(tptr
);
1191 case BGP_COMMUNITY_NO_EXPORT
:
1192 printf(" NO_EXPORT");
1194 case BGP_COMMUNITY_NO_ADVERT
:
1195 printf(" NO_ADVERTISE");
1197 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1198 printf(" NO_EXPORT_SUBCONFED");
1202 (comm
>> 16) & 0xffff,
1204 (tlen
>4) ? ", " : "");
1211 case BGPTYPE_ORIGINATOR_ID
:
1213 printf("invalid len");
1216 TCHECK2(tptr
[0], 4);
1217 printf("%s",getname(tptr
));
1219 case BGPTYPE_CLUSTER_LIST
:
1221 printf("invalid len");
1225 TCHECK2(tptr
[0], 4);
1228 (tlen
>4) ? ", " : "");
1233 case BGPTYPE_MP_REACH_NLRI
:
1234 TCHECK2(tptr
[0], 3);
1235 af
= EXTRACT_16BITS(tptr
);
1238 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1239 tok2strbuf(af_values
, "Unknown AFI", af
,
1240 tokbuf
, sizeof(tokbuf
)),
1242 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1243 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1244 tokbuf
, sizeof(tokbuf
)),
1247 switch(af
<<8 | safi
) {
1248 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1249 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1250 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1251 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1252 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1253 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1254 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1255 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1256 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1258 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1259 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1260 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1261 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1262 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1263 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1264 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1266 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1267 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1268 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1269 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1270 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1271 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1272 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1273 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1274 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1275 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1278 TCHECK2(tptr
[0], tlen
);
1279 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1281 print_unknown_data(tptr
,"\n\t ",tlen
);
1294 printf("\n\t nexthop: ");
1296 switch(af
<<8 | safi
) {
1297 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1298 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1299 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1300 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1301 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1302 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1303 if (tlen
< (int)sizeof(struct in_addr
)) {
1304 printf("invalid len");
1307 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1308 printf("%s",getname(tptr
));
1309 tlen
-= sizeof(struct in_addr
);
1310 tptr
+= sizeof(struct in_addr
);
1313 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1314 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1315 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1316 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1317 printf("invalid len");
1320 TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1321 printf("RD: %s, %s",
1322 bgp_vpn_rd_print(tptr
),
1323 getname(tptr
+BGP_VPN_RD_LEN
));
1324 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1325 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1329 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1330 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1331 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1332 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1333 if (tlen
< (int)sizeof(struct in6_addr
)) {
1334 printf("invalid len");
1337 TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1338 printf("%s", getname6(tptr
));
1339 tlen
-= sizeof(struct in6_addr
);
1340 tptr
+= sizeof(struct in6_addr
);
1343 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1344 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1345 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1346 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1347 printf("invalid len");
1350 TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1351 printf("RD: %s, %s",
1352 bgp_vpn_rd_print(tptr
),
1353 getname6(tptr
+BGP_VPN_RD_LEN
));
1354 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1355 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1359 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1360 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1361 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1362 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1363 if (tlen
< (int)sizeof(struct in_addr
)) {
1364 printf("invalid len");
1367 TCHECK2(tptr
[0], sizeof(struct in_addr
));
1368 printf("%s", getname(tptr
));
1369 tlen
-= (sizeof(struct in_addr
));
1370 tptr
+= (sizeof(struct in_addr
));
1373 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1374 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1375 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1376 TCHECK2(tptr
[0], tlen
);
1377 printf("%s",isonsap_string(tptr
,tlen
));
1382 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1383 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1384 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1385 if (tlen
< BGP_VPN_RD_LEN
+1) {
1386 printf("invalid len");
1389 TCHECK2(tptr
[0], tlen
);
1390 printf("RD: %s, %s",
1391 bgp_vpn_rd_print(tptr
),
1392 isonsap_string(tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
));
1393 /* rfc986 mapped IPv4 address ? */
1394 if (EXTRACT_32BITS(tptr
+BGP_VPN_RD_LEN
) == 0x47000601)
1395 printf(" = %s", getname(tptr
+BGP_VPN_RD_LEN
+4));
1397 /* rfc1888 mapped IPv6 address ? */
1398 else if (EXTRACT_24BITS(tptr
+BGP_VPN_RD_LEN
) == 0x350000)
1399 printf(" = %s", getname6(tptr
+BGP_VPN_RD_LEN
+3));
1406 TCHECK2(tptr
[0], tlen
);
1407 printf("no AFI %u/SAFI %u decoder",af
,safi
);
1409 print_unknown_data(tptr
,"\n\t ",tlen
);
1417 printf(", nh-length: %u", nhlen
);
1425 printf("\n\t %u SNPA", snpa
);
1426 for (/*nothing*/; snpa
> 0; snpa
--) {
1428 printf("\n\t %d bytes", tptr
[0]);
1429 tptr
+= tptr
[0] + 1;
1432 printf(", no SNPA");
1435 while (len
- (tptr
- pptr
) > 0) {
1436 switch (af
<<8 | safi
) {
1437 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1438 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1439 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1440 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1442 printf("\n\t (illegal prefix length)");
1443 else if (advance
== -2)
1446 printf("\n\t %s", buf
);
1448 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1449 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1451 printf("\n\t (illegal prefix length)");
1452 else if (advance
== -2)
1455 printf("\n\t %s", buf
);
1457 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1458 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1459 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1460 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1462 printf("\n\t (illegal prefix length)");
1463 else if (advance
== -2)
1466 printf("\n\t %s", buf
);
1468 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1469 advance
= decode_rt_routing_info(tptr
, buf
, sizeof(buf
));
1471 printf("\n\t (illegal prefix length)");
1472 else if (advance
== -2)
1475 printf("\n\t %s", buf
);
1477 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1478 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1479 advance
= decode_multicast_vpn(tptr
, buf
, sizeof(buf
));
1481 printf("\n\t (illegal prefix length)");
1482 else if (advance
== -2)
1485 printf("\n\t %s", buf
);
1488 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1489 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1490 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1491 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1493 printf("\n\t (illegal prefix length)");
1494 else if (advance
== -2)
1497 printf("\n\t %s", buf
);
1499 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1500 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1502 printf("\n\t (illegal prefix length)");
1503 else if (advance
== -2)
1506 printf("\n\t %s", buf
);
1508 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1509 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1510 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1511 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1513 printf("\n\t (illegal prefix length)");
1514 else if (advance
== -2)
1517 printf("\n\t %s", buf
);
1520 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1521 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1522 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1523 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1524 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1526 printf("\n\t (illegal length)");
1527 else if (advance
== -2)
1530 printf("\n\t %s", buf
);
1532 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1533 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1534 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1535 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1537 printf("\n\t (illegal prefix length)");
1538 else if (advance
== -2)
1541 printf("\n\t %s", buf
);
1543 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1544 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1545 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1546 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1548 printf("\n\t (illegal prefix length)");
1549 else if (advance
== -2)
1552 printf("\n\t %s", buf
);
1555 TCHECK2(*tptr
,tlen
);
1556 printf("\n\t no AFI %u / SAFI %u decoder",af
,safi
);
1558 print_unknown_data(tptr
,"\n\t ",tlen
);
1570 case BGPTYPE_MP_UNREACH_NLRI
:
1571 TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1572 af
= EXTRACT_16BITS(tptr
);
1575 printf("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1576 tok2strbuf(af_values
, "Unknown AFI", af
,
1577 tokbuf
, sizeof(tokbuf
)),
1579 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1580 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1581 tokbuf
, sizeof(tokbuf
)),
1584 if (len
== BGP_MP_NLRI_MINSIZE
)
1585 printf("\n\t End-of-Rib Marker (empty NLRI)");
1589 while (len
- (tptr
- pptr
) > 0) {
1590 switch (af
<<8 | safi
) {
1591 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1592 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1593 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1594 advance
= decode_prefix4(tptr
, buf
, sizeof(buf
));
1596 printf("\n\t (illegal prefix length)");
1597 else if (advance
== -2)
1600 printf("\n\t %s", buf
);
1602 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1603 advance
= decode_labeled_prefix4(tptr
, buf
, sizeof(buf
));
1605 printf("\n\t (illegal prefix length)");
1606 else if (advance
== -2)
1609 printf("\n\t %s", buf
);
1611 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1612 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1613 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1614 advance
= decode_labeled_vpn_prefix4(tptr
, buf
, sizeof(buf
));
1616 printf("\n\t (illegal prefix length)");
1617 else if (advance
== -2)
1620 printf("\n\t %s", buf
);
1623 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1624 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1625 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1626 advance
= decode_prefix6(tptr
, buf
, sizeof(buf
));
1628 printf("\n\t (illegal prefix length)");
1629 else if (advance
== -2)
1632 printf("\n\t %s", buf
);
1634 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1635 advance
= decode_labeled_prefix6(tptr
, buf
, sizeof(buf
));
1637 printf("\n\t (illegal prefix length)");
1638 else if (advance
== -2)
1641 printf("\n\t %s", buf
);
1643 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1644 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1645 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1646 advance
= decode_labeled_vpn_prefix6(tptr
, buf
, sizeof(buf
));
1648 printf("\n\t (illegal prefix length)");
1649 else if (advance
== -2)
1652 printf("\n\t %s", buf
);
1655 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1656 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1657 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1658 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1659 advance
= decode_labeled_vpn_l2(tptr
, buf
, sizeof(buf
));
1661 printf("\n\t (illegal length)");
1662 else if (advance
== -2)
1665 printf("\n\t %s", buf
);
1667 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1668 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1669 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1670 advance
= decode_clnp_prefix(tptr
, buf
, sizeof(buf
));
1672 printf("\n\t (illegal prefix length)");
1673 else if (advance
== -2)
1676 printf("\n\t %s", buf
);
1678 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1679 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1680 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1681 advance
= decode_labeled_vpn_clnp_prefix(tptr
, buf
, sizeof(buf
));
1683 printf("\n\t (illegal prefix length)");
1684 else if (advance
== -2)
1687 printf("\n\t %s", buf
);
1689 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1690 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1691 advance
= decode_multicast_vpn(tptr
, buf
, sizeof(buf
));
1693 printf("\n\t (illegal prefix length)");
1694 else if (advance
== -2)
1697 printf("\n\t %s", buf
);
1700 TCHECK2(*(tptr
-3),tlen
);
1701 printf("no AFI %u / SAFI %u decoder",af
,safi
);
1703 print_unknown_data(tptr
-3,"\n\t ",tlen
);
1713 case BGPTYPE_EXTD_COMMUNITIES
:
1715 printf("invalid len");
1719 u_int16_t extd_comm
;
1721 TCHECK2(tptr
[0], 2);
1722 extd_comm
=EXTRACT_16BITS(tptr
);
1724 printf("\n\t %s (0x%04x), Flags [%s]",
1725 tok2strbuf(bgp_extd_comm_subtype_values
,
1726 "unknown extd community typecode",
1727 extd_comm
, tokbuf
, sizeof(tokbuf
)),
1729 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
1731 TCHECK2(*(tptr
+2), 6);
1733 case BGP_EXT_COM_RT_0
:
1734 case BGP_EXT_COM_RO_0
:
1736 EXTRACT_16BITS(tptr
+2),
1739 case BGP_EXT_COM_RT_1
:
1740 case BGP_EXT_COM_RO_1
:
1741 case BGP_EXT_COM_VRF_RT_IMP
:
1744 EXTRACT_16BITS(tptr
+6));
1746 case BGP_EXT_COM_RT_2
:
1747 case BGP_EXT_COM_RO_2
:
1749 EXTRACT_32BITS(tptr
+2),
1750 EXTRACT_16BITS(tptr
+6));
1752 case BGP_EXT_COM_LINKBAND
:
1753 bw
.i
= EXTRACT_32BITS(tptr
+2);
1754 printf(": bandwidth: %.3f Mbps",
1757 case BGP_EXT_COM_VPN_ORIGIN
:
1758 case BGP_EXT_COM_VPN_ORIGIN2
:
1759 case BGP_EXT_COM_VPN_ORIGIN3
:
1760 case BGP_EXT_COM_VPN_ORIGIN4
:
1761 case BGP_EXT_COM_OSPF_RID
:
1762 case BGP_EXT_COM_OSPF_RID2
:
1763 printf("%s", getname(tptr
+2));
1765 case BGP_EXT_COM_OSPF_RTYPE
:
1766 case BGP_EXT_COM_OSPF_RTYPE2
:
1767 printf(": area:%s, router-type:%s, metric-type:%s%s",
1769 tok2strbuf(bgp_extd_comm_ospf_rtype_values
,
1772 tokbuf
, sizeof(tokbuf
)),
1773 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
1774 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
1776 case BGP_EXT_COM_L2INFO
:
1777 printf(": %s Control Flags [0x%02x]:MTU %u",
1778 tok2strbuf(l2vpn_encaps_values
,
1781 tokbuf
, sizeof(tokbuf
)),
1783 EXTRACT_16BITS(tptr
+4));
1785 case BGP_EXT_COM_SOURCE_AS
:
1786 printf(": AS %u", EXTRACT_16BITS(tptr
+2));
1790 print_unknown_data(tptr
,"\n\t ",8);
1798 case BGPTYPE_PMSI_TUNNEL
:
1800 u_int8_t tunnel_type
, flags
;
1802 tunnel_type
= *(tptr
+1);
1806 TCHECK2(tptr
[0], 5);
1807 printf("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
1808 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
1810 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
1811 EXTRACT_24BITS(tptr
+2)>>4);
1816 switch (tunnel_type
) {
1817 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
1818 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
1819 TCHECK2(tptr
[0], 8);
1820 printf("\n\t Sender %s, P-Group %s",
1821 ipaddr_string(tptr
),
1822 ipaddr_string(tptr
+4));
1825 case BGP_PMSI_TUNNEL_PIM_SSM
:
1826 TCHECK2(tptr
[0], 8);
1827 printf("\n\t Root-Node %s, P-Group %s",
1828 ipaddr_string(tptr
),
1829 ipaddr_string(tptr
+4));
1831 case BGP_PMSI_TUNNEL_INGRESS
:
1832 TCHECK2(tptr
[0], 4);
1833 printf("\n\t Tunnel-Endpoint %s",
1834 ipaddr_string(tptr
));
1836 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
1837 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
1838 TCHECK2(tptr
[0], 8);
1839 printf("\n\t Root-Node %s, LSP-ID 0x%08x",
1840 ipaddr_string(tptr
),
1841 EXTRACT_32BITS(tptr
+4));
1843 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
1844 TCHECK2(tptr
[0], 8);
1845 printf("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
1846 ipaddr_string(tptr
),
1847 EXTRACT_32BITS(tptr
+4));
1851 print_unknown_data(tptr
,"\n\t ",tlen
);
1856 case BGPTYPE_ATTR_SET
:
1857 TCHECK2(tptr
[0], 4);
1858 printf("\n\t Origin AS: %u", EXTRACT_32BITS(tptr
));
1864 struct bgp_attr bgpa
;
1866 TCHECK2(tptr
[0], sizeof(bgpa
));
1867 memcpy(&bgpa
, tptr
, sizeof(bgpa
));
1868 alen
= bgp_attr_len(&bgpa
);
1869 tptr
+= bgp_attr_off(&bgpa
);
1870 len
-= bgp_attr_off(&bgpa
);
1872 printf("\n\t %s (%u), length: %u",
1873 tok2strbuf(bgp_attr_values
,
1874 "Unknown Attribute", bgpa
.bgpa_type
,
1875 tokbuf
, sizeof(tokbuf
)),
1879 if (bgpa
.bgpa_flags
) {
1880 printf(", Flags [%s%s%s%s",
1881 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
1882 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
1883 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
1884 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
1885 if (bgpa
.bgpa_flags
& 0xf)
1886 printf("+%x", bgpa
.bgpa_flags
& 0xf);
1889 /* FIXME check for recursion */
1890 if (!bgp_attr_print(&bgpa
, tptr
, alen
))
1900 printf("\n\t no Attribute %u decoder",attr
->bgpa_type
); /* we have no decoder for the attribute */
1902 print_unknown_data(pptr
,"\n\t ",len
);
1905 if (vflag
> 1 && len
) { /* omit zero length attributes*/
1907 print_unknown_data(pptr
,"\n\t ",len
);
1916 bgp_open_print(const u_char
*dat
, int length
)
1918 struct bgp_open bgpo
;
1919 struct bgp_opt bgpopt
;
1921 int i
,cap_type
,cap_len
,tcap_len
,cap_offset
;
1922 char tokbuf
[TOKBUFSIZE
];
1923 char tokbuf2
[TOKBUFSIZE
];
1925 TCHECK2(dat
[0], BGP_OPEN_SIZE
);
1926 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
1928 printf("\n\t Version %d, ", bgpo
.bgpo_version
);
1929 printf("my AS %u, ", ntohs(bgpo
.bgpo_myas
));
1930 printf("Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
));
1931 printf("ID %s", getname((u_char
*)&bgpo
.bgpo_id
));
1932 printf("\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
);
1934 /* some little sanity checking */
1935 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
1939 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
1943 while (i
< bgpo
.bgpo_optlen
) {
1944 TCHECK2(opt
[i
], BGP_OPT_SIZE
);
1945 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
1946 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
1947 printf("\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
);
1951 printf("\n\t Option %s (%u), length: %u",
1952 tok2strbuf(bgp_opt_values
,"Unknown",
1954 tokbuf
, sizeof(tokbuf
)),
1958 /* now lets decode the options we know*/
1959 switch(bgpopt
.bgpopt_type
) {
1961 cap_type
=opt
[i
+BGP_OPT_SIZE
];
1962 cap_len
=opt
[i
+BGP_OPT_SIZE
+1];
1964 printf("\n\t %s (%u), length: %u",
1965 tok2strbuf(bgp_capcode_values
, "Unknown",
1966 cap_type
, tokbuf
, sizeof(tokbuf
)),
1970 case BGP_CAPCODE_MP
:
1971 printf("\n\t\tAFI %s (%u), SAFI %s (%u)",
1972 tok2strbuf(af_values
, "Unknown",
1973 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1974 tokbuf
, sizeof(tokbuf
)),
1975 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2),
1976 tok2strbuf(bgp_safi_values
, "Unknown",
1977 opt
[i
+BGP_OPT_SIZE
+5],
1978 tokbuf
, sizeof(tokbuf
)),
1979 opt
[i
+BGP_OPT_SIZE
+5]);
1981 case BGP_CAPCODE_RESTART
:
1982 printf("\n\t\tRestart Flags: [%s], Restart Time %us",
1983 ((opt
[i
+BGP_OPT_SIZE
+2])&0x80) ? "R" : "none",
1984 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+2)&0xfff);
1987 while(tcap_len
>=4) {
1988 printf("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
1989 tok2strbuf(af_values
,"Unknown",
1990 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1991 tokbuf
, sizeof(tokbuf
)),
1992 EXTRACT_16BITS(opt
+i
+BGP_OPT_SIZE
+cap_offset
),
1993 tok2strbuf(bgp_safi_values
,"Unknown",
1994 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1995 tokbuf2
, sizeof(tokbuf2
)),
1996 opt
[i
+BGP_OPT_SIZE
+cap_offset
+2],
1997 ((opt
[i
+BGP_OPT_SIZE
+cap_offset
+3])&0x80) ? "yes" : "no" );
2002 case BGP_CAPCODE_RR
:
2003 case BGP_CAPCODE_RR_CISCO
:
2006 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
2007 printf("\n\t\tno decoder for Capability %u",
2010 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
2014 TCHECK2(opt
[i
+BGP_OPT_SIZE
+2],cap_len
);
2015 print_unknown_data(&opt
[i
+BGP_OPT_SIZE
+2],"\n\t\t",cap_len
);
2020 printf("\n\t no decoder for option %u",
2021 bgpopt
.bgpopt_type
);
2025 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
2033 bgp_update_print(const u_char
*dat
, int length
)
2036 struct bgp_attr bgpa
;
2040 char tokbuf
[TOKBUFSIZE
];
2042 TCHECK2(dat
[0], BGP_SIZE
);
2043 memcpy(&bgp
, dat
, BGP_SIZE
);
2044 p
= dat
+ BGP_SIZE
; /*XXX*/
2046 /* Unfeasible routes */
2047 len
= EXTRACT_16BITS(p
);
2050 * Without keeping state from the original NLRI message,
2051 * it's not possible to tell if this a v4 or v6 route,
2052 * so only try to decode it if we're not v6 enabled.
2055 printf("\n\t Withdrawn routes: %d bytes", len
);
2057 char buf
[MAXHOSTNAMELEN
+ 100];
2063 printf("\n\t Withdrawn routes:");
2065 while(i
< 2 + len
) {
2066 wpfx
= decode_prefix4(&p
[i
], buf
, sizeof(buf
));
2068 printf("\n\t (illegal prefix length)");
2070 } else if (wpfx
== -2)
2074 printf("\n\t %s", buf
);
2082 len
= EXTRACT_16BITS(p
);
2084 if (len
== 0 && length
== BGP_UPDATE_MINSIZE
) {
2085 printf("\n\t End-of-Rib Marker (empty NLRI)");
2090 /* do something more useful!*/
2092 while (i
< 2 + len
) {
2095 TCHECK2(p
[i
], sizeof(bgpa
));
2096 memcpy(&bgpa
, &p
[i
], sizeof(bgpa
));
2097 alen
= bgp_attr_len(&bgpa
);
2098 aoff
= bgp_attr_off(&bgpa
);
2100 printf("\n\t %s (%u), length: %u",
2101 tok2strbuf(bgp_attr_values
, "Unknown Attribute",
2103 tokbuf
, sizeof(tokbuf
)),
2107 if (bgpa
.bgpa_flags
) {
2108 printf(", Flags [%s%s%s%s",
2109 bgpa
.bgpa_flags
& 0x80 ? "O" : "",
2110 bgpa
.bgpa_flags
& 0x40 ? "T" : "",
2111 bgpa
.bgpa_flags
& 0x20 ? "P" : "",
2112 bgpa
.bgpa_flags
& 0x10 ? "E" : "");
2113 if (bgpa
.bgpa_flags
& 0xf)
2114 printf("+%x", bgpa
.bgpa_flags
& 0xf);
2117 if (!bgp_attr_print(&bgpa
, &p
[i
+ aoff
], alen
))
2124 if (dat
+ length
> p
) {
2125 printf("\n\t Updated routes:");
2126 while (dat
+ length
> p
) {
2127 char buf
[MAXHOSTNAMELEN
+ 100];
2128 i
= decode_prefix4(p
, buf
, sizeof(buf
));
2130 printf("\n\t (illegal prefix length)");
2135 printf("\n\t %s", buf
);
2146 bgp_notification_print(const u_char
*dat
, int length
)
2148 struct bgp_notification bgpn
;
2150 char tokbuf
[TOKBUFSIZE
];
2151 char tokbuf2
[TOKBUFSIZE
];
2153 TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
2154 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
2156 /* some little sanity checking */
2157 if (length
<BGP_NOTIFICATION_SIZE
)
2161 tok2strbuf(bgp_notify_major_values
, "Unknown Error",
2162 bgpn
.bgpn_major
, tokbuf
, sizeof(tokbuf
)),
2165 switch (bgpn
.bgpn_major
) {
2167 case BGP_NOTIFY_MAJOR_MSG
:
2168 printf(", subcode %s (%u)",
2169 tok2strbuf(bgp_notify_minor_msg_values
, "Unknown",
2170 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2173 case BGP_NOTIFY_MAJOR_OPEN
:
2174 printf(", subcode %s (%u)",
2175 tok2strbuf(bgp_notify_minor_open_values
, "Unknown",
2176 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2179 case BGP_NOTIFY_MAJOR_UPDATE
:
2180 printf(", subcode %s (%u)",
2181 tok2strbuf(bgp_notify_minor_update_values
, "Unknown",
2182 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2185 case BGP_NOTIFY_MAJOR_CAP
:
2186 printf(" subcode %s (%u)",
2187 tok2strbuf(bgp_notify_minor_cap_values
, "Unknown",
2188 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2190 case BGP_NOTIFY_MAJOR_CEASE
:
2191 printf(", subcode %s (%u)",
2192 tok2strbuf(bgp_notify_minor_cease_values
, "Unknown",
2193 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2196 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2197 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2199 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2200 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2202 printf(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2203 tok2strbuf(af_values
, "Unknown",
2204 EXTRACT_16BITS(tptr
), tokbuf
, sizeof(tokbuf
)),
2205 EXTRACT_16BITS(tptr
),
2206 tok2strbuf(bgp_safi_values
, "Unknown", *(tptr
+2),
2207 tokbuf2
, sizeof(tokbuf
)),
2209 EXTRACT_32BITS(tptr
+3));
2222 bgp_route_refresh_print(const u_char
*pptr
, int len
) {
2224 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2225 char tokbuf
[TOKBUFSIZE
];
2226 char tokbuf2
[TOKBUFSIZE
];
2228 TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
2230 /* some little sanity checking */
2231 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2234 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2236 printf("\n\t AFI %s (%u), SAFI %s (%u)",
2237 tok2strbuf(af_values
,"Unknown",
2238 /* this stinks but the compiler pads the structure
2240 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2241 tokbuf
, sizeof(tokbuf
)),
2242 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2243 tok2strbuf(bgp_safi_values
,"Unknown",
2244 bgp_route_refresh_header
->safi
,
2245 tokbuf2
, sizeof(tokbuf2
)),
2246 bgp_route_refresh_header
->safi
);
2249 TCHECK2(*pptr
, len
);
2250 print_unknown_data(pptr
,"\n\t ", len
);
2259 bgp_header_print(const u_char
*dat
, int length
)
2262 char tokbuf
[TOKBUFSIZE
];
2264 TCHECK2(dat
[0], BGP_SIZE
);
2265 memcpy(&bgp
, dat
, BGP_SIZE
);
2266 printf("\n\t%s Message (%u), length: %u",
2267 tok2strbuf(bgp_msg_values
, "Unknown", bgp
.bgp_type
,
2268 tokbuf
, sizeof(tokbuf
)),
2272 switch (bgp
.bgp_type
) {
2274 bgp_open_print(dat
, length
);
2277 bgp_update_print(dat
, length
);
2279 case BGP_NOTIFICATION
:
2280 bgp_notification_print(dat
, length
);
2284 case BGP_ROUTE_REFRESH
:
2285 bgp_route_refresh_print(dat
, length
);
2288 /* we have no decoder for the BGP message */
2289 TCHECK2(*dat
, length
);
2290 printf("\n\t no Message %u decoder",bgp
.bgp_type
);
2291 print_unknown_data(dat
,"\n\t ",length
);
2301 bgp_print(const u_char
*dat
, int length
)
2305 const u_char
*start
;
2306 const u_char marker
[] = {
2307 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2308 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2312 char tokbuf
[TOKBUFSIZE
];
2315 if (snapend
< dat
+ length
)
2318 printf(": BGP, length: %u",length
);
2320 if (vflag
< 1) /* lets be less chatty */
2326 if (!TTEST2(p
[0], 1))
2333 if (!TTEST2(p
[0], sizeof(marker
)))
2335 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2340 /* found BGP header */
2341 TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2342 memcpy(&bgp
, p
, BGP_SIZE
);
2347 hlen
= ntohs(bgp
.bgp_len
);
2348 if (hlen
< BGP_SIZE
) {
2349 printf("\n[|BGP Bogus header length %u < %u]", hlen
,
2354 if (TTEST2(p
[0], hlen
)) {
2355 if (!bgp_header_print(p
, hlen
))
2360 printf("\n[|BGP %s]",
2361 tok2strbuf(bgp_msg_values
,
2362 "Unknown Message Type",
2364 tokbuf
, sizeof(tokbuf
)));