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
293 static const struct tok bgp_notify_major_values
[] = {
294 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
295 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
296 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
297 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
298 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
299 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
300 { BGP_NOTIFY_MAJOR_ROUTEREFRESH
, "ROUTE-REFRESH Message Error"},
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 decode_labeled_prefix4(netdissect_options
*ndo
,
699 const u_char
*pptr
, u_int itemlen
, char *buf
,
703 u_int plen
, plenbytes
;
705 /* prefix length and label = 4 bytes */
708 plen
= GET_U_1(pptr
); /* get prefix length */
710 /* this is one of the weirdnesses of rfc3107
711 the label length (actually the label + COS bits)
712 is added to the prefix length;
713 we also do only read out just one label -
714 there is no real application for advertisement of
715 stacked labels in a single BGP message
721 plen
-=24; /* adjust prefixlen - labellength */
727 memset(&addr
, 0, sizeof(addr
));
728 plenbytes
= (plen
+ 7) / 8;
729 ITEMCHECK(plenbytes
);
730 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
732 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
734 /* the label may get offsetted by 4 bits so lets shift it right */
735 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
736 ipaddr_string(ndo
, (const u_char
*)&addr
),
738 GET_BE_U_3(pptr
+ 1)>>4,
739 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
741 return 4 + plenbytes
;
753 * print an ipv4 or ipv6 address into a buffer dependent on address length.
756 bgp_vpn_ip_print(netdissect_options
*ndo
,
757 const u_char
*pptr
, u_int addr_length
)
760 /* worst case string is s fully formatted v6 address */
761 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
764 switch(addr_length
) {
765 case (sizeof(nd_ipv4
) << 3): /* 32 */
766 snprintf(pos
, sizeof(addr
), "%s", GET_IPADDR_STRING(pptr
));
768 case (sizeof(nd_ipv6
) << 3): /* 128 */
769 snprintf(pos
, sizeof(addr
), "%s", GET_IP6ADDR_STRING(pptr
));
772 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
784 * print an multicast s,g entry into a buffer.
785 * the s,g entry is encoded like this.
787 * +-----------------------------------+
788 * | Multicast Source Length (1 octet) |
789 * +-----------------------------------+
790 * | Multicast Source (Variable) |
791 * +-----------------------------------+
792 * | Multicast Group Length (1 octet) |
793 * +-----------------------------------+
794 * | Multicast Group (Variable) |
795 * +-----------------------------------+
797 * return the number of bytes read from the wire.
800 bgp_vpn_sg_print(netdissect_options
*ndo
,
801 const u_char
*pptr
, char *buf
, size_t buflen
)
804 u_int total_length
, offset
;
808 /* Source address length, encoded in bits */
809 addr_length
= GET_U_1(pptr
);
813 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
814 total_length
+= (addr_length
>> 3) + 1;
815 offset
= (u_int
)strlen(buf
);
817 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
818 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
819 pptr
+= (addr_length
>> 3);
822 /* Group address length, encoded in bits */
823 addr_length
= GET_U_1(pptr
);
827 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
828 total_length
+= (addr_length
>> 3) + 1;
829 offset
= (u_int
)strlen(buf
);
831 snprintf(buf
+ offset
, buflen
- offset
, ", 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
,
845 /* allocate space for the largest possible string */
846 static char rd
[sizeof("xxxxx.xxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
848 /* allocate space for the largest possible string */
849 char astostr
[AS_STR_SIZE
];
851 /* ok lets load the RD format */
852 switch (GET_BE_U_2(pptr
)) {
855 /* 2-byte-AS:number fmt */
856 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
857 GET_BE_U_2(pptr
+ 2),
858 GET_BE_U_4(pptr
+ 4),
859 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
860 GET_U_1(pptr
+ 6), GET_U_1(pptr
+ 7));
864 /* IP-address:AS fmt */
865 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
866 GET_U_1(pptr
+ 2), GET_U_1(pptr
+ 3),
867 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
868 GET_BE_U_2(pptr
+ 6));
872 /* 4-byte-AS:number fmt */
873 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
874 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 2)),
875 GET_BE_U_2(pptr
+ 6), GET_U_1(pptr
+ 2),
876 GET_U_1(pptr
+ 3), GET_U_1(pptr
+ 4),
877 GET_U_1(pptr
+ 5), GET_BE_U_2(pptr
+ 6));
880 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
889 * Print an RFC 4360 Extended Community.
892 bgp_extended_community_print(netdissect_options
*ndo
,
895 union { /* copy buffer for bandwidth values */
899 /* allocate space for the largest possible string */
900 char astostr
[AS_STR_SIZE
];
902 switch (GET_BE_U_2(pptr
)) {
904 case BGP_EXT_COM_RT_0
:
905 case BGP_EXT_COM_RO_0
:
906 case BGP_EXT_COM_L2VPN_RT_0
:
907 ND_PRINT("%u:%u (= %s)",
908 GET_BE_U_2(pptr
+ 2),
909 GET_BE_U_4(pptr
+ 4),
910 GET_IPADDR_STRING(pptr
+4));
913 case BGP_EXT_COM_RT_1
:
914 case BGP_EXT_COM_RO_1
:
915 case BGP_EXT_COM_L2VPN_RT_1
:
916 case BGP_EXT_COM_VRF_RT_IMP
:
918 GET_IPADDR_STRING(pptr
+2),
919 GET_BE_U_2(pptr
+ 6));
922 case BGP_EXT_COM_RT_2
:
923 case BGP_EXT_COM_RO_2
:
925 as_printf(ndo
, astostr
, sizeof(astostr
),
926 GET_BE_U_4(pptr
+ 2)), GET_BE_U_2(pptr
+ 6));
929 case BGP_EXT_COM_LINKBAND
:
930 bw
.i
= GET_BE_U_4(pptr
+ 4);
931 ND_PRINT("bandwidth: %.3f Mbps",
935 case BGP_EXT_COM_OVS
:
936 /* The Reserved field MUST be set to 0 and ignored upon the
937 * receipt of this community.
940 uint64_t reserved
= GET_BE_U_5(pptr
+ 2);
943 ND_PRINT("[the reserved field 0x%" PRIx64
" MUST be 0] ",
946 tok2str(bgp_prefix_origin_validation_state
,
947 "unknown origin validation state",
952 case BGP_EXT_COM_VPN_ORIGIN
:
953 case BGP_EXT_COM_VPN_ORIGIN2
:
954 case BGP_EXT_COM_VPN_ORIGIN3
:
955 case BGP_EXT_COM_VPN_ORIGIN4
:
956 case BGP_EXT_COM_OSPF_RID
:
957 case BGP_EXT_COM_OSPF_RID2
:
958 ND_PRINT("%s", GET_IPADDR_STRING(pptr
+2));
961 case BGP_EXT_COM_OSPF_RTYPE
:
962 case BGP_EXT_COM_OSPF_RTYPE2
:
963 ND_PRINT("area:%s, router-type:%s, metric-type:%s%s",
964 GET_IPADDR_STRING(pptr
+2),
965 tok2str(bgp_extd_comm_ospf_rtype_values
,
967 GET_U_1((pptr
+ 6))),
968 (GET_U_1(pptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
969 ((GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
972 case BGP_EXT_COM_L2INFO
:
973 ND_PRINT("%s Control Flags [0x%02x]:MTU %u",
974 tok2str(l2vpn_encaps_values
,
976 GET_U_1((pptr
+ 2))),
978 GET_BE_U_2(pptr
+ 4));
981 case BGP_EXT_COM_SOURCE_AS
:
982 ND_PRINT("AS %u", GET_BE_U_2(pptr
+ 2));
985 case BGP_EXT_COM_ENCAP
:
986 ND_PRINT("Tunnel type: %s", tok2str(bgp_extd_comm_encap_tunnel_values
,
988 GET_BE_U_2(pptr
+ 6)));
992 ND_PRINT("%02x%02x%02x%02x%02x%02x",
1004 * RFC4684 (Section 4)/RFC2858 (Section 4).
1005 * RTC membership prefix is structured as follows
1006 * [prefix-len] [origin-as] [route-target]
1007 * The route-target is encoded as RT ext-comms.
1008 * Prefix-len may be 0, 32..96
1010 * Note that pptr is not packet data - it is
1011 * a buffer owned by our caller - therefore GET_*
1012 * macros can not be used.
1015 bgp_rt_prefix_print(netdissect_options
*ndo
,
1019 /* allocate space for the largest possible string */
1020 char rtc_prefix_in_hex
[sizeof("0000 0000 0000 0000")] = "";
1021 u_int rtc_prefix_in_hex_len
= 0;
1022 static char output
[61]; /* max response string */
1023 /* allocate space for the largest possible string */
1024 char astostr
[AS_STR_SIZE
];
1025 uint16_t ec_type
= 0;
1030 snprintf(output
, sizeof(output
), "route-target: 0:0/0");
1034 /* hex representation of the prefix */
1035 octet_count
= (plen
+7)/8;
1036 for (i
=0; i
<octet_count
; i
++) {
1037 rtc_prefix_in_hex_len
+= snprintf(rtc_prefix_in_hex
+rtc_prefix_in_hex_len
,
1038 sizeof(rtc_prefix_in_hex
)-rtc_prefix_in_hex_len
,
1039 "%02x%s", *(pptr
+i
),
1040 ((i
%2 == 1) && (i
<octet_count
-1)) ? " " : "");
1045 * The prefix is too short to include the full ext-comm type,
1046 * so we have no way to parse it further.
1048 snprintf(output
, sizeof(output
), "route-target: partial-type: (%s/%d)",
1049 rtc_prefix_in_hex
, plen
);
1054 * get the ext-comm type
1055 * Note: pptr references a static 8 octet buffer with unused bits set to 0,
1056 * hence EXTRACT_*() macros are safe.
1058 ec_type
= EXTRACT_BE_U_2(pptr
);
1060 case BGP_EXT_COM_RT_0
:
1061 /* 2-byte-AS:number fmt */
1062 snprintf(output
, sizeof(output
), "route-target: %u:%u/%d (%s)",
1063 EXTRACT_BE_U_2(pptr
+2),
1064 EXTRACT_BE_U_4(pptr
+4),
1065 plen
, rtc_prefix_in_hex
);
1068 case BGP_EXT_COM_RT_1
:
1069 /* IP-address:AS fmt */
1070 snprintf(output
, sizeof(output
), "route-target: %u.%u.%u.%u:%u/%d (%s)",
1071 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5),
1072 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
1075 case BGP_EXT_COM_RT_2
:
1076 /* 4-byte-AS:number fmt */
1077 snprintf(output
, sizeof(output
), "route-target: %s:%u/%d (%s)",
1078 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(pptr
+2)),
1079 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
1083 snprintf(output
, sizeof(output
), "route target: unknown-type(%04x) (%s/%d)",
1085 rtc_prefix_in_hex
, plen
);
1093 decode_rt_routing_info(netdissect_options
*ndo
,
1096 uint8_t route_target
[8];
1098 /* allocate space for the largest possible string */
1099 char astostr
[AS_STR_SIZE
];
1102 /* NLRI "prefix length" from RFC 2858 Section 4. */
1103 plen
= GET_U_1(pptr
); /* get prefix length */
1105 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
1106 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
1107 * target" fields inside the "prefix" depending on its length.
1110 /* Without "origin AS", without "route target". */
1111 ND_PRINT("\n\t default route target");
1116 ND_PRINT("\n\t (illegal prefix length)");
1120 /* With at least "origin AS", possibly with "route target". */
1121 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 1));
1123 plen
-= 32; /* adjust prefix length */
1126 ND_PRINT("\n\t (illegal prefix length)");
1130 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
1131 * and gives the number of octets in the variable-length "route
1132 * target" field inside this NLRI "prefix". Look for it.
1134 memset(&route_target
, 0, sizeof(route_target
));
1135 num_octets
= (plen
+ 7) / 8;
1136 GET_CPY_BYTES(&route_target
, pptr
+ 5, num_octets
);
1137 /* If mask-len is not on octet boundary, ensure all extra bits are 0 */
1139 ((u_char
*)&route_target
)[num_octets
- 1] &=
1140 ((0xff00 >> (plen
% 8)) & 0xff);
1142 ND_PRINT("\n\t origin AS: %s, %s",
1144 bgp_rt_prefix_print(ndo
, (u_char
*)&route_target
, plen
));
1146 return 5 + num_octets
;
1150 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
1151 const u_char
*pptr
, char *buf
, size_t buflen
)
1156 plen
= GET_U_1(pptr
); /* get prefix length */
1161 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1166 memset(&addr
, 0, sizeof(addr
));
1167 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1169 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
1170 ((0xff00 >> (plen
% 8)) & 0xff);
1172 /* the label may get offsetted by 4 bits so lets shift it right */
1173 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1174 bgp_vpn_rd_print(ndo
, pptr
+4),
1175 ipaddr_string(ndo
, (const u_char
*)&addr
),
1177 GET_BE_U_3(pptr
+ 1)>>4,
1178 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1180 return 12 + (plen
+ 7) / 8;
1184 * +-------------------------------+
1186 * | RD:IPv4-address (12 octets) |
1188 * +-------------------------------+
1189 * | MDT Group-address (4 octets) |
1190 * +-------------------------------+
1193 #define MDT_VPN_NLRI_LEN 16
1196 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
1197 const u_char
*pptr
, char *buf
, size_t buflen
)
1200 const u_char
*vpn_ip
;
1202 /* if the NLRI is not predefined length, quit.*/
1203 if (GET_U_1(pptr
) != MDT_VPN_NLRI_LEN
* 8)
1214 pptr
+= sizeof(nd_ipv4
);
1216 /* MDT Group Address */
1217 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
1218 bgp_vpn_rd_print(ndo
, rd
), GET_IPADDR_STRING(vpn_ip
), GET_IPADDR_STRING(pptr
));
1220 return MDT_VPN_NLRI_LEN
+ 1;
1226 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
1227 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
1228 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
1229 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
1230 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
1231 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
1232 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
1234 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
1235 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
1236 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
1237 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
1238 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
1239 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
1240 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
1241 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
1246 decode_multicast_vpn(netdissect_options
*ndo
,
1247 const u_char
*pptr
, char *buf
, size_t buflen
)
1249 /* allocate space for the largest possible string */
1250 char astostr
[AS_STR_SIZE
];
1251 uint8_t route_type
, route_length
;
1252 u_int addr_length
, sg_length
;
1255 route_type
= GET_U_1(pptr
);
1257 route_length
= GET_U_1(pptr
);
1260 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
1261 tok2str(bgp_multicast_vpn_route_type_values
,
1262 "Unknown", route_type
),
1263 route_type
, route_length
);
1265 switch(route_type
) {
1266 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
1267 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1268 if (route_length
< BGP_VPN_RD_LEN
)
1270 offset
= (u_int
)strlen(buf
);
1271 snprintf(buf
+ offset
, buflen
- offset
, ", 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 offset
= (u_int
)strlen(buf
);
1279 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1280 bgp_vpn_rd_print(ndo
, pptr
),
1281 as_printf(ndo
, astostr
, sizeof(astostr
),
1282 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1285 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
1286 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1287 offset
= (u_int
)strlen(buf
);
1288 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1289 bgp_vpn_rd_print(ndo
, pptr
));
1290 pptr
+= BGP_VPN_RD_LEN
;
1292 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1293 addr_length
= route_length
- sg_length
;
1295 ND_TCHECK_LEN(pptr
, addr_length
);
1296 offset
= (u_int
)strlen(buf
);
1297 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
1298 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
1301 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
1302 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1303 offset
= (u_int
)strlen(buf
);
1304 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1305 bgp_vpn_rd_print(ndo
, pptr
));
1306 pptr
+= BGP_VPN_RD_LEN
;
1308 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1311 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
1312 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
1313 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1314 offset
= (u_int
)strlen(buf
);
1315 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1316 bgp_vpn_rd_print(ndo
, pptr
),
1317 as_printf(ndo
, astostr
, sizeof(astostr
),
1318 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1319 pptr
+= BGP_VPN_RD_LEN
+ 4;
1321 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1325 * no per route-type printing yet.
1327 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1332 return route_length
+ 2;
1339 * As I remember, some versions of systems have an snprintf() that
1340 * returns -1 if the buffer would have overflowed. If the return
1341 * value is negative, set buflen to 0, to indicate that we've filled
1344 * If the return value is greater than buflen, that means that
1345 * the buffer would have overflowed; again, set buflen to 0 in
1348 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1351 else if ((u_int)stringlen>buflen) \
1354 buflen-=stringlen; \
1359 decode_labeled_vpn_l2(netdissect_options
*ndo
,
1360 const u_char
*pptr
, char *buf
, size_t buflen
)
1362 u_int plen
, tlen
, tlv_type
, tlv_len
, ttlv_len
;
1365 plen
= GET_BE_U_2(pptr
);
1368 /* Old and new L2VPN NLRI share AFI/SAFI
1369 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1370 * and > 17 as old format. Complain for the middle case
1373 /* assume AD-only with RD, BGPNH */
1374 ND_TCHECK_LEN(pptr
, 12);
1376 stringlen
= snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
1377 bgp_vpn_rd_print(ndo
, pptr
),
1378 GET_IPADDR_STRING(pptr
+8));
1379 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1383 } else if (plen
> 17) {
1384 /* assume old format */
1385 /* RD, ID, LBLKOFF, LBLBASE */
1387 ND_TCHECK_LEN(pptr
, 15);
1389 stringlen
= snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1390 bgp_vpn_rd_print(ndo
, pptr
),
1391 GET_BE_U_2(pptr
+ 8),
1392 GET_BE_U_2(pptr
+ 10),
1393 GET_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1394 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1398 /* ok now the variable part - lets read out TLVs*/
1402 stringlen
=snprintf(buf
,buflen
, "\n\t\tran past the end");
1403 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1407 tlv_type
= GET_U_1(pptr
);
1409 tlv_len
= GET_BE_U_2(pptr
); /* length, in *bits* */
1410 ttlv_len
= (tlv_len
+ 7)/8; /* length, in *bytes* */
1416 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1419 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1421 while (ttlv_len
!= 0) {
1424 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1425 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1431 stringlen
=snprintf(buf
,buflen
, "%02x",
1434 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1442 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1445 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1447 if (tlen
< ttlv_len
) {
1449 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1450 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1460 /* complain bitterly ? */
1470 decode_prefix6(netdissect_options
*ndo
,
1471 const u_char
*pd
, u_int itemlen
, char *buf
, size_t buflen
)
1474 u_int plen
, plenbytes
;
1482 memset(&addr
, 0, sizeof(addr
));
1483 plenbytes
= (plen
+ 7) / 8;
1484 ITEMCHECK(plenbytes
);
1485 GET_CPY_BYTES(&addr
, pd
+ 1, plenbytes
);
1487 addr
[plenbytes
- 1] &=
1488 ((0xff00 >> (plen
% 8)) & 0xff);
1490 snprintf(buf
, buflen
, "%s/%u", ip6addr_string(ndo
, (const u_char
*)&addr
), plen
);
1491 return 1 + plenbytes
;
1498 decode_labeled_prefix6(netdissect_options
*ndo
,
1499 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
1502 u_int plen
, plenbytes
;
1504 /* prefix length and label = 4 bytes */
1507 plen
= GET_U_1(pptr
); /* get prefix length */
1512 plen
-= 24; /* adjust prefixlen - labellength */
1518 memset(&addr
, 0, sizeof(addr
));
1519 plenbytes
= (plen
+ 7) / 8;
1520 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
1522 addr
[plenbytes
- 1] &=
1523 ((0xff00 >> (plen
% 8)) & 0xff);
1525 /* the label may get offsetted by 4 bits so lets shift it right */
1526 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
1527 ip6addr_string(ndo
, (const u_char
*)&addr
),
1529 GET_BE_U_3(pptr
+ 1)>>4,
1530 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1532 return 4 + plenbytes
;
1542 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1543 const u_char
*pptr
, char *buf
, size_t buflen
)
1548 plen
= GET_U_1(pptr
); /* get prefix length */
1553 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1558 memset(&addr
, 0, sizeof(addr
));
1559 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1561 addr
[(plen
+ 7) / 8 - 1] &=
1562 ((0xff00 >> (plen
% 8)) & 0xff);
1564 /* the label may get offsetted by 4 bits so lets shift it right */
1565 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1566 bgp_vpn_rd_print(ndo
, pptr
+4),
1567 ip6addr_string(ndo
, (const u_char
*)&addr
),
1569 GET_BE_U_3(pptr
+ 1)>>4,
1570 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1572 return 12 + (plen
+ 7) / 8;
1576 decode_clnp_prefix(netdissect_options
*ndo
,
1577 const u_char
*pptr
, char *buf
, size_t buflen
)
1582 plen
= GET_U_1(pptr
); /* get prefix length */
1587 memset(&addr
, 0, sizeof(addr
));
1588 GET_CPY_BYTES(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1590 addr
[(plen
+ 7) / 8 - 1] &=
1591 ((0xff00 >> (plen
% 8)) & 0xff);
1593 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1594 snprintf(buf
, buflen
, "%s/%u",
1595 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1598 return 1 + (plen
+ 7) / 8;
1602 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1603 const u_char
*pptr
, char *buf
, size_t buflen
)
1608 plen
= GET_U_1(pptr
); /* get prefix length */
1613 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1618 memset(&addr
, 0, sizeof(addr
));
1619 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1621 addr
[(plen
+ 7) / 8 - 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
1623 /* the label may get offsetted by 4 bits so lets shift it right */
1624 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1625 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1626 bgp_vpn_rd_print(ndo
, pptr
+4),
1627 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1629 GET_BE_U_3(pptr
+ 1)>>4,
1630 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1632 return 12 + (plen
+ 7) / 8;
1636 * bgp_attr_get_as_size
1638 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1639 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1640 * support, exchange AS-Path with the same path-attribute type value 0x02.
1643 bgp_attr_get_as_size(netdissect_options
*ndo
,
1644 uint8_t bgpa_type
, const u_char
*pptr
, u_int len
)
1646 const u_char
*tptr
= pptr
;
1649 * If the path attribute is the optional AS4 path type, then we already
1650 * know, that ASs must be encoded in 4 byte format.
1652 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1657 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1658 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1661 while (tptr
< pptr
+ len
) {
1663 * If we do not find a valid segment type, our guess might be wrong.
1665 if (GET_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| GET_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1668 tptr
+= 2 + GET_U_1(tptr
+ 1) * 2;
1672 * If we correctly reached end of the AS path attribute data content,
1673 * then most likely ASs were indeed encoded as 2 bytes.
1675 if (tptr
== pptr
+ len
) {
1682 * We can come here, either we did not have enough data, or if we
1683 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1684 * so that caller can try to decode each AS as of 4 bytes. If indeed
1685 * there was not enough data, it will crib and end the parse anyways.
1691 * The only way to know that a BGP UPDATE message is using add path is
1692 * by checking if the capability is in the OPEN message which we may have missed.
1693 * So this function checks if it is possible that the update could contain add path
1694 * and if so it checks that standard BGP doesn't make sense.
1697 check_add_path(netdissect_options
*ndo
, const u_char
*pptr
, u_int length
,
1698 u_int max_prefix_length
)
1700 u_int offset
, prefix_length
;
1707 * Scan through the NLRI information under the assumption that
1708 * it doesn't have path IDs.
1710 for (offset
= 0; offset
< length
;) {
1712 if (!ND_TTEST_1(pptr
+ offset
)) {
1713 /* We ran out of captured data; quit scanning. */
1716 prefix_length
= GET_U_1(pptr
+ offset
);
1718 * Add 4 to cover the path id
1719 * and check the prefix length isn't greater than 32/128.
1721 if (prefix_length
> max_prefix_length
) {
1724 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1725 offset
+= 1 + ((prefix_length
+ 7) / 8);
1727 /* check we haven't gone past the end of the section */
1728 if (offset
> length
) {
1732 /* check it's not standard BGP */
1733 for (offset
= 0; offset
< length
; ) {
1734 if (!ND_TTEST_1(pptr
+ offset
)) {
1735 /* We ran out of captured data; quit scanning. */
1738 prefix_length
= GET_U_1(pptr
+ offset
);
1740 * If the prefix_length is zero (0.0.0.0/0)
1741 * and since it's not the only address (length >= 5)
1742 * then it is add-path
1744 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1747 offset
+= 1 + ((prefix_length
+ 7) / 8);
1749 if (offset
> length
) {
1753 /* assume not add-path by default */
1758 bgp_mp_af_print(netdissect_options
*ndo
,
1759 const u_char
*tptr
, u_int tlen
,
1760 uint16_t *afp
, uint8_t *safip
)
1765 af
= GET_BE_U_2(tptr
);
1767 safi
= GET_U_1(tptr
+ 2);
1770 ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1771 tok2str(af_values
, "Unknown AFI", af
),
1773 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1774 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1777 switch(af
<<8 | safi
) {
1778 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
1779 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
1780 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
1781 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
1782 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
1783 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
1784 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
1785 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1786 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
):
1787 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
1788 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
1789 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
1790 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
1791 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
1792 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
1793 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
1794 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1795 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1796 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1797 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1798 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1799 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1800 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1801 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1802 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1803 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1804 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1807 ND_TCHECK_LEN(tptr
, tlen
);
1808 ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af
, safi
);
1809 if (ndo
->ndo_vflag
<= 1)
1810 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1819 bgp_nlri_print(netdissect_options
*ndo
, uint16_t af
, uint8_t safi
,
1820 const u_char
*tptr
, u_int len
,
1821 char *buf
, size_t buflen
,
1822 int add_path4
, int add_path6
)
1827 switch (af
<<8 | safi
) {
1828 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
1829 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
1830 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
1832 path_id
= GET_BE_U_4(tptr
);
1835 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1837 ND_PRINT("\n\t (illegal prefix length)");
1838 else if (advance
== -2)
1839 break; /* bytes left, but not enough */
1841 ND_PRINT("\n\t %s", buf
);
1843 ND_PRINT(" Path Id: %u", path_id
);
1847 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
1848 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1850 ND_PRINT("\n\t (illegal prefix length)");
1851 else if (advance
== -2)
1853 else if (advance
== -3)
1854 break; /* bytes left, but not enough */
1856 ND_PRINT("\n\t %s", buf
);
1858 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
1859 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
1860 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1861 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, buflen
);
1863 ND_PRINT("\n\t (illegal prefix length)");
1865 ND_PRINT("\n\t %s", buf
);
1867 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
1868 advance
= decode_rt_routing_info(ndo
, tptr
);
1870 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1871 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST_VPN
):
1872 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, buflen
);
1874 ND_PRINT("\n\t (illegal prefix length)");
1875 else if (advance
== -2)
1878 ND_PRINT("\n\t %s", buf
);
1881 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
1882 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, buflen
);
1884 ND_PRINT("\n\t (illegal prefix length)");
1885 else if (advance
== -2)
1888 ND_PRINT("\n\t %s", buf
);
1890 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
1891 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
1892 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
1894 path_id
= GET_BE_U_4(tptr
);
1897 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1899 ND_PRINT("\n\t (illegal prefix length)");
1900 else if (advance
== -2)
1901 break; /* bytes left, but not enough */
1903 ND_PRINT("\n\t %s", buf
);
1905 ND_PRINT(" Path Id: %u", path_id
);
1909 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
1910 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1912 ND_PRINT("\n\t (illegal prefix length)");
1913 else if (advance
== -2)
1915 else if (advance
== -3)
1916 break; /* bytes left, but not enough */
1918 ND_PRINT("\n\t %s", buf
);
1920 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
1921 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
1922 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1923 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, buflen
);
1925 ND_PRINT("\n\t (illegal prefix length)");
1927 ND_PRINT("\n\t %s", buf
);
1929 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1930 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1931 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1932 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1933 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, buflen
);
1935 ND_PRINT("\n\t (illegal length)");
1936 else if (advance
== -2)
1939 ND_PRINT("\n\t %s", buf
);
1941 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1942 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1943 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1944 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1946 ND_PRINT("\n\t (illegal prefix length)");
1948 ND_PRINT("\n\t %s", buf
);
1950 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1951 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1952 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1953 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1955 ND_PRINT("\n\t (illegal prefix length)");
1957 ND_PRINT("\n\t %s", buf
);
1961 * This should not happen, we should have been protected
1962 * by bgp_mp_af_print()'s return value.
1964 ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af
, safi
);
1969 trunc
: /* we rely on the caller to recognize -2 return value */
1973 static const struct tok bgp_flags
[] = {
1982 bgp_attr_print(netdissect_options
*ndo
,
1983 uint8_t atype
, const u_char
*pptr
, u_int len
,
1984 const unsigned attr_set_level
)
1986 /* allocate space for the largest possible string */
1987 char astostr
[AS_STR_SIZE
];
1990 uint8_t safi
, snpa
, nhlen
;
1996 int add_path4
, add_path6
;
2003 case BGPTYPE_ORIGIN
:
2005 ND_PRINT("invalid len");
2007 ND_PRINT("%s", tok2str(bgp_origin_values
,
2008 "Unknown Origin Typecode",
2014 * Process AS4 byte path and AS2 byte path attributes here.
2016 case BGPTYPE_AS4_PATH
:
2017 case BGPTYPE_AS_PATH
:
2019 ND_PRINT("invalid len");
2028 * BGP updates exchanged between New speakers that support 4
2029 * byte AS, ASs are always encoded in 4 bytes. There is no
2030 * definitive way to find this, just by the packet's
2031 * contents. So, check for packet's TLV's sanity assuming
2032 * 2 bytes first, and it does not pass, assume that ASs are
2033 * encoded in 4 bytes format and move on.
2035 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
2037 while (tptr
< pptr
+ len
) {
2038 ND_PRINT("%s", tok2str(bgp_as_path_segment_open_values
,
2039 "?", GET_U_1(tptr
)));
2040 for (i
= 0; i
< GET_U_1(tptr
+ 1) * as_size
; i
+= as_size
) {
2041 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
2043 as_printf(ndo
, astostr
, sizeof(astostr
),
2045 GET_BE_U_2(tptr
+ i
+ 2) :
2046 GET_BE_U_4(tptr
+ i
+ 2)));
2048 ND_PRINT("%s", tok2str(bgp_as_path_segment_close_values
,
2049 "?", GET_U_1(tptr
)));
2050 tptr
+= 2 + GET_U_1(tptr
+ 1) * as_size
;
2053 case BGPTYPE_NEXT_HOP
:
2055 ND_PRINT("invalid len");
2057 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
2060 case BGPTYPE_MULTI_EXIT_DISC
:
2061 case BGPTYPE_LOCAL_PREF
:
2063 ND_PRINT("invalid len");
2065 ND_PRINT("%u", GET_BE_U_4(tptr
));
2068 case BGPTYPE_ATOMIC_AGGREGATE
:
2070 ND_PRINT("invalid len");
2072 case BGPTYPE_AGGREGATOR
:
2075 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
2076 * the length of this PA can be either 6 bytes or 8 bytes.
2078 if (len
!= 6 && len
!= 8) {
2079 ND_PRINT("invalid len");
2082 ND_TCHECK_LEN(tptr
, len
);
2084 ND_PRINT(" AS #%s, origin %s",
2085 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(tptr
)),
2086 GET_IPADDR_STRING(tptr
+ 2));
2088 ND_PRINT(" AS #%s, origin %s",
2089 as_printf(ndo
, astostr
, sizeof(astostr
),
2090 GET_BE_U_4(tptr
)), GET_IPADDR_STRING(tptr
+ 4));
2093 case BGPTYPE_AGGREGATOR4
:
2095 ND_PRINT("invalid len");
2098 ND_PRINT(" AS #%s, origin %s",
2099 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)),
2100 GET_IPADDR_STRING(tptr
+ 4));
2102 case BGPTYPE_COMMUNITIES
:
2104 ND_PRINT("invalid len");
2112 comm
= GET_BE_U_4(tptr
);
2114 case BGP_COMMUNITY_NO_EXPORT
:
2115 ND_PRINT(" NO_EXPORT");
2117 case BGP_COMMUNITY_NO_ADVERT
:
2118 ND_PRINT(" NO_ADVERTISE");
2120 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
2121 ND_PRINT(" NO_EXPORT_SUBCONFED");
2125 (comm
>> 16) & 0xffff,
2127 (tlen
>4) ? ", " : "");
2134 case BGPTYPE_ORIGINATOR_ID
:
2136 ND_PRINT("invalid len");
2139 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2141 case BGPTYPE_CLUSTER_LIST
:
2143 ND_PRINT("invalid len");
2150 GET_IPADDR_STRING(tptr
),
2151 (tlen
>4) ? ", " : "");
2156 case BGPTYPE_MP_REACH_NLRI
:
2160 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2172 nhlen
= GET_U_1(tptr
);
2178 uint8_t tnhlen
= nhlen
;
2181 ND_PRINT("\n\t nexthop: ");
2182 while (tnhlen
!= 0) {
2186 switch(af
<<8 | safi
) {
2187 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
2188 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
2189 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
2190 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
2191 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
2192 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
):
2193 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
2194 if (tnhlen
< sizeof(nd_ipv4
)) {
2195 ND_PRINT("invalid len");
2200 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2201 tptr
+= sizeof(nd_ipv4
);
2202 tnhlen
-= sizeof(nd_ipv4
);
2203 tlen
-= sizeof(nd_ipv4
);
2206 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
2207 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
2208 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2209 if (tnhlen
< sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
) {
2210 ND_PRINT("invalid len");
2215 ND_PRINT("RD: %s, %s",
2216 bgp_vpn_rd_print(ndo
, tptr
),
2217 GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2218 tptr
+= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2219 tlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2220 tnhlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2223 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
2224 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
2225 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
2226 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
2227 if (tnhlen
< sizeof(nd_ipv6
)) {
2228 ND_PRINT("invalid len");
2233 ND_PRINT("%s", GET_IP6ADDR_STRING(tptr
));
2234 tptr
+= sizeof(nd_ipv6
);
2235 tlen
-= sizeof(nd_ipv6
);
2236 tnhlen
-= sizeof(nd_ipv6
);
2239 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
2240 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
2241 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2242 if (tnhlen
< sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
) {
2243 ND_PRINT("invalid len");
2248 ND_PRINT("RD: %s, %s",
2249 bgp_vpn_rd_print(ndo
, tptr
),
2250 GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2251 tptr
+= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2252 tlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2253 tnhlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2256 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2257 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2258 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2259 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2260 if (tnhlen
< sizeof(nd_ipv4
)) {
2261 ND_PRINT("invalid len");
2266 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
2267 tptr
+= (sizeof(nd_ipv4
));
2268 tlen
-= (sizeof(nd_ipv4
));
2269 tnhlen
-= (sizeof(nd_ipv4
));
2272 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2273 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2274 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2275 ND_PRINT("%s", GET_ISONSAP_STRING(tptr
, tnhlen
));
2281 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2282 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2283 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2284 if (tnhlen
< BGP_VPN_RD_LEN
+1) {
2285 ND_PRINT("invalid len");
2290 ND_TCHECK_LEN(tptr
, tnhlen
);
2291 ND_PRINT("RD: %s, %s",
2292 bgp_vpn_rd_print(ndo
, tptr
),
2293 GET_ISONSAP_STRING(tptr
+BGP_VPN_RD_LEN
,tnhlen
-BGP_VPN_RD_LEN
));
2294 /* rfc986 mapped IPv4 address ? */
2295 if (GET_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
2296 ND_PRINT(" = %s", GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
+4));
2297 /* rfc1888 mapped IPv6 address ? */
2298 else if (GET_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
2299 ND_PRINT(" = %s", GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
+3));
2307 * bgp_mp_af_print() should have saved us from
2308 * an unsupported AFI/SAFI.
2310 ND_PRINT("ERROR: no AFI %u/SAFI %u nexthop decoder", af
, safi
);
2319 ND_PRINT(", nh-length: %u", nhlen
);
2321 /* As per RFC 2858; this is reserved in RFC 4760 */
2324 snpa
= GET_U_1(tptr
);
2329 ND_PRINT("\n\t %u SNPA", snpa
);
2330 for (/*nothing*/; snpa
!= 0; snpa
--) {
2334 snpalen
= GET_U_1(tptr
);
2335 ND_PRINT("\n\t %u bytes", snpalen
);
2340 ND_TCHECK_LEN(tptr
, snpalen
);
2345 ND_PRINT(", no SNPA");
2348 add_path4
= check_add_path(ndo
, tptr
,
2349 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 32);
2350 add_path6
= check_add_path(ndo
, tptr
,
2351 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 128);
2353 while (tptr
< pptr
+ len
) {
2354 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2355 add_path4
, add_path6
);
2364 case BGPTYPE_MP_UNREACH_NLRI
:
2365 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
2366 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2372 if (len
== BGP_MP_NLRI_MINSIZE
)
2373 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2377 add_path4
= check_add_path(ndo
, tptr
,
2378 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 32);
2379 add_path6
= check_add_path(ndo
, tptr
,
2380 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 128);
2382 while (tptr
< pptr
+ len
) {
2383 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2384 add_path4
, add_path6
);
2392 case BGPTYPE_EXTD_COMMUNITIES
:
2394 ND_PRINT("invalid len");
2403 extd_comm
=GET_BE_U_2(tptr
);
2405 ND_PRINT("\n\t %s (0x%04x), Flags [%s]",
2406 tok2str(bgp_extd_comm_subtype_values
,
2407 "unknown extd community typecode",
2410 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
2416 bgp_extended_community_print(ndo
, tptr
);
2422 case BGPTYPE_PMSI_TUNNEL
:
2424 uint8_t tunnel_type
, flags
;
2429 flags
= GET_U_1(tptr
);
2430 tunnel_type
= GET_U_1(tptr
+ 1);
2432 ND_PRINT("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2433 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2435 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2436 GET_BE_U_3(tptr
+ 2)>>4);
2441 switch (tunnel_type
) {
2442 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2443 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2444 ND_PRINT("\n\t Sender %s, P-Group %s",
2445 GET_IPADDR_STRING(tptr
),
2446 GET_IPADDR_STRING(tptr
+4));
2449 case BGP_PMSI_TUNNEL_PIM_SSM
:
2450 ND_PRINT("\n\t Root-Node %s, P-Group %s",
2451 GET_IPADDR_STRING(tptr
),
2452 GET_IPADDR_STRING(tptr
+4));
2454 case BGP_PMSI_TUNNEL_INGRESS
:
2455 ND_PRINT("\n\t Tunnel-Endpoint %s",
2456 GET_IPADDR_STRING(tptr
));
2458 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2459 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2460 ND_PRINT("\n\t Root-Node %s, LSP-ID 0x%08x",
2461 GET_IPADDR_STRING(tptr
),
2462 GET_BE_U_4(tptr
+ 4));
2464 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2465 ND_PRINT("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2466 GET_IPADDR_STRING(tptr
),
2467 GET_BE_U_4(tptr
+ 4));
2470 if (ndo
->ndo_vflag
<= 1) {
2471 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2482 type
= GET_U_1(tptr
);
2483 length
= GET_BE_U_2(tptr
+ 1);
2487 ND_PRINT("\n\t %s TLV (%u), length %u",
2488 tok2str(bgp_aigp_values
, "Unknown", type
),
2496 * Check if we can read the TLV data.
2506 ND_PRINT(", metric %" PRIu64
,
2511 if (ndo
->ndo_vflag
<= 1) {
2512 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2521 case BGPTYPE_ATTR_SET
:
2525 ND_PRINT("\n\t Origin AS: %s",
2526 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)));
2531 u_int aflags
, alenlen
, alen
;
2535 ND_PRINT(" [path attr too short]");
2539 aflags
= GET_U_1(tptr
);
2540 atype
= GET_U_1(tptr
+ 1);
2543 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2544 ND_TCHECK_LEN(tptr
, alenlen
);
2545 if (len
< alenlen
) {
2546 ND_PRINT(" [path attr too short]");
2550 alen
= bgp_attr_len(aflags
, tptr
);
2554 ND_PRINT("\n\t %s (%u), length: %u",
2555 tok2str(bgp_attr_values
,
2556 "Unknown Attribute", atype
),
2561 ND_PRINT(", Flags [%s",
2562 bittok2str_nosep(bgp_flags
, "", aflags
));
2564 ND_PRINT("+%x", aflags
& 0xf);
2569 ND_PRINT(" [path attr too short]");
2574 * The protocol encoding per se allows ATTR_SET to be nested
2575 * as many times as the message can accommodate. This printer
2576 * used to be able to recurse into ATTR_SET contents until the
2577 * stack exhaustion, but now there is a limit on that (if live
2578 * protocol exchange goes that many levels deep, something is
2579 * probably wrong anyway). Feel free to refine this value if
2580 * you can find the spec with respective normative text.
2582 if (attr_set_level
== 10)
2583 ND_PRINT("(too many nested levels, not recursing)");
2584 else if (!bgp_attr_print(ndo
, atype
, tptr
, alen
, attr_set_level
+ 1))
2591 case BGPTYPE_LARGE_COMMUNITY
:
2592 if (len
== 0 || len
% 12) {
2593 ND_PRINT("invalid len");
2598 ND_PRINT("%u:%u:%u%s",
2600 GET_BE_U_4(tptr
+ 4),
2601 GET_BE_U_4(tptr
+ 8),
2602 (len
> 12) ? ", " : "");
2605 * len will always be a multiple of 12, as per the above,
2606 * so this will never underflow.
2611 case BGPTYPE_BGPSEC_PATH
:
2613 uint16_t sblen
, splen
;
2615 splen
= GET_BE_U_2(tptr
);
2618 * A secure path has a minimum length of 8 bytes:
2619 * 2 bytes length field
2620 * 6 bytes per secure path segment
2622 ND_ICHECKMSG_U("secure path length", splen
, <, 8);
2624 ND_PRINT("\n\t Secure Path Length: %u", splen
);
2628 /* Make sure the secure path length does not signal trailing bytes */
2630 ND_PRINT(" [total segments length %u != N x 6]", splen
);
2634 /* Parse secure path segments */
2635 while (splen
!= 0) {
2636 uint8_t pcount
= GET_U_1(tptr
);
2637 uint8_t flags
= GET_U_1(tptr
+ 1);
2638 uint32_t asn
= GET_BE_U_4(tptr
+ 2);
2639 ND_PRINT("\n\t Secure Path Segment: pCount: %u, Flags: [%s] (0x%02x), AS: %u",
2641 bittok2str(bgp_bgpsec_bitmap_str
, "none", flags
),
2648 sblen
= GET_BE_U_2(tptr
);
2650 ND_PRINT("\n\t Signature Block: Length: %u, Algo ID: %u",
2656 /* Parse signature segments */
2660 ND_PRINT("\n\t Signature Segment:\n\t SKI: ");
2661 ND_ICHECKMSG_U("remaining length", sblen
, <, 20);
2662 hex_print(ndo
, "\n\t ", tptr
, 20);
2665 ND_ICHECKMSG_U("remaining length", sblen
, <, 2);
2666 siglen
= GET_BE_U_2(tptr
);
2670 ND_PRINT("\n\t Length: %u", siglen
);
2671 ND_ICHECKMSG_U("remaining length", sblen
, <, siglen
);
2672 ND_PRINT("\n\t Signature:");
2673 hex_print(ndo
, "\n\t ", tptr
, siglen
);
2682 ND_PRINT("invalid len");
2685 ND_PRINT("\n\t OTC %u", GET_BE_U_4(pptr
));
2689 ND_TCHECK_LEN(pptr
, len
);
2690 ND_PRINT("\n\t no Attribute %u decoder", atype
); /* we have no decoder for the attribute */
2691 if (ndo
->ndo_vflag
<= 1)
2692 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2696 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2697 ND_TCHECK_LEN(pptr
, len
);
2698 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2703 nd_print_invalid(ndo
);
2711 bgp_capabilities_print(netdissect_options
*ndo
,
2712 const u_char
*opt
, u_int caps_len
)
2714 /* allocate space for the largest possible string */
2715 char astostr
[AS_STR_SIZE
];
2716 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2719 while (i
< caps_len
) {
2720 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2721 cap_type
=GET_U_1(opt
+ i
);
2722 cap_len
=GET_U_1(opt
+ i
+ 1);
2723 ND_PRINT("\n\t %s (%u), length: %u",
2724 tok2str(bgp_capcode_values
, "Unknown", cap_type
),
2727 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2729 case BGP_CAPCODE_MP
:
2730 /* AFI (16 bits), Reserved (8 bits), SAFI (8 bits) */
2732 ND_PRINT(" (too short, < 4)");
2735 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u)",
2736 tok2str(af_values
, "Unknown", GET_BE_U_2(opt
+ i
+ 2)),
2737 GET_BE_U_2(opt
+ i
+ 2),
2738 tok2str(bgp_safi_values
, "Unknown", GET_U_1(opt
+ i
+ 5)),
2739 GET_U_1(opt
+ i
+ 5));
2741 case BGP_CAPCODE_BGPSEC
:
2742 /* Version (4 bits), Direction (1 bit), Flags (3 bits), AFI (16 bits) */
2744 /* The capability length [...] MUST be set to 3. */
2746 ND_PRINT(" [%u != 3]", cap_len
);
2750 ND_PRINT("\n\t\tVersion %u, Direction %s (%u), AFI %s (%u)",
2751 GET_U_1(opt
+ i
+ 2)&0xf0,
2752 (GET_U_1(opt
+ i
+ 2)&0x08) ? "Send" : "Receive",
2753 (GET_U_1(opt
+ i
+ 2)&0x08)>>3,
2754 bittok2str(af_values
, "Unknown",
2755 GET_BE_U_2(opt
+ i
+ cap_offset
+ 2)),
2756 GET_BE_U_2(opt
+ i
+ cap_offset
+ 2));
2758 case BGP_CAPCODE_ML
:
2761 while (tcap_len
>= 4) {
2762 ND_PRINT( "\n\t\tAFI %s (%u), SAFI %s (%u), Count: %u",
2763 tok2str(af_values
, "Unknown",
2764 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2765 GET_BE_U_2(opt
+ i
+ cap_offset
),
2766 tok2str(bgp_safi_values
, "Unknown",
2767 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2768 GET_U_1(opt
+ i
+ cap_offset
+ 2),
2769 GET_U_1(opt
+ i
+ cap_offset
+ 3));
2774 case BGP_CAPCODE_RESTART
:
2775 /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */
2777 ND_PRINT(" (too short, < 2)");
2781 ND_PRINT("\n\t\tRestart Flags: [%s], Restart Time %us",
2782 bittok2str(bgp_graceful_restart_comm_flag_values
,
2783 "none", GET_U_1(opt
+ i
+ 2) >> 4),
2784 GET_BE_U_2(opt
+ i
+ 2)&0xfff);
2787 while(tcap_len
>=4) {
2788 ND_PRINT("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2789 tok2str(af_values
,"Unknown",
2790 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2791 GET_BE_U_2(opt
+ i
+ cap_offset
),
2792 tok2str(bgp_safi_values
,"Unknown",
2793 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2794 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2795 ((GET_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" );
2800 case BGP_CAPCODE_ROLE
:
2802 ND_PRINT(" (too short, < 1)");
2805 ND_PRINT("\n\t\tRole name %s (%u)",
2806 tok2str(bgp_role_values
, "Unassigned",
2807 GET_U_1(opt
+ i
+ 2)), GET_U_1(opt
+ i
+ 2));
2809 case BGP_CAPCODE_RR
:
2810 case BGP_CAPCODE_LLGR
:
2811 case BGP_CAPCODE_RR_CISCO
:
2812 case BGP_CAPCODE_EXT_MSG
:
2813 case BGP_CAPCODE_ENH_RR
:
2815 case BGP_CAPCODE_AS_NEW
:
2817 * Extract the 4 byte AS number encoded.
2820 ND_PRINT(" (too short, < 4)");
2823 ND_PRINT("\n\t\t 4 Byte AS %s",
2824 as_printf(ndo
, astostr
, sizeof(astostr
),
2825 GET_BE_U_4(opt
+ i
+ 2)));
2827 case BGP_CAPCODE_ADD_PATH
:
2829 ND_PRINT(" (bogus)"); /* length */
2834 while (tcap_len
!= 0) {
2836 nd_print_invalid(ndo
);
2839 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2840 tok2str(af_values
,"Unknown",GET_BE_U_2(opt
+ i
+ cap_offset
)),
2841 GET_BE_U_2(opt
+ i
+ cap_offset
),
2842 tok2str(bgp_safi_values
,"Unknown",GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2843 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2844 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",GET_U_1(opt
+ i
+ cap_offset
+ 3))
2851 ND_PRINT("\n\t\tno decoder for Capability %u",
2853 if (ndo
->ndo_vflag
<= 1)
2854 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2858 if (ndo
->ndo_vflag
> 1 && cap_len
!= 0) {
2859 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2861 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2866 nd_print_trunc(ndo
);
2870 bgp_open_print(netdissect_options
*ndo
,
2871 const u_char
*dat
, u_int length
)
2873 /* allocate space for the largest possible string */
2874 char astostr
[AS_STR_SIZE
];
2875 const struct bgp_open
*bgp_open_header
;
2878 const struct bgp_opt
*bgpopt
;
2881 uint8_t extended_opt_params
= 0;
2882 u_int open_size
= BGP_OPEN_SIZE
;
2883 u_int opt_size
= BGP_OPT_SIZE
;
2885 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2886 if (length
< BGP_OPEN_SIZE
)
2889 bgp_open_header
= (const struct bgp_open
*)dat
;
2891 ND_PRINT("\n\t Version %u, ",
2892 GET_U_1(bgp_open_header
->bgpo_version
));
2893 ND_PRINT("my AS %s, ",
2894 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(bgp_open_header
->bgpo_myas
)));
2895 ND_PRINT("Holdtime %us, ",
2896 GET_BE_U_2(bgp_open_header
->bgpo_holdtime
));
2897 ND_PRINT("ID %s", GET_IPADDR_STRING(bgp_open_header
->bgpo_id
));
2898 optslen
= GET_U_1(bgp_open_header
->bgpo_optlen
);
2899 opsttype
= GET_U_1(bgp_open_header
->bgpo_opttype
);
2900 if (opsttype
== BGP_OPEN_NON_EXT_OPT_TYPE_EXTENDED_LENGTH
) {
2901 optslen
= GET_BE_U_2(bgp_open_header
->bgpo_optlen_extended
);
2902 extended_opt_params
= 1;
2906 ND_PRINT("\n\t Optional parameters%s, length: %u",
2907 extended_opt_params
? " (Extended)" : "", optslen
);
2909 opt
= dat
+ open_size
;
2910 length
-= open_size
;
2913 while (i
< optslen
) {
2917 ND_TCHECK_LEN(opt
+ i
, opt_size
);
2918 if (length
< opt_size
+ i
)
2920 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2921 opt_type
= GET_U_1(bgpopt
->bgpopt_type
);
2922 opt_len
= extended_opt_params
? GET_BE_U_2(bgpopt
->bgpopt_len
)
2923 : GET_U_1(bgpopt
->bgpopt_len
);
2924 if (opt_size
+ i
+ opt_len
> optslen
) {
2925 ND_PRINT("\n\t Option %u, length: %u, goes past the end of the options",
2930 ND_PRINT("\n\t Option %s (%u), length: %u",
2931 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2935 /* now let's decode the options we know*/
2939 bgp_capabilities_print(ndo
, opt
+ opt_size
+ i
,
2945 ND_PRINT("\n\t no decoder for option %u",
2949 i
+= opt_size
+ opt_len
;
2953 nd_print_trunc(ndo
);
2957 bgp_update_print(netdissect_options
*ndo
,
2958 const u_char
*dat
, u_int length
)
2961 u_int withdrawn_routes_len
;
2969 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2970 if (length
< BGP_SIZE
)
2975 /* Unfeasible routes */
2979 withdrawn_routes_len
= GET_BE_U_2(p
);
2982 if (withdrawn_routes_len
> 1) {
2984 * Without keeping state from the original NLRI message,
2985 * it's not possible to tell if this a v4 or v6 route,
2986 * so only try to decode it if we're not v6 enabled.
2988 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2989 if (length
< withdrawn_routes_len
)
2991 ND_PRINT("\n\t Withdrawn routes:");
2992 add_path
= check_add_path(ndo
, p
, withdrawn_routes_len
, 32);
2993 while (withdrawn_routes_len
!= 0) {
2995 if (withdrawn_routes_len
< 4) {
2996 p
+= withdrawn_routes_len
;
2997 length
-= withdrawn_routes_len
;
3000 path_id
= GET_BE_U_4(p
);
3003 withdrawn_routes_len
-= 4;
3005 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
3007 ND_PRINT("\n\t (illegal prefix length)");
3009 } else if (wpfx
== -2)
3010 goto trunc
; /* bytes left, but not enough */
3012 ND_PRINT("\n\t %s", buf
);
3014 ND_PRINT(" Path Id: %u", path_id
);
3018 withdrawn_routes_len
-= wpfx
;
3022 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
3023 if (length
< withdrawn_routes_len
)
3025 p
+= withdrawn_routes_len
;
3026 length
-= withdrawn_routes_len
;
3032 len
= GET_BE_U_2(p
);
3036 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
3037 /* No withdrawn routes, no path attributes, no NLRI */
3038 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
3043 /* Make sure the path attributes don't go past the end of the packet */
3046 /* do something more useful!*/
3048 uint8_t aflags
, atype
, alenlen
;
3055 ND_PRINT("\n\t [path attrs too short]");
3060 aflags
= GET_U_1(p
);
3061 atype
= GET_U_1(p
+ 1);
3065 alenlen
= bgp_attr_lenlen(aflags
, p
);
3066 ND_TCHECK_LEN(p
, alenlen
);
3067 if (length
< alenlen
)
3069 if (len
< alenlen
) {
3070 ND_PRINT("\n\t [path attrs too short]");
3075 alen
= bgp_attr_len(aflags
, p
);
3080 ND_PRINT("\n\t %s (%u), length: %u",
3081 tok2str(bgp_attr_values
, "Unknown Attribute", atype
),
3086 ND_PRINT(", Flags [%s",
3087 bittok2str_nosep(bgp_flags
, "", aflags
));
3089 ND_PRINT("+%x", aflags
& 0xf);
3093 ND_PRINT(" [path attrs too short]");
3100 if (!bgp_attr_print(ndo
, atype
, p
, alen
, 0))
3109 add_path
= check_add_path(ndo
, p
, length
, 32);
3110 ND_PRINT("\n\t Updated routes:");
3111 while (length
!= 0) {
3116 path_id
= GET_BE_U_4(p
);
3120 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
3122 ND_PRINT("\n\t (illegal prefix length)");
3125 goto trunc
; /* bytes left, but not enough */
3127 ND_PRINT("\n\t %s", buf
);
3129 ND_PRINT(" Path Id: %u", path_id
);
3138 nd_print_trunc(ndo
);
3142 bgp_notification_print_code(netdissect_options
*ndo
,
3143 const u_char
*dat
, u_int length
,
3144 uint8_t bgpn_major
, uint8_t bgpn_minor
)
3146 ND_PRINT(", %s (%u)",
3147 tok2str(bgp_notify_major_values
, "Unknown Error",
3151 switch (bgpn_major
) {
3153 case BGP_NOTIFY_MAJOR_MSG
:
3154 ND_PRINT(", subcode %s (%u)",
3155 tok2str(bgp_notify_minor_msg_values
, "Unknown",
3159 case BGP_NOTIFY_MAJOR_OPEN
:
3160 ND_PRINT(", subcode %s (%u)",
3161 tok2str(bgp_notify_minor_open_values
, "Unknown",
3165 case BGP_NOTIFY_MAJOR_UPDATE
:
3166 ND_PRINT(", subcode %s (%u)",
3167 tok2str(bgp_notify_minor_update_values
, "Unknown",
3171 case BGP_NOTIFY_MAJOR_FSM
:
3172 ND_PRINT(" subcode %s (%u)",
3173 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
3177 case BGP_NOTIFY_MAJOR_ROUTEREFRESH
:
3178 ND_PRINT(" subcode %s (%u)",
3179 tok2str(bgp_notify_minor_routerefresh_values
, "Unknown",
3183 case BGP_NOTIFY_MAJOR_CEASE
:
3184 ND_PRINT(", subcode %s (%u)",
3185 tok2str(bgp_notify_minor_cease_values
, "Unknown",
3189 /* RFC 4486 mentions optionally 7 bytes
3190 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
3192 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= 7) {
3193 ND_PRINT(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
3194 tok2str(af_values
, "Unknown", GET_BE_U_2(dat
)),
3196 tok2str(bgp_safi_values
, "Unknown", GET_U_1((dat
+ 2))),
3198 GET_BE_U_4(dat
+ 3));
3201 * RFC 9003 describes a method to send a communication
3202 * intended for human consumption regarding the Administrative Shutdown
3204 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
3205 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
3207 uint8_t shutdown_comm_length
= GET_U_1(dat
);
3208 uint8_t remainder_offset
= 0;
3209 /* garbage, hexdump it all */
3210 if (shutdown_comm_length
> length
- 1) {
3211 ND_PRINT(", invalid Shutdown Communication length");
3212 } else if (shutdown_comm_length
== 0) {
3213 ND_PRINT(", empty Shutdown Communication");
3214 remainder_offset
+= 1;
3216 /* a proper shutdown communication */
3218 ND_PRINT(", Shutdown Communication (length: %u): \"", shutdown_comm_length
);
3219 nd_printjn(ndo
, dat
+1, shutdown_comm_length
);
3221 remainder_offset
+= shutdown_comm_length
+ 1;
3223 /* if there is trailing data, hexdump it */
3224 if(length
- remainder_offset
> 0) {
3225 ND_PRINT(", Data: (length: %u)", length
- remainder_offset
);
3226 hex_print(ndo
, "\n\t\t", dat
+ remainder_offset
, length
- remainder_offset
);
3230 * RFC8538 describes the Hard Reset cease subcode, which contains another
3231 * notification code and subcode.
3233 if (bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_HARDRESET
&& length
>= 2) {
3234 bgpn_major
= GET_U_1(dat
++);
3235 bgpn_minor
= GET_U_1(dat
++);
3237 bgp_notification_print_code(ndo
, dat
, length
, bgpn_major
, bgpn_minor
);
3241 if (bgpn_minor
!= 0) {
3242 ND_PRINT(", subcode %u", bgpn_minor
);
3251 bgp_notification_print(netdissect_options
*ndo
,
3252 const u_char
*dat
, u_int length
)
3254 const struct bgp_notification
*bgp_notification_header
;
3255 uint8_t bgpn_major
, bgpn_minor
;
3257 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
3258 if (length
<BGP_NOTIFICATION_SIZE
)
3261 bgp_notification_header
= (const struct bgp_notification
*)dat
;
3262 bgpn_major
= GET_U_1(bgp_notification_header
->bgpn_major
);
3263 bgpn_minor
= GET_U_1(bgp_notification_header
->bgpn_minor
);
3264 bgp_notification_print_code(ndo
, dat
+ BGP_NOTIFICATION_SIZE
,
3265 length
- BGP_NOTIFICATION_SIZE
, bgpn_major
, bgpn_minor
);
3268 nd_print_trunc(ndo
);
3272 bgp_route_refresh_print(netdissect_options
*ndo
,
3273 const u_char
*pptr
, u_int len
)
3275 const struct bgp_route_refresh
*bgp_route_refresh_header
;
3277 /* some little sanity checking */
3278 if (len
<BGP_ROUTE_REFRESH_SIZE
)
3281 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
3283 ND_PRINT("\n\t AFI %s (%u), SAFI %s (%u), Subtype %s (%u)",
3284 tok2str(af_values
, "Unknown",
3285 GET_BE_U_2(bgp_route_refresh_header
->afi
)),
3286 GET_BE_U_2(bgp_route_refresh_header
->afi
),
3287 tok2str(bgp_safi_values
, "Unknown",
3288 GET_U_1(bgp_route_refresh_header
->safi
)),
3289 GET_U_1(bgp_route_refresh_header
->safi
),
3290 tok2str(bgp_route_refresh_subtype_values
, "Unknown",
3291 GET_U_1(bgp_route_refresh_header
->subtype
)),
3292 GET_U_1(bgp_route_refresh_header
->subtype
));
3295 if (len
>= BGP_ROUTE_REFRESH_SIZE_ORF
) {
3296 const struct bgp_route_refresh_orf
*orf_header
;
3299 (const struct bgp_route_refresh_orf
*)(pptr
+ BGP_ROUTE_REFRESH_SIZE
);
3301 ND_PRINT("\n\t ORF refresh %s (%u), ORF type %s (%u), ORF length %u",
3302 tok2str(bgp_orf_refresh_type
, "Unknown",
3303 GET_U_1(orf_header
->refresh
)),
3304 GET_U_1(orf_header
->refresh
),
3305 tok2str(bgp_orf_type
, "Unknown", GET_U_1(orf_header
->type
)),
3306 GET_U_1(orf_header
->type
), GET_BE_U_2(orf_header
->len
));
3309 if (ndo
->ndo_vflag
> 1) {
3310 ND_TCHECK_LEN(pptr
, len
);
3311 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
3316 nd_print_trunc(ndo
);
3320 bgp_pdu_print(netdissect_options
*ndo
,
3321 const u_char
*dat
, u_int length
)
3323 const struct bgp
*bgp_header
;
3326 ND_TCHECK_LEN(dat
, BGP_SIZE
);
3327 bgp_header
= (const struct bgp
*)dat
;
3328 bgp_type
= GET_U_1(bgp_header
->bgp_type
);
3330 ND_PRINT("\n\t%s Message (%u), length: %u",
3331 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
3337 bgp_open_print(ndo
, dat
, length
);
3340 bgp_update_print(ndo
, dat
, length
);
3342 case BGP_NOTIFICATION
:
3343 bgp_notification_print(ndo
, dat
, length
);
3347 case BGP_ROUTE_REFRESH
:
3348 bgp_route_refresh_print(ndo
, dat
, length
);
3351 /* we have no decoder for the BGP message */
3352 ND_TCHECK_LEN(dat
, length
);
3353 ND_PRINT("\n\t no Message %u decoder", bgp_type
);
3354 print_unknown_data(ndo
, dat
, "\n\t ", length
);
3359 nd_print_trunc(ndo
);
3364 bgp_print(netdissect_options
*ndo
,
3365 const u_char
*dat
, u_int length _U_
)
3368 const u_char
*ep
= ndo
->ndo_snapend
;
3369 const u_char
*start
;
3370 const u_char marker
[] = {
3371 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3372 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3374 const struct bgp
*bgp_header
;
3377 ndo
->ndo_protocol
= "bgp";
3380 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
3388 if (GET_U_1(p
) != 0xff) {
3393 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
3395 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
3400 /* found BGP header */
3401 ND_TCHECK_LEN(p
, BGP_SIZE
);
3402 bgp_header
= (const struct bgp
*)p
;
3405 nd_print_trunc(ndo
);
3407 hlen
= GET_BE_U_2(bgp_header
->bgp_len
);
3408 if (hlen
< BGP_SIZE
) {
3409 ND_PRINT("\nmessage length %u < %u", hlen
, BGP_SIZE
);
3410 nd_print_invalid(ndo
);
3414 if (ND_TTEST_LEN(p
, hlen
)) {
3415 if (!bgp_pdu_print(ndo
, p
, hlen
))
3420 ND_PRINT("\n[|BGP %s]",
3421 tok2str(bgp_msg_values
,
3422 "Unknown Message Type",
3423 GET_U_1(bgp_header
->bgp_type
)));
3431 nd_print_trunc(ndo
);