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 nd_uint8_t bgpo_opttype
; /* RFC9072 */
84 nd_uint16_t bgpo_optlen_extended
; /* RFC9072 */
85 /* options should follow */
87 #define BGP_OPEN_SIZE 29 /* unaligned */
90 nd_uint8_t bgpopt_type
;
91 nd_uint16_t bgpopt_len
; /* Can be one or two bytes, depending on RFC9072 */
94 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
95 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
97 struct bgp_notification
{
98 nd_byte bgpn_marker
[16];
100 nd_uint8_t bgpn_type
;
101 nd_uint8_t bgpn_major
;
102 nd_uint8_t bgpn_minor
;
104 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
106 struct bgp_route_refresh_orf
{
112 struct bgp_route_refresh
{
113 nd_byte bgp_marker
[16];
115 nd_uint8_t type
; /* No padding after this; afi is, in fact, not aligned */
121 static const struct tok bgp_orf_refresh_type
[] = {
127 static const struct tok bgp_orf_type
[] = {
128 { 64, "Address Prefix ORF"},
133 #define BGP_ROUTE_REFRESH_SIZE 23
134 #define BGP_ROUTE_REFRESH_SIZE_ORF BGP_ROUTE_REFRESH_SIZE + 5
135 #define BGP_ROUTE_REFRESH_SUBTYPE_NORMAL 0
136 #define BGP_ROUTE_REFRESH_SUBTYPE_BORR 1
137 #define BGP_ROUTE_REFRESH_SUBTYPE_EORR 2
138 #define BGP_ROUTE_REFRESH_SUBTYPE_RESERVED 255
140 static const struct tok bgp_route_refresh_subtype_values
[] = {
141 {BGP_ROUTE_REFRESH_SUBTYPE_NORMAL
, "Normal route refresh request"},
142 {BGP_ROUTE_REFRESH_SUBTYPE_BORR
,
143 "Demarcation of the beginning of a route refresh"},
144 {BGP_ROUTE_REFRESH_SUBTYPE_EORR
,
145 "Demarcation of the ending of a route refresh"},
148 #define bgp_attr_lenlen(flags, p) \
149 (((flags) & 0x10) ? 2U : 1U)
150 #define bgp_attr_len(flags, p) \
151 (((flags) & 0x10) ? GET_BE_U_2(p) : GET_U_1(p))
153 #define BGPTYPE_ORIGIN 1
154 #define BGPTYPE_AS_PATH 2
155 #define BGPTYPE_NEXT_HOP 3
156 #define BGPTYPE_MULTI_EXIT_DISC 4
157 #define BGPTYPE_LOCAL_PREF 5
158 #define BGPTYPE_ATOMIC_AGGREGATE 6
159 #define BGPTYPE_AGGREGATOR 7
160 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
161 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC4456 */
162 #define BGPTYPE_CLUSTER_LIST 10 /* RFC4456 */
163 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */
164 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */
165 #define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */
166 #define BGPTYPE_AS4_PATH 17 /* RFC6793 */
167 #define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */
168 #define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */
169 #define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */
170 #define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */
171 #define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */
172 #define BGPTYPE_AIGP 26 /* RFC7311 */
173 #define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */
174 #define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */
175 #define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */
176 #define BGPTYPE_BGPSEC_PATH 33 /* RFC8205 */
177 #define BGPTYPE_OTC 35 /* RFC9234 */
178 #define BGPTYPE_ATTR_SET 128 /* RFC6368 */
180 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
182 static const struct tok bgp_attr_values
[] = {
183 { BGPTYPE_ORIGIN
, "Origin"},
184 { BGPTYPE_AS_PATH
, "AS Path"},
185 { BGPTYPE_AS4_PATH
, "AS4 Path"},
186 { BGPTYPE_NEXT_HOP
, "Next Hop"},
187 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
188 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
189 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
190 { BGPTYPE_AGGREGATOR
, "Aggregator"},
191 { BGPTYPE_AGGREGATOR4
, "Aggregator4"},
192 { BGPTYPE_COMMUNITIES
, "Community"},
193 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
194 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
195 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
196 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
197 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
198 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
199 { BGPTYPE_TUNNEL_ENCAP
, "Tunnel Encapsulation"},
200 { BGPTYPE_TRAFFIC_ENG
, "Traffic Engineering"},
201 { BGPTYPE_IPV6_EXTD_COMMUNITIES
, "IPv6 Extended Community"},
202 { BGPTYPE_AIGP
, "Accumulated IGP Metric"},
203 { BGPTYPE_PE_DISTINGUISHER_LABEL
, "PE Distinguisher Label"},
204 { BGPTYPE_ENTROPY_LABEL
, "Entropy Label"},
205 { BGPTYPE_LARGE_COMMUNITY
, "Large Community"},
206 { BGPTYPE_BGPSEC_PATH
, "BGPsec Path"},
207 { BGPTYPE_OTC
, "Only to Customer (OTC)"},
208 { BGPTYPE_ATTR_SET
, "Attribute Set"},
209 { 255, "Reserved for development"},
214 #define BGP_AS_SEQUENCE 2
215 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
216 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
218 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
219 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
221 static const struct tok bgp_as_path_segment_open_values
[] = {
222 { BGP_AS_SEQUENCE
, ""},
224 { BGP_CONFED_AS_SEQUENCE
, "( "},
225 { BGP_CONFED_AS_SET
, "({ "},
229 static const struct tok bgp_as_path_segment_close_values
[] = {
230 { BGP_AS_SEQUENCE
, ""},
232 { BGP_CONFED_AS_SEQUENCE
, ")"},
233 { BGP_CONFED_AS_SET
, "})"},
237 #define BGP_OPT_AUTH 1
238 #define BGP_OPT_CAP 2
240 static const struct tok bgp_opt_values
[] = {
241 { BGP_OPT_AUTH
, "Authentication Information"},
242 { BGP_OPT_CAP
, "Capabilities Advertisement"},
246 #define BGP_CAPCODE_MP 1 /* RFC2858 */
247 #define BGP_CAPCODE_RR 2 /* RFC2918 */
248 #define BGP_CAPCODE_ORF 3 /* RFC5291 */
249 #define BGP_CAPCODE_MR 4 /* RFC3107 */
250 #define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */
251 #define BGP_CAPCODE_EXT_MSG 6 /* RFC8654 */
252 #define BGP_CAPCODE_BGPSEC 7 /* RFC8205 */
253 #define BGP_CAPCODE_ML 8 /* RFC8277 */
254 #define BGP_CAPCODE_ROLE 9 /* RFC9234 */
255 #define BGP_CAPCODE_RESTART 64 /* RFC4724 */
256 #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */
257 #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */
258 #define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */
259 #define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */
260 #define BGP_CAPCODE_ENH_RR 70 /* RFC7313 */
261 #define BGP_CAPCODE_LLGR 71 /* draft-uttaro-idr-bgp-persistence-05 */
262 #define BGP_CAPCODE_RR_CISCO 128
264 static const struct tok bgp_capcode_values
[] = {
265 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
266 { BGP_CAPCODE_RR
, "Route Refresh"},
267 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
268 { BGP_CAPCODE_MR
, "Multiple Routes to a Destination"},
269 { BGP_CAPCODE_EXT_NH
, "Extended Next Hop Encoding"},
270 { BGP_CAPCODE_EXT_MSG
, "BGP Extended Message"},
271 { BGP_CAPCODE_BGPSEC
, "BGPsec"},
272 { BGP_CAPCODE_ML
, "Multiple Labels"},
273 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
274 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
275 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
276 { BGP_CAPCODE_MULTISESS
, "Multisession BGP"},
277 { BGP_CAPCODE_ADD_PATH
, "Multiple Paths"},
278 { BGP_CAPCODE_ENH_RR
, "Enhanced Route Refresh"},
279 { BGP_CAPCODE_LLGR
, "Long-lived Graceful Restart"},
280 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
281 { BGP_CAPCODE_ROLE
, "Role Capability"},
285 #define BGP_NOTIFY_MAJOR_MSG 1
286 #define BGP_NOTIFY_MAJOR_OPEN 2
287 #define BGP_NOTIFY_MAJOR_UPDATE 3
288 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
289 #define BGP_NOTIFY_MAJOR_FSM 5
290 #define BGP_NOTIFY_MAJOR_CEASE 6
291 #define BGP_NOTIFY_MAJOR_ROUTEREFRESH 7
292 #define BGP_NOTIFY_MAJOR_SENDHOLDTIME 8
294 static const struct tok bgp_notify_major_values
[] = {
295 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
296 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
297 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
298 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
299 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
300 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
301 { BGP_NOTIFY_MAJOR_ROUTEREFRESH
, "ROUTE-REFRESH Message Error"},
302 { BGP_NOTIFY_MAJOR_SENDHOLDTIME
, "Send Hold Timer Expired"},
307 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
309 #define BGP_NOTIFY_MINOR_CEASE_SHUT 2
310 #define BGP_NOTIFY_MINOR_CEASE_RESET 4
312 #define BGP_NOTIFY_MINOR_CEASE_HARDRESET 9
313 static const struct tok bgp_notify_minor_cease_values
[] = {
314 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
315 { BGP_NOTIFY_MINOR_CEASE_SHUT
, "Administrative Shutdown"},
316 { 3, "Peer Unconfigured"},
317 { BGP_NOTIFY_MINOR_CEASE_RESET
, "Administrative Reset"},
318 { 5, "Connection Rejected"},
319 { 6, "Other Configuration Change"},
320 { 7, "Connection Collision Resolution"},
321 { 8, "Out of Resources"},
322 { BGP_NOTIFY_MINOR_CEASE_HARDRESET
, "Hard Reset"},
327 static const struct tok bgp_notify_minor_msg_values
[] = {
328 { 1, "Connection Not Synchronized"},
329 { 2, "Bad Message Length"},
330 { 3, "Bad Message Type"},
334 static const struct tok bgp_notify_minor_open_values
[] = {
335 { 1, "Unsupported Version Number"},
337 { 3, "Bad BGP Identifier"},
338 { 4, "Unsupported Optional Parameter"},
339 { 5, "Authentication Failure"},
340 { 6, "Unacceptable Hold Time"},
341 { 7, "Capability Message Error"},
345 static const struct tok bgp_notify_minor_update_values
[] = {
346 { 1, "Malformed Attribute List"},
347 { 2, "Unrecognized Well-known Attribute"},
348 { 3, "Missing Well-known Attribute"},
349 { 4, "Attribute Flags Error"},
350 { 5, "Attribute Length Error"},
351 { 6, "Invalid ORIGIN Attribute"},
352 { 7, "AS Routing Loop"},
353 { 8, "Invalid NEXT_HOP Attribute"},
354 { 9, "Optional Attribute Error"},
355 { 10, "Invalid Network Field"},
356 { 11, "Malformed AS_PATH"},
360 static const struct tok bgp_notify_minor_fsm_values
[] = {
361 { 0, "Unspecified Error"},
362 { 1, "In OpenSent State"},
363 { 2, "In OpenConfirm State"},
364 { 3, "In Established State"},
368 static const struct tok bgp_notify_minor_routerefresh_values
[] = {
369 { 1, "Invalid Message Length" },
373 static const struct tok bgp_origin_values
[] = {
380 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
381 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
382 #define BGP_PMSI_TUNNEL_PIM_SSM 3
383 #define BGP_PMSI_TUNNEL_PIM_SM 4
384 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
385 #define BGP_PMSI_TUNNEL_INGRESS 6
386 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
388 static const struct tok bgp_pmsi_tunnel_values
[] = {
389 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
390 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
391 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
392 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
393 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
394 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
395 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
399 static const struct tok bgp_pmsi_flag_values
[] = {
400 { 0x01, "Leaf Information required"},
404 #define BGP_AIGP_TLV 1
406 static const struct tok bgp_aigp_values
[] = {
407 { BGP_AIGP_TLV
, "AIGP"},
411 #define BGP_ROLE_PROVIDER 0
412 #define BGP_ROLE_RS 1
413 #define BGP_ROLE_RS_CLIENT 2
414 #define BGP_ROLE_CUSTOMER 3
415 #define BGP_ROLE_PEER 4
417 static const struct tok bgp_role_values
[] = {
418 { BGP_ROLE_PROVIDER
, "Provider"},
419 { BGP_ROLE_RS
, "RS"},
420 { BGP_ROLE_RS_CLIENT
, "RS-Client"},
421 { BGP_ROLE_CUSTOMER
, "Customer"},
422 { BGP_ROLE_PEER
, "Peer"},
426 /* Subsequent address family identifier, RFC2283 section 7 */
428 #define SAFNUM_UNICAST 1
429 #define SAFNUM_MULTICAST 2
430 #define SAFNUM_UNIMULTICAST 3 /* deprecated now */
431 /* labeled BGP RFC3107 */
432 #define SAFNUM_LABUNICAST 4
434 #define SAFNUM_MULTICAST_VPN 5
435 /* draft-nalawade-kapoor-tunnel-safi */
436 #define SAFNUM_TUNNEL 64
438 #define SAFNUM_VPLS 65
440 #define SAFNUM_MDT 66
442 #define SAFNUM_EVPN 70
444 #define SAFNUM_VPNUNICAST 128
446 #define SAFNUM_VPNMULTICAST 129
447 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
449 #define SAFNUM_RT_ROUTING_INFO 132
451 #define BGP_VPN_RD_LEN 8
453 static const struct tok bgp_safi_values
[] = {
454 { SAFNUM_RES
, "Reserved"},
455 { SAFNUM_UNICAST
, "Unicast"},
456 { SAFNUM_MULTICAST
, "Multicast"},
457 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
458 { SAFNUM_LABUNICAST
, "labeled Unicast"},
459 { SAFNUM_TUNNEL
, "Tunnel"},
460 { SAFNUM_VPLS
, "VPLS"},
461 { SAFNUM_MDT
, "MDT"},
462 { SAFNUM_EVPN
, "EVPN"},
463 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
464 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
465 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
466 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
467 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
471 static const struct tok bgp_graceful_restart_comm_flag_values
[] = {
477 /* well-known community */
478 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
479 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
480 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
482 /* Extended community type - RFC 4360 */
483 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
484 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
485 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
486 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
487 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
488 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
489 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
490 #define BGP_EXT_COM_OVS 0x4300 /* BGP Prefix Origin Validation State Extended Community */
491 /* rfc2547 bgp-mpls-vpns */
492 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
493 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatibility */
494 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatibility */
495 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatibility */
497 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
498 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatibility */
499 #define BGP_EXT_COM_ENCAP 0x030c /* rfc5512 */
501 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
502 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatibility */
504 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
506 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
507 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
508 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
509 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
511 /* https://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
512 #define BGP_EXT_COM_EIGRP_GEN 0x8800
513 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
514 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
515 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
516 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
517 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
519 /* Optional Parameters */
520 #define BGP_OPEN_NON_EXT_OPT_TYPE_EXTENDED_LENGTH 255 /* Non-Ext OP Type */
522 static const struct tok bgp_extd_comm_flag_values
[] = {
523 { 0x8000, "vendor-specific"},
524 { 0x4000, "non-transitive"},
529 static const struct tok bgp_prefix_origin_validation_state
[] = {
536 static const struct tok bgp_extd_comm_subtype_values
[] = {
537 { BGP_EXT_COM_RT_0
, "target"},
538 { BGP_EXT_COM_RT_1
, "target"},
539 { BGP_EXT_COM_RT_2
, "target"},
540 { BGP_EXT_COM_RO_0
, "origin"},
541 { BGP_EXT_COM_RO_1
, "origin"},
542 { BGP_EXT_COM_RO_2
, "origin"},
543 { BGP_EXT_COM_LINKBAND
, "link-BW"},
544 { BGP_EXT_COM_OVS
, "origin-validation-state"},
545 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
546 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
547 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
548 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
549 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
550 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
551 { BGP_EXT_COM_ENCAP
, "encapsulation"},
552 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
553 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
554 { BGP_EXT_COM_L2INFO
, "layer2-info"},
555 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
556 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
557 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
558 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
559 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
560 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
561 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
562 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
563 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
564 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
568 /* RFC RFC5512 BGP Tunnel Encapsulation Attribute Tunnel Types */
569 #define BGP_ENCAP_TUNNEL_L2TPV3_IP 1
570 #define BGP_ENCAP_TUNNEL_GRE 2
571 #define BGP_ENCAP_TUNNEL_TRANSMIT 3
572 #define BGP_ENCAP_TUNNEL_IPSEC 4
573 #define BGP_ENCAP_TUNNEL_IP_IPSEC 5
574 #define BGP_ENCAP_TUNNEL_MPLS_IP 6
575 #define BGP_ENCAP_TUNNEL_IP_IP 7
576 #define BGP_ENCAP_TUNNEL_VXLAN 8
577 #define BGP_ENCAP_TUNNEL_NVGRE 9
578 #define BGP_ENCAP_TUNNEL_MPLS 10
579 #define BGP_ENCAP_TUNNEL_MPLS_GRE 11
580 #define BGP_ENCAP_TUNNEL_VXLAN_GPE 12
581 #define BGP_ENCAP_TUNNEL_MPLS_UDP 13
582 #define BGP_ENCAP_TUNNEL_IPV6 14
583 #define BGP_ENCAP_TUNNEL_SR_TE 15
584 #define BGP_ENCAP_TUNNEL_BARE 16
585 #define BGP_ENCAP_TUNNEL_SR 17
587 static const struct tok bgp_extd_comm_encap_tunnel_values
[] = {
588 { BGP_ENCAP_TUNNEL_L2TPV3_IP
, "L2TPv3 over IP"},
589 { BGP_ENCAP_TUNNEL_GRE
, "GRE"},
590 { BGP_ENCAP_TUNNEL_TRANSMIT
, "Transmit Tunnel"},
591 { BGP_ENCAP_TUNNEL_IPSEC
, "IPsec"},
592 { BGP_ENCAP_TUNNEL_IP_IPSEC
, "IP in IP with IPsec"},
593 { BGP_ENCAP_TUNNEL_MPLS_IP
, "MPLS in IP with IPsec"},
594 { BGP_ENCAP_TUNNEL_IP_IP
, "IP in IP"},
595 { BGP_ENCAP_TUNNEL_VXLAN
, "VXLAN"},
596 { BGP_ENCAP_TUNNEL_NVGRE
, "NVGRE"},
597 { BGP_ENCAP_TUNNEL_MPLS
, "MPLS"},
598 { BGP_ENCAP_TUNNEL_MPLS_GRE
, "MPLS in GRE"},
599 { BGP_ENCAP_TUNNEL_VXLAN_GPE
, "VXLAN GPE"},
600 { BGP_ENCAP_TUNNEL_MPLS_UDP
, "MPLS in UDP"},
601 { BGP_ENCAP_TUNNEL_IPV6
, "IPv6"},
602 { BGP_ENCAP_TUNNEL_SR_TE
, "SR TE"},
603 { BGP_ENCAP_TUNNEL_BARE
, "Bare"},
604 { BGP_ENCAP_TUNNEL_SR
, "SR"},
608 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
609 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
610 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
611 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
612 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
613 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
614 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
615 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
617 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
618 { BGP_OSPF_RTYPE_RTR
, "Router" },
619 { BGP_OSPF_RTYPE_NET
, "Network" },
620 { BGP_OSPF_RTYPE_SUM
, "Summary" },
621 { BGP_OSPF_RTYPE_EXT
, "External" },
622 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
623 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
627 /* ADD-PATH Send/Receive field values */
628 static const struct tok bgp_add_path_recvsend
[] = {
635 static const struct tok bgp_bgpsec_bitmap_str
[] = {
636 { 1U << 0, "MBZ-0" },
637 { 1U << 1, "MBZ-1" },
638 { 1U << 2, "MBZ-2" },
639 { 1U << 3, "MBZ-3" },
640 { 1U << 4, "MBZ-4" },
641 { 1U << 5, "MBZ-5" },
642 { 1U << 6, "MBZ-6" },
647 #define AS_STR_SIZE sizeof("xxxxx.xxxxx")
652 * Convert an AS number into a string and return string pointer.
654 * Depending on bflag is set or not, AS number is converted into ASDOT notation
655 * or plain number notation.
659 as_printf(netdissect_options
*ndo
,
660 char *str
, size_t size
, u_int asnum
)
662 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
663 snprintf(str
, size
, "%u", asnum
);
665 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
670 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
673 decode_prefix4(netdissect_options
*ndo
,
674 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
677 u_int plen
, plenbytes
;
680 plen
= GET_U_1(pptr
);
685 memset(&addr
, 0, sizeof(addr
));
686 plenbytes
= (plen
+ 7) / 8;
687 ITEMCHECK(plenbytes
);
688 GET_CPY_BYTES(&addr
, pptr
+ 1, plenbytes
);
690 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
692 snprintf(buf
, buflen
, "%s/%u", ipaddr_string(ndo
, (const u_char
*)&addr
), plen
);
693 return 1 + plenbytes
;
700 print_labeled_prefix4(netdissect_options
*ndo
,
701 const u_char
*pptr
, u_int itemlen
)
704 u_int plen
, plenbytes
;
706 /* prefix length and label = 4 bytes */
709 plen
= GET_U_1(pptr
); /* get prefix length */
711 /* this is one of the weirdnesses of rfc3107
712 the label length (actually the label + COS bits)
713 is added to the prefix length;
714 we also do only read out just one label -
715 there is no real application for advertisement of
716 stacked labels in a single BGP message
722 plen
-=24; /* adjust prefixlen - labellength */
728 memset(&addr
, 0, sizeof(addr
));
729 plenbytes
= (plen
+ 7) / 8;
730 ITEMCHECK(plenbytes
);
731 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
733 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
735 /* the label may get offsetted by 4 bits so lets shift it right */
736 ND_PRINT("\n\t %s/%u, label:%u %s",
737 ipaddr_string(ndo
, (const u_char
*)&addr
),
739 GET_BE_U_3(pptr
+ 1)>>4,
740 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
742 return 4 + plenbytes
;
745 ND_PRINT("\n\t (illegal prefix length)");
758 * print an ipv4 or ipv6 address into a buffer dependent on address length.
761 bgp_vpn_ip_print(netdissect_options
*ndo
,
762 const u_char
*pptr
, u_int addr_length
)
765 /* worst case string is s fully formatted v6 address */
766 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
769 switch(addr_length
) {
770 case (sizeof(nd_ipv4
) << 3): /* 32 */
771 snprintf(pos
, sizeof(addr
), "%s", GET_IPADDR_STRING(pptr
));
773 case (sizeof(nd_ipv6
) << 3): /* 128 */
774 snprintf(pos
, sizeof(addr
), "%s", GET_IP6ADDR_STRING(pptr
));
777 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
789 * print an multicast s,g entry into a buffer.
790 * the s,g entry is encoded like this.
792 * +-----------------------------------+
793 * | Multicast Source Length (1 octet) |
794 * +-----------------------------------+
795 * | Multicast Source (Variable) |
796 * +-----------------------------------+
797 * | Multicast Group Length (1 octet) |
798 * +-----------------------------------+
799 * | Multicast Group (Variable) |
800 * +-----------------------------------+
802 * return the number of bytes read from the wire.
805 bgp_vpn_sg_print(netdissect_options
*ndo
, const u_char
*pptr
)
812 /* Source address length, encoded in bits */
813 addr_length
= GET_U_1(pptr
);
817 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
818 total_length
+= (addr_length
>> 3) + 1;
820 ND_PRINT(", Source %s",
821 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
822 pptr
+= (addr_length
>> 3);
825 /* Group address length, encoded in bits */
826 addr_length
= GET_U_1(pptr
);
830 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
831 total_length
+= (addr_length
>> 3) + 1;
833 ND_PRINT(", Group %s",
834 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
835 pptr
+= (addr_length
>> 3);
839 return (total_length
);
842 /* Print an RFC 4364 Route Distinguisher */
844 bgp_vpn_rd_print(netdissect_options
*ndo
, const u_char
*pptr
)
846 /* allocate space for the largest possible string */
847 static char rd
[sizeof("xxxxx.xxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
849 /* allocate space for the largest possible string */
850 char astostr
[AS_STR_SIZE
];
852 /* ok lets load the RD format */
853 switch (GET_BE_U_2(pptr
)) {
856 /* 2-byte-AS:number fmt */
857 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
858 GET_BE_U_2(pptr
+ 2),
859 GET_BE_U_4(pptr
+ 4),
860 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
861 GET_U_1(pptr
+ 6), GET_U_1(pptr
+ 7));
865 /* IP-address:AS fmt */
866 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
867 GET_U_1(pptr
+ 2), GET_U_1(pptr
+ 3),
868 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
869 GET_BE_U_2(pptr
+ 6));
873 /* 4-byte-AS:number fmt */
874 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
875 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 2)),
876 GET_BE_U_2(pptr
+ 6), GET_U_1(pptr
+ 2),
877 GET_U_1(pptr
+ 3), GET_U_1(pptr
+ 4),
878 GET_U_1(pptr
+ 5), GET_BE_U_2(pptr
+ 6));
881 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
890 * Print an RFC 4360 Extended Community.
893 bgp_extended_community_print(netdissect_options
*ndo
,
896 /* allocate space for the largest possible string */
897 char astostr
[AS_STR_SIZE
];
899 switch (GET_BE_U_2(pptr
)) {
901 case BGP_EXT_COM_RT_0
:
902 case BGP_EXT_COM_RO_0
:
903 case BGP_EXT_COM_L2VPN_RT_0
:
904 ND_PRINT("%u:%u (= %s)",
905 GET_BE_U_2(pptr
+ 2),
906 GET_BE_U_4(pptr
+ 4),
907 GET_IPADDR_STRING(pptr
+4));
910 case BGP_EXT_COM_RT_1
:
911 case BGP_EXT_COM_RO_1
:
912 case BGP_EXT_COM_L2VPN_RT_1
:
913 case BGP_EXT_COM_VRF_RT_IMP
:
915 GET_IPADDR_STRING(pptr
+2),
916 GET_BE_U_2(pptr
+ 6));
919 case BGP_EXT_COM_RT_2
:
920 case BGP_EXT_COM_RO_2
:
922 as_printf(ndo
, astostr
, sizeof(astostr
),
923 GET_BE_U_4(pptr
+ 2)), GET_BE_U_2(pptr
+ 6));
926 case BGP_EXT_COM_LINKBAND
:
927 ND_PRINT("bandwidth: %.3f Mbps",
928 GET_BE_F_4(pptr
+ 4)*8/1000000);
931 case BGP_EXT_COM_OVS
:
932 /* The Reserved field MUST be set to 0 and ignored upon the
933 * receipt of this community.
936 uint64_t reserved
= GET_BE_U_5(pptr
+ 2);
939 ND_PRINT("[the reserved field 0x%" PRIx64
" MUST be 0] ",
942 tok2str(bgp_prefix_origin_validation_state
,
943 "unknown origin validation state",
948 case BGP_EXT_COM_VPN_ORIGIN
:
949 case BGP_EXT_COM_VPN_ORIGIN2
:
950 case BGP_EXT_COM_VPN_ORIGIN3
:
951 case BGP_EXT_COM_VPN_ORIGIN4
:
952 case BGP_EXT_COM_OSPF_RID
:
953 case BGP_EXT_COM_OSPF_RID2
:
954 ND_PRINT("%s", GET_IPADDR_STRING(pptr
+2));
957 case BGP_EXT_COM_OSPF_RTYPE
:
958 case BGP_EXT_COM_OSPF_RTYPE2
:
959 ND_PRINT("area:%s, router-type:%s, metric-type:%s%s",
960 GET_IPADDR_STRING(pptr
+2),
961 tok2str(bgp_extd_comm_ospf_rtype_values
,
963 GET_U_1((pptr
+ 6))),
964 (GET_U_1(pptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
965 ((GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
968 case BGP_EXT_COM_L2INFO
:
969 ND_PRINT("%s Control Flags [0x%02x]:MTU %u",
970 tok2str(l2vpn_encaps_values
,
972 GET_U_1((pptr
+ 2))),
974 GET_BE_U_2(pptr
+ 4));
977 case BGP_EXT_COM_SOURCE_AS
:
978 ND_PRINT("AS %u", GET_BE_U_2(pptr
+ 2));
981 case BGP_EXT_COM_ENCAP
:
982 ND_PRINT("Tunnel type: %s", tok2str(bgp_extd_comm_encap_tunnel_values
,
984 GET_BE_U_2(pptr
+ 6)));
988 ND_PRINT("%02x%02x%02x%02x%02x%02x",
1000 * RFC4684 (Section 4)/RFC2858 (Section 4).
1001 * RTC membership prefix is structured as follows
1002 * [prefix-len] [origin-as] [route-target]
1003 * The route-target is encoded as RT ext-comms.
1004 * Prefix-len may be 0, 32..96
1006 * Note that pptr is not packet data - it is
1007 * a buffer owned by our caller - therefore GET_*
1008 * macros can not be used.
1011 bgp_rt_prefix_print(netdissect_options
*ndo
,
1015 /* allocate space for the largest possible string */
1016 char rtc_prefix_in_hex
[sizeof("0000 0000 0000 0000")] = "";
1017 u_int rtc_prefix_in_hex_len
= 0;
1018 static char output
[61]; /* max response string */
1019 /* allocate space for the largest possible string */
1020 char astostr
[AS_STR_SIZE
];
1021 uint16_t ec_type
= 0;
1026 snprintf(output
, sizeof(output
), "route-target: 0:0/0");
1030 /* hex representation of the prefix */
1031 octet_count
= (plen
+7)/8;
1032 for (i
=0; i
<octet_count
; i
++) {
1033 rtc_prefix_in_hex_len
+= snprintf(rtc_prefix_in_hex
+rtc_prefix_in_hex_len
,
1034 sizeof(rtc_prefix_in_hex
)-rtc_prefix_in_hex_len
,
1035 "%02x%s", *(pptr
+i
),
1036 ((i
%2 == 1) && (i
<octet_count
-1)) ? " " : "");
1041 * The prefix is too short to include the full ext-comm type,
1042 * so we have no way to parse it further.
1044 snprintf(output
, sizeof(output
), "route-target: partial-type: (%s/%d)",
1045 rtc_prefix_in_hex
, plen
);
1050 * get the ext-comm type
1051 * Note: pptr references a static 8 octet buffer with unused bits set to 0,
1052 * hence EXTRACT_*() macros are safe.
1054 ec_type
= EXTRACT_BE_U_2(pptr
);
1056 case BGP_EXT_COM_RT_0
:
1057 /* 2-byte-AS:number fmt */
1058 snprintf(output
, sizeof(output
), "route-target: %u:%u/%d (%s)",
1059 EXTRACT_BE_U_2(pptr
+2),
1060 EXTRACT_BE_U_4(pptr
+4),
1061 plen
, rtc_prefix_in_hex
);
1064 case BGP_EXT_COM_RT_1
:
1065 /* IP-address:AS fmt */
1066 snprintf(output
, sizeof(output
), "route-target: %u.%u.%u.%u:%u/%d (%s)",
1067 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5),
1068 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
1071 case BGP_EXT_COM_RT_2
:
1072 /* 4-byte-AS:number fmt */
1073 snprintf(output
, sizeof(output
), "route-target: %s:%u/%d (%s)",
1074 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(pptr
+2)),
1075 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
1079 snprintf(output
, sizeof(output
), "route target: unknown-type(%04x) (%s/%d)",
1081 rtc_prefix_in_hex
, plen
);
1089 print_rt_routing_info(netdissect_options
*ndo
, const u_char
*pptr
)
1091 uint8_t route_target
[8];
1093 /* allocate space for the largest possible string */
1094 char astostr
[AS_STR_SIZE
];
1097 /* NLRI "prefix length" from RFC 2858 Section 4. */
1098 plen
= GET_U_1(pptr
); /* get prefix length */
1100 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
1101 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
1102 * target" fields inside the "prefix" depending on its length.
1105 /* Without "origin AS", without "route target". */
1106 ND_PRINT("\n\t default route target");
1111 ND_PRINT("\n\t (illegal prefix length)");
1115 /* With at least "origin AS", possibly with "route target". */
1116 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 1));
1118 plen
-= 32; /* adjust prefix length */
1121 ND_PRINT("\n\t (illegal prefix length)");
1125 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
1126 * and gives the number of octets in the variable-length "route
1127 * target" field inside this NLRI "prefix". Look for it.
1129 memset(&route_target
, 0, sizeof(route_target
));
1130 num_octets
= (plen
+ 7) / 8;
1131 GET_CPY_BYTES(&route_target
, pptr
+ 5, num_octets
);
1132 /* If mask-len is not on octet boundary, ensure all extra bits are 0 */
1134 ((u_char
*)&route_target
)[num_octets
- 1] &=
1135 ((0xff00 >> (plen
% 8)) & 0xff);
1137 ND_PRINT("\n\t origin AS: %s, %s",
1139 bgp_rt_prefix_print(ndo
, (u_char
*)&route_target
, plen
));
1141 return 5 + num_octets
;
1145 print_labeled_vpn_prefix4(netdissect_options
*ndo
, const u_char
*pptr
)
1150 plen
= GET_U_1(pptr
); /* get prefix length */
1155 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1160 memset(&addr
, 0, sizeof(addr
));
1161 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1163 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
1164 ((0xff00 >> (plen
% 8)) & 0xff);
1166 /* the label may get offsetted by 4 bits so lets shift it right */
1167 ND_PRINT("\n\t RD: %s, %s/%u, label:%u %s",
1168 bgp_vpn_rd_print(ndo
, pptr
+4),
1169 ipaddr_string(ndo
, (const u_char
*)&addr
),
1171 GET_BE_U_3(pptr
+ 1)>>4,
1172 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1174 return 12 + (plen
+ 7) / 8;
1177 ND_PRINT("\n\t (illegal prefix length)");
1182 * +-------------------------------+
1184 * | RD:IPv4-address (12 octets) |
1186 * +-------------------------------+
1187 * | MDT Group-address (4 octets) |
1188 * +-------------------------------+
1191 #define MDT_VPN_NLRI_LEN 16
1194 print_mdt_vpn_nlri(netdissect_options
*ndo
, const u_char
*pptr
)
1197 const u_char
*vpn_ip
;
1199 /* if the NLRI is not predefined length, quit.*/
1200 if (GET_U_1(pptr
) != MDT_VPN_NLRI_LEN
* 8) {
1201 ND_PRINT("\n\t (illegal prefix length)");
1213 pptr
+= sizeof(nd_ipv4
);
1215 /* MDT Group Address */
1216 ND_PRINT("\n\t RD: %s, VPN IP Address: %s, MC Group Address: %s",
1217 bgp_vpn_rd_print(ndo
, rd
),
1218 GET_IPADDR_STRING(vpn_ip
),
1219 GET_IPADDR_STRING(pptr
));
1221 return MDT_VPN_NLRI_LEN
+ 1;
1227 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
1228 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
1229 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
1230 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
1231 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
1232 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
1233 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
1235 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
1236 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
1237 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
1238 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
1239 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
1240 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
1241 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
1242 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
1247 print_multicast_vpn(netdissect_options
*ndo
, const u_char
*pptr
)
1249 /* allocate space for the largest possible string */
1250 char astostr
[AS_STR_SIZE
];
1251 uint8_t route_type
, route_length
;
1252 u_int addr_length
, sg_length
;
1254 route_type
= GET_U_1(pptr
);
1256 route_length
= GET_U_1(pptr
);
1259 ND_PRINT("\n\t Route-Type: %s (%u), length: %u",
1260 tok2str(bgp_multicast_vpn_route_type_values
,
1261 "Unknown", route_type
),
1262 route_type
, route_length
);
1264 switch(route_type
) {
1265 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
1266 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1267 if (route_length
< BGP_VPN_RD_LEN
)
1269 ND_PRINT(", RD: %s, Originator %s",
1270 bgp_vpn_rd_print(ndo
, pptr
),
1271 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
1272 (route_length
- BGP_VPN_RD_LEN
) << 3));
1274 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
1275 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1276 ND_PRINT(", RD: %s, Source-AS %s",
1277 bgp_vpn_rd_print(ndo
, pptr
),
1278 as_printf(ndo
, astostr
, sizeof(astostr
),
1279 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1282 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
1283 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1284 ND_PRINT(", RD: %s", bgp_vpn_rd_print(ndo
, pptr
));
1285 pptr
+= BGP_VPN_RD_LEN
;
1287 sg_length
= bgp_vpn_sg_print(ndo
, pptr
);
1288 addr_length
= route_length
- sg_length
;
1290 ND_TCHECK_LEN(pptr
, addr_length
);
1291 ND_PRINT(", Originator %s",
1292 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
1295 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
1296 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1297 ND_PRINT(", RD: %s", bgp_vpn_rd_print(ndo
, pptr
));
1298 pptr
+= BGP_VPN_RD_LEN
;
1300 bgp_vpn_sg_print(ndo
, pptr
);
1303 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
1304 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
1305 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1306 ND_PRINT(", RD: %s, Source-AS %s",
1307 bgp_vpn_rd_print(ndo
, pptr
),
1308 as_printf(ndo
, astostr
, sizeof(astostr
),
1309 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1310 pptr
+= BGP_VPN_RD_LEN
+ 4;
1312 bgp_vpn_sg_print(ndo
, pptr
);
1316 * no per route-type printing yet.
1318 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1323 return route_length
+ 2;
1330 * As I remember, some versions of systems have an snprintf() that
1331 * returns -1 if the buffer would have overflowed. If the return
1332 * value is negative, set buflen to 0, to indicate that we've filled
1335 * If the return value is greater than buflen, that means that
1336 * the buffer would have overflowed; again, set buflen to 0 in
1339 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1342 else if ((u_int)stringlen>buflen) \
1345 buflen-=stringlen; \
1350 print_labeled_vpn_l2(netdissect_options
*ndo
, const u_char
*pptr
)
1352 u_int plen
, tlen
, tlv_type
, tlv_len
, ttlv_len
;
1354 plen
= GET_BE_U_2(pptr
);
1357 /* Old and new L2VPN NLRI share AFI/SAFI
1358 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1359 * and > 17 as old format. Complain for the middle case
1362 /* assume AD-only with RD, BGPNH */
1363 ND_TCHECK_LEN(pptr
, 12);
1364 ND_PRINT("\n\t RD: %s, BGPNH: %s",
1365 bgp_vpn_rd_print(ndo
, pptr
),
1366 GET_IPADDR_STRING(pptr
+8));
1368 } else if (plen
> 17) {
1369 /* assume old format */
1370 /* RD, ID, LBLKOFF, LBLBASE */
1372 ND_TCHECK_LEN(pptr
, 15);
1373 ND_PRINT("\n\t RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1374 bgp_vpn_rd_print(ndo
, pptr
),
1375 GET_BE_U_2(pptr
+ 8),
1376 GET_BE_U_2(pptr
+ 10),
1377 GET_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1381 /* ok now the variable part - lets read out TLVs*/
1384 ND_PRINT("\n\t\tran past the end");
1387 tlv_type
= GET_U_1(pptr
);
1389 tlv_len
= GET_BE_U_2(pptr
); /* length, in *bits* */
1390 ttlv_len
= (tlv_len
+ 7)/8; /* length, in *bytes* */
1395 ND_PRINT("\n\t\tcircuit status vector (%u) length: %u: 0x",
1398 while (ttlv_len
!= 0) {
1400 ND_PRINT(" (ran past the end)");
1404 ND_PRINT("%02x", GET_U_1(pptr
));
1411 ND_PRINT("\n\t\tunknown TLV #%u, length: %u",
1414 if (tlen
< ttlv_len
) {
1415 ND_PRINT(" (ran past the end)");
1424 /* complain bitterly ? */
1434 decode_prefix6(netdissect_options
*ndo
,
1435 const u_char
*pd
, u_int itemlen
, char *buf
, size_t buflen
)
1438 u_int plen
, plenbytes
;
1446 memset(&addr
, 0, sizeof(addr
));
1447 plenbytes
= (plen
+ 7) / 8;
1448 ITEMCHECK(plenbytes
);
1449 GET_CPY_BYTES(&addr
, pd
+ 1, plenbytes
);
1451 addr
[plenbytes
- 1] &=
1452 ((0xff00 >> (plen
% 8)) & 0xff);
1454 snprintf(buf
, buflen
, "%s/%u", ip6addr_string(ndo
, (const u_char
*)&addr
), plen
);
1455 return 1 + plenbytes
;
1462 print_labeled_prefix6(netdissect_options
*ndo
,
1463 const u_char
*pptr
, u_int itemlen
)
1466 u_int plen
, plenbytes
;
1468 /* prefix length and label = 4 bytes */
1471 plen
= GET_U_1(pptr
); /* get prefix length */
1476 plen
-= 24; /* adjust prefixlen - labellength */
1482 memset(&addr
, 0, sizeof(addr
));
1483 plenbytes
= (plen
+ 7) / 8;
1484 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
1486 addr
[plenbytes
- 1] &=
1487 ((0xff00 >> (plen
% 8)) & 0xff);
1489 /* the label may get offsetted by 4 bits so lets shift it right */
1490 ND_PRINT("\n\t %s/%u, label:%u %s",
1491 ip6addr_string(ndo
, (const u_char
*)&addr
),
1493 GET_BE_U_3(pptr
+ 1)>>4,
1494 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1496 return 4 + plenbytes
;
1499 ND_PRINT("\n\t (illegal prefix length)");
1510 print_labeled_vpn_prefix6(netdissect_options
*ndo
, const u_char
*pptr
)
1515 plen
= GET_U_1(pptr
); /* get prefix length */
1520 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1525 memset(&addr
, 0, sizeof(addr
));
1526 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1528 addr
[(plen
+ 7) / 8 - 1] &=
1529 ((0xff00 >> (plen
% 8)) & 0xff);
1531 /* the label may get offsetted by 4 bits so lets shift it right */
1532 ND_PRINT("\n\t RD: %s, %s/%u, label:%u %s",
1533 bgp_vpn_rd_print(ndo
, pptr
+4),
1534 ip6addr_string(ndo
, (const u_char
*)&addr
),
1536 GET_BE_U_3(pptr
+ 1)>>4,
1537 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1539 return 12 + (plen
+ 7) / 8;
1542 ND_PRINT("\n\t (illegal prefix length)");
1547 print_clnp_prefix(netdissect_options
*ndo
, const u_char
*pptr
)
1552 plen
= GET_U_1(pptr
); /* get prefix length */
1557 memset(&addr
, 0, sizeof(addr
));
1558 GET_CPY_BYTES(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1560 addr
[(plen
+ 7) / 8 - 1] &=
1561 ((0xff00 >> (plen
% 8)) & 0xff);
1563 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1564 ND_PRINT("\n\t %s/%u",
1565 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1568 return 1 + (plen
+ 7) / 8;
1571 ND_PRINT("\n\t (illegal prefix length)");
1576 print_labeled_vpn_clnp_prefix(netdissect_options
*ndo
, const u_char
*pptr
)
1581 plen
= GET_U_1(pptr
); /* get prefix length */
1586 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1591 memset(&addr
, 0, sizeof(addr
));
1592 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1594 addr
[(plen
+ 7) / 8 - 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
1596 /* the label may get offsetted by 4 bits so lets shift it right */
1597 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1598 ND_PRINT("\n\t RD: %s, %s/%u, label:%u %s",
1599 bgp_vpn_rd_print(ndo
, pptr
+4),
1600 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1602 GET_BE_U_3(pptr
+ 1)>>4,
1603 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1605 return 12 + (plen
+ 7) / 8;
1608 ND_PRINT("\n\t (illegal prefix length)");
1613 * bgp_attr_get_as_size
1615 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1616 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1617 * support, exchange AS-Path with the same path-attribute type value 0x02.
1620 bgp_attr_get_as_size(netdissect_options
*ndo
,
1621 uint8_t bgpa_type
, const u_char
*pptr
, u_int len
)
1623 const u_char
*tptr
= pptr
;
1626 * If the path attribute is the optional AS4 path type, then we already
1627 * know, that ASs must be encoded in 4 byte format.
1629 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1634 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1635 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1638 while (tptr
< pptr
+ len
) {
1640 * If we do not find a valid segment type, our guess might be wrong.
1642 if (GET_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| GET_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1645 tptr
+= 2 + GET_U_1(tptr
+ 1) * 2;
1649 * If we correctly reached end of the AS path attribute data content,
1650 * then most likely ASs were indeed encoded as 2 bytes.
1652 if (tptr
== pptr
+ len
) {
1659 * We can come here, either we did not have enough data, or if we
1660 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1661 * so that caller can try to decode each AS as of 4 bytes. If indeed
1662 * there was not enough data, it will crib and end the parse anyways.
1668 * The only way to know that a BGP UPDATE message is using add path is
1669 * by checking if the capability is in the OPEN message which we may have missed.
1670 * So this function checks if it is possible that the update could contain add path
1671 * and if so it checks that standard BGP doesn't make sense.
1674 check_add_path(netdissect_options
*ndo
, const u_char
*pptr
, u_int length
,
1675 u_int max_prefix_length
)
1677 u_int offset
, prefix_length
;
1684 * Scan through the NLRI information under the assumption that
1685 * it doesn't have path IDs.
1687 for (offset
= 0; offset
< length
;) {
1689 if (!ND_TTEST_1(pptr
+ offset
)) {
1690 /* We ran out of captured data; quit scanning. */
1693 prefix_length
= GET_U_1(pptr
+ offset
);
1695 * Add 4 to cover the path id
1696 * and check the prefix length isn't greater than 32/128.
1698 if (prefix_length
> max_prefix_length
) {
1701 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1702 offset
+= 1 + ((prefix_length
+ 7) / 8);
1704 /* check we haven't gone past the end of the section */
1705 if (offset
> length
) {
1709 /* check it's not standard BGP */
1710 for (offset
= 0; offset
< length
; ) {
1711 if (!ND_TTEST_1(pptr
+ offset
)) {
1712 /* We ran out of captured data; quit scanning. */
1715 prefix_length
= GET_U_1(pptr
+ offset
);
1717 * If the prefix_length is zero (0.0.0.0/0)
1718 * and since it's not the only address (length >= 5)
1719 * then it is add-path
1721 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1724 offset
+= 1 + ((prefix_length
+ 7) / 8);
1726 if (offset
> length
) {
1730 /* assume not add-path by default */
1735 bgp_mp_af_print(netdissect_options
*ndo
,
1736 const u_char
*tptr
, u_int tlen
,
1737 uint16_t *afp
, uint8_t *safip
)
1742 af
= GET_BE_U_2(tptr
);
1744 safi
= GET_U_1(tptr
+ 2);
1747 ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1748 tok2str(af_values
, "Unknown AFI", af
),
1750 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1751 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1754 switch(af
<<8 | safi
) {
1755 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
1756 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
1757 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
1758 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
1759 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
1760 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
1761 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
1762 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1763 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
):
1764 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
1765 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
1766 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
1767 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
1768 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
1769 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
1770 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
1771 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1772 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1773 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1774 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1775 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1776 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1777 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1778 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1779 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1780 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1781 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1784 ND_TCHECK_LEN(tptr
, tlen
);
1785 ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af
, safi
);
1786 if (ndo
->ndo_vflag
<= 1)
1787 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1796 bgp_nlri_print(netdissect_options
*ndo
, uint16_t af
, uint8_t safi
,
1797 const u_char
*tptr
, u_int len
,
1798 int add_path4
, int add_path6
)
1804 switch (af
<<8 | safi
) {
1805 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
1806 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
1807 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
1809 path_id
= GET_BE_U_4(tptr
);
1812 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1814 ND_PRINT("\n\t (illegal prefix length)");
1815 else if (advance
== -2)
1816 break; /* bytes left, but not enough */
1818 ND_PRINT("\n\t %s", buf
);
1820 ND_PRINT(" Path Id: %u", path_id
);
1824 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
1825 advance
= print_labeled_prefix4(ndo
, tptr
, len
);
1829 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
1830 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
1831 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1832 advance
= print_labeled_vpn_prefix4(ndo
, tptr
);
1834 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
1835 advance
= print_rt_routing_info(ndo
, tptr
);
1837 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1838 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST_VPN
):
1839 advance
= print_multicast_vpn(ndo
, tptr
);
1844 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
1845 advance
= print_mdt_vpn_nlri(ndo
, tptr
);
1849 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
1850 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
1851 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
1853 path_id
= GET_BE_U_4(tptr
);
1856 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1858 ND_PRINT("\n\t (illegal prefix length)");
1859 else if (advance
== -2)
1860 break; /* bytes left, but not enough */
1862 ND_PRINT("\n\t %s", buf
);
1864 ND_PRINT(" Path Id: %u", path_id
);
1868 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
1869 advance
= print_labeled_prefix6(ndo
, tptr
, len
);
1873 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
1874 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
1875 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1876 advance
= print_labeled_vpn_prefix6(ndo
, tptr
);
1878 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1879 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1880 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1881 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1882 advance
= print_labeled_vpn_l2(ndo
, tptr
);
1886 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1887 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1888 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1889 advance
= print_clnp_prefix(ndo
, tptr
);
1891 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1892 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1893 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1894 advance
= print_labeled_vpn_clnp_prefix(ndo
, tptr
);
1898 * This should not happen, we should have been protected
1899 * by bgp_mp_af_print()'s return value.
1901 ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af
, safi
);
1906 trunc
: /* we rely on the caller to recognize -2 return value */
1910 static const struct tok bgp_flags
[] = {
1919 bgp_attr_print(netdissect_options
*ndo
,
1920 uint8_t atype
, const u_char
*pptr
, u_int len
,
1921 const unsigned attr_set_level
)
1923 /* allocate space for the largest possible string */
1924 char astostr
[AS_STR_SIZE
];
1927 uint8_t safi
, snpa
, nhlen
;
1932 int add_path4
, add_path6
;
1939 case BGPTYPE_ORIGIN
:
1941 ND_PRINT("invalid len");
1943 ND_PRINT("%s", tok2str(bgp_origin_values
,
1944 "Unknown Origin Typecode",
1950 * Process AS4 byte path and AS2 byte path attributes here.
1952 case BGPTYPE_AS4_PATH
:
1953 case BGPTYPE_AS_PATH
:
1955 ND_PRINT("invalid len");
1964 * BGP updates exchanged between New speakers that support 4
1965 * byte AS, ASs are always encoded in 4 bytes. There is no
1966 * definitive way to find this, just by the packet's
1967 * contents. So, check for packet's TLV's sanity assuming
1968 * 2 bytes first, and it does not pass, assume that ASs are
1969 * encoded in 4 bytes format and move on.
1971 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1973 while (tptr
< pptr
+ len
) {
1974 ND_PRINT("%s", tok2str(bgp_as_path_segment_open_values
,
1975 "?", GET_U_1(tptr
)));
1976 for (i
= 0; i
< GET_U_1(tptr
+ 1) * as_size
; i
+= as_size
) {
1977 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
1979 as_printf(ndo
, astostr
, sizeof(astostr
),
1981 GET_BE_U_2(tptr
+ i
+ 2) :
1982 GET_BE_U_4(tptr
+ i
+ 2)));
1984 ND_PRINT("%s", tok2str(bgp_as_path_segment_close_values
,
1985 "?", GET_U_1(tptr
)));
1986 tptr
+= 2 + GET_U_1(tptr
+ 1) * as_size
;
1989 case BGPTYPE_NEXT_HOP
:
1991 ND_PRINT("invalid len");
1993 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
1996 case BGPTYPE_MULTI_EXIT_DISC
:
1997 case BGPTYPE_LOCAL_PREF
:
1999 ND_PRINT("invalid len");
2001 ND_PRINT("%u", GET_BE_U_4(tptr
));
2004 case BGPTYPE_ATOMIC_AGGREGATE
:
2006 ND_PRINT("invalid len");
2008 case BGPTYPE_AGGREGATOR
:
2011 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
2012 * the length of this PA can be either 6 bytes or 8 bytes.
2014 if (len
!= 6 && len
!= 8) {
2015 ND_PRINT("invalid len");
2018 ND_TCHECK_LEN(tptr
, len
);
2020 ND_PRINT(" AS #%s, origin %s",
2021 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(tptr
)),
2022 GET_IPADDR_STRING(tptr
+ 2));
2024 ND_PRINT(" AS #%s, origin %s",
2025 as_printf(ndo
, astostr
, sizeof(astostr
),
2026 GET_BE_U_4(tptr
)), GET_IPADDR_STRING(tptr
+ 4));
2029 case BGPTYPE_AGGREGATOR4
:
2031 ND_PRINT("invalid len");
2034 ND_PRINT(" AS #%s, origin %s",
2035 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)),
2036 GET_IPADDR_STRING(tptr
+ 4));
2038 case BGPTYPE_COMMUNITIES
:
2040 ND_PRINT("invalid len");
2048 comm
= GET_BE_U_4(tptr
);
2050 case BGP_COMMUNITY_NO_EXPORT
:
2051 ND_PRINT(" NO_EXPORT");
2053 case BGP_COMMUNITY_NO_ADVERT
:
2054 ND_PRINT(" NO_ADVERTISE");
2056 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
2057 ND_PRINT(" NO_EXPORT_SUBCONFED");
2061 (comm
>> 16) & 0xffff,
2063 (tlen
>4) ? ", " : "");
2070 case BGPTYPE_ORIGINATOR_ID
:
2072 ND_PRINT("invalid len");
2075 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2077 case BGPTYPE_CLUSTER_LIST
:
2079 ND_PRINT("invalid len");
2086 GET_IPADDR_STRING(tptr
),
2087 (tlen
>4) ? ", " : "");
2092 case BGPTYPE_MP_REACH_NLRI
:
2096 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2108 nhlen
= GET_U_1(tptr
);
2114 uint8_t tnhlen
= nhlen
;
2117 ND_PRINT("\n\t nexthop: ");
2118 while (tnhlen
!= 0) {
2122 switch(af
<<8 | safi
) {
2123 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
2124 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
2125 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
2126 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
2127 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
2128 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
):
2129 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
2130 if (tnhlen
< sizeof(nd_ipv4
)) {
2131 ND_PRINT("invalid len");
2136 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2137 tptr
+= sizeof(nd_ipv4
);
2138 tnhlen
-= sizeof(nd_ipv4
);
2139 tlen
-= sizeof(nd_ipv4
);
2142 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
2143 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
2144 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2145 if (tnhlen
< sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
) {
2146 ND_PRINT("invalid len");
2151 ND_PRINT("RD: %s, %s",
2152 bgp_vpn_rd_print(ndo
, tptr
),
2153 GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2154 tptr
+= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2155 tlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2156 tnhlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2159 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
2160 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
2161 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
2162 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
2163 if (tnhlen
< sizeof(nd_ipv6
)) {
2164 ND_PRINT("invalid len");
2169 ND_PRINT("%s", GET_IP6ADDR_STRING(tptr
));
2170 tptr
+= sizeof(nd_ipv6
);
2171 tlen
-= sizeof(nd_ipv6
);
2172 tnhlen
-= sizeof(nd_ipv6
);
2175 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
2176 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
2177 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2178 if (tnhlen
< sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
) {
2179 ND_PRINT("invalid len");
2184 ND_PRINT("RD: %s, %s",
2185 bgp_vpn_rd_print(ndo
, tptr
),
2186 GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2187 tptr
+= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2188 tlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2189 tnhlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2192 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2193 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2194 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2195 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2196 if (tnhlen
< sizeof(nd_ipv4
)) {
2197 ND_PRINT("invalid len");
2202 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
2203 tptr
+= (sizeof(nd_ipv4
));
2204 tlen
-= (sizeof(nd_ipv4
));
2205 tnhlen
-= (sizeof(nd_ipv4
));
2208 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2209 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2210 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2211 ND_PRINT("%s", GET_ISONSAP_STRING(tptr
, tnhlen
));
2217 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2218 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2219 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2220 if (tnhlen
< BGP_VPN_RD_LEN
+1) {
2221 ND_PRINT("invalid len");
2226 ND_TCHECK_LEN(tptr
, tnhlen
);
2227 ND_PRINT("RD: %s, %s",
2228 bgp_vpn_rd_print(ndo
, tptr
),
2229 GET_ISONSAP_STRING(tptr
+BGP_VPN_RD_LEN
,tnhlen
-BGP_VPN_RD_LEN
));
2230 /* rfc986 mapped IPv4 address ? */
2231 if (GET_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
2232 ND_PRINT(" = %s", GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
+4));
2233 /* rfc1888 mapped IPv6 address ? */
2234 else if (GET_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
2235 ND_PRINT(" = %s", GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
+3));
2243 * bgp_mp_af_print() should have saved us from
2244 * an unsupported AFI/SAFI.
2246 ND_PRINT("ERROR: no AFI %u/SAFI %u nexthop decoder", af
, safi
);
2254 ND_PRINT(", nh-length: %u", nhlen
);
2256 /* As per RFC 2858; this is reserved in RFC 4760 */
2259 snpa
= GET_U_1(tptr
);
2264 ND_PRINT("\n\t %u SNPA", snpa
);
2265 for (/*nothing*/; snpa
!= 0; snpa
--) {
2269 snpalen
= GET_U_1(tptr
);
2270 ND_PRINT("\n\t %u bytes", snpalen
);
2275 ND_TCHECK_LEN(tptr
, snpalen
);
2280 ND_PRINT(", no SNPA");
2283 add_path4
= check_add_path(ndo
, tptr
,
2284 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 32);
2285 add_path6
= check_add_path(ndo
, tptr
,
2286 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 128);
2288 while (tptr
< pptr
+ len
) {
2289 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
,
2290 add_path4
, add_path6
);
2299 case BGPTYPE_MP_UNREACH_NLRI
:
2300 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
2301 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2307 if (len
== BGP_MP_NLRI_MINSIZE
)
2308 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2312 add_path4
= check_add_path(ndo
, tptr
,
2313 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 32);
2314 add_path6
= check_add_path(ndo
, tptr
,
2315 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 128);
2317 while (tptr
< pptr
+ len
) {
2318 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
,
2319 add_path4
, add_path6
);
2327 case BGPTYPE_EXTD_COMMUNITIES
:
2329 ND_PRINT("invalid len");
2338 extd_comm
=GET_BE_U_2(tptr
);
2340 ND_PRINT("\n\t %s (0x%04x), Flags [%s]",
2341 tok2str(bgp_extd_comm_subtype_values
,
2342 "unknown extd community typecode",
2345 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
2351 bgp_extended_community_print(ndo
, tptr
);
2357 case BGPTYPE_PMSI_TUNNEL
:
2359 uint8_t tunnel_type
, flags
;
2364 flags
= GET_U_1(tptr
);
2365 tunnel_type
= GET_U_1(tptr
+ 1);
2367 ND_PRINT("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2368 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2370 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2371 GET_BE_U_3(tptr
+ 2)>>4);
2376 switch (tunnel_type
) {
2377 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2378 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2379 ND_PRINT("\n\t Sender %s, P-Group %s",
2380 GET_IPADDR_STRING(tptr
),
2381 GET_IPADDR_STRING(tptr
+4));
2384 case BGP_PMSI_TUNNEL_PIM_SSM
:
2385 ND_PRINT("\n\t Root-Node %s, P-Group %s",
2386 GET_IPADDR_STRING(tptr
),
2387 GET_IPADDR_STRING(tptr
+4));
2389 case BGP_PMSI_TUNNEL_INGRESS
:
2390 ND_PRINT("\n\t Tunnel-Endpoint %s",
2391 GET_IPADDR_STRING(tptr
));
2393 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2394 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2395 ND_PRINT("\n\t Root-Node %s, LSP-ID 0x%08x",
2396 GET_IPADDR_STRING(tptr
),
2397 GET_BE_U_4(tptr
+ 4));
2399 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2400 ND_PRINT("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2401 GET_IPADDR_STRING(tptr
),
2402 GET_BE_U_4(tptr
+ 4));
2405 if (ndo
->ndo_vflag
<= 1) {
2406 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2417 type
= GET_U_1(tptr
);
2418 length
= GET_BE_U_2(tptr
+ 1);
2422 ND_PRINT("\n\t %s TLV (%u), length %u",
2423 tok2str(bgp_aigp_values
, "Unknown", type
),
2431 * Check if we can read the TLV data.
2441 ND_PRINT(", metric %" PRIu64
,
2446 if (ndo
->ndo_vflag
<= 1) {
2447 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2456 case BGPTYPE_ATTR_SET
:
2460 ND_PRINT("\n\t Origin AS: %s",
2461 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)));
2466 u_int aflags
, alenlen
, alen
;
2470 ND_PRINT(" [path attr too short]");
2474 aflags
= GET_U_1(tptr
);
2475 atype
= GET_U_1(tptr
+ 1);
2478 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2479 ND_TCHECK_LEN(tptr
, alenlen
);
2480 if (len
< alenlen
) {
2481 ND_PRINT(" [path attr too short]");
2485 alen
= bgp_attr_len(aflags
, tptr
);
2489 ND_PRINT("\n\t %s (%u), length: %u",
2490 tok2str(bgp_attr_values
,
2491 "Unknown Attribute", atype
),
2496 ND_PRINT(", Flags [%s",
2497 bittok2str_nosep(bgp_flags
, "", aflags
));
2499 ND_PRINT("+%x", aflags
& 0xf);
2504 ND_PRINT(" [path attr too short]");
2509 * The protocol encoding per se allows ATTR_SET to be nested
2510 * as many times as the message can accommodate. This printer
2511 * used to be able to recurse into ATTR_SET contents until the
2512 * stack exhaustion, but now there is a limit on that (if live
2513 * protocol exchange goes that many levels deep, something is
2514 * probably wrong anyway). Feel free to refine this value if
2515 * you can find the spec with respective normative text.
2517 if (attr_set_level
== 10)
2518 ND_PRINT("(too many nested levels, not recursing)");
2519 else if (!bgp_attr_print(ndo
, atype
, tptr
, alen
, attr_set_level
+ 1))
2526 case BGPTYPE_LARGE_COMMUNITY
:
2527 if (len
== 0 || len
% 12) {
2528 ND_PRINT("invalid len");
2533 ND_PRINT("%u:%u:%u%s",
2535 GET_BE_U_4(tptr
+ 4),
2536 GET_BE_U_4(tptr
+ 8),
2537 (len
> 12) ? ", " : "");
2540 * len will always be a multiple of 12, as per the above,
2541 * so this will never underflow.
2546 case BGPTYPE_BGPSEC_PATH
:
2548 uint16_t sblen
, splen
;
2550 splen
= GET_BE_U_2(tptr
);
2553 * A secure path has a minimum length of 8 bytes:
2554 * 2 bytes length field
2555 * 6 bytes per secure path segment
2557 ND_ICHECKMSG_U("secure path length", splen
, <, 8);
2559 ND_PRINT("\n\t Secure Path Length: %u", splen
);
2563 /* Make sure the secure path length does not signal trailing bytes */
2565 ND_PRINT(" [total segments length %u != N x 6]", splen
);
2569 /* Parse secure path segments */
2570 while (splen
!= 0) {
2571 uint8_t pcount
= GET_U_1(tptr
);
2572 uint8_t flags
= GET_U_1(tptr
+ 1);
2573 uint32_t asn
= GET_BE_U_4(tptr
+ 2);
2574 ND_PRINT("\n\t Secure Path Segment: pCount: %u, Flags: [%s] (0x%02x), AS: %u",
2576 bittok2str(bgp_bgpsec_bitmap_str
, "none", flags
),
2583 sblen
= GET_BE_U_2(tptr
);
2585 ND_PRINT("\n\t Signature Block: Length: %u, Algo ID: %u",
2591 /* Parse signature segments */
2592 while (sblen
!= 0) {
2595 ND_PRINT("\n\t Signature Segment:\n\t SKI: ");
2596 ND_ICHECKMSG_U("remaining length", sblen
, <, 20);
2597 hex_print(ndo
, "\n\t ", tptr
, 20);
2600 ND_ICHECKMSG_U("remaining length", sblen
, <, 2);
2601 siglen
= GET_BE_U_2(tptr
);
2605 ND_PRINT("\n\t Length: %u", siglen
);
2606 ND_ICHECKMSG_U("remaining length", sblen
, <, siglen
);
2607 ND_PRINT("\n\t Signature:");
2608 hex_print(ndo
, "\n\t ", tptr
, siglen
);
2617 ND_PRINT("invalid len");
2620 ND_PRINT("\n\t OTC %u", GET_BE_U_4(pptr
));
2624 ND_TCHECK_LEN(pptr
, len
);
2625 ND_PRINT("\n\t no Attribute %u decoder", atype
); /* we have no decoder for the attribute */
2626 if (ndo
->ndo_vflag
<= 1)
2627 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2631 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2632 ND_TCHECK_LEN(pptr
, len
);
2633 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2638 nd_print_invalid(ndo
);
2646 bgp_capabilities_print(netdissect_options
*ndo
,
2647 const u_char
*opt
, u_int caps_len
)
2649 /* allocate space for the largest possible string */
2650 char astostr
[AS_STR_SIZE
];
2651 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2654 while (i
< caps_len
) {
2655 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2656 cap_type
=GET_U_1(opt
+ i
);
2657 cap_len
=GET_U_1(opt
+ i
+ 1);
2658 ND_PRINT("\n\t %s (%u), length: %u",
2659 tok2str(bgp_capcode_values
, "Unknown", cap_type
),
2662 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2664 case BGP_CAPCODE_MP
:
2665 /* AFI (16 bits), Reserved (8 bits), SAFI (8 bits) */
2667 ND_PRINT(" (too short, < 4)");
2670 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u)",
2671 tok2str(af_values
, "Unknown", GET_BE_U_2(opt
+ i
+ 2)),
2672 GET_BE_U_2(opt
+ i
+ 2),
2673 tok2str(bgp_safi_values
, "Unknown", GET_U_1(opt
+ i
+ 5)),
2674 GET_U_1(opt
+ i
+ 5));
2676 case BGP_CAPCODE_BGPSEC
:
2677 /* Version (4 bits), Direction (1 bit), Flags (3 bits), AFI (16 bits) */
2679 /* The capability length [...] MUST be set to 3. */
2681 ND_PRINT(" [%u != 3]", cap_len
);
2685 ND_PRINT("\n\t\tVersion %u, Direction %s (%u), AFI %s (%u)",
2686 GET_U_1(opt
+ i
+ 2)&0xf0,
2687 (GET_U_1(opt
+ i
+ 2)&0x08) ? "Send" : "Receive",
2688 (GET_U_1(opt
+ i
+ 2)&0x08)>>3,
2689 bittok2str(af_values
, "Unknown",
2690 GET_BE_U_2(opt
+ i
+ cap_offset
+ 2)),
2691 GET_BE_U_2(opt
+ i
+ cap_offset
+ 2));
2693 case BGP_CAPCODE_ML
:
2696 while (tcap_len
>= 4) {
2697 ND_PRINT( "\n\t\tAFI %s (%u), SAFI %s (%u), Count: %u",
2698 tok2str(af_values
, "Unknown",
2699 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2700 GET_BE_U_2(opt
+ i
+ cap_offset
),
2701 tok2str(bgp_safi_values
, "Unknown",
2702 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2703 GET_U_1(opt
+ i
+ cap_offset
+ 2),
2704 GET_U_1(opt
+ i
+ cap_offset
+ 3));
2709 case BGP_CAPCODE_RESTART
:
2710 /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */
2712 ND_PRINT(" (too short, < 2)");
2716 ND_PRINT("\n\t\tRestart Flags: [%s], Restart Time %us",
2717 bittok2str(bgp_graceful_restart_comm_flag_values
,
2718 "none", GET_U_1(opt
+ i
+ 2) >> 4),
2719 GET_BE_U_2(opt
+ i
+ 2)&0xfff);
2722 while(tcap_len
>=4) {
2723 ND_PRINT("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2724 tok2str(af_values
,"Unknown",
2725 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2726 GET_BE_U_2(opt
+ i
+ cap_offset
),
2727 tok2str(bgp_safi_values
,"Unknown",
2728 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2729 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2730 ((GET_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" );
2735 case BGP_CAPCODE_ROLE
:
2737 ND_PRINT(" (too short, < 1)");
2740 ND_PRINT("\n\t\tRole name %s (%u)",
2741 tok2str(bgp_role_values
, "Unassigned",
2742 GET_U_1(opt
+ i
+ 2)), GET_U_1(opt
+ i
+ 2));
2744 case BGP_CAPCODE_RR
:
2745 case BGP_CAPCODE_LLGR
:
2746 case BGP_CAPCODE_RR_CISCO
:
2747 case BGP_CAPCODE_EXT_MSG
:
2748 case BGP_CAPCODE_ENH_RR
:
2750 case BGP_CAPCODE_AS_NEW
:
2752 * Extract the 4 byte AS number encoded.
2755 ND_PRINT(" (too short, < 4)");
2758 ND_PRINT("\n\t\t 4 Byte AS %s",
2759 as_printf(ndo
, astostr
, sizeof(astostr
),
2760 GET_BE_U_4(opt
+ i
+ 2)));
2762 case BGP_CAPCODE_ADD_PATH
:
2764 ND_PRINT(" (bogus)"); /* length */
2769 while (tcap_len
!= 0) {
2771 nd_print_invalid(ndo
);
2774 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2775 tok2str(af_values
,"Unknown",GET_BE_U_2(opt
+ i
+ cap_offset
)),
2776 GET_BE_U_2(opt
+ i
+ cap_offset
),
2777 tok2str(bgp_safi_values
,"Unknown",GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2778 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2779 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",GET_U_1(opt
+ i
+ cap_offset
+ 3))
2786 ND_PRINT("\n\t\tno decoder for Capability %u",
2788 if (ndo
->ndo_vflag
<= 1)
2789 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2793 if (ndo
->ndo_vflag
> 1 && cap_len
!= 0) {
2794 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2796 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2801 nd_print_trunc(ndo
);
2805 bgp_open_print(netdissect_options
*ndo
,
2806 const u_char
*dat
, u_int length
)
2808 /* allocate space for the largest possible string */
2809 char astostr
[AS_STR_SIZE
];
2810 const struct bgp_open
*bgp_open_header
;
2813 const struct bgp_opt
*bgpopt
;
2816 uint8_t extended_opt_params
= 0;
2817 u_int open_size
= BGP_OPEN_SIZE
;
2818 u_int opt_size
= BGP_OPT_SIZE
;
2820 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2821 if (length
< BGP_OPEN_SIZE
)
2824 bgp_open_header
= (const struct bgp_open
*)dat
;
2826 ND_PRINT("\n\t Version %u, ",
2827 GET_U_1(bgp_open_header
->bgpo_version
));
2828 ND_PRINT("my AS %s, ",
2829 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(bgp_open_header
->bgpo_myas
)));
2830 ND_PRINT("Holdtime %us, ",
2831 GET_BE_U_2(bgp_open_header
->bgpo_holdtime
));
2832 ND_PRINT("ID %s", GET_IPADDR_STRING(bgp_open_header
->bgpo_id
));
2833 optslen
= GET_U_1(bgp_open_header
->bgpo_optlen
);
2834 opsttype
= GET_U_1(bgp_open_header
->bgpo_opttype
);
2835 if (opsttype
== BGP_OPEN_NON_EXT_OPT_TYPE_EXTENDED_LENGTH
) {
2836 optslen
= GET_BE_U_2(bgp_open_header
->bgpo_optlen_extended
);
2837 extended_opt_params
= 1;
2841 ND_PRINT("\n\t Optional parameters%s, length: %u",
2842 extended_opt_params
? " (Extended)" : "", optslen
);
2844 opt
= dat
+ open_size
;
2845 length
-= open_size
;
2848 while (i
< optslen
) {
2852 ND_TCHECK_LEN(opt
+ i
, opt_size
);
2853 if (length
< opt_size
+ i
)
2855 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2856 opt_type
= GET_U_1(bgpopt
->bgpopt_type
);
2857 opt_len
= extended_opt_params
? GET_BE_U_2(bgpopt
->bgpopt_len
)
2858 : GET_U_1(bgpopt
->bgpopt_len
);
2859 if (opt_size
+ i
+ opt_len
> optslen
) {
2860 ND_PRINT("\n\t Option %u, length: %u, goes past the end of the options",
2865 ND_PRINT("\n\t Option %s (%u), length: %u",
2866 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2870 /* now let's decode the options we know*/
2874 bgp_capabilities_print(ndo
, opt
+ opt_size
+ i
,
2880 ND_PRINT("\n\t no decoder for option %u",
2884 i
+= opt_size
+ opt_len
;
2888 nd_print_trunc(ndo
);
2892 bgp_update_print(netdissect_options
*ndo
,
2893 const u_char
*dat
, u_int length
)
2896 u_int withdrawn_routes_len
;
2904 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2905 if (length
< BGP_SIZE
)
2910 /* Unfeasible routes */
2914 withdrawn_routes_len
= GET_BE_U_2(p
);
2917 if (withdrawn_routes_len
> 1) {
2919 * Without keeping state from the original NLRI message,
2920 * it's not possible to tell if this a v4 or v6 route,
2921 * so only try to decode it if we're not v6 enabled.
2923 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2924 if (length
< withdrawn_routes_len
)
2926 ND_PRINT("\n\t Withdrawn routes:");
2927 add_path
= check_add_path(ndo
, p
, withdrawn_routes_len
, 32);
2928 while (withdrawn_routes_len
!= 0) {
2930 if (withdrawn_routes_len
< 4) {
2931 p
+= withdrawn_routes_len
;
2932 length
-= withdrawn_routes_len
;
2935 path_id
= GET_BE_U_4(p
);
2938 withdrawn_routes_len
-= 4;
2940 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2942 ND_PRINT("\n\t (illegal prefix length)");
2944 } else if (wpfx
== -2)
2945 goto trunc
; /* bytes left, but not enough */
2947 ND_PRINT("\n\t %s", buf
);
2949 ND_PRINT(" Path Id: %u", path_id
);
2953 withdrawn_routes_len
-= wpfx
;
2957 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2958 if (length
< withdrawn_routes_len
)
2960 p
+= withdrawn_routes_len
;
2961 length
-= withdrawn_routes_len
;
2967 len
= GET_BE_U_2(p
);
2971 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2972 /* No withdrawn routes, no path attributes, no NLRI */
2973 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2978 /* Make sure the path attributes don't go past the end of the packet */
2981 /* do something more useful!*/
2983 uint8_t aflags
, atype
, alenlen
;
2990 ND_PRINT("\n\t [path attrs too short]");
2995 aflags
= GET_U_1(p
);
2996 atype
= GET_U_1(p
+ 1);
3000 alenlen
= bgp_attr_lenlen(aflags
, p
);
3001 ND_TCHECK_LEN(p
, alenlen
);
3002 if (length
< alenlen
)
3004 if (len
< alenlen
) {
3005 ND_PRINT("\n\t [path attrs too short]");
3010 alen
= bgp_attr_len(aflags
, p
);
3015 ND_PRINT("\n\t %s (%u), length: %u",
3016 tok2str(bgp_attr_values
, "Unknown Attribute", atype
),
3021 ND_PRINT(", Flags [%s",
3022 bittok2str_nosep(bgp_flags
, "", aflags
));
3024 ND_PRINT("+%x", aflags
& 0xf);
3028 ND_PRINT(" [path attrs too short]");
3035 if (!bgp_attr_print(ndo
, atype
, p
, alen
, 0))
3044 add_path
= check_add_path(ndo
, p
, length
, 32);
3045 ND_PRINT("\n\t Updated routes:");
3046 while (length
!= 0) {
3051 path_id
= GET_BE_U_4(p
);
3055 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
3057 ND_PRINT("\n\t (illegal prefix length)");
3060 goto trunc
; /* bytes left, but not enough */
3062 ND_PRINT("\n\t %s", buf
);
3064 ND_PRINT(" Path Id: %u", path_id
);
3073 nd_print_trunc(ndo
);
3077 bgp_notification_print_code(netdissect_options
*ndo
,
3078 const u_char
*dat
, u_int length
,
3079 uint8_t bgpn_major
, uint8_t bgpn_minor
)
3081 ND_PRINT(", %s (%u)",
3082 tok2str(bgp_notify_major_values
, "Unknown Error",
3086 switch (bgpn_major
) {
3088 case BGP_NOTIFY_MAJOR_MSG
:
3089 ND_PRINT(", subcode %s (%u)",
3090 tok2str(bgp_notify_minor_msg_values
, "Unknown",
3094 case BGP_NOTIFY_MAJOR_OPEN
:
3095 ND_PRINT(", subcode %s (%u)",
3096 tok2str(bgp_notify_minor_open_values
, "Unknown",
3100 case BGP_NOTIFY_MAJOR_UPDATE
:
3101 ND_PRINT(", subcode %s (%u)",
3102 tok2str(bgp_notify_minor_update_values
, "Unknown",
3106 case BGP_NOTIFY_MAJOR_FSM
:
3107 ND_PRINT(" subcode %s (%u)",
3108 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
3112 case BGP_NOTIFY_MAJOR_ROUTEREFRESH
:
3113 ND_PRINT(" subcode %s (%u)",
3114 tok2str(bgp_notify_minor_routerefresh_values
, "Unknown",
3118 case BGP_NOTIFY_MAJOR_CEASE
:
3119 ND_PRINT(", subcode %s (%u)",
3120 tok2str(bgp_notify_minor_cease_values
, "Unknown",
3124 /* RFC 4486 mentions optionally 7 bytes
3125 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
3127 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= 7) {
3128 ND_PRINT(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
3129 tok2str(af_values
, "Unknown", GET_BE_U_2(dat
)),
3131 tok2str(bgp_safi_values
, "Unknown", GET_U_1((dat
+ 2))),
3133 GET_BE_U_4(dat
+ 3));
3136 * RFC 9003 describes a method to send a communication
3137 * intended for human consumption regarding the Administrative Shutdown
3139 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
3140 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
3142 uint8_t shutdown_comm_length
= GET_U_1(dat
);
3143 uint8_t remainder_offset
= 0;
3144 /* garbage, hexdump it all */
3145 if (shutdown_comm_length
> length
- 1) {
3146 ND_PRINT(", invalid Shutdown Communication length");
3147 } else if (shutdown_comm_length
== 0) {
3148 ND_PRINT(", empty Shutdown Communication");
3149 remainder_offset
+= 1;
3151 /* a proper shutdown communication */
3153 ND_PRINT(", Shutdown Communication (length: %u): \"", shutdown_comm_length
);
3154 nd_printjn(ndo
, dat
+1, shutdown_comm_length
);
3156 remainder_offset
+= shutdown_comm_length
+ 1;
3158 /* if there is trailing data, hexdump it */
3159 if(length
- remainder_offset
> 0) {
3160 ND_PRINT(", Data: (length: %u)", length
- remainder_offset
);
3161 hex_print(ndo
, "\n\t\t", dat
+ remainder_offset
, length
- remainder_offset
);
3165 * RFC8538 describes the Hard Reset cease subcode, which contains another
3166 * notification code and subcode.
3168 if (bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_HARDRESET
&& length
>= 2) {
3169 bgpn_major
= GET_U_1(dat
++);
3170 bgpn_minor
= GET_U_1(dat
++);
3172 bgp_notification_print_code(ndo
, dat
, length
, bgpn_major
, bgpn_minor
);
3176 if (bgpn_minor
!= 0) {
3177 ND_PRINT(", subcode %u", bgpn_minor
);
3186 bgp_notification_print(netdissect_options
*ndo
,
3187 const u_char
*dat
, u_int length
)
3189 const struct bgp_notification
*bgp_notification_header
;
3190 uint8_t bgpn_major
, bgpn_minor
;
3192 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
3193 if (length
<BGP_NOTIFICATION_SIZE
)
3196 bgp_notification_header
= (const struct bgp_notification
*)dat
;
3197 bgpn_major
= GET_U_1(bgp_notification_header
->bgpn_major
);
3198 bgpn_minor
= GET_U_1(bgp_notification_header
->bgpn_minor
);
3199 bgp_notification_print_code(ndo
, dat
+ BGP_NOTIFICATION_SIZE
,
3200 length
- BGP_NOTIFICATION_SIZE
, bgpn_major
, bgpn_minor
);
3203 nd_print_trunc(ndo
);
3207 bgp_route_refresh_print(netdissect_options
*ndo
,
3208 const u_char
*pptr
, u_int len
)
3210 const struct bgp_route_refresh
*bgp_route_refresh_header
;
3212 /* some little sanity checking */
3213 if (len
<BGP_ROUTE_REFRESH_SIZE
)
3216 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
3218 ND_PRINT("\n\t AFI %s (%u), SAFI %s (%u), Subtype %s (%u)",
3219 tok2str(af_values
, "Unknown",
3220 GET_BE_U_2(bgp_route_refresh_header
->afi
)),
3221 GET_BE_U_2(bgp_route_refresh_header
->afi
),
3222 tok2str(bgp_safi_values
, "Unknown",
3223 GET_U_1(bgp_route_refresh_header
->safi
)),
3224 GET_U_1(bgp_route_refresh_header
->safi
),
3225 tok2str(bgp_route_refresh_subtype_values
, "Unknown",
3226 GET_U_1(bgp_route_refresh_header
->subtype
)),
3227 GET_U_1(bgp_route_refresh_header
->subtype
));
3230 if (len
>= BGP_ROUTE_REFRESH_SIZE_ORF
) {
3231 const struct bgp_route_refresh_orf
*orf_header
;
3234 (const struct bgp_route_refresh_orf
*)(pptr
+ BGP_ROUTE_REFRESH_SIZE
);
3236 ND_PRINT("\n\t ORF refresh %s (%u), ORF type %s (%u), ORF length %u",
3237 tok2str(bgp_orf_refresh_type
, "Unknown",
3238 GET_U_1(orf_header
->refresh
)),
3239 GET_U_1(orf_header
->refresh
),
3240 tok2str(bgp_orf_type
, "Unknown", GET_U_1(orf_header
->type
)),
3241 GET_U_1(orf_header
->type
), GET_BE_U_2(orf_header
->len
));
3244 if (ndo
->ndo_vflag
> 1) {
3245 ND_TCHECK_LEN(pptr
, len
);
3246 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
3251 nd_print_trunc(ndo
);
3255 bgp_pdu_print(netdissect_options
*ndo
,
3256 const u_char
*dat
, u_int length
)
3258 const struct bgp
*bgp_header
;
3261 ND_TCHECK_LEN(dat
, BGP_SIZE
);
3262 bgp_header
= (const struct bgp
*)dat
;
3263 bgp_type
= GET_U_1(bgp_header
->bgp_type
);
3265 ND_PRINT("\n\t%s Message (%u), length: %u",
3266 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
3272 bgp_open_print(ndo
, dat
, length
);
3275 bgp_update_print(ndo
, dat
, length
);
3277 case BGP_NOTIFICATION
:
3278 bgp_notification_print(ndo
, dat
, length
);
3282 case BGP_ROUTE_REFRESH
:
3283 bgp_route_refresh_print(ndo
, dat
, length
);
3286 /* we have no decoder for the BGP message */
3287 ND_TCHECK_LEN(dat
, length
);
3288 ND_PRINT("\n\t no Message %u decoder", bgp_type
);
3289 print_unknown_data(ndo
, dat
, "\n\t ", length
);
3294 nd_print_trunc(ndo
);
3299 bgp_print(netdissect_options
*ndo
,
3300 const u_char
*dat
, u_int length _U_
)
3303 const u_char
*ep
= ndo
->ndo_snapend
;
3304 const u_char
*start
;
3305 const u_char marker
[] = {
3306 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3307 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3309 const struct bgp
*bgp_header
;
3312 ndo
->ndo_protocol
= "bgp";
3315 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
3323 if (GET_U_1(p
) != 0xff) {
3328 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
3330 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
3335 /* found BGP header */
3336 ND_TCHECK_LEN(p
, BGP_SIZE
);
3337 bgp_header
= (const struct bgp
*)p
;
3340 nd_print_trunc(ndo
);
3342 hlen
= GET_BE_U_2(bgp_header
->bgp_len
);
3343 if (hlen
< BGP_SIZE
) {
3344 ND_PRINT("\nmessage length %u < %u", hlen
, BGP_SIZE
);
3345 nd_print_invalid(ndo
);
3349 if (ND_TTEST_LEN(p
, hlen
)) {
3350 if (!bgp_pdu_print(ndo
, p
, hlen
))
3355 ND_PRINT("\n[|BGP %s]",
3356 tok2str(bgp_msg_values
,
3357 "Unknown Message Type",
3358 GET_U_1(bgp_header
->bgp_type
)));
3366 nd_print_trunc(ndo
);