2 * Copyright (C) 1999 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Extensively modified by Hannes Gredler (hannes@gredler.at) for more
30 * complete BGP support.
33 /* \summary: Border Gateway Protocol (BGP) printer */
35 /* specification: RFC 4271 */
39 #include "netdissect-stdinc.h"
44 #include "netdissect.h"
45 #include "addrtoname.h"
51 nd_byte bgp_marker
[16];
55 #define BGP_SIZE 19 /* unaligned */
59 #define BGP_NOTIFICATION 3
60 #define BGP_KEEPALIVE 4
61 #define BGP_ROUTE_REFRESH 5
63 static const struct tok bgp_msg_values
[] = {
65 { BGP_UPDATE
, "Update"},
66 { BGP_NOTIFICATION
, "Notification"},
67 { BGP_KEEPALIVE
, "Keepalive"},
68 { BGP_ROUTE_REFRESH
, "Route Refresh"},
73 nd_byte bgpo_marker
[16];
76 nd_uint8_t bgpo_version
;
77 nd_uint16_t bgpo_myas
;
78 nd_uint16_t bgpo_holdtime
;
80 nd_uint8_t bgpo_optlen
;
81 nd_uint8_t bgpo_opttype
; /* RFC9072 */
82 nd_uint16_t bgpo_optlen_extended
; /* RFC9072 */
83 /* options should follow */
85 #define BGP_OPEN_SIZE 29 /* unaligned */
88 nd_uint8_t bgpopt_type
;
89 nd_uint16_t bgpopt_len
; /* Can be one or two bytes, depending on RFC9072 */
92 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
93 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
95 struct bgp_notification
{
96 nd_byte bgpn_marker
[16];
99 nd_uint8_t bgpn_major
;
100 nd_uint8_t bgpn_minor
;
102 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
104 struct bgp_route_refresh_orf
{
110 struct bgp_route_refresh
{
111 nd_byte bgp_marker
[16];
113 nd_uint8_t type
; /* No padding after this; afi is, in fact, not aligned */
119 static const struct tok bgp_orf_refresh_type
[] = {
125 static const struct tok bgp_orf_type
[] = {
126 { 64, "Address Prefix ORF"},
131 #define BGP_ROUTE_REFRESH_SIZE 23
132 #define BGP_ROUTE_REFRESH_SIZE_ORF BGP_ROUTE_REFRESH_SIZE + 5
133 #define BGP_ROUTE_REFRESH_SUBTYPE_NORMAL 0
134 #define BGP_ROUTE_REFRESH_SUBTYPE_BORR 1
135 #define BGP_ROUTE_REFRESH_SUBTYPE_EORR 2
136 #define BGP_ROUTE_REFRESH_SUBTYPE_RESERVED 255
138 static const struct tok bgp_route_refresh_subtype_values
[] = {
139 {BGP_ROUTE_REFRESH_SUBTYPE_NORMAL
, "Normal route refresh request"},
140 {BGP_ROUTE_REFRESH_SUBTYPE_BORR
,
141 "Demarcation of the beginning of a route refresh"},
142 {BGP_ROUTE_REFRESH_SUBTYPE_EORR
,
143 "Demarcation of the ending of a route refresh"},
146 #define bgp_attr_lenlen(flags, p) \
147 (((flags) & 0x10) ? 2U : 1U)
148 #define bgp_attr_len(flags, p) \
149 (((flags) & 0x10) ? GET_BE_U_2(p) : GET_U_1(p))
151 #define BGPTYPE_ORIGIN 1
152 #define BGPTYPE_AS_PATH 2
153 #define BGPTYPE_NEXT_HOP 3
154 #define BGPTYPE_MULTI_EXIT_DISC 4
155 #define BGPTYPE_LOCAL_PREF 5
156 #define BGPTYPE_ATOMIC_AGGREGATE 6
157 #define BGPTYPE_AGGREGATOR 7
158 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
159 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC4456 */
160 #define BGPTYPE_CLUSTER_LIST 10 /* RFC4456 */
161 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */
162 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */
163 #define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */
164 #define BGPTYPE_AS4_PATH 17 /* RFC6793 */
165 #define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */
166 #define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */
167 #define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */
168 #define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */
169 #define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */
170 #define BGPTYPE_AIGP 26 /* RFC7311 */
171 #define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */
172 #define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */
173 #define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */
174 #define BGPTYPE_BGPSEC_PATH 33 /* RFC8205 */
175 #define BGPTYPE_OTC 35 /* RFC9234 */
176 #define BGPTYPE_ATTR_SET 128 /* RFC6368 */
178 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
180 static const struct tok bgp_attr_values
[] = {
181 { BGPTYPE_ORIGIN
, "Origin"},
182 { BGPTYPE_AS_PATH
, "AS Path"},
183 { BGPTYPE_AS4_PATH
, "AS4 Path"},
184 { BGPTYPE_NEXT_HOP
, "Next Hop"},
185 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
186 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
187 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
188 { BGPTYPE_AGGREGATOR
, "Aggregator"},
189 { BGPTYPE_AGGREGATOR4
, "Aggregator4"},
190 { BGPTYPE_COMMUNITIES
, "Community"},
191 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
192 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
193 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
194 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
195 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
196 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
197 { BGPTYPE_TUNNEL_ENCAP
, "Tunnel Encapsulation"},
198 { BGPTYPE_TRAFFIC_ENG
, "Traffic Engineering"},
199 { BGPTYPE_IPV6_EXTD_COMMUNITIES
, "IPv6 Extended Community"},
200 { BGPTYPE_AIGP
, "Accumulated IGP Metric"},
201 { BGPTYPE_PE_DISTINGUISHER_LABEL
, "PE Distinguisher Label"},
202 { BGPTYPE_ENTROPY_LABEL
, "Entropy Label"},
203 { BGPTYPE_LARGE_COMMUNITY
, "Large Community"},
204 { BGPTYPE_BGPSEC_PATH
, "BGPsec Path"},
205 { BGPTYPE_OTC
, "Only to Customer (OTC)"},
206 { BGPTYPE_ATTR_SET
, "Attribute Set"},
207 { 255, "Reserved for development"},
212 #define BGP_AS_SEQUENCE 2
213 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
214 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
216 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
217 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
219 static const struct tok bgp_as_path_segment_open_values
[] = {
220 { BGP_AS_SEQUENCE
, ""},
222 { BGP_CONFED_AS_SEQUENCE
, "( "},
223 { BGP_CONFED_AS_SET
, "({ "},
227 static const struct tok bgp_as_path_segment_close_values
[] = {
228 { BGP_AS_SEQUENCE
, ""},
230 { BGP_CONFED_AS_SEQUENCE
, ")"},
231 { BGP_CONFED_AS_SET
, "})"},
235 #define BGP_OPT_AUTH 1
236 #define BGP_OPT_CAP 2
238 static const struct tok bgp_opt_values
[] = {
239 { BGP_OPT_AUTH
, "Authentication Information"},
240 { BGP_OPT_CAP
, "Capabilities Advertisement"},
244 #define BGP_CAPCODE_MP 1 /* RFC2858 */
245 #define BGP_CAPCODE_RR 2 /* RFC2918 */
246 #define BGP_CAPCODE_ORF 3 /* RFC5291 */
247 #define BGP_CAPCODE_MR 4 /* RFC3107 */
248 #define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */
249 #define BGP_CAPCODE_EXT_MSG 6 /* RFC8654 */
250 #define BGP_CAPCODE_BGPSEC 7 /* RFC8205 */
251 #define BGP_CAPCODE_ML 8 /* RFC8277 */
252 #define BGP_CAPCODE_ROLE 9 /* RFC9234 */
253 #define BGP_CAPCODE_RESTART 64 /* RFC4724 */
254 #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */
255 #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */
256 #define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */
257 #define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */
258 #define BGP_CAPCODE_ENH_RR 70 /* RFC7313 */
259 #define BGP_CAPCODE_LLGR 71 /* draft-uttaro-idr-bgp-persistence-05 */
260 #define BGP_CAPCODE_RR_CISCO 128
262 static const struct tok bgp_capcode_values
[] = {
263 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
264 { BGP_CAPCODE_RR
, "Route Refresh"},
265 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
266 { BGP_CAPCODE_MR
, "Multiple Routes to a Destination"},
267 { BGP_CAPCODE_EXT_NH
, "Extended Next Hop Encoding"},
268 { BGP_CAPCODE_EXT_MSG
, "BGP Extended Message"},
269 { BGP_CAPCODE_BGPSEC
, "BGPsec"},
270 { BGP_CAPCODE_ML
, "Multiple Labels"},
271 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
272 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
273 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
274 { BGP_CAPCODE_MULTISESS
, "Multisession BGP"},
275 { BGP_CAPCODE_ADD_PATH
, "Multiple Paths"},
276 { BGP_CAPCODE_ENH_RR
, "Enhanced Route Refresh"},
277 { BGP_CAPCODE_LLGR
, "Long-lived Graceful Restart"},
278 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
279 { BGP_CAPCODE_ROLE
, "Role Capability"},
283 #define BGP_NOTIFY_MAJOR_MSG 1
284 #define BGP_NOTIFY_MAJOR_OPEN 2
285 #define BGP_NOTIFY_MAJOR_UPDATE 3
286 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
287 #define BGP_NOTIFY_MAJOR_FSM 5
288 #define BGP_NOTIFY_MAJOR_CEASE 6
289 #define BGP_NOTIFY_MAJOR_ROUTEREFRESH 7
290 #define BGP_NOTIFY_MAJOR_SENDHOLDTIME 8
292 static const struct tok bgp_notify_major_values
[] = {
293 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
294 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
295 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
296 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
297 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
298 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
299 { BGP_NOTIFY_MAJOR_ROUTEREFRESH
, "ROUTE-REFRESH Message Error"},
300 { BGP_NOTIFY_MAJOR_SENDHOLDTIME
, "Send Hold Timer Expired"},
305 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
307 #define BGP_NOTIFY_MINOR_CEASE_SHUT 2
308 #define BGP_NOTIFY_MINOR_CEASE_RESET 4
310 #define BGP_NOTIFY_MINOR_CEASE_HARDRESET 9
311 static const struct tok bgp_notify_minor_cease_values
[] = {
312 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
313 { BGP_NOTIFY_MINOR_CEASE_SHUT
, "Administrative Shutdown"},
314 { 3, "Peer Unconfigured"},
315 { BGP_NOTIFY_MINOR_CEASE_RESET
, "Administrative Reset"},
316 { 5, "Connection Rejected"},
317 { 6, "Other Configuration Change"},
318 { 7, "Connection Collision Resolution"},
319 { 8, "Out of Resources"},
320 { BGP_NOTIFY_MINOR_CEASE_HARDRESET
, "Hard Reset"},
325 static const struct tok bgp_notify_minor_msg_values
[] = {
326 { 1, "Connection Not Synchronized"},
327 { 2, "Bad Message Length"},
328 { 3, "Bad Message Type"},
332 static const struct tok bgp_notify_minor_open_values
[] = {
333 { 1, "Unsupported Version Number"},
335 { 3, "Bad BGP Identifier"},
336 { 4, "Unsupported Optional Parameter"},
337 { 5, "Authentication Failure"},
338 { 6, "Unacceptable Hold Time"},
339 { 7, "Capability Message Error"},
343 static const struct tok bgp_notify_minor_update_values
[] = {
344 { 1, "Malformed Attribute List"},
345 { 2, "Unrecognized Well-known Attribute"},
346 { 3, "Missing Well-known Attribute"},
347 { 4, "Attribute Flags Error"},
348 { 5, "Attribute Length Error"},
349 { 6, "Invalid ORIGIN Attribute"},
350 { 7, "AS Routing Loop"},
351 { 8, "Invalid NEXT_HOP Attribute"},
352 { 9, "Optional Attribute Error"},
353 { 10, "Invalid Network Field"},
354 { 11, "Malformed AS_PATH"},
358 static const struct tok bgp_notify_minor_fsm_values
[] = {
359 { 0, "Unspecified Error"},
360 { 1, "In OpenSent State"},
361 { 2, "In OpenConfirm State"},
362 { 3, "In Established State"},
366 static const struct tok bgp_notify_minor_routerefresh_values
[] = {
367 { 1, "Invalid Message Length" },
371 static const struct tok bgp_origin_values
[] = {
378 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
379 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
380 #define BGP_PMSI_TUNNEL_PIM_SSM 3
381 #define BGP_PMSI_TUNNEL_PIM_SM 4
382 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
383 #define BGP_PMSI_TUNNEL_INGRESS 6
384 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
386 static const struct tok bgp_pmsi_tunnel_values
[] = {
387 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
388 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
389 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
390 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
391 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
392 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
393 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
397 static const struct tok bgp_pmsi_flag_values
[] = {
398 { 0x01, "Leaf Information required"},
402 #define BGP_AIGP_TLV 1
404 static const struct tok bgp_aigp_values
[] = {
405 { BGP_AIGP_TLV
, "AIGP"},
409 #define BGP_ROLE_PROVIDER 0
410 #define BGP_ROLE_RS 1
411 #define BGP_ROLE_RS_CLIENT 2
412 #define BGP_ROLE_CUSTOMER 3
413 #define BGP_ROLE_PEER 4
415 static const struct tok bgp_role_values
[] = {
416 { BGP_ROLE_PROVIDER
, "Provider"},
417 { BGP_ROLE_RS
, "RS"},
418 { BGP_ROLE_RS_CLIENT
, "RS-Client"},
419 { BGP_ROLE_CUSTOMER
, "Customer"},
420 { BGP_ROLE_PEER
, "Peer"},
424 /* Subsequent address family identifier, RFC2283 section 7 */
426 #define SAFNUM_UNICAST 1
427 #define SAFNUM_MULTICAST 2
428 #define SAFNUM_UNIMULTICAST 3 /* deprecated now */
429 /* labeled BGP RFC3107 */
430 #define SAFNUM_LABUNICAST 4
432 #define SAFNUM_MULTICAST_VPN 5
433 /* draft-nalawade-kapoor-tunnel-safi */
434 #define SAFNUM_TUNNEL 64
436 #define SAFNUM_VPLS 65
438 #define SAFNUM_MDT 66
440 #define SAFNUM_EVPN 70
442 #define SAFNUM_VPNUNICAST 128
444 #define SAFNUM_VPNMULTICAST 129
445 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
447 #define SAFNUM_RT_ROUTING_INFO 132
449 #define BGP_VPN_RD_LEN 8
451 static const struct tok bgp_safi_values
[] = {
452 { SAFNUM_RES
, "Reserved"},
453 { SAFNUM_UNICAST
, "Unicast"},
454 { SAFNUM_MULTICAST
, "Multicast"},
455 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
456 { SAFNUM_LABUNICAST
, "labeled Unicast"},
457 { SAFNUM_TUNNEL
, "Tunnel"},
458 { SAFNUM_VPLS
, "VPLS"},
459 { SAFNUM_MDT
, "MDT"},
460 { SAFNUM_EVPN
, "EVPN"},
461 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
462 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
463 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
464 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
465 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
469 static const struct tok bgp_graceful_restart_comm_flag_values
[] = {
475 /* well-known community */
476 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
477 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
478 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
480 /* Extended community type - RFC 4360 */
481 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
482 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
483 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
484 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
485 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
486 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
487 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
488 #define BGP_EXT_COM_OVS 0x4300 /* BGP Prefix Origin Validation State Extended Community */
489 /* rfc2547 bgp-mpls-vpns */
490 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
491 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatibility */
492 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatibility */
493 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatibility */
495 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
496 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatibility */
497 #define BGP_EXT_COM_ENCAP 0x030c /* rfc5512 */
499 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
500 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatibility */
502 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
504 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
505 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
506 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
507 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
509 /* https://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
510 #define BGP_EXT_COM_EIGRP_GEN 0x8800
511 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
512 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
513 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
514 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
515 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
517 /* Optional Parameters */
518 #define BGP_OPEN_NON_EXT_OPT_TYPE_EXTENDED_LENGTH 255 /* Non-Ext OP Type */
520 static const struct tok bgp_extd_comm_flag_values
[] = {
521 { 0x8000, "vendor-specific"},
522 { 0x4000, "non-transitive"},
527 static const struct tok bgp_prefix_origin_validation_state
[] = {
534 static const struct tok bgp_extd_comm_subtype_values
[] = {
535 { BGP_EXT_COM_RT_0
, "target"},
536 { BGP_EXT_COM_RT_1
, "target"},
537 { BGP_EXT_COM_RT_2
, "target"},
538 { BGP_EXT_COM_RO_0
, "origin"},
539 { BGP_EXT_COM_RO_1
, "origin"},
540 { BGP_EXT_COM_RO_2
, "origin"},
541 { BGP_EXT_COM_LINKBAND
, "link-BW"},
542 { BGP_EXT_COM_OVS
, "origin-validation-state"},
543 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
544 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
545 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
546 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
547 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
548 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
549 { BGP_EXT_COM_ENCAP
, "encapsulation"},
550 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
551 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
552 { BGP_EXT_COM_L2INFO
, "layer2-info"},
553 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
554 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
555 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
556 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
557 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
558 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
559 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
560 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
561 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
562 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
566 /* RFC RFC5512 BGP Tunnel Encapsulation Attribute Tunnel Types */
567 #define BGP_ENCAP_TUNNEL_L2TPV3_IP 1
568 #define BGP_ENCAP_TUNNEL_GRE 2
569 #define BGP_ENCAP_TUNNEL_TRANSMIT 3
570 #define BGP_ENCAP_TUNNEL_IPSEC 4
571 #define BGP_ENCAP_TUNNEL_IP_IPSEC 5
572 #define BGP_ENCAP_TUNNEL_MPLS_IP 6
573 #define BGP_ENCAP_TUNNEL_IP_IP 7
574 #define BGP_ENCAP_TUNNEL_VXLAN 8
575 #define BGP_ENCAP_TUNNEL_NVGRE 9
576 #define BGP_ENCAP_TUNNEL_MPLS 10
577 #define BGP_ENCAP_TUNNEL_MPLS_GRE 11
578 #define BGP_ENCAP_TUNNEL_VXLAN_GPE 12
579 #define BGP_ENCAP_TUNNEL_MPLS_UDP 13
580 #define BGP_ENCAP_TUNNEL_IPV6 14
581 #define BGP_ENCAP_TUNNEL_SR_TE 15
582 #define BGP_ENCAP_TUNNEL_BARE 16
583 #define BGP_ENCAP_TUNNEL_SR 17
585 static const struct tok bgp_extd_comm_encap_tunnel_values
[] = {
586 { BGP_ENCAP_TUNNEL_L2TPV3_IP
, "L2TPv3 over IP"},
587 { BGP_ENCAP_TUNNEL_GRE
, "GRE"},
588 { BGP_ENCAP_TUNNEL_TRANSMIT
, "Transmit Tunnel"},
589 { BGP_ENCAP_TUNNEL_IPSEC
, "IPsec"},
590 { BGP_ENCAP_TUNNEL_IP_IPSEC
, "IP in IP with IPsec"},
591 { BGP_ENCAP_TUNNEL_MPLS_IP
, "MPLS in IP with IPsec"},
592 { BGP_ENCAP_TUNNEL_IP_IP
, "IP in IP"},
593 { BGP_ENCAP_TUNNEL_VXLAN
, "VXLAN"},
594 { BGP_ENCAP_TUNNEL_NVGRE
, "NVGRE"},
595 { BGP_ENCAP_TUNNEL_MPLS
, "MPLS"},
596 { BGP_ENCAP_TUNNEL_MPLS_GRE
, "MPLS in GRE"},
597 { BGP_ENCAP_TUNNEL_VXLAN_GPE
, "VXLAN GPE"},
598 { BGP_ENCAP_TUNNEL_MPLS_UDP
, "MPLS in UDP"},
599 { BGP_ENCAP_TUNNEL_IPV6
, "IPv6"},
600 { BGP_ENCAP_TUNNEL_SR_TE
, "SR TE"},
601 { BGP_ENCAP_TUNNEL_BARE
, "Bare"},
602 { BGP_ENCAP_TUNNEL_SR
, "SR"},
606 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
607 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
608 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
609 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
610 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
611 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
612 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
613 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
615 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
616 { BGP_OSPF_RTYPE_RTR
, "Router" },
617 { BGP_OSPF_RTYPE_NET
, "Network" },
618 { BGP_OSPF_RTYPE_SUM
, "Summary" },
619 { BGP_OSPF_RTYPE_EXT
, "External" },
620 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
621 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
625 /* ADD-PATH Send/Receive field values */
626 static const struct tok bgp_add_path_recvsend
[] = {
633 static const struct tok bgp_bgpsec_bitmap_str
[] = {
634 { 1U << 0, "MBZ-0" },
635 { 1U << 1, "MBZ-1" },
636 { 1U << 2, "MBZ-2" },
637 { 1U << 3, "MBZ-3" },
638 { 1U << 4, "MBZ-4" },
639 { 1U << 5, "MBZ-5" },
640 { 1U << 6, "MBZ-6" },
645 #define AS_STR_SIZE sizeof("xxxxx.xxxxx")
650 * Convert an AS number into a string and return string pointer.
652 * Depending on bflag is set or not, AS number is converted into ASDOT notation
653 * or plain number notation.
657 as_printf(netdissect_options
*ndo
,
658 char *str
, size_t size
, u_int asnum
)
660 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
661 snprintf(str
, size
, "%u", asnum
);
663 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
668 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
671 decode_prefix4(netdissect_options
*ndo
,
672 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
675 u_int plen
, plenbytes
;
678 plen
= GET_U_1(pptr
);
683 memset(&addr
, 0, sizeof(addr
));
684 plenbytes
= (plen
+ 7) / 8;
685 ITEMCHECK(plenbytes
);
686 GET_CPY_BYTES(&addr
, pptr
+ 1, plenbytes
);
688 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
690 snprintf(buf
, buflen
, "%s/%u", ipaddr_string(ndo
, (const u_char
*)&addr
), plen
);
691 return 1 + plenbytes
;
698 print_labeled_prefix4(netdissect_options
*ndo
,
699 const u_char
*pptr
, u_int itemlen
)
702 u_int plen
, plenbytes
;
704 /* prefix length and label = 4 bytes */
707 plen
= GET_U_1(pptr
); /* get prefix length */
709 /* this is one of the weirdnesses of rfc3107
710 the label length (actually the label + COS bits)
711 is added to the prefix length;
712 we also do only read out just one label -
713 there is no real application for advertisement of
714 stacked labels in a single BGP message
720 plen
-=24; /* adjust prefixlen - labellength */
726 memset(&addr
, 0, sizeof(addr
));
727 plenbytes
= (plen
+ 7) / 8;
728 ITEMCHECK(plenbytes
);
729 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
731 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
733 /* the label may get offsetted by 4 bits so lets shift it right */
734 ND_PRINT("\n\t %s/%u, label:%u %s",
735 ipaddr_string(ndo
, (const u_char
*)&addr
),
737 GET_BE_U_3(pptr
+ 1)>>4,
738 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
740 return 4 + plenbytes
;
743 ND_PRINT("\n\t (illegal prefix length)");
756 * print an ipv4 or ipv6 address into a buffer dependent on address length.
759 bgp_vpn_ip_print(netdissect_options
*ndo
,
760 const u_char
*pptr
, u_int addr_length
)
763 /* worst case string is s fully formatted v6 address */
764 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
767 switch(addr_length
) {
768 case (sizeof(nd_ipv4
) << 3): /* 32 */
769 snprintf(pos
, sizeof(addr
), "%s", GET_IPADDR_STRING(pptr
));
771 case (sizeof(nd_ipv6
) << 3): /* 128 */
772 snprintf(pos
, sizeof(addr
), "%s", GET_IP6ADDR_STRING(pptr
));
775 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
787 * print an multicast s,g entry into a buffer.
788 * the s,g entry is encoded like this.
790 * +-----------------------------------+
791 * | Multicast Source Length (1 octet) |
792 * +-----------------------------------+
793 * | Multicast Source (Variable) |
794 * +-----------------------------------+
795 * | Multicast Group Length (1 octet) |
796 * +-----------------------------------+
797 * | Multicast Group (Variable) |
798 * +-----------------------------------+
800 * return the number of bytes read from the wire.
803 bgp_vpn_sg_print(netdissect_options
*ndo
, const u_char
*pptr
)
810 /* Source address length, encoded in bits */
811 addr_length
= GET_U_1(pptr
);
815 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
816 total_length
+= (addr_length
>> 3) + 1;
818 ND_PRINT(", Source %s",
819 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
820 pptr
+= (addr_length
>> 3);
823 /* Group address length, encoded in bits */
824 addr_length
= GET_U_1(pptr
);
828 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
829 total_length
+= (addr_length
>> 3) + 1;
831 ND_PRINT(", Group %s",
832 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
833 pptr
+= (addr_length
>> 3);
837 return (total_length
);
840 /* Print an RFC 4364 Route Distinguisher */
842 bgp_vpn_rd_print(netdissect_options
*ndo
, const u_char
*pptr
)
844 /* allocate space for the largest possible string */
845 static char rd
[sizeof("xxxxx.xxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
847 /* allocate space for the largest possible string */
848 char astostr
[AS_STR_SIZE
];
850 /* ok lets load the RD format */
851 switch (GET_BE_U_2(pptr
)) {
854 /* 2-byte-AS:number fmt */
855 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
856 GET_BE_U_2(pptr
+ 2),
857 GET_BE_U_4(pptr
+ 4),
858 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
859 GET_U_1(pptr
+ 6), GET_U_1(pptr
+ 7));
863 /* IP-address:AS fmt */
864 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
865 GET_U_1(pptr
+ 2), GET_U_1(pptr
+ 3),
866 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
867 GET_BE_U_2(pptr
+ 6));
871 /* 4-byte-AS:number fmt */
872 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
873 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 2)),
874 GET_BE_U_2(pptr
+ 6), GET_U_1(pptr
+ 2),
875 GET_U_1(pptr
+ 3), GET_U_1(pptr
+ 4),
876 GET_U_1(pptr
+ 5), GET_BE_U_2(pptr
+ 6));
879 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
888 * Print an RFC 4360 Extended Community.
891 bgp_extended_community_print(netdissect_options
*ndo
,
894 /* allocate space for the largest possible string */
895 char astostr
[AS_STR_SIZE
];
897 switch (GET_BE_U_2(pptr
)) {
899 case BGP_EXT_COM_RT_0
:
900 case BGP_EXT_COM_RO_0
:
901 case BGP_EXT_COM_L2VPN_RT_0
:
902 ND_PRINT("%u:%u (= %s)",
903 GET_BE_U_2(pptr
+ 2),
904 GET_BE_U_4(pptr
+ 4),
905 GET_IPADDR_STRING(pptr
+4));
908 case BGP_EXT_COM_RT_1
:
909 case BGP_EXT_COM_RO_1
:
910 case BGP_EXT_COM_L2VPN_RT_1
:
911 case BGP_EXT_COM_VRF_RT_IMP
:
913 GET_IPADDR_STRING(pptr
+2),
914 GET_BE_U_2(pptr
+ 6));
917 case BGP_EXT_COM_RT_2
:
918 case BGP_EXT_COM_RO_2
:
920 as_printf(ndo
, astostr
, sizeof(astostr
),
921 GET_BE_U_4(pptr
+ 2)), GET_BE_U_2(pptr
+ 6));
924 case BGP_EXT_COM_LINKBAND
:
925 ND_PRINT("bandwidth: %.3f Mbps",
926 GET_BE_F_4(pptr
+ 4)*8/1000000);
929 case BGP_EXT_COM_OVS
:
930 /* The Reserved field MUST be set to 0 and ignored upon the
931 * receipt of this community.
934 uint64_t reserved
= GET_BE_U_5(pptr
+ 2);
937 ND_PRINT("[the reserved field 0x%" PRIx64
" MUST be 0] ",
940 tok2str(bgp_prefix_origin_validation_state
,
941 "unknown origin validation state",
946 case BGP_EXT_COM_VPN_ORIGIN
:
947 case BGP_EXT_COM_VPN_ORIGIN2
:
948 case BGP_EXT_COM_VPN_ORIGIN3
:
949 case BGP_EXT_COM_VPN_ORIGIN4
:
950 case BGP_EXT_COM_OSPF_RID
:
951 case BGP_EXT_COM_OSPF_RID2
:
952 ND_PRINT("%s", GET_IPADDR_STRING(pptr
+2));
955 case BGP_EXT_COM_OSPF_RTYPE
:
956 case BGP_EXT_COM_OSPF_RTYPE2
:
957 ND_PRINT("area:%s, router-type:%s, metric-type:%s%s",
958 GET_IPADDR_STRING(pptr
+2),
959 tok2str(bgp_extd_comm_ospf_rtype_values
,
961 GET_U_1((pptr
+ 6))),
962 (GET_U_1(pptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
963 ((GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
966 case BGP_EXT_COM_L2INFO
:
967 ND_PRINT("%s Control Flags [0x%02x]:MTU %u",
968 tok2str(l2vpn_encaps_values
,
970 GET_U_1((pptr
+ 2))),
972 GET_BE_U_2(pptr
+ 4));
975 case BGP_EXT_COM_SOURCE_AS
:
976 ND_PRINT("AS %u", GET_BE_U_2(pptr
+ 2));
979 case BGP_EXT_COM_ENCAP
:
980 ND_PRINT("Tunnel type: %s", tok2str(bgp_extd_comm_encap_tunnel_values
,
982 GET_BE_U_2(pptr
+ 6)));
986 ND_PRINT("%02x%02x%02x%02x%02x%02x",
998 * RFC4684 (Section 4)/RFC2858 (Section 4).
999 * RTC membership prefix is structured as follows
1000 * [prefix-len] [origin-as] [route-target]
1001 * The route-target is encoded as RT ext-comms.
1002 * Prefix-len may be 0, 32..96
1004 * Note that pptr is not packet data - it is
1005 * a buffer owned by our caller - therefore GET_*
1006 * macros can not be used.
1009 bgp_rt_prefix_print(netdissect_options
*ndo
,
1013 /* allocate space for the largest possible string */
1014 char rtc_prefix_in_hex
[sizeof("0000 0000 0000 0000")] = "";
1015 u_int rtc_prefix_in_hex_len
= 0;
1016 static char output
[61]; /* max response string */
1017 /* allocate space for the largest possible string */
1018 char astostr
[AS_STR_SIZE
];
1019 uint16_t ec_type
= 0;
1024 snprintf(output
, sizeof(output
), "route-target: 0:0/0");
1028 /* hex representation of the prefix */
1029 octet_count
= (plen
+7)/8;
1030 for (i
=0; i
<octet_count
; i
++) {
1031 rtc_prefix_in_hex_len
+= snprintf(rtc_prefix_in_hex
+rtc_prefix_in_hex_len
,
1032 sizeof(rtc_prefix_in_hex
)-rtc_prefix_in_hex_len
,
1033 "%02x%s", *(pptr
+i
),
1034 ((i
%2 == 1) && (i
<octet_count
-1)) ? " " : "");
1039 * The prefix is too short to include the full ext-comm type,
1040 * so we have no way to parse it further.
1042 snprintf(output
, sizeof(output
), "route-target: partial-type: (%s/%d)",
1043 rtc_prefix_in_hex
, plen
);
1048 * get the ext-comm type
1049 * Note: pptr references a static 8 octet buffer with unused bits set to 0,
1050 * hence EXTRACT_*() macros are safe.
1052 ec_type
= EXTRACT_BE_U_2(pptr
);
1054 case BGP_EXT_COM_RT_0
:
1055 /* 2-byte-AS:number fmt */
1056 snprintf(output
, sizeof(output
), "route-target: %u:%u/%d (%s)",
1057 EXTRACT_BE_U_2(pptr
+2),
1058 EXTRACT_BE_U_4(pptr
+4),
1059 plen
, rtc_prefix_in_hex
);
1062 case BGP_EXT_COM_RT_1
:
1063 /* IP-address:AS fmt */
1064 snprintf(output
, sizeof(output
), "route-target: %u.%u.%u.%u:%u/%d (%s)",
1065 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5),
1066 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
1069 case BGP_EXT_COM_RT_2
:
1070 /* 4-byte-AS:number fmt */
1071 snprintf(output
, sizeof(output
), "route-target: %s:%u/%d (%s)",
1072 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(pptr
+2)),
1073 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
1077 snprintf(output
, sizeof(output
), "route target: unknown-type(%04x) (%s/%d)",
1079 rtc_prefix_in_hex
, plen
);
1087 print_rt_routing_info(netdissect_options
*ndo
, const u_char
*pptr
)
1089 uint8_t route_target
[8];
1091 /* allocate space for the largest possible string */
1092 char astostr
[AS_STR_SIZE
];
1095 /* NLRI "prefix length" from RFC 2858 Section 4. */
1096 plen
= GET_U_1(pptr
); /* get prefix length */
1098 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
1099 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
1100 * target" fields inside the "prefix" depending on its length.
1103 /* Without "origin AS", without "route target". */
1104 ND_PRINT("\n\t default route target");
1109 ND_PRINT("\n\t (illegal prefix length)");
1113 /* With at least "origin AS", possibly with "route target". */
1114 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 1));
1116 plen
-= 32; /* adjust prefix length */
1119 ND_PRINT("\n\t (illegal prefix length)");
1123 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
1124 * and gives the number of octets in the variable-length "route
1125 * target" field inside this NLRI "prefix". Look for it.
1127 memset(&route_target
, 0, sizeof(route_target
));
1128 num_octets
= (plen
+ 7) / 8;
1129 GET_CPY_BYTES(&route_target
, pptr
+ 5, num_octets
);
1130 /* If mask-len is not on octet boundary, ensure all extra bits are 0 */
1132 ((u_char
*)&route_target
)[num_octets
- 1] &=
1133 ((0xff00 >> (plen
% 8)) & 0xff);
1135 ND_PRINT("\n\t origin AS: %s, %s",
1137 bgp_rt_prefix_print(ndo
, (u_char
*)&route_target
, plen
));
1139 return 5 + num_octets
;
1143 print_labeled_vpn_prefix4(netdissect_options
*ndo
, const u_char
*pptr
)
1148 plen
= GET_U_1(pptr
); /* get prefix length */
1153 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1158 memset(&addr
, 0, sizeof(addr
));
1159 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1161 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
1162 ((0xff00 >> (plen
% 8)) & 0xff);
1164 /* the label may get offsetted by 4 bits so lets shift it right */
1165 ND_PRINT("\n\t RD: %s, %s/%u, label:%u %s",
1166 bgp_vpn_rd_print(ndo
, pptr
+4),
1167 ipaddr_string(ndo
, (const u_char
*)&addr
),
1169 GET_BE_U_3(pptr
+ 1)>>4,
1170 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1172 return 12 + (plen
+ 7) / 8;
1175 ND_PRINT("\n\t (illegal prefix length)");
1180 * +-------------------------------+
1182 * | RD:IPv4-address (12 octets) |
1184 * +-------------------------------+
1185 * | MDT Group-address (4 octets) |
1186 * +-------------------------------+
1189 #define MDT_VPN_NLRI_LEN 16
1192 print_mdt_vpn_nlri(netdissect_options
*ndo
, const u_char
*pptr
)
1195 const u_char
*vpn_ip
;
1197 /* if the NLRI is not predefined length, quit.*/
1198 if (GET_U_1(pptr
) != MDT_VPN_NLRI_LEN
* 8) {
1199 ND_PRINT("\n\t (illegal prefix length)");
1211 pptr
+= sizeof(nd_ipv4
);
1213 /* MDT Group Address */
1214 ND_PRINT("\n\t RD: %s, VPN IP Address: %s, MC Group Address: %s",
1215 bgp_vpn_rd_print(ndo
, rd
),
1216 GET_IPADDR_STRING(vpn_ip
),
1217 GET_IPADDR_STRING(pptr
));
1219 return MDT_VPN_NLRI_LEN
+ 1;
1225 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
1226 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
1227 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
1228 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
1229 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
1230 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
1231 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
1233 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
1234 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
1235 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
1236 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
1237 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
1238 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
1239 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
1240 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
1245 print_multicast_vpn(netdissect_options
*ndo
, const u_char
*pptr
)
1247 /* allocate space for the largest possible string */
1248 char astostr
[AS_STR_SIZE
];
1249 uint8_t route_type
, route_length
;
1250 u_int addr_length
, sg_length
;
1252 route_type
= GET_U_1(pptr
);
1254 route_length
= GET_U_1(pptr
);
1257 ND_PRINT("\n\t Route-Type: %s (%u), length: %u",
1258 tok2str(bgp_multicast_vpn_route_type_values
,
1259 "Unknown", route_type
),
1260 route_type
, route_length
);
1262 switch(route_type
) {
1263 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
1264 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1265 if (route_length
< BGP_VPN_RD_LEN
)
1267 ND_PRINT(", RD: %s, Originator %s",
1268 bgp_vpn_rd_print(ndo
, pptr
),
1269 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
1270 (route_length
- BGP_VPN_RD_LEN
) << 3));
1272 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
1273 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1274 ND_PRINT(", RD: %s, Source-AS %s",
1275 bgp_vpn_rd_print(ndo
, pptr
),
1276 as_printf(ndo
, astostr
, sizeof(astostr
),
1277 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1280 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
1281 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1282 ND_PRINT(", RD: %s", bgp_vpn_rd_print(ndo
, pptr
));
1283 pptr
+= BGP_VPN_RD_LEN
;
1285 sg_length
= bgp_vpn_sg_print(ndo
, pptr
);
1286 addr_length
= route_length
- sg_length
;
1288 ND_TCHECK_LEN(pptr
, addr_length
);
1289 ND_PRINT(", Originator %s",
1290 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
1293 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
1294 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1295 ND_PRINT(", RD: %s", bgp_vpn_rd_print(ndo
, pptr
));
1296 pptr
+= BGP_VPN_RD_LEN
;
1298 bgp_vpn_sg_print(ndo
, pptr
);
1301 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
1302 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
1303 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1304 ND_PRINT(", RD: %s, Source-AS %s",
1305 bgp_vpn_rd_print(ndo
, pptr
),
1306 as_printf(ndo
, astostr
, sizeof(astostr
),
1307 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1308 pptr
+= BGP_VPN_RD_LEN
+ 4;
1310 bgp_vpn_sg_print(ndo
, pptr
);
1314 * no per route-type printing yet.
1316 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1321 return route_length
+ 2;
1328 print_labeled_vpn_l2(netdissect_options
*ndo
, const u_char
*pptr
)
1330 u_int plen
, tlen
, tlv_type
, tlv_len
, ttlv_len
;
1332 plen
= GET_BE_U_2(pptr
);
1335 /* Old and new L2VPN NLRI share AFI/SAFI
1336 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1337 * and > 17 as old format. Complain for the middle case
1340 /* assume AD-only with RD, BGPNH */
1341 ND_TCHECK_LEN(pptr
, 12);
1342 ND_PRINT("\n\t RD: %s, BGPNH: %s",
1343 bgp_vpn_rd_print(ndo
, pptr
),
1344 GET_IPADDR_STRING(pptr
+8));
1346 } else if (plen
> 17) {
1347 /* assume old format */
1348 /* RD, ID, LBLKOFF, LBLBASE */
1350 ND_TCHECK_LEN(pptr
, 15);
1351 ND_PRINT("\n\t RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1352 bgp_vpn_rd_print(ndo
, pptr
),
1353 GET_BE_U_2(pptr
+ 8),
1354 GET_BE_U_2(pptr
+ 10),
1355 GET_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1359 /* ok now the variable part - lets read out TLVs*/
1362 ND_PRINT("\n\t\tran past the end");
1365 tlv_type
= GET_U_1(pptr
);
1367 tlv_len
= GET_BE_U_2(pptr
); /* length, in *bits* */
1368 ttlv_len
= (tlv_len
+ 7)/8; /* length, in *bytes* */
1373 ND_PRINT("\n\t\tcircuit status vector (%u) length: %u: 0x",
1376 while (ttlv_len
!= 0) {
1378 ND_PRINT(" (ran past the end)");
1382 ND_PRINT("%02x", GET_U_1(pptr
));
1389 ND_PRINT("\n\t\tunknown TLV #%u, length: %u",
1392 if (tlen
< ttlv_len
) {
1393 ND_PRINT(" (ran past the end)");
1402 /* complain bitterly ? */
1412 decode_prefix6(netdissect_options
*ndo
,
1413 const u_char
*pd
, u_int itemlen
, char *buf
, size_t buflen
)
1416 u_int plen
, plenbytes
;
1424 memset(&addr
, 0, sizeof(addr
));
1425 plenbytes
= (plen
+ 7) / 8;
1426 ITEMCHECK(plenbytes
);
1427 GET_CPY_BYTES(&addr
, pd
+ 1, plenbytes
);
1429 addr
[plenbytes
- 1] &=
1430 ((0xff00 >> (plen
% 8)) & 0xff);
1432 snprintf(buf
, buflen
, "%s/%u", ip6addr_string(ndo
, (const u_char
*)&addr
), plen
);
1433 return 1 + plenbytes
;
1440 print_labeled_prefix6(netdissect_options
*ndo
,
1441 const u_char
*pptr
, u_int itemlen
)
1444 u_int plen
, plenbytes
;
1446 /* prefix length and label = 4 bytes */
1449 plen
= GET_U_1(pptr
); /* get prefix length */
1454 plen
-= 24; /* adjust prefixlen - labellength */
1460 memset(&addr
, 0, sizeof(addr
));
1461 plenbytes
= (plen
+ 7) / 8;
1462 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
1464 addr
[plenbytes
- 1] &=
1465 ((0xff00 >> (plen
% 8)) & 0xff);
1467 /* the label may get offsetted by 4 bits so lets shift it right */
1468 ND_PRINT("\n\t %s/%u, label:%u %s",
1469 ip6addr_string(ndo
, (const u_char
*)&addr
),
1471 GET_BE_U_3(pptr
+ 1)>>4,
1472 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1474 return 4 + plenbytes
;
1477 ND_PRINT("\n\t (illegal prefix length)");
1488 print_labeled_vpn_prefix6(netdissect_options
*ndo
, const u_char
*pptr
)
1493 plen
= GET_U_1(pptr
); /* get prefix length */
1498 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1503 memset(&addr
, 0, sizeof(addr
));
1504 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1506 addr
[(plen
+ 7) / 8 - 1] &=
1507 ((0xff00 >> (plen
% 8)) & 0xff);
1509 /* the label may get offsetted by 4 bits so lets shift it right */
1510 ND_PRINT("\n\t RD: %s, %s/%u, label:%u %s",
1511 bgp_vpn_rd_print(ndo
, pptr
+4),
1512 ip6addr_string(ndo
, (const u_char
*)&addr
),
1514 GET_BE_U_3(pptr
+ 1)>>4,
1515 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1517 return 12 + (plen
+ 7) / 8;
1520 ND_PRINT("\n\t (illegal prefix length)");
1525 print_clnp_prefix(netdissect_options
*ndo
, const u_char
*pptr
)
1530 plen
= GET_U_1(pptr
); /* get prefix length */
1535 memset(&addr
, 0, sizeof(addr
));
1536 GET_CPY_BYTES(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1538 addr
[(plen
+ 7) / 8 - 1] &=
1539 ((0xff00 >> (plen
% 8)) & 0xff);
1541 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1542 ND_PRINT("\n\t %s/%u",
1543 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1546 return 1 + (plen
+ 7) / 8;
1549 ND_PRINT("\n\t (illegal prefix length)");
1554 print_labeled_vpn_clnp_prefix(netdissect_options
*ndo
, const u_char
*pptr
)
1559 plen
= GET_U_1(pptr
); /* get prefix length */
1564 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1569 memset(&addr
, 0, sizeof(addr
));
1570 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1572 addr
[(plen
+ 7) / 8 - 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
1574 /* the label may get offsetted by 4 bits so lets shift it right */
1575 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1576 ND_PRINT("\n\t RD: %s, %s/%u, label:%u %s",
1577 bgp_vpn_rd_print(ndo
, pptr
+4),
1578 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1580 GET_BE_U_3(pptr
+ 1)>>4,
1581 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1583 return 12 + (plen
+ 7) / 8;
1586 ND_PRINT("\n\t (illegal prefix length)");
1591 * bgp_attr_get_as_size
1593 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1594 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1595 * support, exchange AS-Path with the same path-attribute type value 0x02.
1598 bgp_attr_get_as_size(netdissect_options
*ndo
,
1599 uint8_t bgpa_type
, const u_char
*pptr
, u_int len
)
1601 const u_char
*tptr
= pptr
;
1604 * If the path attribute is the optional AS4 path type, then we already
1605 * know, that ASs must be encoded in 4 byte format.
1607 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1612 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1613 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1616 while (tptr
< pptr
+ len
) {
1618 * If we do not find a valid segment type, our guess might be wrong.
1620 if (GET_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| GET_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1623 tptr
+= 2 + GET_U_1(tptr
+ 1) * 2;
1627 * If we correctly reached end of the AS path attribute data content,
1628 * then most likely ASs were indeed encoded as 2 bytes.
1630 if (tptr
== pptr
+ len
) {
1637 * We can come here, either we did not have enough data, or if we
1638 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1639 * so that caller can try to decode each AS as of 4 bytes. If indeed
1640 * there was not enough data, it will crib and end the parse anyways.
1646 * The only way to know that a BGP UPDATE message is using add path is
1647 * by checking if the capability is in the OPEN message which we may have missed.
1648 * So this function checks if it is possible that the update could contain add path
1649 * and if so it checks that standard BGP doesn't make sense.
1652 check_add_path(netdissect_options
*ndo
, const u_char
*pptr
, u_int length
,
1653 u_int max_prefix_length
)
1655 u_int offset
, prefix_length
;
1662 * Scan through the NLRI information under the assumption that
1663 * it doesn't have path IDs.
1665 for (offset
= 0; offset
< length
;) {
1667 if (!ND_TTEST_1(pptr
+ offset
)) {
1668 /* We ran out of captured data; quit scanning. */
1671 prefix_length
= GET_U_1(pptr
+ offset
);
1673 * Add 4 to cover the path id
1674 * and check the prefix length isn't greater than 32/128.
1676 if (prefix_length
> max_prefix_length
) {
1679 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1680 offset
+= 1 + ((prefix_length
+ 7) / 8);
1682 /* check we haven't gone past the end of the section */
1683 if (offset
> length
) {
1687 /* check it's not standard BGP */
1688 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 * If the prefix_length is zero (0.0.0.0/0)
1696 * and since it's not the only address (length >= 5)
1697 * then it is add-path
1699 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1702 offset
+= 1 + ((prefix_length
+ 7) / 8);
1704 if (offset
> length
) {
1708 /* assume not add-path by default */
1713 bgp_mp_af_print(netdissect_options
*ndo
,
1714 const u_char
*tptr
, u_int tlen
,
1715 uint16_t *afp
, uint8_t *safip
)
1720 af
= GET_BE_U_2(tptr
);
1722 safi
= GET_U_1(tptr
+ 2);
1725 ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1726 tok2str(af_values
, "Unknown AFI", af
),
1728 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1729 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1732 switch(af
<<8 | safi
) {
1733 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
1734 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
1735 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
1736 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
1737 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
1738 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
1739 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
1740 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1741 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
):
1742 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
1743 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
1744 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
1745 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
1746 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
1747 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
1748 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
1749 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1750 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1751 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1752 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1753 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1754 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1755 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1756 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1757 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1758 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1759 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1762 ND_TCHECK_LEN(tptr
, tlen
);
1763 ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af
, safi
);
1764 if (ndo
->ndo_vflag
<= 1)
1765 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1774 bgp_nlri_print(netdissect_options
*ndo
, uint16_t af
, uint8_t safi
,
1775 const u_char
*tptr
, u_int len
,
1776 int add_path4
, int add_path6
)
1782 switch (af
<<8 | safi
) {
1783 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
1784 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
1785 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
1787 path_id
= GET_BE_U_4(tptr
);
1790 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1792 ND_PRINT("\n\t (illegal prefix length)");
1793 else if (advance
== -2)
1794 break; /* bytes left, but not enough */
1796 ND_PRINT("\n\t %s", buf
);
1798 ND_PRINT(" Path Id: %u", path_id
);
1802 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
1803 advance
= print_labeled_prefix4(ndo
, tptr
, len
);
1807 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
1808 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
1809 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1810 advance
= print_labeled_vpn_prefix4(ndo
, tptr
);
1812 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
1813 advance
= print_rt_routing_info(ndo
, tptr
);
1815 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1816 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST_VPN
):
1817 advance
= print_multicast_vpn(ndo
, tptr
);
1822 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
1823 advance
= print_mdt_vpn_nlri(ndo
, tptr
);
1827 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
1828 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
1829 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
1831 path_id
= GET_BE_U_4(tptr
);
1834 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1836 ND_PRINT("\n\t (illegal prefix length)");
1837 else if (advance
== -2)
1838 break; /* bytes left, but not enough */
1840 ND_PRINT("\n\t %s", buf
);
1842 ND_PRINT(" Path Id: %u", path_id
);
1846 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
1847 advance
= print_labeled_prefix6(ndo
, tptr
, len
);
1851 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
1852 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
1853 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1854 advance
= print_labeled_vpn_prefix6(ndo
, tptr
);
1856 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1857 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1858 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1859 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1860 advance
= print_labeled_vpn_l2(ndo
, tptr
);
1864 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1865 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1866 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1867 advance
= print_clnp_prefix(ndo
, tptr
);
1869 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1870 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1871 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1872 advance
= print_labeled_vpn_clnp_prefix(ndo
, tptr
);
1876 * This should not happen, we should have been protected
1877 * by bgp_mp_af_print()'s return value.
1879 ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af
, safi
);
1884 trunc
: /* we rely on the caller to recognize -2 return value */
1888 static const struct tok bgp_flags
[] = {
1897 bgp_attr_print(netdissect_options
*ndo
,
1898 uint8_t atype
, const u_char
*pptr
, u_int len
,
1899 const unsigned attr_set_level
)
1901 /* allocate space for the largest possible string */
1902 char astostr
[AS_STR_SIZE
];
1905 uint8_t safi
, snpa
, nhlen
;
1910 int add_path4
, add_path6
;
1917 case BGPTYPE_ORIGIN
:
1919 ND_PRINT("invalid len");
1921 ND_PRINT("%s", tok2str(bgp_origin_values
,
1922 "Unknown Origin Typecode",
1928 * Process AS4 byte path and AS2 byte path attributes here.
1930 case BGPTYPE_AS4_PATH
:
1931 case BGPTYPE_AS_PATH
:
1933 ND_PRINT("invalid len");
1942 * BGP updates exchanged between New speakers that support 4
1943 * byte AS, ASs are always encoded in 4 bytes. There is no
1944 * definitive way to find this, just by the packet's
1945 * contents. So, check for packet's TLV's sanity assuming
1946 * 2 bytes first, and it does not pass, assume that ASs are
1947 * encoded in 4 bytes format and move on.
1949 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1951 while (tptr
< pptr
+ len
) {
1952 ND_PRINT("%s", tok2str(bgp_as_path_segment_open_values
,
1953 "?", GET_U_1(tptr
)));
1954 for (i
= 0; i
< GET_U_1(tptr
+ 1) * as_size
; i
+= as_size
) {
1955 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
1957 as_printf(ndo
, astostr
, sizeof(astostr
),
1959 GET_BE_U_2(tptr
+ i
+ 2) :
1960 GET_BE_U_4(tptr
+ i
+ 2)));
1962 ND_PRINT("%s", tok2str(bgp_as_path_segment_close_values
,
1963 "?", GET_U_1(tptr
)));
1964 tptr
+= 2 + GET_U_1(tptr
+ 1) * as_size
;
1967 case BGPTYPE_NEXT_HOP
:
1969 ND_PRINT("invalid len");
1971 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
1974 case BGPTYPE_MULTI_EXIT_DISC
:
1975 case BGPTYPE_LOCAL_PREF
:
1977 ND_PRINT("invalid len");
1979 ND_PRINT("%u", GET_BE_U_4(tptr
));
1982 case BGPTYPE_ATOMIC_AGGREGATE
:
1984 ND_PRINT("invalid len");
1986 case BGPTYPE_AGGREGATOR
:
1989 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1990 * the length of this PA can be either 6 bytes or 8 bytes.
1992 if (len
!= 6 && len
!= 8) {
1993 ND_PRINT("invalid len");
1996 ND_TCHECK_LEN(tptr
, len
);
1998 ND_PRINT(" AS #%s, origin %s",
1999 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(tptr
)),
2000 GET_IPADDR_STRING(tptr
+ 2));
2002 ND_PRINT(" AS #%s, origin %s",
2003 as_printf(ndo
, astostr
, sizeof(astostr
),
2004 GET_BE_U_4(tptr
)), GET_IPADDR_STRING(tptr
+ 4));
2007 case BGPTYPE_AGGREGATOR4
:
2009 ND_PRINT("invalid len");
2012 ND_PRINT(" AS #%s, origin %s",
2013 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)),
2014 GET_IPADDR_STRING(tptr
+ 4));
2016 case BGPTYPE_COMMUNITIES
:
2018 ND_PRINT("invalid len");
2026 comm
= GET_BE_U_4(tptr
);
2028 case BGP_COMMUNITY_NO_EXPORT
:
2029 ND_PRINT(" NO_EXPORT");
2031 case BGP_COMMUNITY_NO_ADVERT
:
2032 ND_PRINT(" NO_ADVERTISE");
2034 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
2035 ND_PRINT(" NO_EXPORT_SUBCONFED");
2039 (comm
>> 16) & 0xffff,
2041 (tlen
>4) ? ", " : "");
2048 case BGPTYPE_ORIGINATOR_ID
:
2050 ND_PRINT("invalid len");
2053 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2055 case BGPTYPE_CLUSTER_LIST
:
2057 ND_PRINT("invalid len");
2064 GET_IPADDR_STRING(tptr
),
2065 (tlen
>4) ? ", " : "");
2070 case BGPTYPE_MP_REACH_NLRI
:
2074 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2086 nhlen
= GET_U_1(tptr
);
2092 uint8_t tnhlen
= nhlen
;
2095 ND_PRINT("\n\t nexthop: ");
2096 while (tnhlen
!= 0) {
2100 switch(af
<<8 | safi
) {
2101 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
2102 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
2103 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
2104 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
2105 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
2106 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
):
2107 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
2108 if (tnhlen
< sizeof(nd_ipv4
)) {
2109 ND_PRINT("invalid len");
2114 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2115 tptr
+= sizeof(nd_ipv4
);
2116 tnhlen
-= sizeof(nd_ipv4
);
2117 tlen
-= sizeof(nd_ipv4
);
2120 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
2121 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
2122 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2123 if (tnhlen
< sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
) {
2124 ND_PRINT("invalid len");
2129 ND_PRINT("RD: %s, %s",
2130 bgp_vpn_rd_print(ndo
, tptr
),
2131 GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2132 tptr
+= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2133 tlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2134 tnhlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2137 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
2138 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
2139 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
2140 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
2141 if (tnhlen
< sizeof(nd_ipv6
)) {
2142 ND_PRINT("invalid len");
2147 ND_PRINT("%s", GET_IP6ADDR_STRING(tptr
));
2148 tptr
+= sizeof(nd_ipv6
);
2149 tlen
-= sizeof(nd_ipv6
);
2150 tnhlen
-= sizeof(nd_ipv6
);
2153 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
2154 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
2155 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2156 if (tnhlen
< sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
) {
2157 ND_PRINT("invalid len");
2162 ND_PRINT("RD: %s, %s",
2163 bgp_vpn_rd_print(ndo
, tptr
),
2164 GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2165 tptr
+= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2166 tlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2167 tnhlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2170 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2171 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2172 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2173 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2174 if (tnhlen
< sizeof(nd_ipv4
)) {
2175 ND_PRINT("invalid len");
2180 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
2181 tptr
+= (sizeof(nd_ipv4
));
2182 tlen
-= (sizeof(nd_ipv4
));
2183 tnhlen
-= (sizeof(nd_ipv4
));
2186 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2187 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2188 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2189 ND_PRINT("%s", GET_ISONSAP_STRING(tptr
, tnhlen
));
2195 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2196 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2197 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2198 if (tnhlen
< BGP_VPN_RD_LEN
+1) {
2199 ND_PRINT("invalid len");
2204 ND_TCHECK_LEN(tptr
, tnhlen
);
2205 ND_PRINT("RD: %s, %s",
2206 bgp_vpn_rd_print(ndo
, tptr
),
2207 GET_ISONSAP_STRING(tptr
+BGP_VPN_RD_LEN
,tnhlen
-BGP_VPN_RD_LEN
));
2208 /* rfc986 mapped IPv4 address ? */
2209 if (GET_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
2210 ND_PRINT(" = %s", GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
+4));
2211 /* rfc1888 mapped IPv6 address ? */
2212 else if (GET_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
2213 ND_PRINT(" = %s", GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
+3));
2221 * bgp_mp_af_print() should have saved us from
2222 * an unsupported AFI/SAFI.
2224 ND_PRINT("ERROR: no AFI %u/SAFI %u nexthop decoder", af
, safi
);
2232 ND_PRINT(", nh-length: %u", nhlen
);
2234 /* As per RFC 2858; this is reserved in RFC 4760 */
2237 snpa
= GET_U_1(tptr
);
2242 ND_PRINT("\n\t %u SNPA", snpa
);
2243 for (/*nothing*/; snpa
!= 0; snpa
--) {
2247 snpalen
= GET_U_1(tptr
);
2248 ND_PRINT("\n\t %u bytes", snpalen
);
2253 ND_TCHECK_LEN(tptr
, snpalen
);
2258 ND_PRINT(", no SNPA");
2261 add_path4
= check_add_path(ndo
, tptr
,
2262 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 32);
2263 add_path6
= check_add_path(ndo
, tptr
,
2264 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 128);
2266 while (tptr
< pptr
+ len
) {
2267 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
,
2268 add_path4
, add_path6
);
2277 case BGPTYPE_MP_UNREACH_NLRI
:
2278 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
2279 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2285 if (len
== BGP_MP_NLRI_MINSIZE
)
2286 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2290 add_path4
= check_add_path(ndo
, tptr
,
2291 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 32);
2292 add_path6
= check_add_path(ndo
, tptr
,
2293 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 128);
2295 while (tptr
< pptr
+ len
) {
2296 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
,
2297 add_path4
, add_path6
);
2305 case BGPTYPE_EXTD_COMMUNITIES
:
2307 ND_PRINT("invalid len");
2316 extd_comm
=GET_BE_U_2(tptr
);
2318 ND_PRINT("\n\t %s (0x%04x), Flags [%s]",
2319 tok2str(bgp_extd_comm_subtype_values
,
2320 "unknown extd community typecode",
2323 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
2329 bgp_extended_community_print(ndo
, tptr
);
2335 case BGPTYPE_PMSI_TUNNEL
:
2337 uint8_t tunnel_type
, flags
;
2342 flags
= GET_U_1(tptr
);
2343 tunnel_type
= GET_U_1(tptr
+ 1);
2345 ND_PRINT("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2346 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2348 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2349 GET_BE_U_3(tptr
+ 2)>>4);
2354 switch (tunnel_type
) {
2355 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2356 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2357 ND_PRINT("\n\t Sender %s, P-Group %s",
2358 GET_IPADDR_STRING(tptr
),
2359 GET_IPADDR_STRING(tptr
+4));
2362 case BGP_PMSI_TUNNEL_PIM_SSM
:
2363 ND_PRINT("\n\t Root-Node %s, P-Group %s",
2364 GET_IPADDR_STRING(tptr
),
2365 GET_IPADDR_STRING(tptr
+4));
2367 case BGP_PMSI_TUNNEL_INGRESS
:
2368 ND_PRINT("\n\t Tunnel-Endpoint %s",
2369 GET_IPADDR_STRING(tptr
));
2371 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2372 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2373 ND_PRINT("\n\t Root-Node %s, LSP-ID 0x%08x",
2374 GET_IPADDR_STRING(tptr
),
2375 GET_BE_U_4(tptr
+ 4));
2377 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2378 ND_PRINT("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2379 GET_IPADDR_STRING(tptr
),
2380 GET_BE_U_4(tptr
+ 4));
2383 if (ndo
->ndo_vflag
<= 1) {
2384 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2395 type
= GET_U_1(tptr
);
2396 length
= GET_BE_U_2(tptr
+ 1);
2400 ND_PRINT("\n\t %s TLV (%u), length %u",
2401 tok2str(bgp_aigp_values
, "Unknown", type
),
2409 * Check if we can read the TLV data.
2419 ND_PRINT(", metric %" PRIu64
,
2424 if (ndo
->ndo_vflag
<= 1) {
2425 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2434 case BGPTYPE_ATTR_SET
:
2438 ND_PRINT("\n\t Origin AS: %s",
2439 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)));
2444 u_int aflags
, alenlen
, alen
;
2448 ND_PRINT(" [path attr too short]");
2452 aflags
= GET_U_1(tptr
);
2453 atype
= GET_U_1(tptr
+ 1);
2456 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2457 ND_TCHECK_LEN(tptr
, alenlen
);
2458 if (len
< alenlen
) {
2459 ND_PRINT(" [path attr too short]");
2463 alen
= bgp_attr_len(aflags
, tptr
);
2467 ND_PRINT("\n\t %s (%u), length: %u",
2468 tok2str(bgp_attr_values
,
2469 "Unknown Attribute", atype
),
2474 ND_PRINT(", Flags [%s",
2475 bittok2str_nosep(bgp_flags
, "", aflags
));
2477 ND_PRINT("+%x", aflags
& 0xf);
2482 ND_PRINT(" [path attr too short]");
2487 * The protocol encoding per se allows ATTR_SET to be nested
2488 * as many times as the message can accommodate. This printer
2489 * used to be able to recurse into ATTR_SET contents until the
2490 * stack exhaustion, but now there is a limit on that (if live
2491 * protocol exchange goes that many levels deep, something is
2492 * probably wrong anyway). Feel free to refine this value if
2493 * you can find the spec with respective normative text.
2495 if (attr_set_level
== 10)
2496 ND_PRINT("(too many nested levels, not recursing)");
2497 else if (!bgp_attr_print(ndo
, atype
, tptr
, alen
, attr_set_level
+ 1))
2504 case BGPTYPE_LARGE_COMMUNITY
:
2505 if (len
== 0 || len
% 12) {
2506 ND_PRINT("invalid len");
2511 ND_PRINT("%u:%u:%u%s",
2513 GET_BE_U_4(tptr
+ 4),
2514 GET_BE_U_4(tptr
+ 8),
2515 (len
> 12) ? ", " : "");
2518 * len will always be a multiple of 12, as per the above,
2519 * so this will never underflow.
2524 case BGPTYPE_BGPSEC_PATH
:
2526 uint16_t sblen
, splen
;
2528 splen
= GET_BE_U_2(tptr
);
2531 * A secure path has a minimum length of 8 bytes:
2532 * 2 bytes length field
2533 * 6 bytes per secure path segment
2535 ND_ICHECKMSG_U("secure path length", splen
, <, 8);
2537 ND_PRINT("\n\t Secure Path Length: %u", splen
);
2541 /* Make sure the secure path length does not signal trailing bytes */
2543 ND_PRINT(" [total segments length %u != N x 6]", splen
);
2547 /* Parse secure path segments */
2548 while (splen
!= 0) {
2549 uint8_t pcount
= GET_U_1(tptr
);
2550 uint8_t flags
= GET_U_1(tptr
+ 1);
2551 uint32_t asn
= GET_BE_U_4(tptr
+ 2);
2552 ND_PRINT("\n\t Secure Path Segment: pCount: %u, Flags: [%s] (0x%02x), AS: %u",
2554 bittok2str(bgp_bgpsec_bitmap_str
, "none", flags
),
2561 sblen
= GET_BE_U_2(tptr
);
2563 ND_PRINT("\n\t Signature Block: Length: %u, Algo ID: %u",
2569 /* Parse signature segments */
2570 while (sblen
!= 0) {
2573 ND_PRINT("\n\t Signature Segment:\n\t SKI: ");
2574 ND_ICHECKMSG_U("remaining length", sblen
, <, 20);
2575 hex_print(ndo
, "\n\t ", tptr
, 20);
2578 ND_ICHECKMSG_U("remaining length", sblen
, <, 2);
2579 siglen
= GET_BE_U_2(tptr
);
2583 ND_PRINT("\n\t Length: %u", siglen
);
2584 ND_ICHECKMSG_U("remaining length", sblen
, <, siglen
);
2585 ND_PRINT("\n\t Signature:");
2586 hex_print(ndo
, "\n\t ", tptr
, siglen
);
2595 ND_PRINT("invalid len");
2598 ND_PRINT("\n\t OTC %u", GET_BE_U_4(pptr
));
2602 ND_TCHECK_LEN(pptr
, len
);
2603 ND_PRINT("\n\t no Attribute %u decoder", atype
); /* we have no decoder for the attribute */
2604 if (ndo
->ndo_vflag
<= 1)
2605 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2609 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2610 ND_TCHECK_LEN(pptr
, len
);
2611 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2616 nd_print_invalid(ndo
);
2624 bgp_capabilities_print(netdissect_options
*ndo
,
2625 const u_char
*opt
, u_int caps_len
)
2627 /* allocate space for the largest possible string */
2628 char astostr
[AS_STR_SIZE
];
2629 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2632 while (i
< caps_len
) {
2633 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2634 cap_type
=GET_U_1(opt
+ i
);
2635 cap_len
=GET_U_1(opt
+ i
+ 1);
2636 ND_PRINT("\n\t %s (%u), length: %u",
2637 tok2str(bgp_capcode_values
, "Unknown", cap_type
),
2640 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2642 case BGP_CAPCODE_MP
:
2643 /* AFI (16 bits), Reserved (8 bits), SAFI (8 bits) */
2645 ND_PRINT(" (too short, < 4)");
2648 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u)",
2649 tok2str(af_values
, "Unknown", GET_BE_U_2(opt
+ i
+ 2)),
2650 GET_BE_U_2(opt
+ i
+ 2),
2651 tok2str(bgp_safi_values
, "Unknown", GET_U_1(opt
+ i
+ 5)),
2652 GET_U_1(opt
+ i
+ 5));
2654 case BGP_CAPCODE_BGPSEC
:
2655 /* Version (4 bits), Direction (1 bit), Flags (3 bits), AFI (16 bits) */
2657 /* The capability length [...] MUST be set to 3. */
2659 ND_PRINT(" [%u != 3]", cap_len
);
2663 ND_PRINT("\n\t\tVersion %u, Direction %s (%u), AFI %s (%u)",
2664 GET_U_1(opt
+ i
+ 2)&0xf0,
2665 (GET_U_1(opt
+ i
+ 2)&0x08) ? "Send" : "Receive",
2666 (GET_U_1(opt
+ i
+ 2)&0x08)>>3,
2667 bittok2str(af_values
, "Unknown",
2668 GET_BE_U_2(opt
+ i
+ cap_offset
+ 2)),
2669 GET_BE_U_2(opt
+ i
+ cap_offset
+ 2));
2671 case BGP_CAPCODE_ML
:
2674 while (tcap_len
>= 4) {
2675 ND_PRINT( "\n\t\tAFI %s (%u), SAFI %s (%u), Count: %u",
2676 tok2str(af_values
, "Unknown",
2677 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2678 GET_BE_U_2(opt
+ i
+ cap_offset
),
2679 tok2str(bgp_safi_values
, "Unknown",
2680 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2681 GET_U_1(opt
+ i
+ cap_offset
+ 2),
2682 GET_U_1(opt
+ i
+ cap_offset
+ 3));
2687 case BGP_CAPCODE_RESTART
:
2688 /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */
2690 ND_PRINT(" (too short, < 2)");
2694 ND_PRINT("\n\t\tRestart Flags: [%s], Restart Time %us",
2695 bittok2str(bgp_graceful_restart_comm_flag_values
,
2696 "none", GET_U_1(opt
+ i
+ 2) >> 4),
2697 GET_BE_U_2(opt
+ i
+ 2)&0xfff);
2700 while(tcap_len
>=4) {
2701 ND_PRINT("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2702 tok2str(af_values
,"Unknown",
2703 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2704 GET_BE_U_2(opt
+ i
+ cap_offset
),
2705 tok2str(bgp_safi_values
,"Unknown",
2706 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2707 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2708 ((GET_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" );
2713 case BGP_CAPCODE_ROLE
:
2715 ND_PRINT(" (too short, < 1)");
2718 ND_PRINT("\n\t\tRole name %s (%u)",
2719 tok2str(bgp_role_values
, "Unassigned",
2720 GET_U_1(opt
+ i
+ 2)), GET_U_1(opt
+ i
+ 2));
2722 case BGP_CAPCODE_RR
:
2723 case BGP_CAPCODE_LLGR
:
2724 case BGP_CAPCODE_RR_CISCO
:
2725 case BGP_CAPCODE_EXT_MSG
:
2726 case BGP_CAPCODE_ENH_RR
:
2728 case BGP_CAPCODE_AS_NEW
:
2730 * Extract the 4 byte AS number encoded.
2733 ND_PRINT(" (too short, < 4)");
2736 ND_PRINT("\n\t\t 4 Byte AS %s",
2737 as_printf(ndo
, astostr
, sizeof(astostr
),
2738 GET_BE_U_4(opt
+ i
+ 2)));
2740 case BGP_CAPCODE_ADD_PATH
:
2742 ND_PRINT(" (bogus)"); /* length */
2747 while (tcap_len
!= 0) {
2749 nd_print_invalid(ndo
);
2752 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2753 tok2str(af_values
,"Unknown",GET_BE_U_2(opt
+ i
+ cap_offset
)),
2754 GET_BE_U_2(opt
+ i
+ cap_offset
),
2755 tok2str(bgp_safi_values
,"Unknown",GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2756 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2757 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",GET_U_1(opt
+ i
+ cap_offset
+ 3))
2764 ND_PRINT("\n\t\tno decoder for Capability %u",
2766 if (ndo
->ndo_vflag
<= 1)
2767 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2771 if (ndo
->ndo_vflag
> 1 && cap_len
!= 0) {
2772 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2774 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2779 nd_print_trunc(ndo
);
2783 bgp_open_print(netdissect_options
*ndo
,
2784 const u_char
*dat
, u_int length
)
2786 /* allocate space for the largest possible string */
2787 char astostr
[AS_STR_SIZE
];
2788 const struct bgp_open
*bgp_open_header
;
2791 const struct bgp_opt
*bgpopt
;
2794 uint8_t extended_opt_params
= 0;
2795 u_int open_size
= BGP_OPEN_SIZE
;
2796 u_int opt_size
= BGP_OPT_SIZE
;
2798 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2799 if (length
< BGP_OPEN_SIZE
)
2802 bgp_open_header
= (const struct bgp_open
*)dat
;
2804 ND_PRINT("\n\t Version %u, ",
2805 GET_U_1(bgp_open_header
->bgpo_version
));
2806 ND_PRINT("my AS %s, ",
2807 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(bgp_open_header
->bgpo_myas
)));
2808 ND_PRINT("Holdtime %us, ",
2809 GET_BE_U_2(bgp_open_header
->bgpo_holdtime
));
2810 ND_PRINT("ID %s", GET_IPADDR_STRING(bgp_open_header
->bgpo_id
));
2811 optslen
= GET_U_1(bgp_open_header
->bgpo_optlen
);
2812 opsttype
= GET_U_1(bgp_open_header
->bgpo_opttype
);
2813 if (opsttype
== BGP_OPEN_NON_EXT_OPT_TYPE_EXTENDED_LENGTH
) {
2814 optslen
= GET_BE_U_2(bgp_open_header
->bgpo_optlen_extended
);
2815 extended_opt_params
= 1;
2819 ND_PRINT("\n\t Optional parameters%s, length: %u",
2820 extended_opt_params
? " (Extended)" : "", optslen
);
2822 opt
= dat
+ open_size
;
2823 length
-= open_size
;
2826 while (i
< optslen
) {
2830 ND_TCHECK_LEN(opt
+ i
, opt_size
);
2831 if (length
< opt_size
+ i
)
2833 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2834 opt_type
= GET_U_1(bgpopt
->bgpopt_type
);
2835 opt_len
= extended_opt_params
? GET_BE_U_2(bgpopt
->bgpopt_len
)
2836 : GET_U_1(bgpopt
->bgpopt_len
);
2837 if (opt_size
+ i
+ opt_len
> optslen
) {
2838 ND_PRINT("\n\t Option %u, length: %u, goes past the end of the options",
2843 ND_PRINT("\n\t Option %s (%u), length: %u",
2844 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2848 /* now let's decode the options we know*/
2852 bgp_capabilities_print(ndo
, opt
+ opt_size
+ i
,
2858 ND_PRINT("\n\t no decoder for option %u",
2862 i
+= opt_size
+ opt_len
;
2866 nd_print_trunc(ndo
);
2870 bgp_update_print(netdissect_options
*ndo
,
2871 const u_char
*dat
, u_int length
)
2874 u_int withdrawn_routes_len
;
2882 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2883 if (length
< BGP_SIZE
)
2888 /* Unfeasible routes */
2892 withdrawn_routes_len
= GET_BE_U_2(p
);
2895 if (withdrawn_routes_len
> 1) {
2897 * Without keeping state from the original NLRI message,
2898 * it's not possible to tell if this a v4 or v6 route,
2899 * so only try to decode it if we're not v6 enabled.
2901 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2902 if (length
< withdrawn_routes_len
)
2904 ND_PRINT("\n\t Withdrawn routes:");
2905 add_path
= check_add_path(ndo
, p
, withdrawn_routes_len
, 32);
2906 while (withdrawn_routes_len
!= 0) {
2908 if (withdrawn_routes_len
< 4) {
2909 p
+= withdrawn_routes_len
;
2910 length
-= withdrawn_routes_len
;
2913 path_id
= GET_BE_U_4(p
);
2916 withdrawn_routes_len
-= 4;
2918 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2920 ND_PRINT("\n\t (illegal prefix length)");
2922 } else if (wpfx
== -2)
2923 goto trunc
; /* bytes left, but not enough */
2925 ND_PRINT("\n\t %s", buf
);
2927 ND_PRINT(" Path Id: %u", path_id
);
2931 withdrawn_routes_len
-= wpfx
;
2935 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2936 if (length
< withdrawn_routes_len
)
2938 p
+= withdrawn_routes_len
;
2939 length
-= withdrawn_routes_len
;
2945 len
= GET_BE_U_2(p
);
2949 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2950 /* No withdrawn routes, no path attributes, no NLRI */
2951 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2956 /* Make sure the path attributes don't go past the end of the packet */
2959 /* do something more useful!*/
2961 uint8_t aflags
, atype
, alenlen
;
2968 ND_PRINT("\n\t [path attrs too short]");
2973 aflags
= GET_U_1(p
);
2974 atype
= GET_U_1(p
+ 1);
2978 alenlen
= bgp_attr_lenlen(aflags
, p
);
2979 ND_TCHECK_LEN(p
, alenlen
);
2980 if (length
< alenlen
)
2982 if (len
< alenlen
) {
2983 ND_PRINT("\n\t [path attrs too short]");
2988 alen
= bgp_attr_len(aflags
, p
);
2993 ND_PRINT("\n\t %s (%u), length: %u",
2994 tok2str(bgp_attr_values
, "Unknown Attribute", atype
),
2999 ND_PRINT(", Flags [%s",
3000 bittok2str_nosep(bgp_flags
, "", aflags
));
3002 ND_PRINT("+%x", aflags
& 0xf);
3006 ND_PRINT(" [path attrs too short]");
3013 if (!bgp_attr_print(ndo
, atype
, p
, alen
, 0))
3022 add_path
= check_add_path(ndo
, p
, length
, 32);
3023 ND_PRINT("\n\t Updated routes:");
3024 while (length
!= 0) {
3029 path_id
= GET_BE_U_4(p
);
3033 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
3035 ND_PRINT("\n\t (illegal prefix length)");
3038 goto trunc
; /* bytes left, but not enough */
3040 ND_PRINT("\n\t %s", buf
);
3042 ND_PRINT(" Path Id: %u", path_id
);
3051 nd_print_trunc(ndo
);
3055 bgp_notification_print_code(netdissect_options
*ndo
,
3056 const u_char
*dat
, u_int length
,
3057 uint8_t bgpn_major
, uint8_t bgpn_minor
)
3059 ND_PRINT(", %s (%u)",
3060 tok2str(bgp_notify_major_values
, "Unknown Error",
3064 switch (bgpn_major
) {
3066 case BGP_NOTIFY_MAJOR_MSG
:
3067 ND_PRINT(", subcode %s (%u)",
3068 tok2str(bgp_notify_minor_msg_values
, "Unknown",
3072 case BGP_NOTIFY_MAJOR_OPEN
:
3073 ND_PRINT(", subcode %s (%u)",
3074 tok2str(bgp_notify_minor_open_values
, "Unknown",
3078 case BGP_NOTIFY_MAJOR_UPDATE
:
3079 ND_PRINT(", subcode %s (%u)",
3080 tok2str(bgp_notify_minor_update_values
, "Unknown",
3084 case BGP_NOTIFY_MAJOR_FSM
:
3085 ND_PRINT(" subcode %s (%u)",
3086 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
3090 case BGP_NOTIFY_MAJOR_ROUTEREFRESH
:
3091 ND_PRINT(" subcode %s (%u)",
3092 tok2str(bgp_notify_minor_routerefresh_values
, "Unknown",
3096 case BGP_NOTIFY_MAJOR_CEASE
:
3097 ND_PRINT(", subcode %s (%u)",
3098 tok2str(bgp_notify_minor_cease_values
, "Unknown",
3102 /* RFC 4486 mentions optionally 7 bytes
3103 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
3105 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= 7) {
3106 ND_PRINT(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
3107 tok2str(af_values
, "Unknown", GET_BE_U_2(dat
)),
3109 tok2str(bgp_safi_values
, "Unknown", GET_U_1((dat
+ 2))),
3111 GET_BE_U_4(dat
+ 3));
3114 * RFC 9003 describes a method to send a communication
3115 * intended for human consumption regarding the Administrative Shutdown
3117 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
3118 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
3120 uint8_t shutdown_comm_length
= GET_U_1(dat
);
3121 uint8_t remainder_offset
= 0;
3122 /* garbage, hexdump it all */
3123 if (shutdown_comm_length
> length
- 1) {
3124 ND_PRINT(", invalid Shutdown Communication length");
3125 } else if (shutdown_comm_length
== 0) {
3126 ND_PRINT(", empty Shutdown Communication");
3127 remainder_offset
+= 1;
3129 /* a proper shutdown communication */
3131 ND_PRINT(", Shutdown Communication (length: %u): \"", shutdown_comm_length
);
3132 nd_printjn(ndo
, dat
+1, shutdown_comm_length
);
3134 remainder_offset
+= shutdown_comm_length
+ 1;
3136 /* if there is trailing data, hexdump it */
3137 if(length
- remainder_offset
> 0) {
3138 ND_PRINT(", Data: (length: %u)", length
- remainder_offset
);
3139 hex_print(ndo
, "\n\t\t", dat
+ remainder_offset
, length
- remainder_offset
);
3143 * RFC8538 describes the Hard Reset cease subcode, which contains another
3144 * notification code and subcode.
3146 if (bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_HARDRESET
&& length
>= 2) {
3147 bgpn_major
= GET_U_1(dat
++);
3148 bgpn_minor
= GET_U_1(dat
++);
3150 bgp_notification_print_code(ndo
, dat
, length
, bgpn_major
, bgpn_minor
);
3154 if (bgpn_minor
!= 0) {
3155 ND_PRINT(", subcode %u", bgpn_minor
);
3164 bgp_notification_print(netdissect_options
*ndo
,
3165 const u_char
*dat
, u_int length
)
3167 const struct bgp_notification
*bgp_notification_header
;
3168 uint8_t bgpn_major
, bgpn_minor
;
3170 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
3171 if (length
<BGP_NOTIFICATION_SIZE
)
3174 bgp_notification_header
= (const struct bgp_notification
*)dat
;
3175 bgpn_major
= GET_U_1(bgp_notification_header
->bgpn_major
);
3176 bgpn_minor
= GET_U_1(bgp_notification_header
->bgpn_minor
);
3177 bgp_notification_print_code(ndo
, dat
+ BGP_NOTIFICATION_SIZE
,
3178 length
- BGP_NOTIFICATION_SIZE
, bgpn_major
, bgpn_minor
);
3181 nd_print_trunc(ndo
);
3185 bgp_route_refresh_print(netdissect_options
*ndo
,
3186 const u_char
*pptr
, u_int len
)
3188 const struct bgp_route_refresh
*bgp_route_refresh_header
;
3190 /* some little sanity checking */
3191 if (len
<BGP_ROUTE_REFRESH_SIZE
)
3194 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
3196 ND_PRINT("\n\t AFI %s (%u), SAFI %s (%u), Subtype %s (%u)",
3197 tok2str(af_values
, "Unknown",
3198 GET_BE_U_2(bgp_route_refresh_header
->afi
)),
3199 GET_BE_U_2(bgp_route_refresh_header
->afi
),
3200 tok2str(bgp_safi_values
, "Unknown",
3201 GET_U_1(bgp_route_refresh_header
->safi
)),
3202 GET_U_1(bgp_route_refresh_header
->safi
),
3203 tok2str(bgp_route_refresh_subtype_values
, "Unknown",
3204 GET_U_1(bgp_route_refresh_header
->subtype
)),
3205 GET_U_1(bgp_route_refresh_header
->subtype
));
3208 if (len
>= BGP_ROUTE_REFRESH_SIZE_ORF
) {
3209 const struct bgp_route_refresh_orf
*orf_header
;
3212 (const struct bgp_route_refresh_orf
*)(pptr
+ BGP_ROUTE_REFRESH_SIZE
);
3214 ND_PRINT("\n\t ORF refresh %s (%u), ORF type %s (%u), ORF length %u",
3215 tok2str(bgp_orf_refresh_type
, "Unknown",
3216 GET_U_1(orf_header
->refresh
)),
3217 GET_U_1(orf_header
->refresh
),
3218 tok2str(bgp_orf_type
, "Unknown", GET_U_1(orf_header
->type
)),
3219 GET_U_1(orf_header
->type
), GET_BE_U_2(orf_header
->len
));
3222 if (ndo
->ndo_vflag
> 1) {
3223 ND_TCHECK_LEN(pptr
, len
);
3224 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
3229 nd_print_trunc(ndo
);
3233 bgp_pdu_print(netdissect_options
*ndo
,
3234 const u_char
*dat
, u_int length
)
3236 const struct bgp
*bgp_header
;
3239 ND_TCHECK_LEN(dat
, BGP_SIZE
);
3240 bgp_header
= (const struct bgp
*)dat
;
3241 bgp_type
= GET_U_1(bgp_header
->bgp_type
);
3243 ND_PRINT("\n\t%s Message (%u), length: %u",
3244 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
3250 bgp_open_print(ndo
, dat
, length
);
3253 bgp_update_print(ndo
, dat
, length
);
3255 case BGP_NOTIFICATION
:
3256 bgp_notification_print(ndo
, dat
, length
);
3260 case BGP_ROUTE_REFRESH
:
3261 bgp_route_refresh_print(ndo
, dat
, length
);
3264 /* we have no decoder for the BGP message */
3265 ND_TCHECK_LEN(dat
, length
);
3266 ND_PRINT("\n\t no Message %u decoder", bgp_type
);
3267 print_unknown_data(ndo
, dat
, "\n\t ", length
);
3272 nd_print_trunc(ndo
);
3277 bgp_print(netdissect_options
*ndo
,
3278 const u_char
*dat
, u_int length _U_
)
3281 const u_char
*ep
= ndo
->ndo_snapend
;
3282 const u_char
*start
;
3283 const u_char marker
[] = {
3284 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3285 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3287 const struct bgp
*bgp_header
;
3290 ndo
->ndo_protocol
= "bgp";
3293 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
3301 if (GET_U_1(p
) != 0xff) {
3306 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
3308 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
3313 /* found BGP header */
3314 ND_TCHECK_LEN(p
, BGP_SIZE
);
3315 bgp_header
= (const struct bgp
*)p
;
3318 nd_print_trunc(ndo
);
3320 hlen
= GET_BE_U_2(bgp_header
->bgp_len
);
3321 if (hlen
< BGP_SIZE
) {
3322 ND_PRINT("\nmessage length %u < %u", hlen
, BGP_SIZE
);
3323 nd_print_invalid(ndo
);
3327 if (ND_TTEST_LEN(p
, hlen
)) {
3328 if (!bgp_pdu_print(ndo
, p
, hlen
))
3333 ND_PRINT("\n[|BGP %s]",
3334 tok2str(bgp_msg_values
,
3335 "Unknown Message Type",
3336 GET_U_1(bgp_header
->bgp_type
)));
3344 nd_print_trunc(ndo
);