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@gredler.at) for more
30 * complete BGP support.
33 /* \summary: Border Gateway Protocol (BGP) printer */
35 /* specification: RFC 4271 */
41 #include "netdissect-stdinc.h"
46 #include "netdissect.h"
47 #include "addrtoname.h"
53 nd_byte bgp_marker
[16];
57 #define BGP_SIZE 19 /* unaligned */
61 #define BGP_NOTIFICATION 3
62 #define BGP_KEEPALIVE 4
63 #define BGP_ROUTE_REFRESH 5
65 static const struct tok bgp_msg_values
[] = {
67 { BGP_UPDATE
, "Update"},
68 { BGP_NOTIFICATION
, "Notification"},
69 { BGP_KEEPALIVE
, "Keepalive"},
70 { BGP_ROUTE_REFRESH
, "Route Refresh"},
75 nd_byte bgpo_marker
[16];
78 nd_uint8_t bgpo_version
;
79 nd_uint16_t bgpo_myas
;
80 nd_uint16_t bgpo_holdtime
;
82 nd_uint8_t bgpo_optlen
;
83 /* options should follow */
85 #define BGP_OPEN_SIZE 29 /* unaligned */
88 nd_uint8_t bgpopt_type
;
89 nd_uint8_t bgpopt_len
;
92 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
93 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
95 struct bgp_notification
{
96 nd_byte bgpn_marker
[16];
99 nd_uint8_t bgpn_major
;
100 nd_uint8_t bgpn_minor
;
102 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
104 struct bgp_route_refresh
{
105 nd_byte bgp_marker
[16];
107 nd_uint8_t type
; /* No padding after this; afi is, in fact, not aligned */
112 #define BGP_ROUTE_REFRESH_SIZE 23
114 #define bgp_attr_lenlen(flags, p) \
115 (((flags) & 0x10) ? 2U : 1U)
116 #define bgp_attr_len(flags, p) \
117 (((flags) & 0x10) ? GET_BE_U_2(p) : GET_U_1(p))
119 #define BGPTYPE_ORIGIN 1
120 #define BGPTYPE_AS_PATH 2
121 #define BGPTYPE_NEXT_HOP 3
122 #define BGPTYPE_MULTI_EXIT_DISC 4
123 #define BGPTYPE_LOCAL_PREF 5
124 #define BGPTYPE_ATOMIC_AGGREGATE 6
125 #define BGPTYPE_AGGREGATOR 7
126 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
127 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC4456 */
128 #define BGPTYPE_CLUSTER_LIST 10 /* RFC4456 */
129 #define BGPTYPE_DPA 11 /* deprecated, draft-ietf-idr-bgp-dpa */
130 #define BGPTYPE_ADVERTISERS 12 /* deprecated RFC1863 */
131 #define BGPTYPE_RCID_PATH 13 /* deprecated RFC1863 */
132 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */
133 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */
134 #define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */
135 #define BGPTYPE_AS4_PATH 17 /* RFC6793 */
136 #define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */
137 #define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */
138 #define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */
139 #define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */
140 #define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */
141 #define BGPTYPE_AIGP 26 /* RFC7311 */
142 #define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */
143 #define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */
144 #define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */
145 #define BGPTYPE_ATTR_SET 128 /* RFC6368 */
147 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
149 static const struct tok bgp_attr_values
[] = {
150 { BGPTYPE_ORIGIN
, "Origin"},
151 { BGPTYPE_AS_PATH
, "AS Path"},
152 { BGPTYPE_AS4_PATH
, "AS4 Path"},
153 { BGPTYPE_NEXT_HOP
, "Next Hop"},
154 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
155 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
156 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
157 { BGPTYPE_AGGREGATOR
, "Aggregator"},
158 { BGPTYPE_AGGREGATOR4
, "Aggregator4"},
159 { BGPTYPE_COMMUNITIES
, "Community"},
160 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
161 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
162 { BGPTYPE_DPA
, "DPA"},
163 { BGPTYPE_ADVERTISERS
, "Advertisers"},
164 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
165 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
166 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
167 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
168 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
169 { BGPTYPE_TUNNEL_ENCAP
, "Tunnel Encapsulation"},
170 { BGPTYPE_TRAFFIC_ENG
, "Traffic Engineering"},
171 { BGPTYPE_IPV6_EXTD_COMMUNITIES
, "IPv6 Extended Community"},
172 { BGPTYPE_AIGP
, "Accumulated IGP Metric"},
173 { BGPTYPE_PE_DISTINGUISHER_LABEL
, "PE Distinguisher Label"},
174 { BGPTYPE_ENTROPY_LABEL
, "Entropy Label"},
175 { BGPTYPE_LARGE_COMMUNITY
, "Large Community"},
176 { BGPTYPE_ATTR_SET
, "Attribute Set"},
177 { 255, "Reserved for development"},
182 #define BGP_AS_SEQUENCE 2
183 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
184 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
186 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
187 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
189 static const struct tok bgp_as_path_segment_open_values
[] = {
190 { BGP_AS_SEQUENCE
, ""},
192 { BGP_CONFED_AS_SEQUENCE
, "( "},
193 { BGP_CONFED_AS_SET
, "({ "},
197 static const struct tok bgp_as_path_segment_close_values
[] = {
198 { BGP_AS_SEQUENCE
, ""},
200 { BGP_CONFED_AS_SEQUENCE
, ")"},
201 { BGP_CONFED_AS_SET
, "})"},
205 #define BGP_OPT_AUTH 1
206 #define BGP_OPT_CAP 2
208 static const struct tok bgp_opt_values
[] = {
209 { BGP_OPT_AUTH
, "Authentication Information"},
210 { BGP_OPT_CAP
, "Capabilities Advertisement"},
214 #define BGP_CAPCODE_MP 1 /* RFC2858 */
215 #define BGP_CAPCODE_RR 2 /* RFC2918 */
216 #define BGP_CAPCODE_ORF 3 /* RFC5291 */
217 #define BGP_CAPCODE_MR 4 /* RFC3107 */
218 #define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */
219 #define BGP_CAPCODE_RESTART 64 /* RFC4724 */
220 #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */
221 #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */
222 #define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */
223 #define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */
224 #define BGP_CAPCODE_ENH_RR 70 /* draft-keyur-bgp-enhanced-route-refresh */
225 #define BGP_CAPCODE_RR_CISCO 128
227 static const struct tok bgp_capcode_values
[] = {
228 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
229 { BGP_CAPCODE_RR
, "Route Refresh"},
230 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
231 { BGP_CAPCODE_MR
, "Multiple Routes to a Destination"},
232 { BGP_CAPCODE_EXT_NH
, "Extended Next Hop Encoding"},
233 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
234 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
235 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
236 { BGP_CAPCODE_MULTISESS
, "Multisession BGP"},
237 { BGP_CAPCODE_ADD_PATH
, "Multiple Paths"},
238 { BGP_CAPCODE_ENH_RR
, "Enhanced Route Refresh"},
239 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
243 #define BGP_NOTIFY_MAJOR_MSG 1
244 #define BGP_NOTIFY_MAJOR_OPEN 2
245 #define BGP_NOTIFY_MAJOR_UPDATE 3
246 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
247 #define BGP_NOTIFY_MAJOR_FSM 5
248 #define BGP_NOTIFY_MAJOR_CEASE 6
249 #define BGP_NOTIFY_MAJOR_CAP 7
251 static const struct tok bgp_notify_major_values
[] = {
252 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
253 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
254 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
255 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
256 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
257 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
258 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
262 /* draft-ietf-idr-cease-subcode-02 */
263 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
264 /* draft-ietf-idr-shutdown-07 */
265 #define BGP_NOTIFY_MINOR_CEASE_SHUT 2
266 #define BGP_NOTIFY_MINOR_CEASE_RESET 4
267 #define BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN 128
268 static const struct tok bgp_notify_minor_cease_values
[] = {
269 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
270 { BGP_NOTIFY_MINOR_CEASE_SHUT
, "Administrative Shutdown"},
271 { 3, "Peer Unconfigured"},
272 { BGP_NOTIFY_MINOR_CEASE_RESET
, "Administrative Reset"},
273 { 5, "Connection Rejected"},
274 { 6, "Other Configuration Change"},
275 { 7, "Connection Collision Resolution"},
279 static const struct tok bgp_notify_minor_msg_values
[] = {
280 { 1, "Connection Not Synchronized"},
281 { 2, "Bad Message Length"},
282 { 3, "Bad Message Type"},
286 static const struct tok bgp_notify_minor_open_values
[] = {
287 { 1, "Unsupported Version Number"},
289 { 3, "Bad BGP Identifier"},
290 { 4, "Unsupported Optional Parameter"},
291 { 5, "Authentication Failure"},
292 { 6, "Unacceptable Hold Time"},
293 { 7, "Capability Message Error"},
297 static const struct tok bgp_notify_minor_update_values
[] = {
298 { 1, "Malformed Attribute List"},
299 { 2, "Unrecognized Well-known Attribute"},
300 { 3, "Missing Well-known Attribute"},
301 { 4, "Attribute Flags Error"},
302 { 5, "Attribute Length Error"},
303 { 6, "Invalid ORIGIN Attribute"},
304 { 7, "AS Routing Loop"},
305 { 8, "Invalid NEXT_HOP Attribute"},
306 { 9, "Optional Attribute Error"},
307 { 10, "Invalid Network Field"},
308 { 11, "Malformed AS_PATH"},
312 static const struct tok bgp_notify_minor_fsm_values
[] = {
313 { 0, "Unspecified Error"},
314 { 1, "In OpenSent State"},
315 { 2, "In OpenConfirm State"},
316 { 3, "In Established State"},
320 static const struct tok bgp_notify_minor_cap_values
[] = {
321 { 1, "Invalid Action Value" },
322 { 2, "Invalid Capability Length" },
323 { 3, "Malformed Capability Value" },
324 { 4, "Unsupported Capability Code" },
328 static const struct tok bgp_origin_values
[] = {
335 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
336 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
337 #define BGP_PMSI_TUNNEL_PIM_SSM 3
338 #define BGP_PMSI_TUNNEL_PIM_SM 4
339 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
340 #define BGP_PMSI_TUNNEL_INGRESS 6
341 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
343 static const struct tok bgp_pmsi_tunnel_values
[] = {
344 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
345 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
346 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
347 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
348 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
349 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
350 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
354 static const struct tok bgp_pmsi_flag_values
[] = {
355 { 0x01, "Leaf Information required"},
359 #define BGP_AIGP_TLV 1
361 static const struct tok bgp_aigp_values
[] = {
362 { BGP_AIGP_TLV
, "AIGP"},
366 /* Subsequent address family identifier, RFC2283 section 7 */
368 #define SAFNUM_UNICAST 1
369 #define SAFNUM_MULTICAST 2
370 #define SAFNUM_UNIMULTICAST 3 /* deprecated now */
371 /* labeled BGP RFC3107 */
372 #define SAFNUM_LABUNICAST 4
374 #define SAFNUM_MULTICAST_VPN 5
375 /* draft-nalawade-kapoor-tunnel-safi */
376 #define SAFNUM_TUNNEL 64
378 #define SAFNUM_VPLS 65
380 #define SAFNUM_MDT 66
382 #define SAFNUM_VPNUNICAST 128
384 #define SAFNUM_VPNMULTICAST 129
385 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
387 #define SAFNUM_RT_ROUTING_INFO 132
389 #define BGP_VPN_RD_LEN 8
391 static const struct tok bgp_safi_values
[] = {
392 { SAFNUM_RES
, "Reserved"},
393 { SAFNUM_UNICAST
, "Unicast"},
394 { SAFNUM_MULTICAST
, "Multicast"},
395 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
396 { SAFNUM_LABUNICAST
, "labeled Unicast"},
397 { SAFNUM_TUNNEL
, "Tunnel"},
398 { SAFNUM_VPLS
, "VPLS"},
399 { SAFNUM_MDT
, "MDT"},
400 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
401 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
402 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
403 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
404 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
408 /* well-known community */
409 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
410 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
411 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
413 /* Extended community type - RFC 4360 */
414 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
415 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
416 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
417 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
418 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
419 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
420 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
421 /* rfc2547 bgp-mpls-vpns */
422 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
423 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatibility */
424 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatibility */
425 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatibility */
427 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
428 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatibility */
430 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
431 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatibility */
433 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
435 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
436 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
437 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
438 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
440 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
441 #define BGP_EXT_COM_EIGRP_GEN 0x8800
442 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
443 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
444 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
445 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
446 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
448 static const struct tok bgp_extd_comm_flag_values
[] = {
449 { 0x8000, "vendor-specific"},
450 { 0x4000, "non-transitive"},
454 static const struct tok bgp_extd_comm_subtype_values
[] = {
455 { BGP_EXT_COM_RT_0
, "target"},
456 { BGP_EXT_COM_RT_1
, "target"},
457 { BGP_EXT_COM_RT_2
, "target"},
458 { BGP_EXT_COM_RO_0
, "origin"},
459 { BGP_EXT_COM_RO_1
, "origin"},
460 { BGP_EXT_COM_RO_2
, "origin"},
461 { BGP_EXT_COM_LINKBAND
, "link-BW"},
462 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
463 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
464 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
465 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
466 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
467 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
468 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
469 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
470 { BGP_EXT_COM_L2INFO
, "layer2-info"},
471 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
472 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
473 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
474 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
475 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
476 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
477 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
478 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
479 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
480 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
484 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
485 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
486 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
487 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
488 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
489 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
490 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
491 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
493 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
494 { BGP_OSPF_RTYPE_RTR
, "Router" },
495 { BGP_OSPF_RTYPE_NET
, "Network" },
496 { BGP_OSPF_RTYPE_SUM
, "Summary" },
497 { BGP_OSPF_RTYPE_EXT
, "External" },
498 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
499 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
503 /* ADD-PATH Send/Receive field values */
504 static const struct tok bgp_add_path_recvsend
[] = {
511 static char astostr
[20];
516 * Convert an AS number into a string and return string pointer.
518 * Depending on bflag is set or not, AS number is converted into ASDOT notation
519 * or plain number notation.
523 as_printf(netdissect_options
*ndo
,
524 char *str
, size_t size
, u_int asnum
)
526 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
527 nd_snprintf(str
, size
, "%u", asnum
);
529 nd_snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
534 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
537 decode_prefix4(netdissect_options
*ndo
,
538 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
541 u_int plen
, plenbytes
;
545 plen
= GET_U_1(pptr
);
550 memset(&addr
, 0, sizeof(addr
));
551 plenbytes
= (plen
+ 7) / 8;
552 ND_TCHECK_LEN(pptr
+ 1, plenbytes
);
553 ITEMCHECK(plenbytes
);
554 memcpy(&addr
, pptr
+ 1, plenbytes
);
556 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
558 nd_snprintf(buf
, buflen
, "%s/%u", ipaddr_string(ndo
, (const u_char
*)&addr
), plen
);
559 return 1 + plenbytes
;
569 decode_labeled_prefix4(netdissect_options
*ndo
,
570 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
573 u_int plen
, plenbytes
;
575 /* prefix length and label = 4 bytes */
578 plen
= GET_U_1(pptr
); /* get prefix length */
580 /* this is one of the weirdnesses of rfc3107
581 the label length (actually the label + COS bits)
582 is added to the prefix length;
583 we also do only read out just one label -
584 there is no real application for advertisement of
585 stacked labels in a single BGP message
591 plen
-=24; /* adjust prefixlen - labellength */
597 memset(&addr
, 0, sizeof(addr
));
598 plenbytes
= (plen
+ 7) / 8;
599 ND_TCHECK_LEN(pptr
+ 4, plenbytes
);
600 ITEMCHECK(plenbytes
);
601 memcpy(&addr
, pptr
+ 4, plenbytes
);
603 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
605 /* the label may get offsetted by 4 bits so lets shift it right */
606 nd_snprintf(buf
, buflen
, "%s/%u, label:%u %s",
607 ipaddr_string(ndo
, (const u_char
*)&addr
),
609 GET_BE_U_3(pptr
+ 1)>>4,
610 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
612 return 4 + plenbytes
;
624 * print an ipv4 or ipv6 address into a buffer dependend on address length.
627 bgp_vpn_ip_print(netdissect_options
*ndo
,
628 const u_char
*pptr
, u_int addr_length
)
631 /* worst case string is s fully formatted v6 address */
632 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
635 switch(addr_length
) {
636 case (sizeof(nd_ipv4
) << 3): /* 32 */
637 ND_TCHECK_LEN(pptr
, sizeof(nd_ipv4
));
638 nd_snprintf(pos
, sizeof(addr
), "%s", ipaddr_string(ndo
, pptr
));
640 case (sizeof(nd_ipv6
) << 3): /* 128 */
641 ND_TCHECK_LEN(pptr
, sizeof(nd_ipv6
));
642 nd_snprintf(pos
, sizeof(addr
), "%s", ip6addr_string(ndo
, pptr
));
645 nd_snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
658 * print an multicast s,g entry into a buffer.
659 * the s,g entry is encoded like this.
661 * +-----------------------------------+
662 * | Multicast Source Length (1 octet) |
663 * +-----------------------------------+
664 * | Multicast Source (Variable) |
665 * +-----------------------------------+
666 * | Multicast Group Length (1 octet) |
667 * +-----------------------------------+
668 * | Multicast Group (Variable) |
669 * +-----------------------------------+
671 * return the number of bytes read from the wire.
674 bgp_vpn_sg_print(netdissect_options
*ndo
,
675 const u_char
*pptr
, char *buf
, u_int buflen
)
678 u_int total_length
, offset
;
682 /* Source address length, encoded in bits */
684 addr_length
= GET_U_1(pptr
);
688 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
689 total_length
+= (addr_length
>> 3) + 1;
690 offset
= strlen(buf
);
692 nd_snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
693 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
694 pptr
+= (addr_length
>> 3);
697 /* Group address length, encoded in bits */
699 addr_length
= GET_U_1(pptr
);
703 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
704 total_length
+= (addr_length
>> 3) + 1;
705 offset
= strlen(buf
);
707 nd_snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
708 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
709 pptr
+= (addr_length
>> 3);
713 return (total_length
);
716 /* Print an RFC 4364 Route Distinguisher */
718 bgp_vpn_rd_print(netdissect_options
*ndo
,
721 /* allocate space for the largest possible string */
722 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
725 /* ok lets load the RD format */
726 switch (GET_BE_U_2(pptr
)) {
729 /* 2-byte-AS:number fmt */
730 nd_snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
731 GET_BE_U_2(pptr
+ 2),
732 GET_BE_U_4(pptr
+ 4),
733 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
734 GET_U_1(pptr
+ 6), GET_U_1(pptr
+ 7));
738 /* IP-address:AS fmt */
739 nd_snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
740 GET_U_1(pptr
+ 2), GET_U_1(pptr
+ 3),
741 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
742 GET_BE_U_2(pptr
+ 6));
746 /* 4-byte-AS:number fmt */
747 nd_snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
748 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 2)),
749 GET_BE_U_2(pptr
+ 6), GET_U_1(pptr
+ 2),
750 GET_U_1(pptr
+ 3), GET_U_1(pptr
+ 4),
751 GET_U_1(pptr
+ 5), GET_BE_U_2(pptr
+ 6));
754 nd_snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
763 * Print an RFC 4360 Extended Community.
766 bgp_extended_community_print(netdissect_options
*ndo
,
769 union { /* copy buffer for bandwidth values */
774 switch (GET_BE_U_2(pptr
)) {
776 case BGP_EXT_COM_RT_0
:
777 case BGP_EXT_COM_RO_0
:
778 case BGP_EXT_COM_L2VPN_RT_0
:
779 ND_PRINT("%u:%u (= %s)",
780 GET_BE_U_2(pptr
+ 2),
781 GET_BE_U_4(pptr
+ 4),
782 ipaddr_string(ndo
, pptr
+4));
785 case BGP_EXT_COM_RT_1
:
786 case BGP_EXT_COM_RO_1
:
787 case BGP_EXT_COM_L2VPN_RT_1
:
788 case BGP_EXT_COM_VRF_RT_IMP
:
790 ipaddr_string(ndo
, pptr
+2),
791 GET_BE_U_2(pptr
+ 6));
794 case BGP_EXT_COM_RT_2
:
795 case BGP_EXT_COM_RO_2
:
797 as_printf(ndo
, astostr
, sizeof(astostr
),
798 GET_BE_U_4(pptr
+ 2)), GET_BE_U_2(pptr
+ 6));
801 case BGP_EXT_COM_LINKBAND
:
802 bw
.i
= GET_BE_U_4(pptr
+ 2);
803 ND_PRINT("bandwidth: %.3f Mbps",
807 case BGP_EXT_COM_VPN_ORIGIN
:
808 case BGP_EXT_COM_VPN_ORIGIN2
:
809 case BGP_EXT_COM_VPN_ORIGIN3
:
810 case BGP_EXT_COM_VPN_ORIGIN4
:
811 case BGP_EXT_COM_OSPF_RID
:
812 case BGP_EXT_COM_OSPF_RID2
:
813 ND_PRINT("%s", ipaddr_string(ndo
, pptr
+2));
816 case BGP_EXT_COM_OSPF_RTYPE
:
817 case BGP_EXT_COM_OSPF_RTYPE2
:
818 ND_PRINT("area:%s, router-type:%s, metric-type:%s%s",
819 ipaddr_string(ndo
, pptr
+2),
820 tok2str(bgp_extd_comm_ospf_rtype_values
,
822 GET_U_1((pptr
+ 6))),
823 (GET_U_1(pptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
824 ((GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
827 case BGP_EXT_COM_L2INFO
:
828 ND_PRINT("%s Control Flags [0x%02x]:MTU %u",
829 tok2str(l2vpn_encaps_values
,
831 GET_U_1((pptr
+ 2))),
833 GET_BE_U_2(pptr
+ 4));
836 case BGP_EXT_COM_SOURCE_AS
:
837 ND_PRINT("AS %u", GET_BE_U_2(pptr
+ 2));
841 ND_PRINT("%02x%02x%02x%02x%02x%02x",
854 decode_rt_routing_info(netdissect_options
*ndo
,
858 char asbuf
[sizeof(astostr
)]; /* bgp_vpn_rd_print() overwrites astostr */
860 /* NLRI "prefix length" from RFC 2858 Section 4. */
862 plen
= GET_U_1(pptr
); /* get prefix length */
864 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
865 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
866 * target" fields inside the "prefix" depending on its length.
869 /* Without "origin AS", without "route target". */
870 ND_PRINT("\n\t default route target");
875 ND_PRINT("\n\t (illegal prefix length)");
879 /* With at least "origin AS", possibly with "route target". */
880 ND_TCHECK_4(pptr
+ 1);
881 as_printf(ndo
, asbuf
, sizeof(asbuf
), GET_BE_U_4(pptr
+ 1));
883 plen
-= 32; /* adjust prefix length */
885 /* An extended community is 8 octets, so the remaining prefix
889 ND_PRINT("\n\t (illegal prefix length)");
892 ND_TCHECK_LEN(pptr
+ 5, 8);
893 ND_PRINT("\n\t origin AS: %s, route target ", asbuf
);
894 bgp_extended_community_print(ndo
, pptr
+ 5);
903 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
904 const u_char
*pptr
, char *buf
, u_int buflen
)
910 plen
= GET_U_1(pptr
); /* get prefix length */
915 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
920 memset(&addr
, 0, sizeof(addr
));
921 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
922 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
924 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
925 ((0xff00 >> (plen
% 8)) & 0xff);
927 /* the label may get offsetted by 4 bits so lets shift it right */
928 nd_snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
929 bgp_vpn_rd_print(ndo
, pptr
+4),
930 ipaddr_string(ndo
, (const u_char
*)&addr
),
932 GET_BE_U_3(pptr
+ 1)>>4,
933 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
935 return 12 + (plen
+ 7) / 8;
942 * +-------------------------------+
944 * | RD:IPv4-address (12 octets) |
946 * +-------------------------------+
947 * | MDT Group-address (4 octets) |
948 * +-------------------------------+
951 #define MDT_VPN_NLRI_LEN 16
954 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
955 const u_char
*pptr
, char *buf
, u_int buflen
)
958 const u_char
*vpn_ip
;
962 /* if the NLRI is not predefined length, quit.*/
963 if (GET_U_1(pptr
) != MDT_VPN_NLRI_LEN
* 8)
973 ND_TCHECK_LEN(pptr
, sizeof(nd_ipv4
));
975 pptr
+= sizeof(nd_ipv4
);
977 /* MDT Group Address */
978 ND_TCHECK_LEN(pptr
, sizeof(nd_ipv4
));
980 nd_snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
981 bgp_vpn_rd_print(ndo
, rd
), ipaddr_string(ndo
, vpn_ip
), ipaddr_string(ndo
, pptr
));
983 return MDT_VPN_NLRI_LEN
+ 1;
989 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
990 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
991 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
992 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
993 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
994 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
995 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
997 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
998 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
999 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
1000 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
1001 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
1002 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
1003 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
1004 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
1009 decode_multicast_vpn(netdissect_options
*ndo
,
1010 const u_char
*pptr
, char *buf
, size_t buflen
)
1012 uint8_t route_type
, route_length
, addr_length
;
1017 route_type
= GET_U_1(pptr
);
1019 route_length
= GET_U_1(pptr
);
1022 nd_snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
1023 tok2str(bgp_multicast_vpn_route_type_values
,
1024 "Unknown", route_type
),
1025 route_type
, route_length
);
1027 switch(route_type
) {
1028 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
1029 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1030 offset
= strlen(buf
);
1031 nd_snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
1032 bgp_vpn_rd_print(ndo
, pptr
),
1033 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
1034 (route_length
- BGP_VPN_RD_LEN
) << 3));
1036 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
1037 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1038 offset
= strlen(buf
);
1039 nd_snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1040 bgp_vpn_rd_print(ndo
, pptr
),
1041 as_printf(ndo
, astostr
, sizeof(astostr
),
1042 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1045 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
1046 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1047 offset
= strlen(buf
);
1048 nd_snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1049 bgp_vpn_rd_print(ndo
, pptr
));
1050 pptr
+= BGP_VPN_RD_LEN
;
1052 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1053 addr_length
= route_length
- sg_length
;
1055 ND_TCHECK_LEN(pptr
, addr_length
);
1056 offset
= strlen(buf
);
1057 nd_snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
1058 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
1061 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
1062 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1063 offset
= strlen(buf
);
1064 nd_snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1065 bgp_vpn_rd_print(ndo
, pptr
));
1066 pptr
+= BGP_VPN_RD_LEN
;
1068 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1071 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
1072 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
1073 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1074 offset
= strlen(buf
);
1075 nd_snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1076 bgp_vpn_rd_print(ndo
, pptr
),
1077 as_printf(ndo
, astostr
, sizeof(astostr
),
1078 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1079 pptr
+= BGP_VPN_RD_LEN
+ 4;
1081 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1085 * no per route-type printing yet.
1087 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1092 return route_length
+ 2;
1099 * As I remember, some versions of systems have an snprintf() that
1100 * returns -1 if the buffer would have overflowed. If the return
1101 * value is negative, set buflen to 0, to indicate that we've filled
1104 * If the return value is greater than buflen, that means that
1105 * the buffer would have overflowed; again, set buflen to 0 in
1108 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1111 else if ((u_int)stringlen>buflen) \
1114 buflen-=stringlen; \
1119 decode_labeled_vpn_l2(netdissect_options
*ndo
,
1120 const u_char
*pptr
, char *buf
, u_int buflen
)
1122 u_int plen
, tlen
, tlv_type
, tlv_len
, ttlv_len
;
1126 plen
= GET_BE_U_2(pptr
);
1129 /* Old and new L2VPN NLRI share AFI/SAFI
1130 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1131 * and > 17 as old format. Complain for the middle case
1134 /* assume AD-only with RD, BGPNH */
1135 ND_TCHECK_LEN(pptr
, 12);
1137 stringlen
= nd_snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
1138 bgp_vpn_rd_print(ndo
, pptr
),
1139 ipaddr_string(ndo
, pptr
+8));
1140 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1144 } else if (plen
> 17) {
1145 /* assume old format */
1146 /* RD, ID, LBLKOFF, LBLBASE */
1148 ND_TCHECK_LEN(pptr
, 15);
1150 stringlen
= nd_snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1151 bgp_vpn_rd_print(ndo
, pptr
),
1152 GET_BE_U_2(pptr
+ 8),
1153 GET_BE_U_2(pptr
+ 10),
1154 GET_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1155 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1159 /* ok now the variable part - lets read out TLVs*/
1163 stringlen
=nd_snprintf(buf
,buflen
, "\n\t\tran past the end");
1164 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1169 tlv_type
= GET_U_1(pptr
);
1171 tlv_len
= GET_BE_U_2(pptr
); /* length, in *bits* */
1172 ttlv_len
= (tlv_len
+ 7)/8; /* length, in *bytes* */
1178 stringlen
=nd_snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1181 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1183 while (ttlv_len
!= 0) {
1186 stringlen
=nd_snprintf(buf
,buflen
, " (ran past the end)");
1187 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1193 stringlen
=nd_snprintf(buf
,buflen
, "%02x",
1196 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1204 stringlen
=nd_snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1207 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1209 if (tlen
< ttlv_len
) {
1211 stringlen
=nd_snprintf(buf
,buflen
, " (ran past the end)");
1212 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1222 /* complain bitterly ? */
1232 decode_prefix6(netdissect_options
*ndo
,
1233 const u_char
*pd
, u_int itemlen
, char *buf
, u_int buflen
)
1235 struct in6_addr addr
;
1236 u_int plen
, plenbytes
;
1245 memset(&addr
, 0, sizeof(addr
));
1246 plenbytes
= (plen
+ 7) / 8;
1247 ND_TCHECK_LEN(pd
+ 1, plenbytes
);
1248 ITEMCHECK(plenbytes
);
1249 memcpy(&addr
, pd
+ 1, plenbytes
);
1251 addr
.s6_addr
[plenbytes
- 1] &=
1252 ((0xff00 >> (plen
% 8)) & 0xff);
1254 nd_snprintf(buf
, buflen
, "%s/%u", ip6addr_string(ndo
, (const u_char
*)&addr
), plen
);
1255 return 1 + plenbytes
;
1265 decode_labeled_prefix6(netdissect_options
*ndo
,
1266 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
1268 struct in6_addr addr
;
1269 u_int plen
, plenbytes
;
1271 /* prefix length and label = 4 bytes */
1274 plen
= GET_U_1(pptr
); /* get prefix length */
1279 plen
-= 24; /* adjust prefixlen - labellength */
1285 memset(&addr
, 0, sizeof(addr
));
1286 plenbytes
= (plen
+ 7) / 8;
1287 ND_TCHECK_LEN(pptr
+ 4, plenbytes
);
1288 memcpy(&addr
, pptr
+ 4, plenbytes
);
1290 addr
.s6_addr
[plenbytes
- 1] &=
1291 ((0xff00 >> (plen
% 8)) & 0xff);
1293 /* the label may get offsetted by 4 bits so lets shift it right */
1294 nd_snprintf(buf
, buflen
, "%s/%u, label:%u %s",
1295 ip6addr_string(ndo
, (const u_char
*)&addr
),
1297 GET_BE_U_3(pptr
+ 1)>>4,
1298 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1300 return 4 + plenbytes
;
1310 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1311 const u_char
*pptr
, char *buf
, u_int buflen
)
1313 struct in6_addr addr
;
1317 plen
= GET_U_1(pptr
); /* get prefix length */
1322 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1327 memset(&addr
, 0, sizeof(addr
));
1328 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
1329 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1331 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1332 ((0xff00 >> (plen
% 8)) & 0xff);
1334 /* the label may get offsetted by 4 bits so lets shift it right */
1335 nd_snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1336 bgp_vpn_rd_print(ndo
, pptr
+4),
1337 ip6addr_string(ndo
, (const u_char
*)&addr
),
1339 GET_BE_U_3(pptr
+ 1)>>4,
1340 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1342 return 12 + (plen
+ 7) / 8;
1349 decode_clnp_prefix(netdissect_options
*ndo
,
1350 const u_char
*pptr
, char *buf
, u_int buflen
)
1356 plen
= GET_U_1(pptr
); /* get prefix length */
1361 memset(&addr
, 0, sizeof(addr
));
1362 ND_TCHECK_LEN(pptr
+ 4, (plen
+ 7) / 8);
1363 memcpy(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1365 addr
[(plen
+ 7) / 8 - 1] &=
1366 ((0xff00 >> (plen
% 8)) & 0xff);
1368 nd_snprintf(buf
, buflen
, "%s/%u",
1369 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1372 return 1 + (plen
+ 7) / 8;
1379 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1380 const u_char
*pptr
, char *buf
, u_int buflen
)
1386 plen
= GET_U_1(pptr
); /* get prefix length */
1391 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1396 memset(&addr
, 0, sizeof(addr
));
1397 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
1398 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1400 addr
[(plen
+ 7) / 8 - 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
1402 /* the label may get offsetted by 4 bits so lets shift it right */
1403 nd_snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1404 bgp_vpn_rd_print(ndo
, pptr
+4),
1405 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1407 GET_BE_U_3(pptr
+ 1)>>4,
1408 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1410 return 12 + (plen
+ 7) / 8;
1417 * bgp_attr_get_as_size
1419 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1420 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1421 * support, exchange AS-Path with the same path-attribute type value 0x02.
1424 bgp_attr_get_as_size(netdissect_options
*ndo
,
1425 uint8_t bgpa_type
, const u_char
*pptr
, u_int len
)
1427 const u_char
*tptr
= pptr
;
1430 * If the path attribute is the optional AS4 path type, then we already
1431 * know, that ASs must be encoded in 4 byte format.
1433 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1438 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1439 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1442 while (tptr
< pptr
+ len
) {
1446 * If we do not find a valid segment type, our guess might be wrong.
1448 if (GET_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| GET_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1451 ND_TCHECK_1(tptr
+ 1);
1452 tptr
+= 2 + GET_U_1(tptr
+ 1) * 2;
1456 * If we correctly reached end of the AS path attribute data content,
1457 * then most likely ASs were indeed encoded as 2 bytes.
1459 if (tptr
== pptr
+ len
) {
1466 * We can come here, either we did not have enough data, or if we
1467 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1468 * so that calller can try to decode each AS as of 4 bytes. If indeed
1469 * there was not enough data, it will crib and end the parse anyways.
1475 * The only way to know that a BGP UPDATE message is using add path is
1476 * by checking if the capability is in the OPEN message which we may have missed.
1477 * So this function checks if it is possible that the update could contain add path
1478 * and if so it checks that standard BGP doesn't make sense.
1481 check_add_path(netdissect_options
*ndo
, const u_char
*pptr
, u_int length
,
1482 u_int max_prefix_length
)
1484 u_int offset
, prefix_length
;
1491 * Scan through the NLRI information under the assumpetion that
1492 * it doesn't have path IDs.
1494 for (offset
= 0; offset
< length
;) {
1496 if (!ND_TTEST_1(pptr
+ offset
)) {
1497 /* We ran out of captured data; quit scanning. */
1500 prefix_length
= GET_U_1(pptr
+ offset
);
1502 * Add 4 to cover the path id
1503 * and check the prefix length isn't greater than 32/128.
1505 if (prefix_length
> max_prefix_length
) {
1508 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1509 offset
+= 1 + ((prefix_length
+ 7) / 8);
1511 /* check we haven't gone past the end of the section */
1512 if (offset
> length
) {
1516 /* check it's not standard BGP */
1517 for (offset
= 0; offset
< length
; ) {
1518 if (!ND_TTEST_1(pptr
+ offset
)) {
1519 /* We ran out of captured data; quit scanning. */
1522 prefix_length
= GET_U_1(pptr
+ offset
);
1524 * If the prefix_length is zero (0.0.0.0/0)
1525 * and since it's not the only address (length >= 5)
1526 * then it is add-path
1528 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1531 offset
+= 1 + ((prefix_length
+ 7) / 8);
1533 if (offset
> length
) {
1537 /* assume not add-path by default */
1542 bgp_attr_print(netdissect_options
*ndo
,
1543 uint8_t atype
, const u_char
*pptr
, u_int len
)
1547 uint8_t safi
, snpa
, nhlen
;
1551 char buf
[MAXHOSTNAMELEN
+ 100];
1553 int add_path4
, add_path6
;
1560 case BGPTYPE_ORIGIN
:
1562 ND_PRINT("invalid len");
1565 ND_PRINT("%s", tok2str(bgp_origin_values
,
1566 "Unknown Origin Typecode",
1572 * Process AS4 byte path and AS2 byte path attributes here.
1574 case BGPTYPE_AS4_PATH
:
1575 case BGPTYPE_AS_PATH
:
1577 ND_PRINT("invalid len");
1586 * BGP updates exchanged between New speakers that support 4
1587 * byte AS, ASs are always encoded in 4 bytes. There is no
1588 * definitive way to find this, just by the packet's
1589 * contents. So, check for packet's TLV's sanity assuming
1590 * 2 bytes first, and it does not pass, assume that ASs are
1591 * encoded in 4 bytes format and move on.
1593 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1595 while (tptr
< pptr
+ len
) {
1597 ND_PRINT("%s", tok2str(bgp_as_path_segment_open_values
,
1598 "?", GET_U_1(tptr
)));
1599 ND_TCHECK_1(tptr
+ 1);
1600 for (i
= 0; i
< GET_U_1(tptr
+ 1) * as_size
; i
+= as_size
) {
1601 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
1603 as_printf(ndo
, astostr
, sizeof(astostr
),
1605 GET_BE_U_2(tptr
+ i
+ 2) :
1606 GET_BE_U_4(tptr
+ i
+ 2)));
1609 ND_PRINT("%s", tok2str(bgp_as_path_segment_close_values
,
1610 "?", GET_U_1(tptr
)));
1611 ND_TCHECK_1(tptr
+ 1);
1612 tptr
+= 2 + GET_U_1(tptr
+ 1) * as_size
;
1615 case BGPTYPE_NEXT_HOP
:
1617 ND_PRINT("invalid len");
1620 ND_PRINT("%s", ipaddr_string(ndo
, tptr
));
1623 case BGPTYPE_MULTI_EXIT_DISC
:
1624 case BGPTYPE_LOCAL_PREF
:
1626 ND_PRINT("invalid len");
1629 ND_PRINT("%u", GET_BE_U_4(tptr
));
1632 case BGPTYPE_ATOMIC_AGGREGATE
:
1634 ND_PRINT("invalid len");
1636 case BGPTYPE_AGGREGATOR
:
1639 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1640 * the length of this PA can be either 6 bytes or 8 bytes.
1642 if (len
!= 6 && len
!= 8) {
1643 ND_PRINT("invalid len");
1646 ND_TCHECK_LEN(tptr
, len
);
1648 ND_PRINT(" AS #%s, origin %s",
1649 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(tptr
)),
1650 ipaddr_string(ndo
, tptr
+ 2));
1652 ND_PRINT(" AS #%s, origin %s",
1653 as_printf(ndo
, astostr
, sizeof(astostr
),
1654 GET_BE_U_4(tptr
)), ipaddr_string(ndo
, tptr
+ 4));
1657 case BGPTYPE_AGGREGATOR4
:
1659 ND_PRINT("invalid len");
1663 ND_PRINT(" AS #%s, origin %s",
1664 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)),
1665 ipaddr_string(ndo
, tptr
+ 4));
1667 case BGPTYPE_COMMUNITIES
:
1669 ND_PRINT("invalid len");
1677 comm
= GET_BE_U_4(tptr
);
1679 case BGP_COMMUNITY_NO_EXPORT
:
1680 ND_PRINT(" NO_EXPORT");
1682 case BGP_COMMUNITY_NO_ADVERT
:
1683 ND_PRINT(" NO_ADVERTISE");
1685 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1686 ND_PRINT(" NO_EXPORT_SUBCONFED");
1690 (comm
>> 16) & 0xffff,
1692 (tlen
>4) ? ", " : "");
1699 case BGPTYPE_ORIGINATOR_ID
:
1701 ND_PRINT("invalid len");
1705 ND_PRINT("%s",ipaddr_string(ndo
, tptr
));
1707 case BGPTYPE_CLUSTER_LIST
:
1709 ND_PRINT("invalid len");
1717 ipaddr_string(ndo
, tptr
),
1718 (tlen
>4) ? ", " : "");
1723 case BGPTYPE_MP_REACH_NLRI
:
1727 af
= GET_BE_U_2(tptr
);
1728 safi
= GET_U_1(tptr
+ 2);
1730 ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1731 tok2str(af_values
, "Unknown AFI", af
),
1733 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1734 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1737 switch(af
<<8 | safi
) {
1738 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1739 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1740 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1741 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1742 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1743 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1744 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1745 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1746 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1747 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1748 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1749 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1750 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1751 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1752 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1753 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1754 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1755 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1756 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1757 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1758 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1759 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1760 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1761 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1762 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1763 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1764 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1767 ND_TCHECK_LEN(tptr
, tlen
);
1768 ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af
, safi
);
1769 if (ndo
->ndo_vflag
<= 1)
1770 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1778 nhlen
= GET_U_1(tptr
);
1784 ND_PRINT("\n\t nexthop: ");
1789 switch(af
<<8 | safi
) {
1790 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1791 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1792 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1793 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1794 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1795 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1796 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1797 if (tlen
< sizeof(nd_ipv4
)) {
1798 ND_PRINT("invalid len");
1801 ND_TCHECK_LEN(tptr
, sizeof(nd_ipv4
));
1802 ND_PRINT("%s",ipaddr_string(ndo
, tptr
));
1803 tlen
-= sizeof(nd_ipv4
);
1804 tptr
+= sizeof(nd_ipv4
);
1807 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1808 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1809 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1810 if (tlen
< sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
) {
1811 ND_PRINT("invalid len");
1815 sizeof(nd_ipv4
) + BGP_VPN_RD_LEN
);
1816 ND_PRINT("RD: %s, %s",
1817 bgp_vpn_rd_print(ndo
, tptr
),
1818 ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
));
1819 tlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
1820 tptr
+= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
1823 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1824 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1825 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1826 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1827 if (tlen
< sizeof(nd_ipv6
)) {
1828 ND_PRINT("invalid len");
1831 ND_TCHECK_LEN(tptr
, sizeof(nd_ipv6
));
1832 ND_PRINT("%s", ip6addr_string(ndo
, tptr
));
1833 tlen
-= sizeof(nd_ipv6
);
1834 tptr
+= sizeof(nd_ipv6
);
1837 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1838 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1839 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1840 if (tlen
< sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
) {
1841 ND_PRINT("invalid len");
1845 sizeof(nd_ipv6
) + BGP_VPN_RD_LEN
);
1846 ND_PRINT("RD: %s, %s",
1847 bgp_vpn_rd_print(ndo
, tptr
),
1848 ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
));
1849 tlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
1850 tptr
+= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
1853 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1854 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1855 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1856 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1857 if (tlen
< sizeof(nd_ipv4
)) {
1858 ND_PRINT("invalid len");
1861 ND_TCHECK_LEN(tptr
, sizeof(nd_ipv4
));
1862 ND_PRINT("%s", ipaddr_string(ndo
, tptr
));
1863 tlen
-= (sizeof(nd_ipv4
));
1864 tptr
+= (sizeof(nd_ipv4
));
1867 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1868 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1869 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1870 ND_TCHECK_LEN(tptr
, tlen
);
1871 ND_PRINT("%s", isonsap_string(ndo
, tptr
, tlen
));
1876 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1877 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1878 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1879 if (tlen
< BGP_VPN_RD_LEN
+1) {
1880 ND_PRINT("invalid len");
1883 ND_TCHECK_LEN(tptr
, tlen
);
1884 ND_PRINT("RD: %s, %s",
1885 bgp_vpn_rd_print(ndo
, tptr
),
1886 isonsap_string(ndo
, tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
));
1887 /* rfc986 mapped IPv4 address ? */
1888 if (GET_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
1889 ND_PRINT(" = %s", ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+4));
1890 /* rfc1888 mapped IPv6 address ? */
1891 else if (GET_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
1892 ND_PRINT(" = %s", ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+3));
1898 ND_TCHECK_LEN(tptr
, tlen
);
1899 ND_PRINT("no AFI %u/SAFI %u decoder", af
, safi
);
1900 if (ndo
->ndo_vflag
<= 1)
1901 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1909 ND_PRINT(", nh-length: %u", nhlen
);
1913 snpa
= GET_U_1(tptr
);
1917 ND_PRINT("\n\t %u SNPA", snpa
);
1918 for (/*nothing*/; snpa
!= 0; snpa
--) {
1920 ND_PRINT("\n\t %u bytes", GET_U_1(tptr
));
1921 tptr
+= GET_U_1(tptr
) + 1;
1924 ND_PRINT(", no SNPA");
1927 add_path4
= check_add_path(ndo
, tptr
, (len
-(tptr
- pptr
)), 32);
1928 add_path6
= check_add_path(ndo
, tptr
, (len
-(tptr
- pptr
)), 128);
1930 while (tptr
< pptr
+ len
) {
1931 switch (af
<<8 | safi
) {
1932 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1933 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1934 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1936 path_id
= GET_BE_U_4(tptr
);
1939 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1941 ND_PRINT("\n\t (illegal prefix length)");
1942 else if (advance
== -2)
1944 else if (advance
== -3)
1945 break; /* bytes left, but not enough */
1947 ND_PRINT("\n\t %s", buf
);
1949 ND_PRINT(" Path Id: %u", path_id
);
1952 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1953 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1955 ND_PRINT("\n\t (illegal prefix length)");
1956 else if (advance
== -2)
1958 else if (advance
== -3)
1959 break; /* bytes left, but not enough */
1961 ND_PRINT("\n\t %s", buf
);
1963 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1964 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1965 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1966 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1968 ND_PRINT("\n\t (illegal prefix length)");
1969 else if (advance
== -2)
1972 ND_PRINT("\n\t %s", buf
);
1974 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1975 advance
= decode_rt_routing_info(ndo
, tptr
);
1979 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1980 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1981 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1983 ND_PRINT("\n\t (illegal prefix length)");
1984 else if (advance
== -2)
1987 ND_PRINT("\n\t %s", buf
);
1990 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1991 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
1993 ND_PRINT("\n\t (illegal prefix length)");
1994 else if (advance
== -2)
1997 ND_PRINT("\n\t %s", buf
);
1999 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
2000 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
2001 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
2003 path_id
= GET_BE_U_4(tptr
);
2006 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
2008 ND_PRINT("\n\t (illegal prefix length)");
2009 else if (advance
== -2)
2011 else if (advance
== -3)
2012 break; /* bytes left, but not enough */
2014 ND_PRINT("\n\t %s", buf
);
2016 ND_PRINT(" Path Id: %u", path_id
);
2019 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
2020 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
2022 ND_PRINT("\n\t (illegal prefix length)");
2023 else if (advance
== -2)
2025 else if (advance
== -3)
2026 break; /* bytes left, but not enough */
2028 ND_PRINT("\n\t %s", buf
);
2030 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
2031 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
2032 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2033 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
2035 ND_PRINT("\n\t (illegal prefix length)");
2036 else if (advance
== -2)
2039 ND_PRINT("\n\t %s", buf
);
2041 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2042 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2043 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2044 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2045 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
2047 ND_PRINT("\n\t (illegal length)");
2048 else if (advance
== -2)
2051 ND_PRINT("\n\t %s", buf
);
2053 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2054 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2055 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2056 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2058 ND_PRINT("\n\t (illegal prefix length)");
2059 else if (advance
== -2)
2062 ND_PRINT("\n\t %s", buf
);
2064 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2065 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2066 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2067 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2069 ND_PRINT("\n\t (illegal prefix length)");
2070 else if (advance
== -2)
2073 ND_PRINT("\n\t %s", buf
);
2076 ND_TCHECK_LEN(tptr
, tlen
);
2077 ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af
, safi
);
2078 if (ndo
->ndo_vflag
<= 1)
2079 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2091 case BGPTYPE_MP_UNREACH_NLRI
:
2092 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
2093 af
= GET_BE_U_2(tptr
);
2094 safi
= GET_U_1(tptr
+ 2);
2096 ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
2097 tok2str(af_values
, "Unknown AFI", af
),
2099 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
2100 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
2103 if (len
== BGP_MP_NLRI_MINSIZE
)
2104 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2108 add_path4
= check_add_path(ndo
, tptr
, (len
-(tptr
- pptr
)), 32);
2109 add_path6
= check_add_path(ndo
, tptr
, (len
-(tptr
- pptr
)), 128);
2111 while (tptr
< pptr
+ len
) {
2112 switch (af
<<8 | safi
) {
2113 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
2114 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
2115 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
2117 path_id
= GET_BE_U_4(tptr
);
2120 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
2122 ND_PRINT("\n\t (illegal prefix length)");
2123 else if (advance
== -2)
2125 else if (advance
== -3)
2126 break; /* bytes left, but not enough */
2128 ND_PRINT("\n\t %s", buf
);
2130 ND_PRINT(" Path Id: %u", path_id
);
2133 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
2134 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
2136 ND_PRINT("\n\t (illegal prefix length)");
2137 else if (advance
== -2)
2139 else if (advance
== -3)
2140 break; /* bytes left, but not enough */
2142 ND_PRINT("\n\t %s", buf
);
2144 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
2145 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
2146 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
2147 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
2149 ND_PRINT("\n\t (illegal prefix length)");
2150 else if (advance
== -2)
2153 ND_PRINT("\n\t %s", buf
);
2155 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
2156 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
2157 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
2159 path_id
= GET_BE_U_4(tptr
);
2162 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
2164 ND_PRINT("\n\t (illegal prefix length)");
2165 else if (advance
== -2)
2167 else if (advance
== -3)
2168 break; /* bytes left, but not enough */
2170 ND_PRINT("\n\t %s", buf
);
2172 ND_PRINT(" Path Id: %u", path_id
);
2175 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
2176 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
2178 ND_PRINT("\n\t (illegal prefix length)");
2179 else if (advance
== -2)
2181 else if (advance
== -3)
2182 break; /* bytes left, but not enough */
2184 ND_PRINT("\n\t %s", buf
);
2186 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
2187 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
2188 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2189 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
2191 ND_PRINT("\n\t (illegal prefix length)");
2192 else if (advance
== -2)
2195 ND_PRINT("\n\t %s", buf
);
2197 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2198 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2199 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2200 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2201 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
2203 ND_PRINT("\n\t (illegal length)");
2204 else if (advance
== -2)
2207 ND_PRINT("\n\t %s", buf
);
2209 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2210 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2211 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2212 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2214 ND_PRINT("\n\t (illegal prefix length)");
2215 else if (advance
== -2)
2218 ND_PRINT("\n\t %s", buf
);
2220 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2221 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2222 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2223 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2225 ND_PRINT("\n\t (illegal prefix length)");
2226 else if (advance
== -2)
2229 ND_PRINT("\n\t %s", buf
);
2231 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
2232 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
2234 ND_PRINT("\n\t (illegal prefix length)");
2235 else if (advance
== -2)
2238 ND_PRINT("\n\t %s", buf
);
2240 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
2241 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
2242 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
2244 ND_PRINT("\n\t (illegal prefix length)");
2245 else if (advance
== -2)
2248 ND_PRINT("\n\t %s", buf
);
2251 ND_TCHECK_LEN(tptr
- 3, tlen
);
2252 ND_PRINT("no AFI %u / SAFI %u decoder", af
, safi
);
2253 if (ndo
->ndo_vflag
<= 1)
2254 print_unknown_data(ndo
, tptr
-3, "\n\t ", tlen
);
2264 case BGPTYPE_EXTD_COMMUNITIES
:
2266 ND_PRINT("invalid len");
2275 extd_comm
=GET_BE_U_2(tptr
);
2277 ND_PRINT("\n\t %s (0x%04x), Flags [%s]",
2278 tok2str(bgp_extd_comm_subtype_values
,
2279 "unknown extd community typecode",
2282 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
2288 bgp_extended_community_print(ndo
, tptr
);
2294 case BGPTYPE_PMSI_TUNNEL
:
2296 uint8_t tunnel_type
, flags
;
2301 flags
= GET_U_1(tptr
);
2302 tunnel_type
= GET_U_1(tptr
+ 1);
2305 ND_PRINT("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2306 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2308 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2309 GET_BE_U_3(tptr
+ 2)>>4);
2314 switch (tunnel_type
) {
2315 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2316 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2318 ND_PRINT("\n\t Sender %s, P-Group %s",
2319 ipaddr_string(ndo
, tptr
),
2320 ipaddr_string(ndo
, tptr
+4));
2323 case BGP_PMSI_TUNNEL_PIM_SSM
:
2325 ND_PRINT("\n\t Root-Node %s, P-Group %s",
2326 ipaddr_string(ndo
, tptr
),
2327 ipaddr_string(ndo
, tptr
+4));
2329 case BGP_PMSI_TUNNEL_INGRESS
:
2331 ND_PRINT("\n\t Tunnel-Endpoint %s",
2332 ipaddr_string(ndo
, tptr
));
2334 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2335 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2337 ND_PRINT("\n\t Root-Node %s, LSP-ID 0x%08x",
2338 ipaddr_string(ndo
, tptr
),
2339 GET_BE_U_4(tptr
+ 4));
2341 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2343 ND_PRINT("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2344 ipaddr_string(ndo
, tptr
),
2345 GET_BE_U_4(tptr
+ 4));
2348 if (ndo
->ndo_vflag
<= 1) {
2349 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2365 type
= GET_U_1(tptr
);
2366 length
= GET_BE_U_2(tptr
+ 1);
2370 ND_PRINT("\n\t %s TLV (%u), length %u",
2371 tok2str(bgp_aigp_values
, "Unknown", type
),
2379 * Check if we can read the TLV data.
2381 ND_TCHECK_LEN(tptr
+ 3, length
);
2390 ND_PRINT(", metric %" PRIu64
,
2395 if (ndo
->ndo_vflag
<= 1) {
2396 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2405 case BGPTYPE_ATTR_SET
:
2409 ND_PRINT("\n\t Origin AS: %s",
2410 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)));
2415 u_int aflags
, alenlen
, alen
;
2419 ND_PRINT(" [path attr too short]");
2423 aflags
= GET_U_1(tptr
);
2424 atype
= GET_U_1(tptr
+ 1);
2427 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2428 ND_TCHECK_LEN(tptr
, alenlen
);
2429 if (len
< alenlen
) {
2430 ND_PRINT(" [path attr too short]");
2434 alen
= bgp_attr_len(aflags
, tptr
);
2438 ND_PRINT("\n\t %s (%u), length: %u",
2439 tok2str(bgp_attr_values
,
2440 "Unknown Attribute", atype
),
2445 ND_PRINT(", Flags [%s%s%s%s",
2446 aflags
& 0x80 ? "O" : "",
2447 aflags
& 0x40 ? "T" : "",
2448 aflags
& 0x20 ? "P" : "",
2449 aflags
& 0x10 ? "E" : "");
2451 ND_PRINT("+%x", aflags
& 0xf);
2456 ND_PRINT(" [path attr too short]");
2460 /* FIXME check for recursion */
2461 if (!bgp_attr_print(ndo
, atype
, tptr
, alen
))
2468 case BGPTYPE_LARGE_COMMUNITY
:
2469 if (len
== 0 || len
% 12) {
2470 ND_PRINT("invalid len");
2475 ND_TCHECK_LEN(tptr
, 12);
2476 ND_PRINT("%u:%u:%u%s",
2478 GET_BE_U_4(tptr
+ 4),
2479 GET_BE_U_4(tptr
+ 8),
2480 (len
> 12) ? ", " : "");
2483 * len will always be a multiple of 12, as per the above,
2484 * so this will never underflow.
2490 ND_TCHECK_LEN(pptr
, len
);
2491 ND_PRINT("\n\t no Attribute %u decoder", atype
); /* we have no decoder for the attribute */
2492 if (ndo
->ndo_vflag
<= 1)
2493 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2496 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2497 ND_TCHECK_LEN(pptr
, len
);
2498 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2507 bgp_capabilities_print(netdissect_options
*ndo
,
2508 const u_char
*opt
, u_int caps_len
)
2510 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2513 while (i
< caps_len
) {
2514 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2515 cap_type
=GET_U_1(opt
+ i
);
2516 cap_len
=GET_U_1(opt
+ i
+ 1);
2517 ND_PRINT("\n\t %s (%u), length: %u",
2518 tok2str(bgp_capcode_values
, "Unknown", cap_type
),
2521 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2523 case BGP_CAPCODE_MP
:
2524 /* AFI (16 bits), Reserved (8 bits), SAFI (8 bits) */
2526 ND_PRINT(" (too short, < 4)");
2529 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u)",
2530 tok2str(af_values
, "Unknown", GET_BE_U_2(opt
+ i
+ 2)),
2531 GET_BE_U_2(opt
+ i
+ 2),
2532 tok2str(bgp_safi_values
, "Unknown", GET_U_1(opt
+ i
+ 5)),
2533 GET_U_1(opt
+ i
+ 5));
2535 case BGP_CAPCODE_RESTART
:
2536 /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */
2538 ND_PRINT(" (too short, < 2)");
2542 ND_PRINT("\n\t\tRestart Flags: [%s], Restart Time %us",
2543 ((GET_U_1(opt
+ i
+ 2))&0x80) ? "R" : "none",
2544 GET_BE_U_2(opt
+ i
+ 2)&0xfff);
2547 while(tcap_len
>=4) {
2548 ND_PRINT("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2549 tok2str(af_values
,"Unknown",
2550 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2551 GET_BE_U_2(opt
+ i
+ cap_offset
),
2552 tok2str(bgp_safi_values
,"Unknown",
2553 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2554 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2555 ((GET_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" );
2560 case BGP_CAPCODE_RR
:
2561 case BGP_CAPCODE_RR_CISCO
:
2563 case BGP_CAPCODE_AS_NEW
:
2565 * Extract the 4 byte AS number encoded.
2568 ND_PRINT(" (too short, < 4)");
2571 ND_PRINT("\n\t\t 4 Byte AS %s",
2572 as_printf(ndo
, astostr
, sizeof(astostr
),
2573 GET_BE_U_4(opt
+ i
+ 2)));
2575 case BGP_CAPCODE_ADD_PATH
:
2577 ND_PRINT(" (bogus)"); /* length */
2582 while (tcap_len
!= 0) {
2584 nd_print_invalid(ndo
);
2587 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2588 tok2str(af_values
,"Unknown",GET_BE_U_2(opt
+ i
+ cap_offset
)),
2589 GET_BE_U_2(opt
+ i
+ cap_offset
),
2590 tok2str(bgp_safi_values
,"Unknown",GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2591 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2592 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",GET_U_1(opt
+ i
+ cap_offset
+ 3))
2599 ND_PRINT("\n\t\tno decoder for Capability %u",
2601 if (ndo
->ndo_vflag
<= 1)
2602 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2606 if (ndo
->ndo_vflag
> 1 && cap_len
!= 0) {
2607 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2609 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2614 nd_print_trunc(ndo
);
2618 bgp_open_print(netdissect_options
*ndo
,
2619 const u_char
*dat
, u_int length
)
2621 const struct bgp_open
*bgp_open_header
;
2623 const struct bgp_opt
*bgpopt
;
2627 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2628 if (length
< BGP_OPEN_SIZE
)
2631 bgp_open_header
= (const struct bgp_open
*)dat
;
2633 ND_PRINT("\n\t Version %u, ",
2634 GET_U_1(bgp_open_header
->bgpo_version
));
2635 ND_PRINT("my AS %s, ",
2636 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(bgp_open_header
->bgpo_myas
)));
2637 ND_PRINT("Holdtime %us, ",
2638 GET_BE_U_2(bgp_open_header
->bgpo_holdtime
));
2639 ND_PRINT("ID %s", ipaddr_string(ndo
, bgp_open_header
->bgpo_id
));
2640 optslen
= GET_U_1(bgp_open_header
->bgpo_optlen
);
2641 ND_PRINT("\n\t Optional parameters, length: %u", optslen
);
2643 opt
= dat
+ BGP_OPEN_SIZE
;
2644 length
-= BGP_OPEN_SIZE
;
2647 while (i
< optslen
) {
2648 uint8_t opt_type
, opt_len
;
2650 ND_TCHECK_LEN(opt
+ i
, BGP_OPT_SIZE
);
2651 if (length
< BGP_OPT_SIZE
+ i
)
2653 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2654 opt_type
= GET_U_1(bgpopt
->bgpopt_type
);
2655 opt_len
= GET_U_1(bgpopt
->bgpopt_len
);
2656 if (BGP_OPT_SIZE
+ i
+ opt_len
> optslen
) {
2657 ND_PRINT("\n\t Option %u, length: %u, goes past the end of the options",
2662 ND_PRINT("\n\t Option %s (%u), length: %u",
2663 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2667 /* now let's decode the options we know*/
2671 bgp_capabilities_print(ndo
, opt
+ BGP_OPT_SIZE
+ i
,
2677 ND_PRINT("\n\t no decoder for option %u",
2681 i
+= BGP_OPT_SIZE
+ opt_len
;
2685 nd_print_trunc(ndo
);
2689 bgp_update_print(netdissect_options
*ndo
,
2690 const u_char
*dat
, u_int length
)
2693 u_int withdrawn_routes_len
;
2694 char buf
[MAXHOSTNAMELEN
+ 100];
2701 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2702 if (length
< BGP_SIZE
)
2707 /* Unfeasible routes */
2711 withdrawn_routes_len
= GET_BE_U_2(p
);
2714 if (withdrawn_routes_len
> 1) {
2716 * Without keeping state from the original NLRI message,
2717 * it's not possible to tell if this a v4 or v6 route,
2718 * so only try to decode it if we're not v6 enabled.
2720 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2721 if (length
< withdrawn_routes_len
)
2723 ND_PRINT("\n\t Withdrawn routes:");
2724 add_path
= check_add_path(ndo
, p
, withdrawn_routes_len
, 32);
2725 while (withdrawn_routes_len
!= 0) {
2727 if (withdrawn_routes_len
< 4) {
2728 p
+= withdrawn_routes_len
;
2729 length
-= withdrawn_routes_len
;
2732 path_id
= GET_BE_U_4(p
);
2735 withdrawn_routes_len
-= 4;
2737 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2739 ND_PRINT("\n\t (illegal prefix length)");
2741 } else if (wpfx
== -2)
2743 else if (wpfx
== -3)
2744 goto trunc
; /* bytes left, but not enough */
2746 ND_PRINT("\n\t %s", buf
);
2748 ND_PRINT(" Path Id: %u", path_id
);
2752 withdrawn_routes_len
-= wpfx
;
2756 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2757 if (length
< withdrawn_routes_len
)
2759 p
+= withdrawn_routes_len
;
2760 length
-= withdrawn_routes_len
;
2766 len
= GET_BE_U_2(p
);
2770 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2771 /* No withdrawn routes, no path attributes, no NLRI */
2772 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2777 /* do something more useful!*/
2779 uint8_t aflags
, atype
, alenlen
;
2786 ND_PRINT("\n\t [path attrs too short]");
2791 aflags
= GET_U_1(p
);
2792 atype
= GET_U_1(p
+ 1);
2796 alenlen
= bgp_attr_lenlen(aflags
, p
);
2797 ND_TCHECK_LEN(p
, alenlen
);
2798 if (length
< alenlen
)
2800 if (len
< alenlen
) {
2801 ND_PRINT("\n\t [path attrs too short]");
2806 alen
= bgp_attr_len(aflags
, p
);
2811 ND_PRINT("\n\t %s (%u), length: %u",
2812 tok2str(bgp_attr_values
, "Unknown Attribute", atype
),
2817 ND_PRINT(", Flags [%s%s%s%s",
2818 aflags
& 0x80 ? "O" : "",
2819 aflags
& 0x40 ? "T" : "",
2820 aflags
& 0x20 ? "P" : "",
2821 aflags
& 0x10 ? "E" : "");
2823 ND_PRINT("+%x", aflags
& 0xf);
2827 ND_PRINT(" [path attrs too short]");
2834 if (!bgp_attr_print(ndo
, atype
, p
, alen
))
2843 add_path
= check_add_path(ndo
, p
, length
, 32);
2844 ND_PRINT("\n\t Updated routes:");
2845 while (length
!= 0) {
2850 path_id
= GET_BE_U_4(p
);
2854 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2856 ND_PRINT("\n\t (illegal prefix length)");
2861 goto trunc
; /* bytes left, but not enough */
2863 ND_PRINT("\n\t %s", buf
);
2865 ND_PRINT(" Path Id: %u", path_id
);
2874 nd_print_trunc(ndo
);
2878 bgp_notification_print(netdissect_options
*ndo
,
2879 const u_char
*dat
, u_int length
)
2881 const struct bgp_notification
*bgp_notification_header
;
2883 uint8_t bgpn_major
, bgpn_minor
;
2884 uint8_t shutdown_comm_length
;
2885 uint8_t remainder_offset
;
2887 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
2888 if (length
<BGP_NOTIFICATION_SIZE
)
2891 bgp_notification_header
= (const struct bgp_notification
*)dat
;
2892 bgpn_major
= GET_U_1(bgp_notification_header
->bgpn_major
);
2893 bgpn_minor
= GET_U_1(bgp_notification_header
->bgpn_minor
);
2895 ND_PRINT(", %s (%u)",
2896 tok2str(bgp_notify_major_values
, "Unknown Error",
2900 switch (bgpn_major
) {
2902 case BGP_NOTIFY_MAJOR_MSG
:
2903 ND_PRINT(", subcode %s (%u)",
2904 tok2str(bgp_notify_minor_msg_values
, "Unknown",
2908 case BGP_NOTIFY_MAJOR_OPEN
:
2909 ND_PRINT(", subcode %s (%u)",
2910 tok2str(bgp_notify_minor_open_values
, "Unknown",
2914 case BGP_NOTIFY_MAJOR_UPDATE
:
2915 ND_PRINT(", subcode %s (%u)",
2916 tok2str(bgp_notify_minor_update_values
, "Unknown",
2920 case BGP_NOTIFY_MAJOR_FSM
:
2921 ND_PRINT(" subcode %s (%u)",
2922 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
2926 case BGP_NOTIFY_MAJOR_CAP
:
2927 ND_PRINT(" subcode %s (%u)",
2928 tok2str(bgp_notify_minor_cap_values
, "Unknown",
2932 case BGP_NOTIFY_MAJOR_CEASE
:
2933 ND_PRINT(", subcode %s (%u)",
2934 tok2str(bgp_notify_minor_cease_values
, "Unknown",
2938 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2939 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2941 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2942 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2944 ND_PRINT(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2945 tok2str(af_values
, "Unknown", GET_BE_U_2(tptr
)),
2947 tok2str(bgp_safi_values
, "Unknown", GET_U_1((tptr
+ 2))),
2948 GET_U_1((tptr
+ 2)),
2949 GET_BE_U_4(tptr
+ 3));
2952 * draft-ietf-idr-shutdown describes a method to send a communication
2953 * intended for human consumption regarding the Administrative Shutdown
2955 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
2956 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
2957 length
>= BGP_NOTIFICATION_SIZE
+ 1) {
2958 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2960 shutdown_comm_length
= GET_U_1(tptr
);
2961 remainder_offset
= 0;
2962 /* garbage, hexdump it all */
2963 if (shutdown_comm_length
> BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN
||
2964 shutdown_comm_length
> length
- (BGP_NOTIFICATION_SIZE
+ 1)) {
2965 ND_PRINT(", invalid Shutdown Communication length");
2967 else if (shutdown_comm_length
== 0) {
2968 ND_PRINT(", empty Shutdown Communication");
2969 remainder_offset
+= 1;
2971 /* a proper shutdown communication */
2973 ND_TCHECK_LEN(tptr
+ 1, shutdown_comm_length
);
2974 ND_PRINT(", Shutdown Communication (length: %u): \"", shutdown_comm_length
);
2975 (void)nd_printn(ndo
, tptr
+1, shutdown_comm_length
, NULL
);
2977 remainder_offset
+= shutdown_comm_length
+ 1;
2979 /* if there is trailing data, hexdump it */
2980 if(length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
) > 0) {
2981 ND_PRINT(", Data: (length: %u)", length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
2982 hex_print(ndo
, "\n\t\t", tptr
+ remainder_offset
, length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
2992 nd_print_trunc(ndo
);
2996 bgp_route_refresh_print(netdissect_options
*ndo
,
2997 const u_char
*pptr
, u_int len
)
2999 const struct bgp_route_refresh
*bgp_route_refresh_header
;
3001 ND_TCHECK_LEN(pptr
, BGP_ROUTE_REFRESH_SIZE
);
3003 /* some little sanity checking */
3004 if (len
<BGP_ROUTE_REFRESH_SIZE
)
3007 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
3009 ND_PRINT("\n\t AFI %s (%u), SAFI %s (%u)",
3010 tok2str(af_values
,"Unknown",
3011 GET_BE_U_2(bgp_route_refresh_header
->afi
)),
3012 GET_BE_U_2(bgp_route_refresh_header
->afi
),
3013 tok2str(bgp_safi_values
,"Unknown",
3014 GET_U_1(bgp_route_refresh_header
->safi
)),
3015 GET_U_1(bgp_route_refresh_header
->safi
));
3017 if (ndo
->ndo_vflag
> 1) {
3018 ND_TCHECK_LEN(pptr
, len
);
3019 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
3024 nd_print_trunc(ndo
);
3028 bgp_pdu_print(netdissect_options
*ndo
,
3029 const u_char
*dat
, u_int length
)
3031 const struct bgp
*bgp_header
;
3034 ND_TCHECK_LEN(dat
, BGP_SIZE
);
3035 bgp_header
= (const struct bgp
*)dat
;
3036 bgp_type
= GET_U_1(bgp_header
->bgp_type
);
3038 ND_PRINT("\n\t%s Message (%u), length: %u",
3039 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
3045 bgp_open_print(ndo
, dat
, length
);
3048 bgp_update_print(ndo
, dat
, length
);
3050 case BGP_NOTIFICATION
:
3051 bgp_notification_print(ndo
, dat
, length
);
3055 case BGP_ROUTE_REFRESH
:
3056 bgp_route_refresh_print(ndo
, dat
, length
);
3059 /* we have no decoder for the BGP message */
3060 ND_TCHECK_LEN(dat
, length
);
3061 ND_PRINT("\n\t no Message %u decoder", bgp_type
);
3062 print_unknown_data(ndo
, dat
, "\n\t ", length
);
3067 nd_print_trunc(ndo
);
3072 bgp_print(netdissect_options
*ndo
,
3073 const u_char
*dat
, u_int length _U_
)
3076 const u_char
*ep
= ndo
->ndo_snapend
;
3077 const u_char
*start
;
3078 const u_char marker
[] = {
3079 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3080 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3082 const struct bgp
*bgp_header
;
3085 ndo
->ndo_protocol
= "bgp";
3088 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
3096 if (GET_U_1(p
) != 0xff) {
3101 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
3103 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
3108 /* found BGP header */
3109 ND_TCHECK_LEN(p
, BGP_SIZE
);
3110 bgp_header
= (const struct bgp
*)p
;
3113 nd_print_trunc(ndo
);
3115 hlen
= GET_BE_U_2(bgp_header
->bgp_len
);
3116 if (hlen
< BGP_SIZE
) {
3117 ND_PRINT("\nmessage length %u < %u", hlen
, BGP_SIZE
);
3118 nd_print_invalid(ndo
);
3122 if (ND_TTEST_LEN(p
, hlen
)) {
3123 if (!bgp_pdu_print(ndo
, p
, hlen
))
3128 ND_PRINT("\n[|BGP %s]",
3129 tok2str(bgp_msg_values
,
3130 "Unknown Message Type",
3131 GET_U_1(bgp_header
->bgp_type
)));
3139 nd_print_trunc(ndo
);