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
,
897 /* allocate space for the largest possible string */
898 char astostr
[AS_STR_SIZE
];
900 switch (GET_BE_U_2(pptr
)) {
902 case BGP_EXT_COM_RT_0
:
903 case BGP_EXT_COM_RO_0
:
904 case BGP_EXT_COM_L2VPN_RT_0
:
905 ND_PRINT("%u:%u (= %s)",
906 GET_BE_U_2(pptr
+ 2),
907 GET_BE_U_4(pptr
+ 4),
908 GET_IPADDR_STRING(pptr
+4));
911 case BGP_EXT_COM_RT_1
:
912 case BGP_EXT_COM_RO_1
:
913 case BGP_EXT_COM_L2VPN_RT_1
:
914 case BGP_EXT_COM_VRF_RT_IMP
:
916 GET_IPADDR_STRING(pptr
+2),
917 GET_BE_U_2(pptr
+ 6));
920 case BGP_EXT_COM_RT_2
:
921 case BGP_EXT_COM_RO_2
:
923 as_printf(ndo
, astostr
, sizeof(astostr
),
924 GET_BE_U_4(pptr
+ 2)), GET_BE_U_2(pptr
+ 6));
927 case BGP_EXT_COM_LINKBAND
:
928 bw
= GET_BE_F_4(pptr
+ 4);
929 ND_PRINT("bandwidth: %.3f Mbps",
933 case BGP_EXT_COM_OVS
:
934 /* The Reserved field MUST be set to 0 and ignored upon the
935 * receipt of this community.
938 uint64_t reserved
= GET_BE_U_5(pptr
+ 2);
941 ND_PRINT("[the reserved field 0x%" PRIx64
" MUST be 0] ",
944 tok2str(bgp_prefix_origin_validation_state
,
945 "unknown origin validation state",
950 case BGP_EXT_COM_VPN_ORIGIN
:
951 case BGP_EXT_COM_VPN_ORIGIN2
:
952 case BGP_EXT_COM_VPN_ORIGIN3
:
953 case BGP_EXT_COM_VPN_ORIGIN4
:
954 case BGP_EXT_COM_OSPF_RID
:
955 case BGP_EXT_COM_OSPF_RID2
:
956 ND_PRINT("%s", GET_IPADDR_STRING(pptr
+2));
959 case BGP_EXT_COM_OSPF_RTYPE
:
960 case BGP_EXT_COM_OSPF_RTYPE2
:
961 ND_PRINT("area:%s, router-type:%s, metric-type:%s%s",
962 GET_IPADDR_STRING(pptr
+2),
963 tok2str(bgp_extd_comm_ospf_rtype_values
,
965 GET_U_1((pptr
+ 6))),
966 (GET_U_1(pptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
967 ((GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
970 case BGP_EXT_COM_L2INFO
:
971 ND_PRINT("%s Control Flags [0x%02x]:MTU %u",
972 tok2str(l2vpn_encaps_values
,
974 GET_U_1((pptr
+ 2))),
976 GET_BE_U_2(pptr
+ 4));
979 case BGP_EXT_COM_SOURCE_AS
:
980 ND_PRINT("AS %u", GET_BE_U_2(pptr
+ 2));
983 case BGP_EXT_COM_ENCAP
:
984 ND_PRINT("Tunnel type: %s", tok2str(bgp_extd_comm_encap_tunnel_values
,
986 GET_BE_U_2(pptr
+ 6)));
990 ND_PRINT("%02x%02x%02x%02x%02x%02x",
1002 * RFC4684 (Section 4)/RFC2858 (Section 4).
1003 * RTC membership prefix is structured as follows
1004 * [prefix-len] [origin-as] [route-target]
1005 * The route-target is encoded as RT ext-comms.
1006 * Prefix-len may be 0, 32..96
1008 * Note that pptr is not packet data - it is
1009 * a buffer owned by our caller - therefore GET_*
1010 * macros can not be used.
1013 bgp_rt_prefix_print(netdissect_options
*ndo
,
1017 /* allocate space for the largest possible string */
1018 char rtc_prefix_in_hex
[sizeof("0000 0000 0000 0000")] = "";
1019 u_int rtc_prefix_in_hex_len
= 0;
1020 static char output
[61]; /* max response string */
1021 /* allocate space for the largest possible string */
1022 char astostr
[AS_STR_SIZE
];
1023 uint16_t ec_type
= 0;
1028 snprintf(output
, sizeof(output
), "route-target: 0:0/0");
1032 /* hex representation of the prefix */
1033 octet_count
= (plen
+7)/8;
1034 for (i
=0; i
<octet_count
; i
++) {
1035 rtc_prefix_in_hex_len
+= snprintf(rtc_prefix_in_hex
+rtc_prefix_in_hex_len
,
1036 sizeof(rtc_prefix_in_hex
)-rtc_prefix_in_hex_len
,
1037 "%02x%s", *(pptr
+i
),
1038 ((i
%2 == 1) && (i
<octet_count
-1)) ? " " : "");
1043 * The prefix is too short to include the full ext-comm type,
1044 * so we have no way to parse it further.
1046 snprintf(output
, sizeof(output
), "route-target: partial-type: (%s/%d)",
1047 rtc_prefix_in_hex
, plen
);
1052 * get the ext-comm type
1053 * Note: pptr references a static 8 octet buffer with unused bits set to 0,
1054 * hence EXTRACT_*() macros are safe.
1056 ec_type
= EXTRACT_BE_U_2(pptr
);
1058 case BGP_EXT_COM_RT_0
:
1059 /* 2-byte-AS:number fmt */
1060 snprintf(output
, sizeof(output
), "route-target: %u:%u/%d (%s)",
1061 EXTRACT_BE_U_2(pptr
+2),
1062 EXTRACT_BE_U_4(pptr
+4),
1063 plen
, rtc_prefix_in_hex
);
1066 case BGP_EXT_COM_RT_1
:
1067 /* IP-address:AS fmt */
1068 snprintf(output
, sizeof(output
), "route-target: %u.%u.%u.%u:%u/%d (%s)",
1069 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5),
1070 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
1073 case BGP_EXT_COM_RT_2
:
1074 /* 4-byte-AS:number fmt */
1075 snprintf(output
, sizeof(output
), "route-target: %s:%u/%d (%s)",
1076 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(pptr
+2)),
1077 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
1081 snprintf(output
, sizeof(output
), "route target: unknown-type(%04x) (%s/%d)",
1083 rtc_prefix_in_hex
, plen
);
1091 print_rt_routing_info(netdissect_options
*ndo
, const u_char
*pptr
)
1093 uint8_t route_target
[8];
1095 /* allocate space for the largest possible string */
1096 char astostr
[AS_STR_SIZE
];
1099 /* NLRI "prefix length" from RFC 2858 Section 4. */
1100 plen
= GET_U_1(pptr
); /* get prefix length */
1102 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
1103 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
1104 * target" fields inside the "prefix" depending on its length.
1107 /* Without "origin AS", without "route target". */
1108 ND_PRINT("\n\t default route target");
1113 ND_PRINT("\n\t (illegal prefix length)");
1117 /* With at least "origin AS", possibly with "route target". */
1118 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 1));
1120 plen
-= 32; /* adjust prefix length */
1123 ND_PRINT("\n\t (illegal prefix length)");
1127 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
1128 * and gives the number of octets in the variable-length "route
1129 * target" field inside this NLRI "prefix". Look for it.
1131 memset(&route_target
, 0, sizeof(route_target
));
1132 num_octets
= (plen
+ 7) / 8;
1133 GET_CPY_BYTES(&route_target
, pptr
+ 5, num_octets
);
1134 /* If mask-len is not on octet boundary, ensure all extra bits are 0 */
1136 ((u_char
*)&route_target
)[num_octets
- 1] &=
1137 ((0xff00 >> (plen
% 8)) & 0xff);
1139 ND_PRINT("\n\t origin AS: %s, %s",
1141 bgp_rt_prefix_print(ndo
, (u_char
*)&route_target
, plen
));
1143 return 5 + num_octets
;
1147 print_labeled_vpn_prefix4(netdissect_options
*ndo
, const u_char
*pptr
)
1152 plen
= GET_U_1(pptr
); /* get prefix length */
1157 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1162 memset(&addr
, 0, sizeof(addr
));
1163 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1165 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
1166 ((0xff00 >> (plen
% 8)) & 0xff);
1168 /* the label may get offsetted by 4 bits so lets shift it right */
1169 ND_PRINT("\n\t RD: %s, %s/%u, label:%u %s",
1170 bgp_vpn_rd_print(ndo
, pptr
+4),
1171 ipaddr_string(ndo
, (const u_char
*)&addr
),
1173 GET_BE_U_3(pptr
+ 1)>>4,
1174 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1176 return 12 + (plen
+ 7) / 8;
1179 ND_PRINT("\n\t (illegal prefix length)");
1184 * +-------------------------------+
1186 * | RD:IPv4-address (12 octets) |
1188 * +-------------------------------+
1189 * | MDT Group-address (4 octets) |
1190 * +-------------------------------+
1193 #define MDT_VPN_NLRI_LEN 16
1196 print_mdt_vpn_nlri(netdissect_options
*ndo
, const u_char
*pptr
)
1199 const u_char
*vpn_ip
;
1201 /* if the NLRI is not predefined length, quit.*/
1202 if (GET_U_1(pptr
) != MDT_VPN_NLRI_LEN
* 8) {
1203 ND_PRINT("\n\t (illegal prefix length)");
1215 pptr
+= sizeof(nd_ipv4
);
1217 /* MDT Group Address */
1218 ND_PRINT("\n\t RD: %s, VPN IP Address: %s, MC Group Address: %s",
1219 bgp_vpn_rd_print(ndo
, rd
),
1220 GET_IPADDR_STRING(vpn_ip
),
1221 GET_IPADDR_STRING(pptr
));
1223 return MDT_VPN_NLRI_LEN
+ 1;
1229 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
1230 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
1231 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
1232 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
1233 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
1234 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
1235 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
1237 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
1238 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
1239 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
1240 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
1241 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
1242 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
1243 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
1244 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
1249 print_multicast_vpn(netdissect_options
*ndo
, const u_char
*pptr
)
1251 /* allocate space for the largest possible string */
1252 char astostr
[AS_STR_SIZE
];
1253 uint8_t route_type
, route_length
;
1254 u_int addr_length
, sg_length
;
1256 route_type
= GET_U_1(pptr
);
1258 route_length
= GET_U_1(pptr
);
1261 ND_PRINT("\n\t Route-Type: %s (%u), length: %u",
1262 tok2str(bgp_multicast_vpn_route_type_values
,
1263 "Unknown", route_type
),
1264 route_type
, route_length
);
1266 switch(route_type
) {
1267 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
1268 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1269 if (route_length
< BGP_VPN_RD_LEN
)
1271 ND_PRINT(", RD: %s, Originator %s",
1272 bgp_vpn_rd_print(ndo
, pptr
),
1273 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
1274 (route_length
- BGP_VPN_RD_LEN
) << 3));
1276 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
1277 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1278 ND_PRINT(", RD: %s, Source-AS %s",
1279 bgp_vpn_rd_print(ndo
, pptr
),
1280 as_printf(ndo
, astostr
, sizeof(astostr
),
1281 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1284 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
1285 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1286 ND_PRINT(", RD: %s", bgp_vpn_rd_print(ndo
, pptr
));
1287 pptr
+= BGP_VPN_RD_LEN
;
1289 sg_length
= bgp_vpn_sg_print(ndo
, pptr
);
1290 addr_length
= route_length
- sg_length
;
1292 ND_TCHECK_LEN(pptr
, addr_length
);
1293 ND_PRINT(", Originator %s",
1294 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
1297 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
1298 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1299 ND_PRINT(", RD: %s", bgp_vpn_rd_print(ndo
, pptr
));
1300 pptr
+= BGP_VPN_RD_LEN
;
1302 bgp_vpn_sg_print(ndo
, pptr
);
1305 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
1306 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
1307 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1308 ND_PRINT(", RD: %s, Source-AS %s",
1309 bgp_vpn_rd_print(ndo
, pptr
),
1310 as_printf(ndo
, astostr
, sizeof(astostr
),
1311 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1312 pptr
+= BGP_VPN_RD_LEN
+ 4;
1314 bgp_vpn_sg_print(ndo
, pptr
);
1318 * no per route-type printing yet.
1320 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1325 return route_length
+ 2;
1332 * As I remember, some versions of systems have an snprintf() that
1333 * returns -1 if the buffer would have overflowed. If the return
1334 * value is negative, set buflen to 0, to indicate that we've filled
1337 * If the return value is greater than buflen, that means that
1338 * the buffer would have overflowed; again, set buflen to 0 in
1341 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1344 else if ((u_int)stringlen>buflen) \
1347 buflen-=stringlen; \
1352 print_labeled_vpn_l2(netdissect_options
*ndo
, const u_char
*pptr
)
1354 u_int plen
, tlen
, tlv_type
, tlv_len
, ttlv_len
;
1356 plen
= GET_BE_U_2(pptr
);
1359 /* Old and new L2VPN NLRI share AFI/SAFI
1360 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1361 * and > 17 as old format. Complain for the middle case
1364 /* assume AD-only with RD, BGPNH */
1365 ND_TCHECK_LEN(pptr
, 12);
1366 ND_PRINT("\n\t RD: %s, BGPNH: %s",
1367 bgp_vpn_rd_print(ndo
, pptr
),
1368 GET_IPADDR_STRING(pptr
+8));
1370 } else if (plen
> 17) {
1371 /* assume old format */
1372 /* RD, ID, LBLKOFF, LBLBASE */
1374 ND_TCHECK_LEN(pptr
, 15);
1375 ND_PRINT("\n\t RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1376 bgp_vpn_rd_print(ndo
, pptr
),
1377 GET_BE_U_2(pptr
+ 8),
1378 GET_BE_U_2(pptr
+ 10),
1379 GET_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1383 /* ok now the variable part - lets read out TLVs*/
1386 ND_PRINT("\n\t\tran past the end");
1389 tlv_type
= GET_U_1(pptr
);
1391 tlv_len
= GET_BE_U_2(pptr
); /* length, in *bits* */
1392 ttlv_len
= (tlv_len
+ 7)/8; /* length, in *bytes* */
1397 ND_PRINT("\n\t\tcircuit status vector (%u) length: %u: 0x",
1400 while (ttlv_len
!= 0) {
1402 ND_PRINT(" (ran past the end)");
1406 ND_PRINT("%02x", GET_U_1(pptr
));
1413 ND_PRINT("\n\t\tunknown TLV #%u, length: %u",
1416 if (tlen
< ttlv_len
) {
1417 ND_PRINT(" (ran past the end)");
1426 /* complain bitterly ? */
1436 decode_prefix6(netdissect_options
*ndo
,
1437 const u_char
*pd
, u_int itemlen
, char *buf
, size_t buflen
)
1440 u_int plen
, plenbytes
;
1448 memset(&addr
, 0, sizeof(addr
));
1449 plenbytes
= (plen
+ 7) / 8;
1450 ITEMCHECK(plenbytes
);
1451 GET_CPY_BYTES(&addr
, pd
+ 1, plenbytes
);
1453 addr
[plenbytes
- 1] &=
1454 ((0xff00 >> (plen
% 8)) & 0xff);
1456 snprintf(buf
, buflen
, "%s/%u", ip6addr_string(ndo
, (const u_char
*)&addr
), plen
);
1457 return 1 + plenbytes
;
1464 print_labeled_prefix6(netdissect_options
*ndo
,
1465 const u_char
*pptr
, u_int itemlen
)
1468 u_int plen
, plenbytes
;
1470 /* prefix length and label = 4 bytes */
1473 plen
= GET_U_1(pptr
); /* get prefix length */
1478 plen
-= 24; /* adjust prefixlen - labellength */
1484 memset(&addr
, 0, sizeof(addr
));
1485 plenbytes
= (plen
+ 7) / 8;
1486 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
1488 addr
[plenbytes
- 1] &=
1489 ((0xff00 >> (plen
% 8)) & 0xff);
1491 /* the label may get offsetted by 4 bits so lets shift it right */
1492 ND_PRINT("\n\t %s/%u, label:%u %s",
1493 ip6addr_string(ndo
, (const u_char
*)&addr
),
1495 GET_BE_U_3(pptr
+ 1)>>4,
1496 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1498 return 4 + plenbytes
;
1501 ND_PRINT("\n\t (illegal prefix length)");
1512 print_labeled_vpn_prefix6(netdissect_options
*ndo
, const u_char
*pptr
)
1517 plen
= GET_U_1(pptr
); /* get prefix length */
1522 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1527 memset(&addr
, 0, sizeof(addr
));
1528 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1530 addr
[(plen
+ 7) / 8 - 1] &=
1531 ((0xff00 >> (plen
% 8)) & 0xff);
1533 /* the label may get offsetted by 4 bits so lets shift it right */
1534 ND_PRINT("\n\t RD: %s, %s/%u, label:%u %s",
1535 bgp_vpn_rd_print(ndo
, pptr
+4),
1536 ip6addr_string(ndo
, (const u_char
*)&addr
),
1538 GET_BE_U_3(pptr
+ 1)>>4,
1539 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1541 return 12 + (plen
+ 7) / 8;
1544 ND_PRINT("\n\t (illegal prefix length)");
1549 print_clnp_prefix(netdissect_options
*ndo
, const u_char
*pptr
)
1554 plen
= GET_U_1(pptr
); /* get prefix length */
1559 memset(&addr
, 0, sizeof(addr
));
1560 GET_CPY_BYTES(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1562 addr
[(plen
+ 7) / 8 - 1] &=
1563 ((0xff00 >> (plen
% 8)) & 0xff);
1565 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1566 ND_PRINT("\n\t %s/%u",
1567 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1570 return 1 + (plen
+ 7) / 8;
1573 ND_PRINT("\n\t (illegal prefix length)");
1578 print_labeled_vpn_clnp_prefix(netdissect_options
*ndo
, const u_char
*pptr
)
1583 plen
= GET_U_1(pptr
); /* get prefix length */
1588 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1593 memset(&addr
, 0, sizeof(addr
));
1594 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1596 addr
[(plen
+ 7) / 8 - 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
1598 /* the label may get offsetted by 4 bits so lets shift it right */
1599 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1600 ND_PRINT("\n\t RD: %s, %s/%u, label:%u %s",
1601 bgp_vpn_rd_print(ndo
, pptr
+4),
1602 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1604 GET_BE_U_3(pptr
+ 1)>>4,
1605 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1607 return 12 + (plen
+ 7) / 8;
1610 ND_PRINT("\n\t (illegal prefix length)");
1615 * bgp_attr_get_as_size
1617 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1618 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1619 * support, exchange AS-Path with the same path-attribute type value 0x02.
1622 bgp_attr_get_as_size(netdissect_options
*ndo
,
1623 uint8_t bgpa_type
, const u_char
*pptr
, u_int len
)
1625 const u_char
*tptr
= pptr
;
1628 * If the path attribute is the optional AS4 path type, then we already
1629 * know, that ASs must be encoded in 4 byte format.
1631 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1636 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1637 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1640 while (tptr
< pptr
+ len
) {
1642 * If we do not find a valid segment type, our guess might be wrong.
1644 if (GET_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| GET_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1647 tptr
+= 2 + GET_U_1(tptr
+ 1) * 2;
1651 * If we correctly reached end of the AS path attribute data content,
1652 * then most likely ASs were indeed encoded as 2 bytes.
1654 if (tptr
== pptr
+ len
) {
1661 * We can come here, either we did not have enough data, or if we
1662 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1663 * so that caller can try to decode each AS as of 4 bytes. If indeed
1664 * there was not enough data, it will crib and end the parse anyways.
1670 * The only way to know that a BGP UPDATE message is using add path is
1671 * by checking if the capability is in the OPEN message which we may have missed.
1672 * So this function checks if it is possible that the update could contain add path
1673 * and if so it checks that standard BGP doesn't make sense.
1676 check_add_path(netdissect_options
*ndo
, const u_char
*pptr
, u_int length
,
1677 u_int max_prefix_length
)
1679 u_int offset
, prefix_length
;
1686 * Scan through the NLRI information under the assumption that
1687 * it doesn't have path IDs.
1689 for (offset
= 0; offset
< length
;) {
1691 if (!ND_TTEST_1(pptr
+ offset
)) {
1692 /* We ran out of captured data; quit scanning. */
1695 prefix_length
= GET_U_1(pptr
+ offset
);
1697 * Add 4 to cover the path id
1698 * and check the prefix length isn't greater than 32/128.
1700 if (prefix_length
> max_prefix_length
) {
1703 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1704 offset
+= 1 + ((prefix_length
+ 7) / 8);
1706 /* check we haven't gone past the end of the section */
1707 if (offset
> length
) {
1711 /* check it's not standard BGP */
1712 for (offset
= 0; offset
< length
; ) {
1713 if (!ND_TTEST_1(pptr
+ offset
)) {
1714 /* We ran out of captured data; quit scanning. */
1717 prefix_length
= GET_U_1(pptr
+ offset
);
1719 * If the prefix_length is zero (0.0.0.0/0)
1720 * and since it's not the only address (length >= 5)
1721 * then it is add-path
1723 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1726 offset
+= 1 + ((prefix_length
+ 7) / 8);
1728 if (offset
> length
) {
1732 /* assume not add-path by default */
1737 bgp_mp_af_print(netdissect_options
*ndo
,
1738 const u_char
*tptr
, u_int tlen
,
1739 uint16_t *afp
, uint8_t *safip
)
1744 af
= GET_BE_U_2(tptr
);
1746 safi
= GET_U_1(tptr
+ 2);
1749 ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1750 tok2str(af_values
, "Unknown AFI", af
),
1752 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1753 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1756 switch(af
<<8 | safi
) {
1757 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
1758 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
1759 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
1760 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
1761 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
1762 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
1763 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
1764 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1765 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
):
1766 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
1767 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
1768 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
1769 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
1770 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
1771 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
1772 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
1773 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1774 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1775 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1776 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1777 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1778 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1779 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1780 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1781 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1782 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1783 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1786 ND_TCHECK_LEN(tptr
, tlen
);
1787 ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af
, safi
);
1788 if (ndo
->ndo_vflag
<= 1)
1789 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1798 bgp_nlri_print(netdissect_options
*ndo
, uint16_t af
, uint8_t safi
,
1799 const u_char
*tptr
, u_int len
,
1800 int add_path4
, int add_path6
)
1806 switch (af
<<8 | safi
) {
1807 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
1808 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
1809 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
1811 path_id
= GET_BE_U_4(tptr
);
1814 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1816 ND_PRINT("\n\t (illegal prefix length)");
1817 else if (advance
== -2)
1818 break; /* bytes left, but not enough */
1820 ND_PRINT("\n\t %s", buf
);
1822 ND_PRINT(" Path Id: %u", path_id
);
1826 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
1827 advance
= print_labeled_prefix4(ndo
, tptr
, len
);
1831 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
1832 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
1833 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1834 advance
= print_labeled_vpn_prefix4(ndo
, tptr
);
1836 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
1837 advance
= print_rt_routing_info(ndo
, tptr
);
1839 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1840 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST_VPN
):
1841 advance
= print_multicast_vpn(ndo
, tptr
);
1846 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
1847 advance
= print_mdt_vpn_nlri(ndo
, tptr
);
1851 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
1852 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
1853 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
1855 path_id
= GET_BE_U_4(tptr
);
1858 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1860 ND_PRINT("\n\t (illegal prefix length)");
1861 else if (advance
== -2)
1862 break; /* bytes left, but not enough */
1864 ND_PRINT("\n\t %s", buf
);
1866 ND_PRINT(" Path Id: %u", path_id
);
1870 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
1871 advance
= print_labeled_prefix6(ndo
, tptr
, len
);
1875 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
1876 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
1877 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1878 advance
= print_labeled_vpn_prefix6(ndo
, tptr
);
1880 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1881 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1882 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1883 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1884 advance
= print_labeled_vpn_l2(ndo
, tptr
);
1888 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1889 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1890 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1891 advance
= print_clnp_prefix(ndo
, tptr
);
1893 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1894 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1895 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1896 advance
= print_labeled_vpn_clnp_prefix(ndo
, tptr
);
1900 * This should not happen, we should have been protected
1901 * by bgp_mp_af_print()'s return value.
1903 ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af
, safi
);
1908 trunc
: /* we rely on the caller to recognize -2 return value */
1912 static const struct tok bgp_flags
[] = {
1921 bgp_attr_print(netdissect_options
*ndo
,
1922 uint8_t atype
, const u_char
*pptr
, u_int len
,
1923 const unsigned attr_set_level
)
1925 /* allocate space for the largest possible string */
1926 char astostr
[AS_STR_SIZE
];
1929 uint8_t safi
, snpa
, nhlen
;
1934 int add_path4
, add_path6
;
1941 case BGPTYPE_ORIGIN
:
1943 ND_PRINT("invalid len");
1945 ND_PRINT("%s", tok2str(bgp_origin_values
,
1946 "Unknown Origin Typecode",
1952 * Process AS4 byte path and AS2 byte path attributes here.
1954 case BGPTYPE_AS4_PATH
:
1955 case BGPTYPE_AS_PATH
:
1957 ND_PRINT("invalid len");
1966 * BGP updates exchanged between New speakers that support 4
1967 * byte AS, ASs are always encoded in 4 bytes. There is no
1968 * definitive way to find this, just by the packet's
1969 * contents. So, check for packet's TLV's sanity assuming
1970 * 2 bytes first, and it does not pass, assume that ASs are
1971 * encoded in 4 bytes format and move on.
1973 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1975 while (tptr
< pptr
+ len
) {
1976 ND_PRINT("%s", tok2str(bgp_as_path_segment_open_values
,
1977 "?", GET_U_1(tptr
)));
1978 for (i
= 0; i
< GET_U_1(tptr
+ 1) * as_size
; i
+= as_size
) {
1979 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
1981 as_printf(ndo
, astostr
, sizeof(astostr
),
1983 GET_BE_U_2(tptr
+ i
+ 2) :
1984 GET_BE_U_4(tptr
+ i
+ 2)));
1986 ND_PRINT("%s", tok2str(bgp_as_path_segment_close_values
,
1987 "?", GET_U_1(tptr
)));
1988 tptr
+= 2 + GET_U_1(tptr
+ 1) * as_size
;
1991 case BGPTYPE_NEXT_HOP
:
1993 ND_PRINT("invalid len");
1995 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
1998 case BGPTYPE_MULTI_EXIT_DISC
:
1999 case BGPTYPE_LOCAL_PREF
:
2001 ND_PRINT("invalid len");
2003 ND_PRINT("%u", GET_BE_U_4(tptr
));
2006 case BGPTYPE_ATOMIC_AGGREGATE
:
2008 ND_PRINT("invalid len");
2010 case BGPTYPE_AGGREGATOR
:
2013 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
2014 * the length of this PA can be either 6 bytes or 8 bytes.
2016 if (len
!= 6 && len
!= 8) {
2017 ND_PRINT("invalid len");
2020 ND_TCHECK_LEN(tptr
, len
);
2022 ND_PRINT(" AS #%s, origin %s",
2023 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(tptr
)),
2024 GET_IPADDR_STRING(tptr
+ 2));
2026 ND_PRINT(" AS #%s, origin %s",
2027 as_printf(ndo
, astostr
, sizeof(astostr
),
2028 GET_BE_U_4(tptr
)), GET_IPADDR_STRING(tptr
+ 4));
2031 case BGPTYPE_AGGREGATOR4
:
2033 ND_PRINT("invalid len");
2036 ND_PRINT(" AS #%s, origin %s",
2037 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)),
2038 GET_IPADDR_STRING(tptr
+ 4));
2040 case BGPTYPE_COMMUNITIES
:
2042 ND_PRINT("invalid len");
2050 comm
= GET_BE_U_4(tptr
);
2052 case BGP_COMMUNITY_NO_EXPORT
:
2053 ND_PRINT(" NO_EXPORT");
2055 case BGP_COMMUNITY_NO_ADVERT
:
2056 ND_PRINT(" NO_ADVERTISE");
2058 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
2059 ND_PRINT(" NO_EXPORT_SUBCONFED");
2063 (comm
>> 16) & 0xffff,
2065 (tlen
>4) ? ", " : "");
2072 case BGPTYPE_ORIGINATOR_ID
:
2074 ND_PRINT("invalid len");
2077 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2079 case BGPTYPE_CLUSTER_LIST
:
2081 ND_PRINT("invalid len");
2088 GET_IPADDR_STRING(tptr
),
2089 (tlen
>4) ? ", " : "");
2094 case BGPTYPE_MP_REACH_NLRI
:
2098 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2110 nhlen
= GET_U_1(tptr
);
2116 uint8_t tnhlen
= nhlen
;
2119 ND_PRINT("\n\t nexthop: ");
2120 while (tnhlen
!= 0) {
2124 switch(af
<<8 | safi
) {
2125 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
2126 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
2127 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
2128 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
2129 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
2130 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
):
2131 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
2132 if (tnhlen
< sizeof(nd_ipv4
)) {
2133 ND_PRINT("invalid len");
2138 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2139 tptr
+= sizeof(nd_ipv4
);
2140 tnhlen
-= sizeof(nd_ipv4
);
2141 tlen
-= sizeof(nd_ipv4
);
2144 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
2145 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
2146 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2147 if (tnhlen
< sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
) {
2148 ND_PRINT("invalid len");
2153 ND_PRINT("RD: %s, %s",
2154 bgp_vpn_rd_print(ndo
, tptr
),
2155 GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2156 tptr
+= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2157 tlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2158 tnhlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2161 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
2162 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
2163 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
2164 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
2165 if (tnhlen
< sizeof(nd_ipv6
)) {
2166 ND_PRINT("invalid len");
2171 ND_PRINT("%s", GET_IP6ADDR_STRING(tptr
));
2172 tptr
+= sizeof(nd_ipv6
);
2173 tlen
-= sizeof(nd_ipv6
);
2174 tnhlen
-= sizeof(nd_ipv6
);
2177 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
2178 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
2179 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2180 if (tnhlen
< sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
) {
2181 ND_PRINT("invalid len");
2186 ND_PRINT("RD: %s, %s",
2187 bgp_vpn_rd_print(ndo
, tptr
),
2188 GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2189 tptr
+= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2190 tlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2191 tnhlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2194 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2195 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2196 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2197 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2198 if (tnhlen
< sizeof(nd_ipv4
)) {
2199 ND_PRINT("invalid len");
2204 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
2205 tptr
+= (sizeof(nd_ipv4
));
2206 tlen
-= (sizeof(nd_ipv4
));
2207 tnhlen
-= (sizeof(nd_ipv4
));
2210 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2211 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2212 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2213 ND_PRINT("%s", GET_ISONSAP_STRING(tptr
, tnhlen
));
2219 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2220 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2221 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2222 if (tnhlen
< BGP_VPN_RD_LEN
+1) {
2223 ND_PRINT("invalid len");
2228 ND_TCHECK_LEN(tptr
, tnhlen
);
2229 ND_PRINT("RD: %s, %s",
2230 bgp_vpn_rd_print(ndo
, tptr
),
2231 GET_ISONSAP_STRING(tptr
+BGP_VPN_RD_LEN
,tnhlen
-BGP_VPN_RD_LEN
));
2232 /* rfc986 mapped IPv4 address ? */
2233 if (GET_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
2234 ND_PRINT(" = %s", GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
+4));
2235 /* rfc1888 mapped IPv6 address ? */
2236 else if (GET_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
2237 ND_PRINT(" = %s", GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
+3));
2245 * bgp_mp_af_print() should have saved us from
2246 * an unsupported AFI/SAFI.
2248 ND_PRINT("ERROR: no AFI %u/SAFI %u nexthop decoder", af
, safi
);
2256 ND_PRINT(", nh-length: %u", nhlen
);
2258 /* As per RFC 2858; this is reserved in RFC 4760 */
2261 snpa
= GET_U_1(tptr
);
2266 ND_PRINT("\n\t %u SNPA", snpa
);
2267 for (/*nothing*/; snpa
!= 0; snpa
--) {
2271 snpalen
= GET_U_1(tptr
);
2272 ND_PRINT("\n\t %u bytes", snpalen
);
2277 ND_TCHECK_LEN(tptr
, snpalen
);
2282 ND_PRINT(", no SNPA");
2285 add_path4
= check_add_path(ndo
, tptr
,
2286 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 32);
2287 add_path6
= check_add_path(ndo
, tptr
,
2288 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 128);
2290 while (tptr
< pptr
+ len
) {
2291 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
,
2292 add_path4
, add_path6
);
2301 case BGPTYPE_MP_UNREACH_NLRI
:
2302 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
2303 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2309 if (len
== BGP_MP_NLRI_MINSIZE
)
2310 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2314 add_path4
= check_add_path(ndo
, tptr
,
2315 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 32);
2316 add_path6
= check_add_path(ndo
, tptr
,
2317 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 128);
2319 while (tptr
< pptr
+ len
) {
2320 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
,
2321 add_path4
, add_path6
);
2329 case BGPTYPE_EXTD_COMMUNITIES
:
2331 ND_PRINT("invalid len");
2340 extd_comm
=GET_BE_U_2(tptr
);
2342 ND_PRINT("\n\t %s (0x%04x), Flags [%s]",
2343 tok2str(bgp_extd_comm_subtype_values
,
2344 "unknown extd community typecode",
2347 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
2353 bgp_extended_community_print(ndo
, tptr
);
2359 case BGPTYPE_PMSI_TUNNEL
:
2361 uint8_t tunnel_type
, flags
;
2366 flags
= GET_U_1(tptr
);
2367 tunnel_type
= GET_U_1(tptr
+ 1);
2369 ND_PRINT("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2370 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2372 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2373 GET_BE_U_3(tptr
+ 2)>>4);
2378 switch (tunnel_type
) {
2379 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2380 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2381 ND_PRINT("\n\t Sender %s, P-Group %s",
2382 GET_IPADDR_STRING(tptr
),
2383 GET_IPADDR_STRING(tptr
+4));
2386 case BGP_PMSI_TUNNEL_PIM_SSM
:
2387 ND_PRINT("\n\t Root-Node %s, P-Group %s",
2388 GET_IPADDR_STRING(tptr
),
2389 GET_IPADDR_STRING(tptr
+4));
2391 case BGP_PMSI_TUNNEL_INGRESS
:
2392 ND_PRINT("\n\t Tunnel-Endpoint %s",
2393 GET_IPADDR_STRING(tptr
));
2395 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2396 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2397 ND_PRINT("\n\t Root-Node %s, LSP-ID 0x%08x",
2398 GET_IPADDR_STRING(tptr
),
2399 GET_BE_U_4(tptr
+ 4));
2401 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2402 ND_PRINT("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2403 GET_IPADDR_STRING(tptr
),
2404 GET_BE_U_4(tptr
+ 4));
2407 if (ndo
->ndo_vflag
<= 1) {
2408 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2419 type
= GET_U_1(tptr
);
2420 length
= GET_BE_U_2(tptr
+ 1);
2424 ND_PRINT("\n\t %s TLV (%u), length %u",
2425 tok2str(bgp_aigp_values
, "Unknown", type
),
2433 * Check if we can read the TLV data.
2443 ND_PRINT(", metric %" PRIu64
,
2448 if (ndo
->ndo_vflag
<= 1) {
2449 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2458 case BGPTYPE_ATTR_SET
:
2462 ND_PRINT("\n\t Origin AS: %s",
2463 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)));
2468 u_int aflags
, alenlen
, alen
;
2472 ND_PRINT(" [path attr too short]");
2476 aflags
= GET_U_1(tptr
);
2477 atype
= GET_U_1(tptr
+ 1);
2480 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2481 ND_TCHECK_LEN(tptr
, alenlen
);
2482 if (len
< alenlen
) {
2483 ND_PRINT(" [path attr too short]");
2487 alen
= bgp_attr_len(aflags
, tptr
);
2491 ND_PRINT("\n\t %s (%u), length: %u",
2492 tok2str(bgp_attr_values
,
2493 "Unknown Attribute", atype
),
2498 ND_PRINT(", Flags [%s",
2499 bittok2str_nosep(bgp_flags
, "", aflags
));
2501 ND_PRINT("+%x", aflags
& 0xf);
2506 ND_PRINT(" [path attr too short]");
2511 * The protocol encoding per se allows ATTR_SET to be nested
2512 * as many times as the message can accommodate. This printer
2513 * used to be able to recurse into ATTR_SET contents until the
2514 * stack exhaustion, but now there is a limit on that (if live
2515 * protocol exchange goes that many levels deep, something is
2516 * probably wrong anyway). Feel free to refine this value if
2517 * you can find the spec with respective normative text.
2519 if (attr_set_level
== 10)
2520 ND_PRINT("(too many nested levels, not recursing)");
2521 else if (!bgp_attr_print(ndo
, atype
, tptr
, alen
, attr_set_level
+ 1))
2528 case BGPTYPE_LARGE_COMMUNITY
:
2529 if (len
== 0 || len
% 12) {
2530 ND_PRINT("invalid len");
2535 ND_PRINT("%u:%u:%u%s",
2537 GET_BE_U_4(tptr
+ 4),
2538 GET_BE_U_4(tptr
+ 8),
2539 (len
> 12) ? ", " : "");
2542 * len will always be a multiple of 12, as per the above,
2543 * so this will never underflow.
2548 case BGPTYPE_BGPSEC_PATH
:
2550 uint16_t sblen
, splen
;
2552 splen
= GET_BE_U_2(tptr
);
2555 * A secure path has a minimum length of 8 bytes:
2556 * 2 bytes length field
2557 * 6 bytes per secure path segment
2559 ND_ICHECKMSG_U("secure path length", splen
, <, 8);
2561 ND_PRINT("\n\t Secure Path Length: %u", splen
);
2565 /* Make sure the secure path length does not signal trailing bytes */
2567 ND_PRINT(" [total segments length %u != N x 6]", splen
);
2571 /* Parse secure path segments */
2572 while (splen
!= 0) {
2573 uint8_t pcount
= GET_U_1(tptr
);
2574 uint8_t flags
= GET_U_1(tptr
+ 1);
2575 uint32_t asn
= GET_BE_U_4(tptr
+ 2);
2576 ND_PRINT("\n\t Secure Path Segment: pCount: %u, Flags: [%s] (0x%02x), AS: %u",
2578 bittok2str(bgp_bgpsec_bitmap_str
, "none", flags
),
2585 sblen
= GET_BE_U_2(tptr
);
2587 ND_PRINT("\n\t Signature Block: Length: %u, Algo ID: %u",
2593 /* Parse signature segments */
2594 while (sblen
!= 0) {
2597 ND_PRINT("\n\t Signature Segment:\n\t SKI: ");
2598 ND_ICHECKMSG_U("remaining length", sblen
, <, 20);
2599 hex_print(ndo
, "\n\t ", tptr
, 20);
2602 ND_ICHECKMSG_U("remaining length", sblen
, <, 2);
2603 siglen
= GET_BE_U_2(tptr
);
2607 ND_PRINT("\n\t Length: %u", siglen
);
2608 ND_ICHECKMSG_U("remaining length", sblen
, <, siglen
);
2609 ND_PRINT("\n\t Signature:");
2610 hex_print(ndo
, "\n\t ", tptr
, siglen
);
2619 ND_PRINT("invalid len");
2622 ND_PRINT("\n\t OTC %u", GET_BE_U_4(pptr
));
2626 ND_TCHECK_LEN(pptr
, len
);
2627 ND_PRINT("\n\t no Attribute %u decoder", atype
); /* we have no decoder for the attribute */
2628 if (ndo
->ndo_vflag
<= 1)
2629 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2633 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2634 ND_TCHECK_LEN(pptr
, len
);
2635 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2640 nd_print_invalid(ndo
);
2648 bgp_capabilities_print(netdissect_options
*ndo
,
2649 const u_char
*opt
, u_int caps_len
)
2651 /* allocate space for the largest possible string */
2652 char astostr
[AS_STR_SIZE
];
2653 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2656 while (i
< caps_len
) {
2657 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2658 cap_type
=GET_U_1(opt
+ i
);
2659 cap_len
=GET_U_1(opt
+ i
+ 1);
2660 ND_PRINT("\n\t %s (%u), length: %u",
2661 tok2str(bgp_capcode_values
, "Unknown", cap_type
),
2664 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2666 case BGP_CAPCODE_MP
:
2667 /* AFI (16 bits), Reserved (8 bits), SAFI (8 bits) */
2669 ND_PRINT(" (too short, < 4)");
2672 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u)",
2673 tok2str(af_values
, "Unknown", GET_BE_U_2(opt
+ i
+ 2)),
2674 GET_BE_U_2(opt
+ i
+ 2),
2675 tok2str(bgp_safi_values
, "Unknown", GET_U_1(opt
+ i
+ 5)),
2676 GET_U_1(opt
+ i
+ 5));
2678 case BGP_CAPCODE_BGPSEC
:
2679 /* Version (4 bits), Direction (1 bit), Flags (3 bits), AFI (16 bits) */
2681 /* The capability length [...] MUST be set to 3. */
2683 ND_PRINT(" [%u != 3]", cap_len
);
2687 ND_PRINT("\n\t\tVersion %u, Direction %s (%u), AFI %s (%u)",
2688 GET_U_1(opt
+ i
+ 2)&0xf0,
2689 (GET_U_1(opt
+ i
+ 2)&0x08) ? "Send" : "Receive",
2690 (GET_U_1(opt
+ i
+ 2)&0x08)>>3,
2691 bittok2str(af_values
, "Unknown",
2692 GET_BE_U_2(opt
+ i
+ cap_offset
+ 2)),
2693 GET_BE_U_2(opt
+ i
+ cap_offset
+ 2));
2695 case BGP_CAPCODE_ML
:
2698 while (tcap_len
>= 4) {
2699 ND_PRINT( "\n\t\tAFI %s (%u), SAFI %s (%u), Count: %u",
2700 tok2str(af_values
, "Unknown",
2701 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2702 GET_BE_U_2(opt
+ i
+ cap_offset
),
2703 tok2str(bgp_safi_values
, "Unknown",
2704 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2705 GET_U_1(opt
+ i
+ cap_offset
+ 2),
2706 GET_U_1(opt
+ i
+ cap_offset
+ 3));
2711 case BGP_CAPCODE_RESTART
:
2712 /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */
2714 ND_PRINT(" (too short, < 2)");
2718 ND_PRINT("\n\t\tRestart Flags: [%s], Restart Time %us",
2719 bittok2str(bgp_graceful_restart_comm_flag_values
,
2720 "none", GET_U_1(opt
+ i
+ 2) >> 4),
2721 GET_BE_U_2(opt
+ i
+ 2)&0xfff);
2724 while(tcap_len
>=4) {
2725 ND_PRINT("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2726 tok2str(af_values
,"Unknown",
2727 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2728 GET_BE_U_2(opt
+ i
+ cap_offset
),
2729 tok2str(bgp_safi_values
,"Unknown",
2730 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2731 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2732 ((GET_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" );
2737 case BGP_CAPCODE_ROLE
:
2739 ND_PRINT(" (too short, < 1)");
2742 ND_PRINT("\n\t\tRole name %s (%u)",
2743 tok2str(bgp_role_values
, "Unassigned",
2744 GET_U_1(opt
+ i
+ 2)), GET_U_1(opt
+ i
+ 2));
2746 case BGP_CAPCODE_RR
:
2747 case BGP_CAPCODE_LLGR
:
2748 case BGP_CAPCODE_RR_CISCO
:
2749 case BGP_CAPCODE_EXT_MSG
:
2750 case BGP_CAPCODE_ENH_RR
:
2752 case BGP_CAPCODE_AS_NEW
:
2754 * Extract the 4 byte AS number encoded.
2757 ND_PRINT(" (too short, < 4)");
2760 ND_PRINT("\n\t\t 4 Byte AS %s",
2761 as_printf(ndo
, astostr
, sizeof(astostr
),
2762 GET_BE_U_4(opt
+ i
+ 2)));
2764 case BGP_CAPCODE_ADD_PATH
:
2766 ND_PRINT(" (bogus)"); /* length */
2771 while (tcap_len
!= 0) {
2773 nd_print_invalid(ndo
);
2776 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2777 tok2str(af_values
,"Unknown",GET_BE_U_2(opt
+ i
+ cap_offset
)),
2778 GET_BE_U_2(opt
+ i
+ cap_offset
),
2779 tok2str(bgp_safi_values
,"Unknown",GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2780 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2781 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",GET_U_1(opt
+ i
+ cap_offset
+ 3))
2788 ND_PRINT("\n\t\tno decoder for Capability %u",
2790 if (ndo
->ndo_vflag
<= 1)
2791 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2795 if (ndo
->ndo_vflag
> 1 && cap_len
!= 0) {
2796 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2798 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2803 nd_print_trunc(ndo
);
2807 bgp_open_print(netdissect_options
*ndo
,
2808 const u_char
*dat
, u_int length
)
2810 /* allocate space for the largest possible string */
2811 char astostr
[AS_STR_SIZE
];
2812 const struct bgp_open
*bgp_open_header
;
2815 const struct bgp_opt
*bgpopt
;
2818 uint8_t extended_opt_params
= 0;
2819 u_int open_size
= BGP_OPEN_SIZE
;
2820 u_int opt_size
= BGP_OPT_SIZE
;
2822 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2823 if (length
< BGP_OPEN_SIZE
)
2826 bgp_open_header
= (const struct bgp_open
*)dat
;
2828 ND_PRINT("\n\t Version %u, ",
2829 GET_U_1(bgp_open_header
->bgpo_version
));
2830 ND_PRINT("my AS %s, ",
2831 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(bgp_open_header
->bgpo_myas
)));
2832 ND_PRINT("Holdtime %us, ",
2833 GET_BE_U_2(bgp_open_header
->bgpo_holdtime
));
2834 ND_PRINT("ID %s", GET_IPADDR_STRING(bgp_open_header
->bgpo_id
));
2835 optslen
= GET_U_1(bgp_open_header
->bgpo_optlen
);
2836 opsttype
= GET_U_1(bgp_open_header
->bgpo_opttype
);
2837 if (opsttype
== BGP_OPEN_NON_EXT_OPT_TYPE_EXTENDED_LENGTH
) {
2838 optslen
= GET_BE_U_2(bgp_open_header
->bgpo_optlen_extended
);
2839 extended_opt_params
= 1;
2843 ND_PRINT("\n\t Optional parameters%s, length: %u",
2844 extended_opt_params
? " (Extended)" : "", optslen
);
2846 opt
= dat
+ open_size
;
2847 length
-= open_size
;
2850 while (i
< optslen
) {
2854 ND_TCHECK_LEN(opt
+ i
, opt_size
);
2855 if (length
< opt_size
+ i
)
2857 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2858 opt_type
= GET_U_1(bgpopt
->bgpopt_type
);
2859 opt_len
= extended_opt_params
? GET_BE_U_2(bgpopt
->bgpopt_len
)
2860 : GET_U_1(bgpopt
->bgpopt_len
);
2861 if (opt_size
+ i
+ opt_len
> optslen
) {
2862 ND_PRINT("\n\t Option %u, length: %u, goes past the end of the options",
2867 ND_PRINT("\n\t Option %s (%u), length: %u",
2868 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2872 /* now let's decode the options we know*/
2876 bgp_capabilities_print(ndo
, opt
+ opt_size
+ i
,
2882 ND_PRINT("\n\t no decoder for option %u",
2886 i
+= opt_size
+ opt_len
;
2890 nd_print_trunc(ndo
);
2894 bgp_update_print(netdissect_options
*ndo
,
2895 const u_char
*dat
, u_int length
)
2898 u_int withdrawn_routes_len
;
2906 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2907 if (length
< BGP_SIZE
)
2912 /* Unfeasible routes */
2916 withdrawn_routes_len
= GET_BE_U_2(p
);
2919 if (withdrawn_routes_len
> 1) {
2921 * Without keeping state from the original NLRI message,
2922 * it's not possible to tell if this a v4 or v6 route,
2923 * so only try to decode it if we're not v6 enabled.
2925 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2926 if (length
< withdrawn_routes_len
)
2928 ND_PRINT("\n\t Withdrawn routes:");
2929 add_path
= check_add_path(ndo
, p
, withdrawn_routes_len
, 32);
2930 while (withdrawn_routes_len
!= 0) {
2932 if (withdrawn_routes_len
< 4) {
2933 p
+= withdrawn_routes_len
;
2934 length
-= withdrawn_routes_len
;
2937 path_id
= GET_BE_U_4(p
);
2940 withdrawn_routes_len
-= 4;
2942 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2944 ND_PRINT("\n\t (illegal prefix length)");
2946 } else if (wpfx
== -2)
2947 goto trunc
; /* bytes left, but not enough */
2949 ND_PRINT("\n\t %s", buf
);
2951 ND_PRINT(" Path Id: %u", path_id
);
2955 withdrawn_routes_len
-= wpfx
;
2959 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2960 if (length
< withdrawn_routes_len
)
2962 p
+= withdrawn_routes_len
;
2963 length
-= withdrawn_routes_len
;
2969 len
= GET_BE_U_2(p
);
2973 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2974 /* No withdrawn routes, no path attributes, no NLRI */
2975 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2980 /* Make sure the path attributes don't go past the end of the packet */
2983 /* do something more useful!*/
2985 uint8_t aflags
, atype
, alenlen
;
2992 ND_PRINT("\n\t [path attrs too short]");
2997 aflags
= GET_U_1(p
);
2998 atype
= GET_U_1(p
+ 1);
3002 alenlen
= bgp_attr_lenlen(aflags
, p
);
3003 ND_TCHECK_LEN(p
, alenlen
);
3004 if (length
< alenlen
)
3006 if (len
< alenlen
) {
3007 ND_PRINT("\n\t [path attrs too short]");
3012 alen
= bgp_attr_len(aflags
, p
);
3017 ND_PRINT("\n\t %s (%u), length: %u",
3018 tok2str(bgp_attr_values
, "Unknown Attribute", atype
),
3023 ND_PRINT(", Flags [%s",
3024 bittok2str_nosep(bgp_flags
, "", aflags
));
3026 ND_PRINT("+%x", aflags
& 0xf);
3030 ND_PRINT(" [path attrs too short]");
3037 if (!bgp_attr_print(ndo
, atype
, p
, alen
, 0))
3046 add_path
= check_add_path(ndo
, p
, length
, 32);
3047 ND_PRINT("\n\t Updated routes:");
3048 while (length
!= 0) {
3053 path_id
= GET_BE_U_4(p
);
3057 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
3059 ND_PRINT("\n\t (illegal prefix length)");
3062 goto trunc
; /* bytes left, but not enough */
3064 ND_PRINT("\n\t %s", buf
);
3066 ND_PRINT(" Path Id: %u", path_id
);
3075 nd_print_trunc(ndo
);
3079 bgp_notification_print_code(netdissect_options
*ndo
,
3080 const u_char
*dat
, u_int length
,
3081 uint8_t bgpn_major
, uint8_t bgpn_minor
)
3083 ND_PRINT(", %s (%u)",
3084 tok2str(bgp_notify_major_values
, "Unknown Error",
3088 switch (bgpn_major
) {
3090 case BGP_NOTIFY_MAJOR_MSG
:
3091 ND_PRINT(", subcode %s (%u)",
3092 tok2str(bgp_notify_minor_msg_values
, "Unknown",
3096 case BGP_NOTIFY_MAJOR_OPEN
:
3097 ND_PRINT(", subcode %s (%u)",
3098 tok2str(bgp_notify_minor_open_values
, "Unknown",
3102 case BGP_NOTIFY_MAJOR_UPDATE
:
3103 ND_PRINT(", subcode %s (%u)",
3104 tok2str(bgp_notify_minor_update_values
, "Unknown",
3108 case BGP_NOTIFY_MAJOR_FSM
:
3109 ND_PRINT(" subcode %s (%u)",
3110 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
3114 case BGP_NOTIFY_MAJOR_ROUTEREFRESH
:
3115 ND_PRINT(" subcode %s (%u)",
3116 tok2str(bgp_notify_minor_routerefresh_values
, "Unknown",
3120 case BGP_NOTIFY_MAJOR_CEASE
:
3121 ND_PRINT(", subcode %s (%u)",
3122 tok2str(bgp_notify_minor_cease_values
, "Unknown",
3126 /* RFC 4486 mentions optionally 7 bytes
3127 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
3129 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= 7) {
3130 ND_PRINT(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
3131 tok2str(af_values
, "Unknown", GET_BE_U_2(dat
)),
3133 tok2str(bgp_safi_values
, "Unknown", GET_U_1((dat
+ 2))),
3135 GET_BE_U_4(dat
+ 3));
3138 * RFC 9003 describes a method to send a communication
3139 * intended for human consumption regarding the Administrative Shutdown
3141 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
3142 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
3144 uint8_t shutdown_comm_length
= GET_U_1(dat
);
3145 uint8_t remainder_offset
= 0;
3146 /* garbage, hexdump it all */
3147 if (shutdown_comm_length
> length
- 1) {
3148 ND_PRINT(", invalid Shutdown Communication length");
3149 } else if (shutdown_comm_length
== 0) {
3150 ND_PRINT(", empty Shutdown Communication");
3151 remainder_offset
+= 1;
3153 /* a proper shutdown communication */
3155 ND_PRINT(", Shutdown Communication (length: %u): \"", shutdown_comm_length
);
3156 nd_printjn(ndo
, dat
+1, shutdown_comm_length
);
3158 remainder_offset
+= shutdown_comm_length
+ 1;
3160 /* if there is trailing data, hexdump it */
3161 if(length
- remainder_offset
> 0) {
3162 ND_PRINT(", Data: (length: %u)", length
- remainder_offset
);
3163 hex_print(ndo
, "\n\t\t", dat
+ remainder_offset
, length
- remainder_offset
);
3167 * RFC8538 describes the Hard Reset cease subcode, which contains another
3168 * notification code and subcode.
3170 if (bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_HARDRESET
&& length
>= 2) {
3171 bgpn_major
= GET_U_1(dat
++);
3172 bgpn_minor
= GET_U_1(dat
++);
3174 bgp_notification_print_code(ndo
, dat
, length
, bgpn_major
, bgpn_minor
);
3178 if (bgpn_minor
!= 0) {
3179 ND_PRINT(", subcode %u", bgpn_minor
);
3188 bgp_notification_print(netdissect_options
*ndo
,
3189 const u_char
*dat
, u_int length
)
3191 const struct bgp_notification
*bgp_notification_header
;
3192 uint8_t bgpn_major
, bgpn_minor
;
3194 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
3195 if (length
<BGP_NOTIFICATION_SIZE
)
3198 bgp_notification_header
= (const struct bgp_notification
*)dat
;
3199 bgpn_major
= GET_U_1(bgp_notification_header
->bgpn_major
);
3200 bgpn_minor
= GET_U_1(bgp_notification_header
->bgpn_minor
);
3201 bgp_notification_print_code(ndo
, dat
+ BGP_NOTIFICATION_SIZE
,
3202 length
- BGP_NOTIFICATION_SIZE
, bgpn_major
, bgpn_minor
);
3205 nd_print_trunc(ndo
);
3209 bgp_route_refresh_print(netdissect_options
*ndo
,
3210 const u_char
*pptr
, u_int len
)
3212 const struct bgp_route_refresh
*bgp_route_refresh_header
;
3214 /* some little sanity checking */
3215 if (len
<BGP_ROUTE_REFRESH_SIZE
)
3218 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
3220 ND_PRINT("\n\t AFI %s (%u), SAFI %s (%u), Subtype %s (%u)",
3221 tok2str(af_values
, "Unknown",
3222 GET_BE_U_2(bgp_route_refresh_header
->afi
)),
3223 GET_BE_U_2(bgp_route_refresh_header
->afi
),
3224 tok2str(bgp_safi_values
, "Unknown",
3225 GET_U_1(bgp_route_refresh_header
->safi
)),
3226 GET_U_1(bgp_route_refresh_header
->safi
),
3227 tok2str(bgp_route_refresh_subtype_values
, "Unknown",
3228 GET_U_1(bgp_route_refresh_header
->subtype
)),
3229 GET_U_1(bgp_route_refresh_header
->subtype
));
3232 if (len
>= BGP_ROUTE_REFRESH_SIZE_ORF
) {
3233 const struct bgp_route_refresh_orf
*orf_header
;
3236 (const struct bgp_route_refresh_orf
*)(pptr
+ BGP_ROUTE_REFRESH_SIZE
);
3238 ND_PRINT("\n\t ORF refresh %s (%u), ORF type %s (%u), ORF length %u",
3239 tok2str(bgp_orf_refresh_type
, "Unknown",
3240 GET_U_1(orf_header
->refresh
)),
3241 GET_U_1(orf_header
->refresh
),
3242 tok2str(bgp_orf_type
, "Unknown", GET_U_1(orf_header
->type
)),
3243 GET_U_1(orf_header
->type
), GET_BE_U_2(orf_header
->len
));
3246 if (ndo
->ndo_vflag
> 1) {
3247 ND_TCHECK_LEN(pptr
, len
);
3248 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
3253 nd_print_trunc(ndo
);
3257 bgp_pdu_print(netdissect_options
*ndo
,
3258 const u_char
*dat
, u_int length
)
3260 const struct bgp
*bgp_header
;
3263 ND_TCHECK_LEN(dat
, BGP_SIZE
);
3264 bgp_header
= (const struct bgp
*)dat
;
3265 bgp_type
= GET_U_1(bgp_header
->bgp_type
);
3267 ND_PRINT("\n\t%s Message (%u), length: %u",
3268 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
3274 bgp_open_print(ndo
, dat
, length
);
3277 bgp_update_print(ndo
, dat
, length
);
3279 case BGP_NOTIFICATION
:
3280 bgp_notification_print(ndo
, dat
, length
);
3284 case BGP_ROUTE_REFRESH
:
3285 bgp_route_refresh_print(ndo
, dat
, length
);
3288 /* we have no decoder for the BGP message */
3289 ND_TCHECK_LEN(dat
, length
);
3290 ND_PRINT("\n\t no Message %u decoder", bgp_type
);
3291 print_unknown_data(ndo
, dat
, "\n\t ", length
);
3296 nd_print_trunc(ndo
);
3301 bgp_print(netdissect_options
*ndo
,
3302 const u_char
*dat
, u_int length _U_
)
3305 const u_char
*ep
= ndo
->ndo_snapend
;
3306 const u_char
*start
;
3307 const u_char marker
[] = {
3308 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3309 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3311 const struct bgp
*bgp_header
;
3314 ndo
->ndo_protocol
= "bgp";
3317 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
3325 if (GET_U_1(p
) != 0xff) {
3330 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
3332 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
3337 /* found BGP header */
3338 ND_TCHECK_LEN(p
, BGP_SIZE
);
3339 bgp_header
= (const struct bgp
*)p
;
3342 nd_print_trunc(ndo
);
3344 hlen
= GET_BE_U_2(bgp_header
->bgp_len
);
3345 if (hlen
< BGP_SIZE
) {
3346 ND_PRINT("\nmessage length %u < %u", hlen
, BGP_SIZE
);
3347 nd_print_invalid(ndo
);
3351 if (ND_TTEST_LEN(p
, hlen
)) {
3352 if (!bgp_pdu_print(ndo
, p
, hlen
))
3357 ND_PRINT("\n[|BGP %s]",
3358 tok2str(bgp_msg_values
,
3359 "Unknown Message Type",
3360 GET_U_1(bgp_header
->bgp_type
)));
3368 nd_print_trunc(ndo
);