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 */
39 #include "netdissect-stdinc.h"
44 #include "netdissect.h"
45 #include "addrtoname.h"
51 nd_byte bgp_marker
[16];
55 #define BGP_SIZE 19 /* unaligned */
59 #define BGP_NOTIFICATION 3
60 #define BGP_KEEPALIVE 4
61 #define BGP_ROUTE_REFRESH 5
63 static const struct tok bgp_msg_values
[] = {
65 { BGP_UPDATE
, "Update"},
66 { BGP_NOTIFICATION
, "Notification"},
67 { BGP_KEEPALIVE
, "Keepalive"},
68 { BGP_ROUTE_REFRESH
, "Route Refresh"},
73 nd_byte bgpo_marker
[16];
76 nd_uint8_t bgpo_version
;
77 nd_uint16_t bgpo_myas
;
78 nd_uint16_t bgpo_holdtime
;
80 nd_uint8_t bgpo_optlen
;
81 /* options should follow */
83 #define BGP_OPEN_SIZE 29 /* unaligned */
86 nd_uint8_t bgpopt_type
;
87 nd_uint8_t bgpopt_len
;
90 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
91 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
93 struct bgp_notification
{
94 nd_byte bgpn_marker
[16];
97 nd_uint8_t bgpn_major
;
98 nd_uint8_t bgpn_minor
;
100 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
102 struct bgp_route_refresh
{
103 nd_byte bgp_marker
[16];
105 nd_uint8_t type
; /* No padding after this; afi is, in fact, not aligned */
110 #define BGP_ROUTE_REFRESH_SIZE 23
112 #define bgp_attr_lenlen(flags, p) \
113 (((flags) & 0x10) ? 2U : 1U)
114 #define bgp_attr_len(flags, p) \
115 (((flags) & 0x10) ? GET_BE_U_2(p) : GET_U_1(p))
117 #define BGPTYPE_ORIGIN 1
118 #define BGPTYPE_AS_PATH 2
119 #define BGPTYPE_NEXT_HOP 3
120 #define BGPTYPE_MULTI_EXIT_DISC 4
121 #define BGPTYPE_LOCAL_PREF 5
122 #define BGPTYPE_ATOMIC_AGGREGATE 6
123 #define BGPTYPE_AGGREGATOR 7
124 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
125 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC4456 */
126 #define BGPTYPE_CLUSTER_LIST 10 /* RFC4456 */
127 #define BGPTYPE_DPA 11 /* deprecated, draft-ietf-idr-bgp-dpa */
128 #define BGPTYPE_ADVERTISERS 12 /* deprecated RFC1863 */
129 #define BGPTYPE_RCID_PATH 13 /* deprecated RFC1863 */
130 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */
131 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */
132 #define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */
133 #define BGPTYPE_AS4_PATH 17 /* RFC6793 */
134 #define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */
135 #define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */
136 #define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */
137 #define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */
138 #define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */
139 #define BGPTYPE_AIGP 26 /* RFC7311 */
140 #define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */
141 #define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */
142 #define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */
143 #define BGPTYPE_ATTR_SET 128 /* RFC6368 */
145 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
147 static const struct tok bgp_attr_values
[] = {
148 { BGPTYPE_ORIGIN
, "Origin"},
149 { BGPTYPE_AS_PATH
, "AS Path"},
150 { BGPTYPE_AS4_PATH
, "AS4 Path"},
151 { BGPTYPE_NEXT_HOP
, "Next Hop"},
152 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
153 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
154 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
155 { BGPTYPE_AGGREGATOR
, "Aggregator"},
156 { BGPTYPE_AGGREGATOR4
, "Aggregator4"},
157 { BGPTYPE_COMMUNITIES
, "Community"},
158 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
159 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
160 { BGPTYPE_DPA
, "DPA"},
161 { BGPTYPE_ADVERTISERS
, "Advertisers"},
162 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
163 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
164 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
165 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
166 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
167 { BGPTYPE_TUNNEL_ENCAP
, "Tunnel Encapsulation"},
168 { BGPTYPE_TRAFFIC_ENG
, "Traffic Engineering"},
169 { BGPTYPE_IPV6_EXTD_COMMUNITIES
, "IPv6 Extended Community"},
170 { BGPTYPE_AIGP
, "Accumulated IGP Metric"},
171 { BGPTYPE_PE_DISTINGUISHER_LABEL
, "PE Distinguisher Label"},
172 { BGPTYPE_ENTROPY_LABEL
, "Entropy Label"},
173 { BGPTYPE_LARGE_COMMUNITY
, "Large Community"},
174 { BGPTYPE_ATTR_SET
, "Attribute Set"},
175 { 255, "Reserved for development"},
180 #define BGP_AS_SEQUENCE 2
181 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
182 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
184 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
185 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
187 static const struct tok bgp_as_path_segment_open_values
[] = {
188 { BGP_AS_SEQUENCE
, ""},
190 { BGP_CONFED_AS_SEQUENCE
, "( "},
191 { BGP_CONFED_AS_SET
, "({ "},
195 static const struct tok bgp_as_path_segment_close_values
[] = {
196 { BGP_AS_SEQUENCE
, ""},
198 { BGP_CONFED_AS_SEQUENCE
, ")"},
199 { BGP_CONFED_AS_SET
, "})"},
203 #define BGP_OPT_AUTH 1
204 #define BGP_OPT_CAP 2
206 static const struct tok bgp_opt_values
[] = {
207 { BGP_OPT_AUTH
, "Authentication Information"},
208 { BGP_OPT_CAP
, "Capabilities Advertisement"},
212 #define BGP_CAPCODE_MP 1 /* RFC2858 */
213 #define BGP_CAPCODE_RR 2 /* RFC2918 */
214 #define BGP_CAPCODE_ORF 3 /* RFC5291 */
215 #define BGP_CAPCODE_MR 4 /* RFC3107 */
216 #define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */
217 #define BGP_CAPCODE_ML 8 /* RFC8277 */
218 #define BGP_CAPCODE_RESTART 64 /* RFC4724 */
219 #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */
220 #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */
221 #define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */
222 #define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */
223 #define BGP_CAPCODE_ENH_RR 70 /* draft-keyur-bgp-enhanced-route-refresh */
224 #define BGP_CAPCODE_LLGR 71 /* draft-uttaro-idr-bgp-persistence-05 */
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_ML
, "Multiple Labels"},
234 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
235 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
236 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
237 { BGP_CAPCODE_MULTISESS
, "Multisession BGP"},
238 { BGP_CAPCODE_ADD_PATH
, "Multiple Paths"},
239 { BGP_CAPCODE_ENH_RR
, "Enhanced Route Refresh"},
240 { BGP_CAPCODE_LLGR
, "Long-lived Graceful Restart"},
241 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
245 #define BGP_NOTIFY_MAJOR_MSG 1
246 #define BGP_NOTIFY_MAJOR_OPEN 2
247 #define BGP_NOTIFY_MAJOR_UPDATE 3
248 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
249 #define BGP_NOTIFY_MAJOR_FSM 5
250 #define BGP_NOTIFY_MAJOR_CEASE 6
251 #define BGP_NOTIFY_MAJOR_CAP 7
253 static const struct tok bgp_notify_major_values
[] = {
254 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
255 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
256 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
257 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
258 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
259 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
260 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
265 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
266 #define BGP_NOTIFY_MINOR_CEASE_SHUT 2
267 #define BGP_NOTIFY_MINOR_CEASE_RESET 4
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_EVPN 70
384 #define SAFNUM_VPNUNICAST 128
386 #define SAFNUM_VPNMULTICAST 129
387 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
389 #define SAFNUM_RT_ROUTING_INFO 132
391 #define BGP_VPN_RD_LEN 8
393 static const struct tok bgp_safi_values
[] = {
394 { SAFNUM_RES
, "Reserved"},
395 { SAFNUM_UNICAST
, "Unicast"},
396 { SAFNUM_MULTICAST
, "Multicast"},
397 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
398 { SAFNUM_LABUNICAST
, "labeled Unicast"},
399 { SAFNUM_TUNNEL
, "Tunnel"},
400 { SAFNUM_VPLS
, "VPLS"},
401 { SAFNUM_MDT
, "MDT"},
402 { SAFNUM_EVPN
, "EVPN"},
403 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
404 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
405 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
406 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
407 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
411 /* well-known community */
412 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
413 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
414 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
416 /* Extended community type - RFC 4360 */
417 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
418 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
419 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
420 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
421 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
422 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
423 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
424 /* rfc2547 bgp-mpls-vpns */
425 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
426 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatibility */
427 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatibility */
428 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatibility */
430 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
431 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatibility */
432 #define BGP_EXT_COM_ENCAP 0x030c /* rfc5512 */
434 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
435 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatibility */
437 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
439 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
440 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
441 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
442 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
444 /* https://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
445 #define BGP_EXT_COM_EIGRP_GEN 0x8800
446 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
447 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
448 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
449 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
450 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
452 static const struct tok bgp_extd_comm_flag_values
[] = {
453 { 0x8000, "vendor-specific"},
454 { 0x4000, "non-transitive"},
458 static const struct tok bgp_extd_comm_subtype_values
[] = {
459 { BGP_EXT_COM_RT_0
, "target"},
460 { BGP_EXT_COM_RT_1
, "target"},
461 { BGP_EXT_COM_RT_2
, "target"},
462 { BGP_EXT_COM_RO_0
, "origin"},
463 { BGP_EXT_COM_RO_1
, "origin"},
464 { BGP_EXT_COM_RO_2
, "origin"},
465 { BGP_EXT_COM_LINKBAND
, "link-BW"},
466 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
467 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
468 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
469 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
470 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
471 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
472 { BGP_EXT_COM_ENCAP
, "encapsulation"},
473 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
474 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
475 { BGP_EXT_COM_L2INFO
, "layer2-info"},
476 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
477 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
478 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
479 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
480 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
481 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
482 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
483 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
484 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
485 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
489 /* RFC RFC5512 BGP Tunnel Encapsulation Attribute Tunnel Types */
490 #define BGP_ENCAP_TUNNEL_L2TPV3_IP 1
491 #define BGP_ENCAP_TUNNEL_GRE 2
492 #define BGP_ENCAP_TUNNEL_TRANSMIT 3
493 #define BGP_ENCAP_TUNNEL_IPSEC 4
494 #define BGP_ENCAP_TUNNEL_IP_IPSEC 5
495 #define BGP_ENCAP_TUNNEL_MPLS_IP 6
496 #define BGP_ENCAP_TUNNEL_IP_IP 7
497 #define BGP_ENCAP_TUNNEL_VXLAN 8
498 #define BGP_ENCAP_TUNNEL_NVGRE 9
499 #define BGP_ENCAP_TUNNEL_MPLS 10
500 #define BGP_ENCAP_TUNNEL_MPLS_GRE 11
501 #define BGP_ENCAP_TUNNEL_VXLAN_GPE 12
502 #define BGP_ENCAP_TUNNEL_MPLS_UDP 13
503 #define BGP_ENCAP_TUNNEL_IPV6 14
504 #define BGP_ENCAP_TUNNEL_SR_TE 15
505 #define BGP_ENCAP_TUNNEL_BARE 16
506 #define BGP_ENCAP_TUNNEL_SR 17
508 static const struct tok bgp_extd_comm_encap_tunnel_values
[] = {
509 { BGP_ENCAP_TUNNEL_L2TPV3_IP
, "L2TPv3 over IP"},
510 { BGP_ENCAP_TUNNEL_GRE
, "GRE"},
511 { BGP_ENCAP_TUNNEL_TRANSMIT
, "Transmit Tunnel"},
512 { BGP_ENCAP_TUNNEL_IPSEC
, "IPsec"},
513 { BGP_ENCAP_TUNNEL_IP_IPSEC
, "IP in IP with IPsec"},
514 { BGP_ENCAP_TUNNEL_MPLS_IP
, "MPLS in IP with IPsec"},
515 { BGP_ENCAP_TUNNEL_IP_IP
, "IP in IP"},
516 { BGP_ENCAP_TUNNEL_VXLAN
, "VXLAN"},
517 { BGP_ENCAP_TUNNEL_NVGRE
, "NVGRE"},
518 { BGP_ENCAP_TUNNEL_MPLS
, "MPLS"},
519 { BGP_ENCAP_TUNNEL_MPLS_GRE
, "MPLS in GRE"},
520 { BGP_ENCAP_TUNNEL_VXLAN_GPE
, "VXLAN GPE"},
521 { BGP_ENCAP_TUNNEL_MPLS_UDP
, "MPLS in UDP"},
522 { BGP_ENCAP_TUNNEL_IPV6
, "IPv6"},
523 { BGP_ENCAP_TUNNEL_SR_TE
, "SR TE"},
524 { BGP_ENCAP_TUNNEL_BARE
, "Bare"},
525 { BGP_ENCAP_TUNNEL_SR
, "SR"},
529 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
530 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
531 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
532 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
533 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
534 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
535 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
536 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
538 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
539 { BGP_OSPF_RTYPE_RTR
, "Router" },
540 { BGP_OSPF_RTYPE_NET
, "Network" },
541 { BGP_OSPF_RTYPE_SUM
, "Summary" },
542 { BGP_OSPF_RTYPE_EXT
, "External" },
543 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
544 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
548 /* ADD-PATH Send/Receive field values */
549 static const struct tok bgp_add_path_recvsend
[] = {
556 #define AS_STR_SIZE sizeof("xxxxx.xxxxx")
561 * Convert an AS number into a string and return string pointer.
563 * Depending on bflag is set or not, AS number is converted into ASDOT notation
564 * or plain number notation.
568 as_printf(netdissect_options
*ndo
,
569 char *str
, size_t size
, u_int asnum
)
571 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
572 snprintf(str
, size
, "%u", asnum
);
574 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
579 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
582 decode_prefix4(netdissect_options
*ndo
,
583 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
586 u_int plen
, plenbytes
;
589 plen
= GET_U_1(pptr
);
594 memset(&addr
, 0, sizeof(addr
));
595 plenbytes
= (plen
+ 7) / 8;
596 ITEMCHECK(plenbytes
);
597 GET_CPY_BYTES(&addr
, pptr
+ 1, plenbytes
);
599 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
601 snprintf(buf
, buflen
, "%s/%u", ipaddr_string(ndo
, (const u_char
*)&addr
), plen
);
602 return 1 + plenbytes
;
609 decode_labeled_prefix4(netdissect_options
*ndo
,
610 const u_char
*pptr
, u_int itemlen
, char *buf
,
614 u_int plen
, plenbytes
;
616 /* prefix length and label = 4 bytes */
619 plen
= GET_U_1(pptr
); /* get prefix length */
621 /* this is one of the weirdnesses of rfc3107
622 the label length (actually the label + COS bits)
623 is added to the prefix length;
624 we also do only read out just one label -
625 there is no real application for advertisement of
626 stacked labels in a single BGP message
632 plen
-=24; /* adjust prefixlen - labellength */
638 memset(&addr
, 0, sizeof(addr
));
639 plenbytes
= (plen
+ 7) / 8;
640 ITEMCHECK(plenbytes
);
641 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
643 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
645 /* the label may get offsetted by 4 bits so lets shift it right */
646 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
647 ipaddr_string(ndo
, (const u_char
*)&addr
),
649 GET_BE_U_3(pptr
+ 1)>>4,
650 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
652 return 4 + plenbytes
;
664 * print an ipv4 or ipv6 address into a buffer dependent on address length.
667 bgp_vpn_ip_print(netdissect_options
*ndo
,
668 const u_char
*pptr
, u_int addr_length
)
671 /* worst case string is s fully formatted v6 address */
672 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
675 switch(addr_length
) {
676 case (sizeof(nd_ipv4
) << 3): /* 32 */
677 snprintf(pos
, sizeof(addr
), "%s", GET_IPADDR_STRING(pptr
));
679 case (sizeof(nd_ipv6
) << 3): /* 128 */
680 snprintf(pos
, sizeof(addr
), "%s", GET_IP6ADDR_STRING(pptr
));
683 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
695 * print an multicast s,g entry into a buffer.
696 * the s,g entry is encoded like this.
698 * +-----------------------------------+
699 * | Multicast Source Length (1 octet) |
700 * +-----------------------------------+
701 * | Multicast Source (Variable) |
702 * +-----------------------------------+
703 * | Multicast Group Length (1 octet) |
704 * +-----------------------------------+
705 * | Multicast Group (Variable) |
706 * +-----------------------------------+
708 * return the number of bytes read from the wire.
711 bgp_vpn_sg_print(netdissect_options
*ndo
,
712 const u_char
*pptr
, char *buf
, size_t buflen
)
715 u_int total_length
, offset
;
719 /* Source address length, encoded in bits */
720 addr_length
= GET_U_1(pptr
);
724 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
725 total_length
+= (addr_length
>> 3) + 1;
726 offset
= (u_int
)strlen(buf
);
728 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
729 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
730 pptr
+= (addr_length
>> 3);
733 /* Group address length, encoded in bits */
734 addr_length
= GET_U_1(pptr
);
738 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
739 total_length
+= (addr_length
>> 3) + 1;
740 offset
= (u_int
)strlen(buf
);
742 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
743 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
744 pptr
+= (addr_length
>> 3);
748 return (total_length
);
751 /* Print an RFC 4364 Route Distinguisher */
753 bgp_vpn_rd_print(netdissect_options
*ndo
,
756 /* allocate space for the largest possible string */
757 static char rd
[sizeof("xxxxx.xxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
759 /* allocate space for the largest possible string */
760 char astostr
[AS_STR_SIZE
];
762 /* ok lets load the RD format */
763 switch (GET_BE_U_2(pptr
)) {
766 /* 2-byte-AS:number fmt */
767 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
768 GET_BE_U_2(pptr
+ 2),
769 GET_BE_U_4(pptr
+ 4),
770 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
771 GET_U_1(pptr
+ 6), GET_U_1(pptr
+ 7));
775 /* IP-address:AS fmt */
776 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
777 GET_U_1(pptr
+ 2), GET_U_1(pptr
+ 3),
778 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
779 GET_BE_U_2(pptr
+ 6));
783 /* 4-byte-AS:number fmt */
784 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
785 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 2)),
786 GET_BE_U_2(pptr
+ 6), GET_U_1(pptr
+ 2),
787 GET_U_1(pptr
+ 3), GET_U_1(pptr
+ 4),
788 GET_U_1(pptr
+ 5), GET_BE_U_2(pptr
+ 6));
791 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
800 * Print an RFC 4360 Extended Community.
803 bgp_extended_community_print(netdissect_options
*ndo
,
806 union { /* copy buffer for bandwidth values */
810 /* allocate space for the largest possible string */
811 char astostr
[AS_STR_SIZE
];
813 switch (GET_BE_U_2(pptr
)) {
815 case BGP_EXT_COM_RT_0
:
816 case BGP_EXT_COM_RO_0
:
817 case BGP_EXT_COM_L2VPN_RT_0
:
818 ND_PRINT("%u:%u (= %s)",
819 GET_BE_U_2(pptr
+ 2),
820 GET_BE_U_4(pptr
+ 4),
821 GET_IPADDR_STRING(pptr
+4));
824 case BGP_EXT_COM_RT_1
:
825 case BGP_EXT_COM_RO_1
:
826 case BGP_EXT_COM_L2VPN_RT_1
:
827 case BGP_EXT_COM_VRF_RT_IMP
:
829 GET_IPADDR_STRING(pptr
+2),
830 GET_BE_U_2(pptr
+ 6));
833 case BGP_EXT_COM_RT_2
:
834 case BGP_EXT_COM_RO_2
:
836 as_printf(ndo
, astostr
, sizeof(astostr
),
837 GET_BE_U_4(pptr
+ 2)), GET_BE_U_2(pptr
+ 6));
840 case BGP_EXT_COM_LINKBAND
:
841 bw
.i
= GET_BE_U_4(pptr
+ 4);
842 ND_PRINT("bandwidth: %.3f Mbps",
846 case BGP_EXT_COM_VPN_ORIGIN
:
847 case BGP_EXT_COM_VPN_ORIGIN2
:
848 case BGP_EXT_COM_VPN_ORIGIN3
:
849 case BGP_EXT_COM_VPN_ORIGIN4
:
850 case BGP_EXT_COM_OSPF_RID
:
851 case BGP_EXT_COM_OSPF_RID2
:
852 ND_PRINT("%s", GET_IPADDR_STRING(pptr
+2));
855 case BGP_EXT_COM_OSPF_RTYPE
:
856 case BGP_EXT_COM_OSPF_RTYPE2
:
857 ND_PRINT("area:%s, router-type:%s, metric-type:%s%s",
858 GET_IPADDR_STRING(pptr
+2),
859 tok2str(bgp_extd_comm_ospf_rtype_values
,
861 GET_U_1((pptr
+ 6))),
862 (GET_U_1(pptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
863 ((GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
866 case BGP_EXT_COM_L2INFO
:
867 ND_PRINT("%s Control Flags [0x%02x]:MTU %u",
868 tok2str(l2vpn_encaps_values
,
870 GET_U_1((pptr
+ 2))),
872 GET_BE_U_2(pptr
+ 4));
875 case BGP_EXT_COM_SOURCE_AS
:
876 ND_PRINT("AS %u", GET_BE_U_2(pptr
+ 2));
879 case BGP_EXT_COM_ENCAP
:
880 ND_PRINT("Tunnel type: %s", tok2str(bgp_extd_comm_encap_tunnel_values
,
882 GET_BE_U_2(pptr
+ 6)));
886 ND_PRINT("%02x%02x%02x%02x%02x%02x",
898 * RFC4684 (Section 4)/RFC2858 (Section 4).
899 * RTC membership prefix is structured as follows
900 * [prefix-len] [origin-as] [route-target]
901 * The route-target is encoded as RT ext-comms.
902 * Prefix-len may be 0, 32..96
904 * Note that pptr is not packet data - it is
905 * a buffer owned by our caller - therefore GET_*
906 * macros can not be used.
909 bgp_rt_prefix_print(netdissect_options
*ndo
,
913 /* allocate space for the largest possible string */
914 char rtc_prefix_in_hex
[sizeof("0000 0000 0000 0000")] = "";
915 u_int rtc_prefix_in_hex_len
= 0;
916 static char output
[61]; /* max response string */
917 /* allocate space for the largest possible string */
918 char astostr
[AS_STR_SIZE
];
919 uint16_t ec_type
= 0;
924 snprintf(output
, sizeof(output
), "route-target: 0:0/0");
928 /* hex representation of the prefix */
929 octet_count
= (plen
+7)/8;
930 for (i
=0; i
<octet_count
; i
++) {
931 rtc_prefix_in_hex_len
+= snprintf(rtc_prefix_in_hex
+rtc_prefix_in_hex_len
,
932 sizeof(rtc_prefix_in_hex
)-rtc_prefix_in_hex_len
,
934 ((i
%2 == 1) && (i
<octet_count
-1)) ? " " : "");
939 * The prefix is too short to include the full ext-comm type,
940 * so we have no way to parse it further.
942 snprintf(output
, sizeof(output
), "route-target: partial-type: (%s/%d)",
943 rtc_prefix_in_hex
, plen
);
948 * get the ext-comm type
949 * Note: pptr references a static 8 octet buffer with unused bits set to 0,
950 * hence EXTRACT_*() macros are safe.
952 ec_type
= EXTRACT_BE_U_2(pptr
);
954 case BGP_EXT_COM_RT_0
:
955 /* 2-byte-AS:number fmt */
956 snprintf(output
, sizeof(output
), "route-target: %u:%u/%d (%s)",
957 EXTRACT_BE_U_2(pptr
+2),
958 EXTRACT_BE_U_4(pptr
+4),
959 plen
, rtc_prefix_in_hex
);
962 case BGP_EXT_COM_RT_1
:
963 /* IP-address:AS fmt */
964 snprintf(output
, sizeof(output
), "route-target: %u.%u.%u.%u:%u/%d (%s)",
965 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5),
966 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
969 case BGP_EXT_COM_RT_2
:
970 /* 4-byte-AS:number fmt */
971 snprintf(output
, sizeof(output
), "route-target: %s:%u/%d (%s)",
972 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(pptr
+2)),
973 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
977 snprintf(output
, sizeof(output
), "route target: unknown-type(%04x) (%s/%d)",
979 rtc_prefix_in_hex
, plen
);
987 decode_rt_routing_info(netdissect_options
*ndo
,
990 uint8_t route_target
[8];
992 /* allocate space for the largest possible string */
993 char astostr
[AS_STR_SIZE
];
996 /* NLRI "prefix length" from RFC 2858 Section 4. */
997 plen
= GET_U_1(pptr
); /* get prefix length */
999 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
1000 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
1001 * target" fields inside the "prefix" depending on its length.
1004 /* Without "origin AS", without "route target". */
1005 ND_PRINT("\n\t default route target");
1010 ND_PRINT("\n\t (illegal prefix length)");
1014 /* With at least "origin AS", possibly with "route target". */
1015 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 1));
1017 plen
-= 32; /* adjust prefix length */
1020 ND_PRINT("\n\t (illegal prefix length)");
1024 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
1025 * and gives the number of octets in the variable-length "route
1026 * target" field inside this NLRI "prefix". Look for it.
1028 memset(&route_target
, 0, sizeof(route_target
));
1029 num_octets
= (plen
+ 7) / 8;
1030 GET_CPY_BYTES(&route_target
, pptr
+ 5, num_octets
);
1031 /* If mask-len is not on octet boundary, ensure all extra bits are 0 */
1033 ((u_char
*)&route_target
)[num_octets
- 1] &=
1034 ((0xff00 >> (plen
% 8)) & 0xff);
1036 ND_PRINT("\n\t origin AS: %s, %s",
1038 bgp_rt_prefix_print(ndo
, (u_char
*)&route_target
, plen
));
1040 return 5 + num_octets
;
1044 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
1045 const u_char
*pptr
, char *buf
, size_t buflen
)
1050 plen
= GET_U_1(pptr
); /* get prefix length */
1055 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1060 memset(&addr
, 0, sizeof(addr
));
1061 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1063 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
1064 ((0xff00 >> (plen
% 8)) & 0xff);
1066 /* the label may get offsetted by 4 bits so lets shift it right */
1067 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1068 bgp_vpn_rd_print(ndo
, pptr
+4),
1069 ipaddr_string(ndo
, (const u_char
*)&addr
),
1071 GET_BE_U_3(pptr
+ 1)>>4,
1072 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1074 return 12 + (plen
+ 7) / 8;
1078 * +-------------------------------+
1080 * | RD:IPv4-address (12 octets) |
1082 * +-------------------------------+
1083 * | MDT Group-address (4 octets) |
1084 * +-------------------------------+
1087 #define MDT_VPN_NLRI_LEN 16
1090 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
1091 const u_char
*pptr
, char *buf
, size_t buflen
)
1094 const u_char
*vpn_ip
;
1096 /* if the NLRI is not predefined length, quit.*/
1097 if (GET_U_1(pptr
) != MDT_VPN_NLRI_LEN
* 8)
1108 pptr
+= sizeof(nd_ipv4
);
1110 /* MDT Group Address */
1111 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
1112 bgp_vpn_rd_print(ndo
, rd
), GET_IPADDR_STRING(vpn_ip
), GET_IPADDR_STRING(pptr
));
1114 return MDT_VPN_NLRI_LEN
+ 1;
1120 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
1121 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
1122 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
1123 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
1124 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
1125 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
1126 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
1128 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
1129 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
1130 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
1131 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
1132 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
1133 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
1134 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
1135 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
1140 decode_multicast_vpn(netdissect_options
*ndo
,
1141 const u_char
*pptr
, char *buf
, size_t buflen
)
1143 /* allocate space for the largest possible string */
1144 char astostr
[AS_STR_SIZE
];
1145 uint8_t route_type
, route_length
;
1146 u_int addr_length
, sg_length
;
1149 route_type
= GET_U_1(pptr
);
1151 route_length
= GET_U_1(pptr
);
1154 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
1155 tok2str(bgp_multicast_vpn_route_type_values
,
1156 "Unknown", route_type
),
1157 route_type
, route_length
);
1159 switch(route_type
) {
1160 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
1161 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1162 if (route_length
< BGP_VPN_RD_LEN
)
1164 offset
= (u_int
)strlen(buf
);
1165 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
1166 bgp_vpn_rd_print(ndo
, pptr
),
1167 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
1168 (route_length
- BGP_VPN_RD_LEN
) << 3));
1170 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
1171 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1172 offset
= (u_int
)strlen(buf
);
1173 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1174 bgp_vpn_rd_print(ndo
, pptr
),
1175 as_printf(ndo
, astostr
, sizeof(astostr
),
1176 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1179 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
1180 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1181 offset
= (u_int
)strlen(buf
);
1182 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1183 bgp_vpn_rd_print(ndo
, pptr
));
1184 pptr
+= BGP_VPN_RD_LEN
;
1186 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1187 addr_length
= route_length
- sg_length
;
1189 ND_TCHECK_LEN(pptr
, addr_length
);
1190 offset
= (u_int
)strlen(buf
);
1191 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
1192 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
1195 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
1196 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1197 offset
= (u_int
)strlen(buf
);
1198 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1199 bgp_vpn_rd_print(ndo
, pptr
));
1200 pptr
+= BGP_VPN_RD_LEN
;
1202 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1205 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
1206 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
1207 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1208 offset
= (u_int
)strlen(buf
);
1209 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1210 bgp_vpn_rd_print(ndo
, pptr
),
1211 as_printf(ndo
, astostr
, sizeof(astostr
),
1212 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1213 pptr
+= BGP_VPN_RD_LEN
+ 4;
1215 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1219 * no per route-type printing yet.
1221 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1226 return route_length
+ 2;
1233 * As I remember, some versions of systems have an snprintf() that
1234 * returns -1 if the buffer would have overflowed. If the return
1235 * value is negative, set buflen to 0, to indicate that we've filled
1238 * If the return value is greater than buflen, that means that
1239 * the buffer would have overflowed; again, set buflen to 0 in
1242 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1245 else if ((u_int)stringlen>buflen) \
1248 buflen-=stringlen; \
1253 decode_labeled_vpn_l2(netdissect_options
*ndo
,
1254 const u_char
*pptr
, char *buf
, size_t buflen
)
1256 u_int plen
, tlen
, tlv_type
, tlv_len
, ttlv_len
;
1259 plen
= GET_BE_U_2(pptr
);
1262 /* Old and new L2VPN NLRI share AFI/SAFI
1263 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1264 * and > 17 as old format. Complain for the middle case
1267 /* assume AD-only with RD, BGPNH */
1268 ND_TCHECK_LEN(pptr
, 12);
1270 stringlen
= snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
1271 bgp_vpn_rd_print(ndo
, pptr
),
1272 GET_IPADDR_STRING(pptr
+8));
1273 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1277 } else if (plen
> 17) {
1278 /* assume old format */
1279 /* RD, ID, LBLKOFF, LBLBASE */
1281 ND_TCHECK_LEN(pptr
, 15);
1283 stringlen
= snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1284 bgp_vpn_rd_print(ndo
, pptr
),
1285 GET_BE_U_2(pptr
+ 8),
1286 GET_BE_U_2(pptr
+ 10),
1287 GET_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1288 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1292 /* ok now the variable part - lets read out TLVs*/
1296 stringlen
=snprintf(buf
,buflen
, "\n\t\tran past the end");
1297 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1301 tlv_type
= GET_U_1(pptr
);
1303 tlv_len
= GET_BE_U_2(pptr
); /* length, in *bits* */
1304 ttlv_len
= (tlv_len
+ 7)/8; /* length, in *bytes* */
1310 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1313 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1315 while (ttlv_len
!= 0) {
1318 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1319 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1325 stringlen
=snprintf(buf
,buflen
, "%02x",
1328 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1336 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1339 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1341 if (tlen
< ttlv_len
) {
1343 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1344 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1354 /* complain bitterly ? */
1364 decode_prefix6(netdissect_options
*ndo
,
1365 const u_char
*pd
, u_int itemlen
, char *buf
, size_t buflen
)
1368 u_int plen
, plenbytes
;
1376 memset(&addr
, 0, sizeof(addr
));
1377 plenbytes
= (plen
+ 7) / 8;
1378 ITEMCHECK(plenbytes
);
1379 GET_CPY_BYTES(&addr
, pd
+ 1, plenbytes
);
1381 addr
[plenbytes
- 1] &=
1382 ((0xff00 >> (plen
% 8)) & 0xff);
1384 snprintf(buf
, buflen
, "%s/%u", ip6addr_string(ndo
, (const u_char
*)&addr
), plen
);
1385 return 1 + plenbytes
;
1392 decode_labeled_prefix6(netdissect_options
*ndo
,
1393 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
1396 u_int plen
, plenbytes
;
1398 /* prefix length and label = 4 bytes */
1401 plen
= GET_U_1(pptr
); /* get prefix length */
1406 plen
-= 24; /* adjust prefixlen - labellength */
1412 memset(&addr
, 0, sizeof(addr
));
1413 plenbytes
= (plen
+ 7) / 8;
1414 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
1416 addr
[plenbytes
- 1] &=
1417 ((0xff00 >> (plen
% 8)) & 0xff);
1419 /* the label may get offsetted by 4 bits so lets shift it right */
1420 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
1421 ip6addr_string(ndo
, (const u_char
*)&addr
),
1423 GET_BE_U_3(pptr
+ 1)>>4,
1424 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1426 return 4 + plenbytes
;
1436 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1437 const u_char
*pptr
, char *buf
, size_t buflen
)
1442 plen
= GET_U_1(pptr
); /* get prefix length */
1447 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1452 memset(&addr
, 0, sizeof(addr
));
1453 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1455 addr
[(plen
+ 7) / 8 - 1] &=
1456 ((0xff00 >> (plen
% 8)) & 0xff);
1458 /* the label may get offsetted by 4 bits so lets shift it right */
1459 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1460 bgp_vpn_rd_print(ndo
, pptr
+4),
1461 ip6addr_string(ndo
, (const u_char
*)&addr
),
1463 GET_BE_U_3(pptr
+ 1)>>4,
1464 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1466 return 12 + (plen
+ 7) / 8;
1470 decode_clnp_prefix(netdissect_options
*ndo
,
1471 const u_char
*pptr
, char *buf
, size_t buflen
)
1476 plen
= GET_U_1(pptr
); /* get prefix length */
1481 memset(&addr
, 0, sizeof(addr
));
1482 GET_CPY_BYTES(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1484 addr
[(plen
+ 7) / 8 - 1] &=
1485 ((0xff00 >> (plen
% 8)) & 0xff);
1487 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1488 snprintf(buf
, buflen
, "%s/%u",
1489 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1492 return 1 + (plen
+ 7) / 8;
1496 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1497 const u_char
*pptr
, char *buf
, size_t buflen
)
1502 plen
= GET_U_1(pptr
); /* get prefix length */
1507 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1512 memset(&addr
, 0, sizeof(addr
));
1513 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1515 addr
[(plen
+ 7) / 8 - 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
1517 /* the label may get offsetted by 4 bits so lets shift it right */
1518 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1519 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1520 bgp_vpn_rd_print(ndo
, pptr
+4),
1521 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1523 GET_BE_U_3(pptr
+ 1)>>4,
1524 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1526 return 12 + (plen
+ 7) / 8;
1530 * bgp_attr_get_as_size
1532 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1533 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1534 * support, exchange AS-Path with the same path-attribute type value 0x02.
1537 bgp_attr_get_as_size(netdissect_options
*ndo
,
1538 uint8_t bgpa_type
, const u_char
*pptr
, u_int len
)
1540 const u_char
*tptr
= pptr
;
1543 * If the path attribute is the optional AS4 path type, then we already
1544 * know, that ASs must be encoded in 4 byte format.
1546 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1551 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1552 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1555 while (tptr
< pptr
+ len
) {
1557 * If we do not find a valid segment type, our guess might be wrong.
1559 if (GET_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| GET_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1562 tptr
+= 2 + GET_U_1(tptr
+ 1) * 2;
1566 * If we correctly reached end of the AS path attribute data content,
1567 * then most likely ASs were indeed encoded as 2 bytes.
1569 if (tptr
== pptr
+ len
) {
1576 * We can come here, either we did not have enough data, or if we
1577 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1578 * so that caller can try to decode each AS as of 4 bytes. If indeed
1579 * there was not enough data, it will crib and end the parse anyways.
1585 * The only way to know that a BGP UPDATE message is using add path is
1586 * by checking if the capability is in the OPEN message which we may have missed.
1587 * So this function checks if it is possible that the update could contain add path
1588 * and if so it checks that standard BGP doesn't make sense.
1591 check_add_path(netdissect_options
*ndo
, const u_char
*pptr
, u_int length
,
1592 u_int max_prefix_length
)
1594 u_int offset
, prefix_length
;
1601 * Scan through the NLRI information under the assumption that
1602 * it doesn't have path IDs.
1604 for (offset
= 0; offset
< length
;) {
1606 if (!ND_TTEST_1(pptr
+ offset
)) {
1607 /* We ran out of captured data; quit scanning. */
1610 prefix_length
= GET_U_1(pptr
+ offset
);
1612 * Add 4 to cover the path id
1613 * and check the prefix length isn't greater than 32/128.
1615 if (prefix_length
> max_prefix_length
) {
1618 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1619 offset
+= 1 + ((prefix_length
+ 7) / 8);
1621 /* check we haven't gone past the end of the section */
1622 if (offset
> length
) {
1626 /* check it's not standard BGP */
1627 for (offset
= 0; offset
< length
; ) {
1628 if (!ND_TTEST_1(pptr
+ offset
)) {
1629 /* We ran out of captured data; quit scanning. */
1632 prefix_length
= GET_U_1(pptr
+ offset
);
1634 * If the prefix_length is zero (0.0.0.0/0)
1635 * and since it's not the only address (length >= 5)
1636 * then it is add-path
1638 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1641 offset
+= 1 + ((prefix_length
+ 7) / 8);
1643 if (offset
> length
) {
1647 /* assume not add-path by default */
1652 bgp_mp_af_print(netdissect_options
*ndo
,
1653 const u_char
*tptr
, u_int tlen
,
1654 uint16_t *afp
, uint8_t *safip
)
1659 af
= GET_BE_U_2(tptr
);
1661 safi
= GET_U_1(tptr
+ 2);
1664 ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1665 tok2str(af_values
, "Unknown AFI", af
),
1667 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1668 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1671 switch(af
<<8 | safi
) {
1672 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1673 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1674 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1675 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1676 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1677 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1678 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1679 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1680 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1681 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1682 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1683 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1684 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1685 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1686 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1687 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1688 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1689 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1690 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1691 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1692 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1693 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1694 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1695 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1696 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1697 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1698 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1701 ND_TCHECK_LEN(tptr
, tlen
);
1702 ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af
, safi
);
1703 if (ndo
->ndo_vflag
<= 1)
1704 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1713 bgp_nlri_print(netdissect_options
*ndo
, uint16_t af
, uint8_t safi
,
1714 const u_char
*tptr
, u_int len
,
1715 char *buf
, size_t buflen
,
1716 int add_path4
, int add_path6
)
1721 switch (af
<<8 | safi
) {
1722 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1723 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1724 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1726 path_id
= GET_BE_U_4(tptr
);
1729 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1731 ND_PRINT("\n\t (illegal prefix length)");
1732 else if (advance
== -2)
1733 break; /* bytes left, but not enough */
1735 ND_PRINT("\n\t %s", buf
);
1737 ND_PRINT(" Path Id: %u", path_id
);
1741 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1742 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1744 ND_PRINT("\n\t (illegal prefix length)");
1745 else if (advance
== -2)
1747 else if (advance
== -3)
1748 break; /* bytes left, but not enough */
1750 ND_PRINT("\n\t %s", buf
);
1752 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1753 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1754 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1755 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, buflen
);
1757 ND_PRINT("\n\t (illegal prefix length)");
1759 ND_PRINT("\n\t %s", buf
);
1761 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1762 advance
= decode_rt_routing_info(ndo
, tptr
);
1764 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1765 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1766 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, buflen
);
1768 ND_PRINT("\n\t (illegal prefix length)");
1769 else if (advance
== -2)
1772 ND_PRINT("\n\t %s", buf
);
1775 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1776 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, buflen
);
1778 ND_PRINT("\n\t (illegal prefix length)");
1779 else if (advance
== -2)
1782 ND_PRINT("\n\t %s", buf
);
1784 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1785 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1786 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1788 path_id
= GET_BE_U_4(tptr
);
1791 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1793 ND_PRINT("\n\t (illegal prefix length)");
1794 else if (advance
== -2)
1795 break; /* bytes left, but not enough */
1797 ND_PRINT("\n\t %s", buf
);
1799 ND_PRINT(" Path Id: %u", path_id
);
1803 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1804 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1806 ND_PRINT("\n\t (illegal prefix length)");
1807 else if (advance
== -2)
1809 else if (advance
== -3)
1810 break; /* bytes left, but not enough */
1812 ND_PRINT("\n\t %s", buf
);
1814 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1815 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1816 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1817 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, buflen
);
1819 ND_PRINT("\n\t (illegal prefix length)");
1821 ND_PRINT("\n\t %s", buf
);
1823 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1824 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1825 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1826 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1827 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, buflen
);
1829 ND_PRINT("\n\t (illegal length)");
1830 else if (advance
== -2)
1833 ND_PRINT("\n\t %s", buf
);
1835 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1836 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1837 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1838 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1840 ND_PRINT("\n\t (illegal prefix length)");
1842 ND_PRINT("\n\t %s", buf
);
1844 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1845 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1846 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1847 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1849 ND_PRINT("\n\t (illegal prefix length)");
1851 ND_PRINT("\n\t %s", buf
);
1855 * This should not happen, we should have been protected
1856 * by bgp_mp_af_print()'s return value.
1858 ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af
, safi
);
1863 trunc
: /* we rely on the caller to recognize -2 return value */
1868 bgp_attr_print(netdissect_options
*ndo
,
1869 uint8_t atype
, const u_char
*pptr
, u_int len
,
1870 const unsigned attr_set_level
)
1872 /* allocate space for the largest possible string */
1873 char astostr
[AS_STR_SIZE
];
1876 uint8_t safi
, snpa
, nhlen
;
1880 char buf
[MAXHOSTNAMELEN
+ 100];
1882 int add_path4
, add_path6
;
1889 case BGPTYPE_ORIGIN
:
1891 ND_PRINT("invalid len");
1893 ND_PRINT("%s", tok2str(bgp_origin_values
,
1894 "Unknown Origin Typecode",
1900 * Process AS4 byte path and AS2 byte path attributes here.
1902 case BGPTYPE_AS4_PATH
:
1903 case BGPTYPE_AS_PATH
:
1905 ND_PRINT("invalid len");
1914 * BGP updates exchanged between New speakers that support 4
1915 * byte AS, ASs are always encoded in 4 bytes. There is no
1916 * definitive way to find this, just by the packet's
1917 * contents. So, check for packet's TLV's sanity assuming
1918 * 2 bytes first, and it does not pass, assume that ASs are
1919 * encoded in 4 bytes format and move on.
1921 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1923 while (tptr
< pptr
+ len
) {
1924 ND_PRINT("%s", tok2str(bgp_as_path_segment_open_values
,
1925 "?", GET_U_1(tptr
)));
1926 for (i
= 0; i
< GET_U_1(tptr
+ 1) * as_size
; i
+= as_size
) {
1927 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
1929 as_printf(ndo
, astostr
, sizeof(astostr
),
1931 GET_BE_U_2(tptr
+ i
+ 2) :
1932 GET_BE_U_4(tptr
+ i
+ 2)));
1934 ND_PRINT("%s", tok2str(bgp_as_path_segment_close_values
,
1935 "?", GET_U_1(tptr
)));
1936 tptr
+= 2 + GET_U_1(tptr
+ 1) * as_size
;
1939 case BGPTYPE_NEXT_HOP
:
1941 ND_PRINT("invalid len");
1943 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
1946 case BGPTYPE_MULTI_EXIT_DISC
:
1947 case BGPTYPE_LOCAL_PREF
:
1949 ND_PRINT("invalid len");
1951 ND_PRINT("%u", GET_BE_U_4(tptr
));
1954 case BGPTYPE_ATOMIC_AGGREGATE
:
1956 ND_PRINT("invalid len");
1958 case BGPTYPE_AGGREGATOR
:
1961 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1962 * the length of this PA can be either 6 bytes or 8 bytes.
1964 if (len
!= 6 && len
!= 8) {
1965 ND_PRINT("invalid len");
1968 ND_TCHECK_LEN(tptr
, len
);
1970 ND_PRINT(" AS #%s, origin %s",
1971 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(tptr
)),
1972 GET_IPADDR_STRING(tptr
+ 2));
1974 ND_PRINT(" AS #%s, origin %s",
1975 as_printf(ndo
, astostr
, sizeof(astostr
),
1976 GET_BE_U_4(tptr
)), GET_IPADDR_STRING(tptr
+ 4));
1979 case BGPTYPE_AGGREGATOR4
:
1981 ND_PRINT("invalid len");
1984 ND_PRINT(" AS #%s, origin %s",
1985 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)),
1986 GET_IPADDR_STRING(tptr
+ 4));
1988 case BGPTYPE_COMMUNITIES
:
1990 ND_PRINT("invalid len");
1998 comm
= GET_BE_U_4(tptr
);
2000 case BGP_COMMUNITY_NO_EXPORT
:
2001 ND_PRINT(" NO_EXPORT");
2003 case BGP_COMMUNITY_NO_ADVERT
:
2004 ND_PRINT(" NO_ADVERTISE");
2006 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
2007 ND_PRINT(" NO_EXPORT_SUBCONFED");
2011 (comm
>> 16) & 0xffff,
2013 (tlen
>4) ? ", " : "");
2020 case BGPTYPE_ORIGINATOR_ID
:
2022 ND_PRINT("invalid len");
2025 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2027 case BGPTYPE_CLUSTER_LIST
:
2029 ND_PRINT("invalid len");
2036 GET_IPADDR_STRING(tptr
),
2037 (tlen
>4) ? ", " : "");
2042 case BGPTYPE_MP_REACH_NLRI
:
2046 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2058 nhlen
= GET_U_1(tptr
);
2064 uint8_t tnhlen
= nhlen
;
2067 ND_PRINT("\n\t nexthop: ");
2068 while (tnhlen
!= 0) {
2072 switch(af
<<8 | safi
) {
2073 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
2074 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
2075 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
2076 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
2077 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
2078 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
2079 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
2080 if (tnhlen
< sizeof(nd_ipv4
)) {
2081 ND_PRINT("invalid len");
2086 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2087 tptr
+= sizeof(nd_ipv4
);
2088 tnhlen
-= sizeof(nd_ipv4
);
2089 tlen
-= sizeof(nd_ipv4
);
2092 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
2093 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
2094 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
2095 if (tnhlen
< sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
) {
2096 ND_PRINT("invalid len");
2101 ND_PRINT("RD: %s, %s",
2102 bgp_vpn_rd_print(ndo
, tptr
),
2103 GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2104 tptr
+= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2105 tlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2106 tnhlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2109 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
2110 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
2111 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
2112 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
2113 if (tnhlen
< sizeof(nd_ipv6
)) {
2114 ND_PRINT("invalid len");
2119 ND_PRINT("%s", GET_IP6ADDR_STRING(tptr
));
2120 tptr
+= sizeof(nd_ipv6
);
2121 tlen
-= sizeof(nd_ipv6
);
2122 tnhlen
-= sizeof(nd_ipv6
);
2125 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
2126 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
2127 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2128 if (tnhlen
< sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
) {
2129 ND_PRINT("invalid len");
2134 ND_PRINT("RD: %s, %s",
2135 bgp_vpn_rd_print(ndo
, tptr
),
2136 GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2137 tptr
+= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2138 tlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2139 tnhlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2142 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2143 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2144 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2145 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2146 if (tnhlen
< sizeof(nd_ipv4
)) {
2147 ND_PRINT("invalid len");
2152 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
2153 tptr
+= (sizeof(nd_ipv4
));
2154 tlen
-= (sizeof(nd_ipv4
));
2155 tnhlen
-= (sizeof(nd_ipv4
));
2158 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2159 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2160 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2161 ND_PRINT("%s", GET_ISONSAP_STRING(tptr
, tnhlen
));
2167 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2168 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2169 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2170 if (tnhlen
< BGP_VPN_RD_LEN
+1) {
2171 ND_PRINT("invalid len");
2176 ND_TCHECK_LEN(tptr
, tnhlen
);
2177 ND_PRINT("RD: %s, %s",
2178 bgp_vpn_rd_print(ndo
, tptr
),
2179 GET_ISONSAP_STRING(tptr
+BGP_VPN_RD_LEN
,tnhlen
-BGP_VPN_RD_LEN
));
2180 /* rfc986 mapped IPv4 address ? */
2181 if (GET_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
2182 ND_PRINT(" = %s", GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
+4));
2183 /* rfc1888 mapped IPv6 address ? */
2184 else if (GET_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
2185 ND_PRINT(" = %s", GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
+3));
2193 * bgp_mp_af_print() should have saved us from
2194 * an unsupported AFI/SAFI.
2196 ND_PRINT("ERROR: no AFI %u/SAFI %u nexthop decoder", af
, safi
);
2205 ND_PRINT(", nh-length: %u", nhlen
);
2207 /* As per RFC 2858; this is reserved in RFC 4760 */
2210 snpa
= GET_U_1(tptr
);
2215 ND_PRINT("\n\t %u SNPA", snpa
);
2216 for (/*nothing*/; snpa
!= 0; snpa
--) {
2220 snpalen
= GET_U_1(tptr
);
2221 ND_PRINT("\n\t %u bytes", snpalen
);
2226 ND_TCHECK_LEN(tptr
, snpalen
);
2231 ND_PRINT(", no SNPA");
2234 add_path4
= check_add_path(ndo
, tptr
,
2235 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 32);
2236 add_path6
= check_add_path(ndo
, tptr
,
2237 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 128);
2239 while (tptr
< pptr
+ len
) {
2240 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2241 add_path4
, add_path6
);
2250 case BGPTYPE_MP_UNREACH_NLRI
:
2251 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
2252 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2258 if (len
== BGP_MP_NLRI_MINSIZE
)
2259 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2263 add_path4
= check_add_path(ndo
, tptr
,
2264 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 32);
2265 add_path6
= check_add_path(ndo
, tptr
,
2266 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 128);
2268 while (tptr
< pptr
+ len
) {
2269 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2270 add_path4
, add_path6
);
2278 case BGPTYPE_EXTD_COMMUNITIES
:
2280 ND_PRINT("invalid len");
2289 extd_comm
=GET_BE_U_2(tptr
);
2291 ND_PRINT("\n\t %s (0x%04x), Flags [%s]",
2292 tok2str(bgp_extd_comm_subtype_values
,
2293 "unknown extd community typecode",
2296 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
2302 bgp_extended_community_print(ndo
, tptr
);
2308 case BGPTYPE_PMSI_TUNNEL
:
2310 uint8_t tunnel_type
, flags
;
2315 flags
= GET_U_1(tptr
);
2316 tunnel_type
= GET_U_1(tptr
+ 1);
2318 ND_PRINT("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2319 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2321 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2322 GET_BE_U_3(tptr
+ 2)>>4);
2327 switch (tunnel_type
) {
2328 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2329 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2330 ND_PRINT("\n\t Sender %s, P-Group %s",
2331 GET_IPADDR_STRING(tptr
),
2332 GET_IPADDR_STRING(tptr
+4));
2335 case BGP_PMSI_TUNNEL_PIM_SSM
:
2336 ND_PRINT("\n\t Root-Node %s, P-Group %s",
2337 GET_IPADDR_STRING(tptr
),
2338 GET_IPADDR_STRING(tptr
+4));
2340 case BGP_PMSI_TUNNEL_INGRESS
:
2341 ND_PRINT("\n\t Tunnel-Endpoint %s",
2342 GET_IPADDR_STRING(tptr
));
2344 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2345 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2346 ND_PRINT("\n\t Root-Node %s, LSP-ID 0x%08x",
2347 GET_IPADDR_STRING(tptr
),
2348 GET_BE_U_4(tptr
+ 4));
2350 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2351 ND_PRINT("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2352 GET_IPADDR_STRING(tptr
),
2353 GET_BE_U_4(tptr
+ 4));
2356 if (ndo
->ndo_vflag
<= 1) {
2357 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2368 type
= GET_U_1(tptr
);
2369 length
= GET_BE_U_2(tptr
+ 1);
2373 ND_PRINT("\n\t %s TLV (%u), length %u",
2374 tok2str(bgp_aigp_values
, "Unknown", type
),
2382 * Check if we can read the TLV data.
2392 ND_PRINT(", metric %" PRIu64
,
2397 if (ndo
->ndo_vflag
<= 1) {
2398 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2407 case BGPTYPE_ATTR_SET
:
2411 ND_PRINT("\n\t Origin AS: %s",
2412 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)));
2417 u_int aflags
, alenlen
, alen
;
2421 ND_PRINT(" [path attr too short]");
2425 aflags
= GET_U_1(tptr
);
2426 atype
= GET_U_1(tptr
+ 1);
2429 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2430 ND_TCHECK_LEN(tptr
, alenlen
);
2431 if (len
< alenlen
) {
2432 ND_PRINT(" [path attr too short]");
2436 alen
= bgp_attr_len(aflags
, tptr
);
2440 ND_PRINT("\n\t %s (%u), length: %u",
2441 tok2str(bgp_attr_values
,
2442 "Unknown Attribute", atype
),
2447 ND_PRINT(", Flags [%s%s%s%s",
2448 aflags
& 0x80 ? "O" : "",
2449 aflags
& 0x40 ? "T" : "",
2450 aflags
& 0x20 ? "P" : "",
2451 aflags
& 0x10 ? "E" : "");
2453 ND_PRINT("+%x", aflags
& 0xf);
2458 ND_PRINT(" [path attr too short]");
2463 * The protocol encoding per se allows ATTR_SET to be nested
2464 * as many times as the message can accommodate. This printer
2465 * used to be able to recurse into ATTR_SET contents until the
2466 * stack exhaustion, but now there is a limit on that (if live
2467 * protocol exchange goes that many levels deep, something is
2468 * probably wrong anyway). Feel free to refine this value if
2469 * you can find the spec with respective normative text.
2471 if (attr_set_level
== 10)
2472 ND_PRINT("(too many nested levels, not recursing)");
2473 else if (!bgp_attr_print(ndo
, atype
, tptr
, alen
, attr_set_level
+ 1))
2480 case BGPTYPE_LARGE_COMMUNITY
:
2481 if (len
== 0 || len
% 12) {
2482 ND_PRINT("invalid len");
2487 ND_PRINT("%u:%u:%u%s",
2489 GET_BE_U_4(tptr
+ 4),
2490 GET_BE_U_4(tptr
+ 8),
2491 (len
> 12) ? ", " : "");
2494 * len will always be a multiple of 12, as per the above,
2495 * so this will never underflow.
2501 ND_TCHECK_LEN(pptr
, len
);
2502 ND_PRINT("\n\t no Attribute %u decoder", atype
); /* we have no decoder for the attribute */
2503 if (ndo
->ndo_vflag
<= 1)
2504 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2508 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2509 ND_TCHECK_LEN(pptr
, len
);
2510 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2519 bgp_capabilities_print(netdissect_options
*ndo
,
2520 const u_char
*opt
, u_int caps_len
)
2522 /* allocate space for the largest possible string */
2523 char astostr
[AS_STR_SIZE
];
2524 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2527 while (i
< caps_len
) {
2528 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2529 cap_type
=GET_U_1(opt
+ i
);
2530 cap_len
=GET_U_1(opt
+ i
+ 1);
2531 ND_PRINT("\n\t %s (%u), length: %u",
2532 tok2str(bgp_capcode_values
, "Unknown", cap_type
),
2535 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2537 case BGP_CAPCODE_MP
:
2538 /* AFI (16 bits), Reserved (8 bits), SAFI (8 bits) */
2540 ND_PRINT(" (too short, < 4)");
2543 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u)",
2544 tok2str(af_values
, "Unknown", GET_BE_U_2(opt
+ i
+ 2)),
2545 GET_BE_U_2(opt
+ i
+ 2),
2546 tok2str(bgp_safi_values
, "Unknown", GET_U_1(opt
+ i
+ 5)),
2547 GET_U_1(opt
+ i
+ 5));
2549 case BGP_CAPCODE_ML
:
2552 while (tcap_len
>= 4) {
2553 ND_PRINT( "\n\t\tAFI %s (%u), SAFI %s (%u), Count: %u",
2554 tok2str(af_values
, "Unknown",
2555 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2556 GET_BE_U_2(opt
+ i
+ cap_offset
),
2557 tok2str(bgp_safi_values
, "Unknown",
2558 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2559 GET_U_1(opt
+ i
+ cap_offset
+ 2),
2560 GET_U_1(opt
+ i
+ cap_offset
+ 3));
2565 case BGP_CAPCODE_RESTART
:
2566 /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */
2568 ND_PRINT(" (too short, < 2)");
2572 ND_PRINT("\n\t\tRestart Flags: [%s], Restart Time %us",
2573 ((GET_U_1(opt
+ i
+ 2))&0x80) ? "R" : "none",
2574 GET_BE_U_2(opt
+ i
+ 2)&0xfff);
2577 while(tcap_len
>=4) {
2578 ND_PRINT("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2579 tok2str(af_values
,"Unknown",
2580 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2581 GET_BE_U_2(opt
+ i
+ cap_offset
),
2582 tok2str(bgp_safi_values
,"Unknown",
2583 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2584 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2585 ((GET_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" );
2590 case BGP_CAPCODE_RR
:
2591 case BGP_CAPCODE_LLGR
:
2592 case BGP_CAPCODE_RR_CISCO
:
2594 case BGP_CAPCODE_AS_NEW
:
2596 * Extract the 4 byte AS number encoded.
2599 ND_PRINT(" (too short, < 4)");
2602 ND_PRINT("\n\t\t 4 Byte AS %s",
2603 as_printf(ndo
, astostr
, sizeof(astostr
),
2604 GET_BE_U_4(opt
+ i
+ 2)));
2606 case BGP_CAPCODE_ADD_PATH
:
2608 ND_PRINT(" (bogus)"); /* length */
2613 while (tcap_len
!= 0) {
2615 nd_print_invalid(ndo
);
2618 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2619 tok2str(af_values
,"Unknown",GET_BE_U_2(opt
+ i
+ cap_offset
)),
2620 GET_BE_U_2(opt
+ i
+ cap_offset
),
2621 tok2str(bgp_safi_values
,"Unknown",GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2622 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2623 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",GET_U_1(opt
+ i
+ cap_offset
+ 3))
2630 ND_PRINT("\n\t\tno decoder for Capability %u",
2632 if (ndo
->ndo_vflag
<= 1)
2633 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2637 if (ndo
->ndo_vflag
> 1 && cap_len
!= 0) {
2638 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2640 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2645 nd_print_trunc(ndo
);
2649 bgp_open_print(netdissect_options
*ndo
,
2650 const u_char
*dat
, u_int length
)
2652 /* allocate space for the largest possible string */
2653 char astostr
[AS_STR_SIZE
];
2654 const struct bgp_open
*bgp_open_header
;
2656 const struct bgp_opt
*bgpopt
;
2660 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2661 if (length
< BGP_OPEN_SIZE
)
2664 bgp_open_header
= (const struct bgp_open
*)dat
;
2666 ND_PRINT("\n\t Version %u, ",
2667 GET_U_1(bgp_open_header
->bgpo_version
));
2668 ND_PRINT("my AS %s, ",
2669 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(bgp_open_header
->bgpo_myas
)));
2670 ND_PRINT("Holdtime %us, ",
2671 GET_BE_U_2(bgp_open_header
->bgpo_holdtime
));
2672 ND_PRINT("ID %s", GET_IPADDR_STRING(bgp_open_header
->bgpo_id
));
2673 optslen
= GET_U_1(bgp_open_header
->bgpo_optlen
);
2674 ND_PRINT("\n\t Optional parameters, length: %u", optslen
);
2676 opt
= dat
+ BGP_OPEN_SIZE
;
2677 length
-= BGP_OPEN_SIZE
;
2680 while (i
< optslen
) {
2681 uint8_t opt_type
, opt_len
;
2683 ND_TCHECK_LEN(opt
+ i
, BGP_OPT_SIZE
);
2684 if (length
< BGP_OPT_SIZE
+ i
)
2686 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2687 opt_type
= GET_U_1(bgpopt
->bgpopt_type
);
2688 opt_len
= GET_U_1(bgpopt
->bgpopt_len
);
2689 if (BGP_OPT_SIZE
+ i
+ opt_len
> optslen
) {
2690 ND_PRINT("\n\t Option %u, length: %u, goes past the end of the options",
2695 ND_PRINT("\n\t Option %s (%u), length: %u",
2696 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2700 /* now let's decode the options we know*/
2704 bgp_capabilities_print(ndo
, opt
+ BGP_OPT_SIZE
+ i
,
2710 ND_PRINT("\n\t no decoder for option %u",
2714 i
+= BGP_OPT_SIZE
+ opt_len
;
2718 nd_print_trunc(ndo
);
2722 bgp_update_print(netdissect_options
*ndo
,
2723 const u_char
*dat
, u_int length
)
2726 u_int withdrawn_routes_len
;
2727 char buf
[MAXHOSTNAMELEN
+ 100];
2734 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2735 if (length
< BGP_SIZE
)
2740 /* Unfeasible routes */
2744 withdrawn_routes_len
= GET_BE_U_2(p
);
2747 if (withdrawn_routes_len
> 1) {
2749 * Without keeping state from the original NLRI message,
2750 * it's not possible to tell if this a v4 or v6 route,
2751 * so only try to decode it if we're not v6 enabled.
2753 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2754 if (length
< withdrawn_routes_len
)
2756 ND_PRINT("\n\t Withdrawn routes:");
2757 add_path
= check_add_path(ndo
, p
, withdrawn_routes_len
, 32);
2758 while (withdrawn_routes_len
!= 0) {
2760 if (withdrawn_routes_len
< 4) {
2761 p
+= withdrawn_routes_len
;
2762 length
-= withdrawn_routes_len
;
2765 path_id
= GET_BE_U_4(p
);
2768 withdrawn_routes_len
-= 4;
2770 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2772 ND_PRINT("\n\t (illegal prefix length)");
2774 } else if (wpfx
== -2)
2775 goto trunc
; /* bytes left, but not enough */
2777 ND_PRINT("\n\t %s", buf
);
2779 ND_PRINT(" Path Id: %u", path_id
);
2783 withdrawn_routes_len
-= wpfx
;
2787 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2788 if (length
< withdrawn_routes_len
)
2790 p
+= withdrawn_routes_len
;
2791 length
-= withdrawn_routes_len
;
2797 len
= GET_BE_U_2(p
);
2801 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2802 /* No withdrawn routes, no path attributes, no NLRI */
2803 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2808 /* Make sure the path attributes don't go past the end of the packet */
2811 /* do something more useful!*/
2813 uint8_t aflags
, atype
, alenlen
;
2820 ND_PRINT("\n\t [path attrs too short]");
2825 aflags
= GET_U_1(p
);
2826 atype
= GET_U_1(p
+ 1);
2830 alenlen
= bgp_attr_lenlen(aflags
, p
);
2831 ND_TCHECK_LEN(p
, alenlen
);
2832 if (length
< alenlen
)
2834 if (len
< alenlen
) {
2835 ND_PRINT("\n\t [path attrs too short]");
2840 alen
= bgp_attr_len(aflags
, p
);
2845 ND_PRINT("\n\t %s (%u), length: %u",
2846 tok2str(bgp_attr_values
, "Unknown Attribute", atype
),
2851 ND_PRINT(", Flags [%s%s%s%s",
2852 aflags
& 0x80 ? "O" : "",
2853 aflags
& 0x40 ? "T" : "",
2854 aflags
& 0x20 ? "P" : "",
2855 aflags
& 0x10 ? "E" : "");
2857 ND_PRINT("+%x", aflags
& 0xf);
2861 ND_PRINT(" [path attrs too short]");
2868 if (!bgp_attr_print(ndo
, atype
, p
, alen
, 0))
2877 add_path
= check_add_path(ndo
, p
, length
, 32);
2878 ND_PRINT("\n\t Updated routes:");
2879 while (length
!= 0) {
2884 path_id
= GET_BE_U_4(p
);
2888 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2890 ND_PRINT("\n\t (illegal prefix length)");
2893 goto trunc
; /* bytes left, but not enough */
2895 ND_PRINT("\n\t %s", buf
);
2897 ND_PRINT(" Path Id: %u", path_id
);
2906 nd_print_trunc(ndo
);
2910 bgp_notification_print(netdissect_options
*ndo
,
2911 const u_char
*dat
, u_int length
)
2913 const struct bgp_notification
*bgp_notification_header
;
2915 uint8_t bgpn_major
, bgpn_minor
;
2917 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
2918 if (length
<BGP_NOTIFICATION_SIZE
)
2921 bgp_notification_header
= (const struct bgp_notification
*)dat
;
2922 bgpn_major
= GET_U_1(bgp_notification_header
->bgpn_major
);
2923 bgpn_minor
= GET_U_1(bgp_notification_header
->bgpn_minor
);
2925 ND_PRINT(", %s (%u)",
2926 tok2str(bgp_notify_major_values
, "Unknown Error",
2930 switch (bgpn_major
) {
2932 case BGP_NOTIFY_MAJOR_MSG
:
2933 ND_PRINT(", subcode %s (%u)",
2934 tok2str(bgp_notify_minor_msg_values
, "Unknown",
2938 case BGP_NOTIFY_MAJOR_OPEN
:
2939 ND_PRINT(", subcode %s (%u)",
2940 tok2str(bgp_notify_minor_open_values
, "Unknown",
2944 case BGP_NOTIFY_MAJOR_UPDATE
:
2945 ND_PRINT(", subcode %s (%u)",
2946 tok2str(bgp_notify_minor_update_values
, "Unknown",
2950 case BGP_NOTIFY_MAJOR_FSM
:
2951 ND_PRINT(" subcode %s (%u)",
2952 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
2956 case BGP_NOTIFY_MAJOR_CAP
:
2957 ND_PRINT(" subcode %s (%u)",
2958 tok2str(bgp_notify_minor_cap_values
, "Unknown",
2962 case BGP_NOTIFY_MAJOR_CEASE
:
2963 ND_PRINT(", subcode %s (%u)",
2964 tok2str(bgp_notify_minor_cease_values
, "Unknown",
2968 /* RFC 4486 mentions optionally 7 bytes
2969 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2971 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2972 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2973 ND_PRINT(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2974 tok2str(af_values
, "Unknown", GET_BE_U_2(tptr
)),
2976 tok2str(bgp_safi_values
, "Unknown", GET_U_1((tptr
+ 2))),
2977 GET_U_1((tptr
+ 2)),
2978 GET_BE_U_4(tptr
+ 3));
2981 * RFC 9003 describes a method to send a communication
2982 * intended for human consumption regarding the Administrative Shutdown
2984 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
2985 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
2986 length
>= BGP_NOTIFICATION_SIZE
+ 1) {
2987 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2988 uint8_t shutdown_comm_length
= GET_U_1(tptr
);
2989 uint8_t remainder_offset
= 0;
2990 /* garbage, hexdump it all */
2991 if (shutdown_comm_length
> length
- (BGP_NOTIFICATION_SIZE
+ 1)) {
2992 ND_PRINT(", invalid Shutdown Communication length");
2993 } else if (shutdown_comm_length
== 0) {
2994 ND_PRINT(", empty Shutdown Communication");
2995 remainder_offset
+= 1;
2997 /* a proper shutdown communication */
2999 ND_PRINT(", Shutdown Communication (length: %u): \"", shutdown_comm_length
);
3000 (void)nd_printn(ndo
, tptr
+1, shutdown_comm_length
, NULL
);
3002 remainder_offset
+= shutdown_comm_length
+ 1;
3004 /* if there is trailing data, hexdump it */
3005 if(length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
) > 0) {
3006 ND_PRINT(", Data: (length: %u)", length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
3007 hex_print(ndo
, "\n\t\t", tptr
+ remainder_offset
, length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
3017 nd_print_trunc(ndo
);
3021 bgp_route_refresh_print(netdissect_options
*ndo
,
3022 const u_char
*pptr
, u_int len
)
3024 const struct bgp_route_refresh
*bgp_route_refresh_header
;
3026 ND_TCHECK_LEN(pptr
, BGP_ROUTE_REFRESH_SIZE
);
3028 /* some little sanity checking */
3029 if (len
<BGP_ROUTE_REFRESH_SIZE
)
3032 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
3034 ND_PRINT("\n\t AFI %s (%u), SAFI %s (%u)",
3035 tok2str(af_values
,"Unknown",
3036 GET_BE_U_2(bgp_route_refresh_header
->afi
)),
3037 GET_BE_U_2(bgp_route_refresh_header
->afi
),
3038 tok2str(bgp_safi_values
,"Unknown",
3039 GET_U_1(bgp_route_refresh_header
->safi
)),
3040 GET_U_1(bgp_route_refresh_header
->safi
));
3042 if (ndo
->ndo_vflag
> 1) {
3043 ND_TCHECK_LEN(pptr
, len
);
3044 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
3049 nd_print_trunc(ndo
);
3053 bgp_pdu_print(netdissect_options
*ndo
,
3054 const u_char
*dat
, u_int length
)
3056 const struct bgp
*bgp_header
;
3059 ND_TCHECK_LEN(dat
, BGP_SIZE
);
3060 bgp_header
= (const struct bgp
*)dat
;
3061 bgp_type
= GET_U_1(bgp_header
->bgp_type
);
3063 ND_PRINT("\n\t%s Message (%u), length: %u",
3064 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
3070 bgp_open_print(ndo
, dat
, length
);
3073 bgp_update_print(ndo
, dat
, length
);
3075 case BGP_NOTIFICATION
:
3076 bgp_notification_print(ndo
, dat
, length
);
3080 case BGP_ROUTE_REFRESH
:
3081 bgp_route_refresh_print(ndo
, dat
, length
);
3084 /* we have no decoder for the BGP message */
3085 ND_TCHECK_LEN(dat
, length
);
3086 ND_PRINT("\n\t no Message %u decoder", bgp_type
);
3087 print_unknown_data(ndo
, dat
, "\n\t ", length
);
3092 nd_print_trunc(ndo
);
3097 bgp_print(netdissect_options
*ndo
,
3098 const u_char
*dat
, u_int length _U_
)
3101 const u_char
*ep
= ndo
->ndo_snapend
;
3102 const u_char
*start
;
3103 const u_char marker
[] = {
3104 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3105 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3107 const struct bgp
*bgp_header
;
3110 ndo
->ndo_protocol
= "bgp";
3113 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
3121 if (GET_U_1(p
) != 0xff) {
3126 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
3128 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
3133 /* found BGP header */
3134 ND_TCHECK_LEN(p
, BGP_SIZE
);
3135 bgp_header
= (const struct bgp
*)p
;
3138 nd_print_trunc(ndo
);
3140 hlen
= GET_BE_U_2(bgp_header
->bgp_len
);
3141 if (hlen
< BGP_SIZE
) {
3142 ND_PRINT("\nmessage length %u < %u", hlen
, BGP_SIZE
);
3143 nd_print_invalid(ndo
);
3147 if (ND_TTEST_LEN(p
, hlen
)) {
3148 if (!bgp_pdu_print(ndo
, p
, hlen
))
3153 ND_PRINT("\n[|BGP %s]",
3154 tok2str(bgp_msg_values
,
3155 "Unknown Message Type",
3156 GET_U_1(bgp_header
->bgp_type
)));
3164 nd_print_trunc(ndo
);