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_CAP 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_CAP
, "Capability 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_cap_values
[] = {
367 { 1, "Invalid Action Value" },
368 { 2, "Invalid Capability Length" },
369 { 3, "Malformed Capability Value" },
370 { 4, "Unsupported Capability Code" },
374 static const struct tok bgp_origin_values
[] = {
381 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
382 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
383 #define BGP_PMSI_TUNNEL_PIM_SSM 3
384 #define BGP_PMSI_TUNNEL_PIM_SM 4
385 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
386 #define BGP_PMSI_TUNNEL_INGRESS 6
387 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
389 static const struct tok bgp_pmsi_tunnel_values
[] = {
390 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
391 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
392 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
393 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
394 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
395 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
396 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
400 static const struct tok bgp_pmsi_flag_values
[] = {
401 { 0x01, "Leaf Information required"},
405 #define BGP_AIGP_TLV 1
407 static const struct tok bgp_aigp_values
[] = {
408 { BGP_AIGP_TLV
, "AIGP"},
412 #define BGP_ROLE_PROVIDER 0
413 #define BGP_ROLE_RS 1
414 #define BGP_ROLE_RS_CLIENT 2
415 #define BGP_ROLE_CUSTOMER 3
416 #define BGP_ROLE_PEER 4
418 static const struct tok bgp_role_values
[] = {
419 { BGP_ROLE_PROVIDER
, "Provider"},
420 { BGP_ROLE_RS
, "RS"},
421 { BGP_ROLE_RS_CLIENT
, "RS-Client"},
422 { BGP_ROLE_CUSTOMER
, "Customer"},
423 { BGP_ROLE_PEER
, "Peer"},
427 /* Subsequent address family identifier, RFC2283 section 7 */
429 #define SAFNUM_UNICAST 1
430 #define SAFNUM_MULTICAST 2
431 #define SAFNUM_UNIMULTICAST 3 /* deprecated now */
432 /* labeled BGP RFC3107 */
433 #define SAFNUM_LABUNICAST 4
435 #define SAFNUM_MULTICAST_VPN 5
436 /* draft-nalawade-kapoor-tunnel-safi */
437 #define SAFNUM_TUNNEL 64
439 #define SAFNUM_VPLS 65
441 #define SAFNUM_MDT 66
443 #define SAFNUM_EVPN 70
445 #define SAFNUM_VPNUNICAST 128
447 #define SAFNUM_VPNMULTICAST 129
448 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
450 #define SAFNUM_RT_ROUTING_INFO 132
452 #define BGP_VPN_RD_LEN 8
454 static const struct tok bgp_safi_values
[] = {
455 { SAFNUM_RES
, "Reserved"},
456 { SAFNUM_UNICAST
, "Unicast"},
457 { SAFNUM_MULTICAST
, "Multicast"},
458 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
459 { SAFNUM_LABUNICAST
, "labeled Unicast"},
460 { SAFNUM_TUNNEL
, "Tunnel"},
461 { SAFNUM_VPLS
, "VPLS"},
462 { SAFNUM_MDT
, "MDT"},
463 { SAFNUM_EVPN
, "EVPN"},
464 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
465 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
466 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
467 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
468 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
472 static const struct tok bgp_graceful_restart_comm_flag_values
[] = {
478 /* well-known community */
479 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
480 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
481 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
483 /* Extended community type - RFC 4360 */
484 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
485 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
486 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
487 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
488 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
489 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
490 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
491 #define BGP_EXT_COM_OVS 0x4300 /* BGP Prefix Origin Validation State Extended Community */
492 /* rfc2547 bgp-mpls-vpns */
493 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
494 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatibility */
495 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatibility */
496 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatibility */
498 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
499 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatibility */
500 #define BGP_EXT_COM_ENCAP 0x030c /* rfc5512 */
502 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
503 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatibility */
505 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
507 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
508 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
509 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
510 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
512 /* https://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
513 #define BGP_EXT_COM_EIGRP_GEN 0x8800
514 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
515 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
516 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
517 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
518 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
520 /* Optional Parameters */
521 #define BGP_OPEN_NON_EXT_OPT_TYPE_EXTENDED_LENGTH 255 /* Non-Ext OP Type */
523 static const struct tok bgp_extd_comm_flag_values
[] = {
524 { 0x8000, "vendor-specific"},
525 { 0x4000, "non-transitive"},
530 static const struct tok bgp_prefix_origin_validation_state
[] = {
537 static const struct tok bgp_extd_comm_subtype_values
[] = {
538 { BGP_EXT_COM_RT_0
, "target"},
539 { BGP_EXT_COM_RT_1
, "target"},
540 { BGP_EXT_COM_RT_2
, "target"},
541 { BGP_EXT_COM_RO_0
, "origin"},
542 { BGP_EXT_COM_RO_1
, "origin"},
543 { BGP_EXT_COM_RO_2
, "origin"},
544 { BGP_EXT_COM_LINKBAND
, "link-BW"},
545 { BGP_EXT_COM_OVS
, "origin-validation-state"},
546 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
547 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
548 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
549 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
550 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
551 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
552 { BGP_EXT_COM_ENCAP
, "encapsulation"},
553 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
554 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
555 { BGP_EXT_COM_L2INFO
, "layer2-info"},
556 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
557 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
558 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
559 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
560 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
561 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
562 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
563 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
564 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
565 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
569 /* RFC RFC5512 BGP Tunnel Encapsulation Attribute Tunnel Types */
570 #define BGP_ENCAP_TUNNEL_L2TPV3_IP 1
571 #define BGP_ENCAP_TUNNEL_GRE 2
572 #define BGP_ENCAP_TUNNEL_TRANSMIT 3
573 #define BGP_ENCAP_TUNNEL_IPSEC 4
574 #define BGP_ENCAP_TUNNEL_IP_IPSEC 5
575 #define BGP_ENCAP_TUNNEL_MPLS_IP 6
576 #define BGP_ENCAP_TUNNEL_IP_IP 7
577 #define BGP_ENCAP_TUNNEL_VXLAN 8
578 #define BGP_ENCAP_TUNNEL_NVGRE 9
579 #define BGP_ENCAP_TUNNEL_MPLS 10
580 #define BGP_ENCAP_TUNNEL_MPLS_GRE 11
581 #define BGP_ENCAP_TUNNEL_VXLAN_GPE 12
582 #define BGP_ENCAP_TUNNEL_MPLS_UDP 13
583 #define BGP_ENCAP_TUNNEL_IPV6 14
584 #define BGP_ENCAP_TUNNEL_SR_TE 15
585 #define BGP_ENCAP_TUNNEL_BARE 16
586 #define BGP_ENCAP_TUNNEL_SR 17
588 static const struct tok bgp_extd_comm_encap_tunnel_values
[] = {
589 { BGP_ENCAP_TUNNEL_L2TPV3_IP
, "L2TPv3 over IP"},
590 { BGP_ENCAP_TUNNEL_GRE
, "GRE"},
591 { BGP_ENCAP_TUNNEL_TRANSMIT
, "Transmit Tunnel"},
592 { BGP_ENCAP_TUNNEL_IPSEC
, "IPsec"},
593 { BGP_ENCAP_TUNNEL_IP_IPSEC
, "IP in IP with IPsec"},
594 { BGP_ENCAP_TUNNEL_MPLS_IP
, "MPLS in IP with IPsec"},
595 { BGP_ENCAP_TUNNEL_IP_IP
, "IP in IP"},
596 { BGP_ENCAP_TUNNEL_VXLAN
, "VXLAN"},
597 { BGP_ENCAP_TUNNEL_NVGRE
, "NVGRE"},
598 { BGP_ENCAP_TUNNEL_MPLS
, "MPLS"},
599 { BGP_ENCAP_TUNNEL_MPLS_GRE
, "MPLS in GRE"},
600 { BGP_ENCAP_TUNNEL_VXLAN_GPE
, "VXLAN GPE"},
601 { BGP_ENCAP_TUNNEL_MPLS_UDP
, "MPLS in UDP"},
602 { BGP_ENCAP_TUNNEL_IPV6
, "IPv6"},
603 { BGP_ENCAP_TUNNEL_SR_TE
, "SR TE"},
604 { BGP_ENCAP_TUNNEL_BARE
, "Bare"},
605 { BGP_ENCAP_TUNNEL_SR
, "SR"},
609 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
610 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
611 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
612 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
613 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
614 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
615 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
616 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
618 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
619 { BGP_OSPF_RTYPE_RTR
, "Router" },
620 { BGP_OSPF_RTYPE_NET
, "Network" },
621 { BGP_OSPF_RTYPE_SUM
, "Summary" },
622 { BGP_OSPF_RTYPE_EXT
, "External" },
623 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
624 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
628 /* ADD-PATH Send/Receive field values */
629 static const struct tok bgp_add_path_recvsend
[] = {
636 static const struct tok bgp_bgpsec_bitmap_str
[] = {
637 { 1U << 0, "MBZ-0" },
638 { 1U << 1, "MBZ-1" },
639 { 1U << 2, "MBZ-2" },
640 { 1U << 3, "MBZ-3" },
641 { 1U << 4, "MBZ-4" },
642 { 1U << 5, "MBZ-5" },
643 { 1U << 6, "MBZ-6" },
648 #define AS_STR_SIZE sizeof("xxxxx.xxxxx")
653 * Convert an AS number into a string and return string pointer.
655 * Depending on bflag is set or not, AS number is converted into ASDOT notation
656 * or plain number notation.
660 as_printf(netdissect_options
*ndo
,
661 char *str
, size_t size
, u_int asnum
)
663 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
664 snprintf(str
, size
, "%u", asnum
);
666 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
671 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
674 decode_prefix4(netdissect_options
*ndo
,
675 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
678 u_int plen
, plenbytes
;
681 plen
= GET_U_1(pptr
);
686 memset(&addr
, 0, sizeof(addr
));
687 plenbytes
= (plen
+ 7) / 8;
688 ITEMCHECK(plenbytes
);
689 GET_CPY_BYTES(&addr
, pptr
+ 1, plenbytes
);
691 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
693 snprintf(buf
, buflen
, "%s/%u", ipaddr_string(ndo
, (const u_char
*)&addr
), plen
);
694 return 1 + plenbytes
;
701 decode_labeled_prefix4(netdissect_options
*ndo
,
702 const u_char
*pptr
, u_int itemlen
, char *buf
,
706 u_int plen
, plenbytes
;
708 /* prefix length and label = 4 bytes */
711 plen
= GET_U_1(pptr
); /* get prefix length */
713 /* this is one of the weirdnesses of rfc3107
714 the label length (actually the label + COS bits)
715 is added to the prefix length;
716 we also do only read out just one label -
717 there is no real application for advertisement of
718 stacked labels in a single BGP message
724 plen
-=24; /* adjust prefixlen - labellength */
730 memset(&addr
, 0, sizeof(addr
));
731 plenbytes
= (plen
+ 7) / 8;
732 ITEMCHECK(plenbytes
);
733 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
735 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
737 /* the label may get offsetted by 4 bits so lets shift it right */
738 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
739 ipaddr_string(ndo
, (const u_char
*)&addr
),
741 GET_BE_U_3(pptr
+ 1)>>4,
742 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
744 return 4 + plenbytes
;
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
,
804 const u_char
*pptr
, char *buf
, size_t buflen
)
807 u_int total_length
, offset
;
811 /* Source address length, encoded in bits */
812 addr_length
= GET_U_1(pptr
);
816 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
817 total_length
+= (addr_length
>> 3) + 1;
818 offset
= (u_int
)strlen(buf
);
820 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
821 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
822 pptr
+= (addr_length
>> 3);
825 /* Group address length, encoded in bits */
826 addr_length
= GET_U_1(pptr
);
830 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
831 total_length
+= (addr_length
>> 3) + 1;
832 offset
= (u_int
)strlen(buf
);
834 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
835 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
836 pptr
+= (addr_length
>> 3);
840 return (total_length
);
843 /* Print an RFC 4364 Route Distinguisher */
845 bgp_vpn_rd_print(netdissect_options
*ndo
,
848 /* allocate space for the largest possible string */
849 static char rd
[sizeof("xxxxx.xxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
851 /* allocate space for the largest possible string */
852 char astostr
[AS_STR_SIZE
];
854 /* ok lets load the RD format */
855 switch (GET_BE_U_2(pptr
)) {
858 /* 2-byte-AS:number fmt */
859 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
860 GET_BE_U_2(pptr
+ 2),
861 GET_BE_U_4(pptr
+ 4),
862 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
863 GET_U_1(pptr
+ 6), GET_U_1(pptr
+ 7));
867 /* IP-address:AS fmt */
868 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
869 GET_U_1(pptr
+ 2), GET_U_1(pptr
+ 3),
870 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
871 GET_BE_U_2(pptr
+ 6));
875 /* 4-byte-AS:number fmt */
876 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
877 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 2)),
878 GET_BE_U_2(pptr
+ 6), GET_U_1(pptr
+ 2),
879 GET_U_1(pptr
+ 3), GET_U_1(pptr
+ 4),
880 GET_U_1(pptr
+ 5), GET_BE_U_2(pptr
+ 6));
883 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
892 * Print an RFC 4360 Extended Community.
895 bgp_extended_community_print(netdissect_options
*ndo
,
898 union { /* copy buffer for bandwidth values */
902 /* allocate space for the largest possible string */
903 char astostr
[AS_STR_SIZE
];
905 switch (GET_BE_U_2(pptr
)) {
907 case BGP_EXT_COM_RT_0
:
908 case BGP_EXT_COM_RO_0
:
909 case BGP_EXT_COM_L2VPN_RT_0
:
910 ND_PRINT("%u:%u (= %s)",
911 GET_BE_U_2(pptr
+ 2),
912 GET_BE_U_4(pptr
+ 4),
913 GET_IPADDR_STRING(pptr
+4));
916 case BGP_EXT_COM_RT_1
:
917 case BGP_EXT_COM_RO_1
:
918 case BGP_EXT_COM_L2VPN_RT_1
:
919 case BGP_EXT_COM_VRF_RT_IMP
:
921 GET_IPADDR_STRING(pptr
+2),
922 GET_BE_U_2(pptr
+ 6));
925 case BGP_EXT_COM_RT_2
:
926 case BGP_EXT_COM_RO_2
:
928 as_printf(ndo
, astostr
, sizeof(astostr
),
929 GET_BE_U_4(pptr
+ 2)), GET_BE_U_2(pptr
+ 6));
932 case BGP_EXT_COM_LINKBAND
:
933 bw
.i
= GET_BE_U_4(pptr
+ 4);
934 ND_PRINT("bandwidth: %.3f Mbps",
938 case BGP_EXT_COM_OVS
:
939 /* The Reserved field MUST be set to 0 and ignored upon the
940 * receipt of this community.
943 uint64_t reserved
= GET_BE_U_5(pptr
+ 2);
946 ND_PRINT("[the reserved field 0x%" PRIx64
" MUST be 0] ",
949 tok2str(bgp_prefix_origin_validation_state
,
950 "unknown origin validation state",
955 case BGP_EXT_COM_VPN_ORIGIN
:
956 case BGP_EXT_COM_VPN_ORIGIN2
:
957 case BGP_EXT_COM_VPN_ORIGIN3
:
958 case BGP_EXT_COM_VPN_ORIGIN4
:
959 case BGP_EXT_COM_OSPF_RID
:
960 case BGP_EXT_COM_OSPF_RID2
:
961 ND_PRINT("%s", GET_IPADDR_STRING(pptr
+2));
964 case BGP_EXT_COM_OSPF_RTYPE
:
965 case BGP_EXT_COM_OSPF_RTYPE2
:
966 ND_PRINT("area:%s, router-type:%s, metric-type:%s%s",
967 GET_IPADDR_STRING(pptr
+2),
968 tok2str(bgp_extd_comm_ospf_rtype_values
,
970 GET_U_1((pptr
+ 6))),
971 (GET_U_1(pptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
972 ((GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
975 case BGP_EXT_COM_L2INFO
:
976 ND_PRINT("%s Control Flags [0x%02x]:MTU %u",
977 tok2str(l2vpn_encaps_values
,
979 GET_U_1((pptr
+ 2))),
981 GET_BE_U_2(pptr
+ 4));
984 case BGP_EXT_COM_SOURCE_AS
:
985 ND_PRINT("AS %u", GET_BE_U_2(pptr
+ 2));
988 case BGP_EXT_COM_ENCAP
:
989 ND_PRINT("Tunnel type: %s", tok2str(bgp_extd_comm_encap_tunnel_values
,
991 GET_BE_U_2(pptr
+ 6)));
995 ND_PRINT("%02x%02x%02x%02x%02x%02x",
1007 * RFC4684 (Section 4)/RFC2858 (Section 4).
1008 * RTC membership prefix is structured as follows
1009 * [prefix-len] [origin-as] [route-target]
1010 * The route-target is encoded as RT ext-comms.
1011 * Prefix-len may be 0, 32..96
1013 * Note that pptr is not packet data - it is
1014 * a buffer owned by our caller - therefore GET_*
1015 * macros can not be used.
1018 bgp_rt_prefix_print(netdissect_options
*ndo
,
1022 /* allocate space for the largest possible string */
1023 char rtc_prefix_in_hex
[sizeof("0000 0000 0000 0000")] = "";
1024 u_int rtc_prefix_in_hex_len
= 0;
1025 static char output
[61]; /* max response string */
1026 /* allocate space for the largest possible string */
1027 char astostr
[AS_STR_SIZE
];
1028 uint16_t ec_type
= 0;
1033 snprintf(output
, sizeof(output
), "route-target: 0:0/0");
1037 /* hex representation of the prefix */
1038 octet_count
= (plen
+7)/8;
1039 for (i
=0; i
<octet_count
; i
++) {
1040 rtc_prefix_in_hex_len
+= snprintf(rtc_prefix_in_hex
+rtc_prefix_in_hex_len
,
1041 sizeof(rtc_prefix_in_hex
)-rtc_prefix_in_hex_len
,
1042 "%02x%s", *(pptr
+i
),
1043 ((i
%2 == 1) && (i
<octet_count
-1)) ? " " : "");
1048 * The prefix is too short to include the full ext-comm type,
1049 * so we have no way to parse it further.
1051 snprintf(output
, sizeof(output
), "route-target: partial-type: (%s/%d)",
1052 rtc_prefix_in_hex
, plen
);
1057 * get the ext-comm type
1058 * Note: pptr references a static 8 octet buffer with unused bits set to 0,
1059 * hence EXTRACT_*() macros are safe.
1061 ec_type
= EXTRACT_BE_U_2(pptr
);
1063 case BGP_EXT_COM_RT_0
:
1064 /* 2-byte-AS:number fmt */
1065 snprintf(output
, sizeof(output
), "route-target: %u:%u/%d (%s)",
1066 EXTRACT_BE_U_2(pptr
+2),
1067 EXTRACT_BE_U_4(pptr
+4),
1068 plen
, rtc_prefix_in_hex
);
1071 case BGP_EXT_COM_RT_1
:
1072 /* IP-address:AS fmt */
1073 snprintf(output
, sizeof(output
), "route-target: %u.%u.%u.%u:%u/%d (%s)",
1074 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5),
1075 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
1078 case BGP_EXT_COM_RT_2
:
1079 /* 4-byte-AS:number fmt */
1080 snprintf(output
, sizeof(output
), "route-target: %s:%u/%d (%s)",
1081 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(pptr
+2)),
1082 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
1086 snprintf(output
, sizeof(output
), "route target: unknown-type(%04x) (%s/%d)",
1088 rtc_prefix_in_hex
, plen
);
1096 decode_rt_routing_info(netdissect_options
*ndo
,
1099 uint8_t route_target
[8];
1101 /* allocate space for the largest possible string */
1102 char astostr
[AS_STR_SIZE
];
1105 /* NLRI "prefix length" from RFC 2858 Section 4. */
1106 plen
= GET_U_1(pptr
); /* get prefix length */
1108 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
1109 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
1110 * target" fields inside the "prefix" depending on its length.
1113 /* Without "origin AS", without "route target". */
1114 ND_PRINT("\n\t default route target");
1119 ND_PRINT("\n\t (illegal prefix length)");
1123 /* With at least "origin AS", possibly with "route target". */
1124 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 1));
1126 plen
-= 32; /* adjust prefix length */
1129 ND_PRINT("\n\t (illegal prefix length)");
1133 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
1134 * and gives the number of octets in the variable-length "route
1135 * target" field inside this NLRI "prefix". Look for it.
1137 memset(&route_target
, 0, sizeof(route_target
));
1138 num_octets
= (plen
+ 7) / 8;
1139 GET_CPY_BYTES(&route_target
, pptr
+ 5, num_octets
);
1140 /* If mask-len is not on octet boundary, ensure all extra bits are 0 */
1142 ((u_char
*)&route_target
)[num_octets
- 1] &=
1143 ((0xff00 >> (plen
% 8)) & 0xff);
1145 ND_PRINT("\n\t origin AS: %s, %s",
1147 bgp_rt_prefix_print(ndo
, (u_char
*)&route_target
, plen
));
1149 return 5 + num_octets
;
1153 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
1154 const u_char
*pptr
, char *buf
, size_t buflen
)
1159 plen
= GET_U_1(pptr
); /* get prefix length */
1164 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1169 memset(&addr
, 0, sizeof(addr
));
1170 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1172 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
1173 ((0xff00 >> (plen
% 8)) & 0xff);
1175 /* the label may get offsetted by 4 bits so lets shift it right */
1176 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1177 bgp_vpn_rd_print(ndo
, pptr
+4),
1178 ipaddr_string(ndo
, (const u_char
*)&addr
),
1180 GET_BE_U_3(pptr
+ 1)>>4,
1181 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1183 return 12 + (plen
+ 7) / 8;
1187 * +-------------------------------+
1189 * | RD:IPv4-address (12 octets) |
1191 * +-------------------------------+
1192 * | MDT Group-address (4 octets) |
1193 * +-------------------------------+
1196 #define MDT_VPN_NLRI_LEN 16
1199 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
1200 const u_char
*pptr
, char *buf
, size_t buflen
)
1203 const u_char
*vpn_ip
;
1205 /* if the NLRI is not predefined length, quit.*/
1206 if (GET_U_1(pptr
) != MDT_VPN_NLRI_LEN
* 8)
1217 pptr
+= sizeof(nd_ipv4
);
1219 /* MDT Group Address */
1220 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
1221 bgp_vpn_rd_print(ndo
, rd
), GET_IPADDR_STRING(vpn_ip
), GET_IPADDR_STRING(pptr
));
1223 return MDT_VPN_NLRI_LEN
+ 1;
1229 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
1230 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
1231 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
1232 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
1233 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
1234 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
1235 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
1237 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
1238 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
1239 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
1240 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
1241 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
1242 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
1243 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
1244 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
1249 decode_multicast_vpn(netdissect_options
*ndo
,
1250 const u_char
*pptr
, char *buf
, size_t buflen
)
1252 /* allocate space for the largest possible string */
1253 char astostr
[AS_STR_SIZE
];
1254 uint8_t route_type
, route_length
;
1255 u_int addr_length
, sg_length
;
1258 route_type
= GET_U_1(pptr
);
1260 route_length
= GET_U_1(pptr
);
1263 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
1264 tok2str(bgp_multicast_vpn_route_type_values
,
1265 "Unknown", route_type
),
1266 route_type
, route_length
);
1268 switch(route_type
) {
1269 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
1270 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1271 offset
= (u_int
)strlen(buf
);
1272 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
1273 bgp_vpn_rd_print(ndo
, pptr
),
1274 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
1275 (route_length
- BGP_VPN_RD_LEN
) << 3));
1277 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
1278 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1279 offset
= (u_int
)strlen(buf
);
1280 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1281 bgp_vpn_rd_print(ndo
, pptr
),
1282 as_printf(ndo
, astostr
, sizeof(astostr
),
1283 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1286 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
1287 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1288 offset
= (u_int
)strlen(buf
);
1289 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1290 bgp_vpn_rd_print(ndo
, pptr
));
1291 pptr
+= BGP_VPN_RD_LEN
;
1293 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1294 addr_length
= route_length
- sg_length
;
1296 ND_TCHECK_LEN(pptr
, addr_length
);
1297 offset
= (u_int
)strlen(buf
);
1298 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
1299 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
1302 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
1303 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1304 offset
= (u_int
)strlen(buf
);
1305 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1306 bgp_vpn_rd_print(ndo
, pptr
));
1307 pptr
+= BGP_VPN_RD_LEN
;
1309 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1312 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
1313 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
1314 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1315 offset
= (u_int
)strlen(buf
);
1316 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1317 bgp_vpn_rd_print(ndo
, pptr
),
1318 as_printf(ndo
, astostr
, sizeof(astostr
),
1319 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1320 pptr
+= BGP_VPN_RD_LEN
+ 4;
1322 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1326 * no per route-type printing yet.
1328 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1333 return route_length
+ 2;
1340 * As I remember, some versions of systems have an snprintf() that
1341 * returns -1 if the buffer would have overflowed. If the return
1342 * value is negative, set buflen to 0, to indicate that we've filled
1345 * If the return value is greater than buflen, that means that
1346 * the buffer would have overflowed; again, set buflen to 0 in
1349 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1352 else if ((u_int)stringlen>buflen) \
1355 buflen-=stringlen; \
1360 decode_labeled_vpn_l2(netdissect_options
*ndo
,
1361 const u_char
*pptr
, char *buf
, size_t buflen
)
1363 u_int plen
, tlen
, tlv_type
, tlv_len
, ttlv_len
;
1366 plen
= GET_BE_U_2(pptr
);
1369 /* Old and new L2VPN NLRI share AFI/SAFI
1370 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1371 * and > 17 as old format. Complain for the middle case
1374 /* assume AD-only with RD, BGPNH */
1375 ND_TCHECK_LEN(pptr
, 12);
1377 stringlen
= snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
1378 bgp_vpn_rd_print(ndo
, pptr
),
1379 GET_IPADDR_STRING(pptr
+8));
1380 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1384 } else if (plen
> 17) {
1385 /* assume old format */
1386 /* RD, ID, LBLKOFF, LBLBASE */
1388 ND_TCHECK_LEN(pptr
, 15);
1390 stringlen
= snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1391 bgp_vpn_rd_print(ndo
, pptr
),
1392 GET_BE_U_2(pptr
+ 8),
1393 GET_BE_U_2(pptr
+ 10),
1394 GET_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1395 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1399 /* ok now the variable part - lets read out TLVs*/
1403 stringlen
=snprintf(buf
,buflen
, "\n\t\tran past the end");
1404 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1408 tlv_type
= GET_U_1(pptr
);
1410 tlv_len
= GET_BE_U_2(pptr
); /* length, in *bits* */
1411 ttlv_len
= (tlv_len
+ 7)/8; /* length, in *bytes* */
1417 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1420 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1422 while (ttlv_len
!= 0) {
1425 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1426 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1432 stringlen
=snprintf(buf
,buflen
, "%02x",
1435 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1443 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1446 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1448 if (tlen
< ttlv_len
) {
1450 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1451 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1461 /* complain bitterly ? */
1471 decode_prefix6(netdissect_options
*ndo
,
1472 const u_char
*pd
, u_int itemlen
, char *buf
, size_t buflen
)
1475 u_int plen
, plenbytes
;
1483 memset(&addr
, 0, sizeof(addr
));
1484 plenbytes
= (plen
+ 7) / 8;
1485 ITEMCHECK(plenbytes
);
1486 GET_CPY_BYTES(&addr
, pd
+ 1, plenbytes
);
1488 addr
[plenbytes
- 1] &=
1489 ((0xff00 >> (plen
% 8)) & 0xff);
1491 snprintf(buf
, buflen
, "%s/%u", ip6addr_string(ndo
, (const u_char
*)&addr
), plen
);
1492 return 1 + plenbytes
;
1499 decode_labeled_prefix6(netdissect_options
*ndo
,
1500 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
1503 u_int plen
, plenbytes
;
1505 /* prefix length and label = 4 bytes */
1508 plen
= GET_U_1(pptr
); /* get prefix length */
1513 plen
-= 24; /* adjust prefixlen - labellength */
1519 memset(&addr
, 0, sizeof(addr
));
1520 plenbytes
= (plen
+ 7) / 8;
1521 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
1523 addr
[plenbytes
- 1] &=
1524 ((0xff00 >> (plen
% 8)) & 0xff);
1526 /* the label may get offsetted by 4 bits so lets shift it right */
1527 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
1528 ip6addr_string(ndo
, (const u_char
*)&addr
),
1530 GET_BE_U_3(pptr
+ 1)>>4,
1531 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1533 return 4 + plenbytes
;
1543 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1544 const u_char
*pptr
, char *buf
, size_t buflen
)
1549 plen
= GET_U_1(pptr
); /* get prefix length */
1554 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1559 memset(&addr
, 0, sizeof(addr
));
1560 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1562 addr
[(plen
+ 7) / 8 - 1] &=
1563 ((0xff00 >> (plen
% 8)) & 0xff);
1565 /* the label may get offsetted by 4 bits so lets shift it right */
1566 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1567 bgp_vpn_rd_print(ndo
, pptr
+4),
1568 ip6addr_string(ndo
, (const u_char
*)&addr
),
1570 GET_BE_U_3(pptr
+ 1)>>4,
1571 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1573 return 12 + (plen
+ 7) / 8;
1577 decode_clnp_prefix(netdissect_options
*ndo
,
1578 const u_char
*pptr
, char *buf
, size_t buflen
)
1583 plen
= GET_U_1(pptr
); /* get prefix length */
1588 memset(&addr
, 0, sizeof(addr
));
1589 GET_CPY_BYTES(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1591 addr
[(plen
+ 7) / 8 - 1] &=
1592 ((0xff00 >> (plen
% 8)) & 0xff);
1594 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1595 snprintf(buf
, buflen
, "%s/%u",
1596 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1599 return 1 + (plen
+ 7) / 8;
1603 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1604 const u_char
*pptr
, char *buf
, size_t buflen
)
1609 plen
= GET_U_1(pptr
); /* get prefix length */
1614 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1619 memset(&addr
, 0, sizeof(addr
));
1620 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1622 addr
[(plen
+ 7) / 8 - 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
1624 /* the label may get offsetted by 4 bits so lets shift it right */
1625 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1626 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1627 bgp_vpn_rd_print(ndo
, pptr
+4),
1628 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1630 GET_BE_U_3(pptr
+ 1)>>4,
1631 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1633 return 12 + (plen
+ 7) / 8;
1637 * bgp_attr_get_as_size
1639 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1640 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1641 * support, exchange AS-Path with the same path-attribute type value 0x02.
1644 bgp_attr_get_as_size(netdissect_options
*ndo
,
1645 uint8_t bgpa_type
, const u_char
*pptr
, u_int len
)
1647 const u_char
*tptr
= pptr
;
1650 * If the path attribute is the optional AS4 path type, then we already
1651 * know, that ASs must be encoded in 4 byte format.
1653 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1658 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1659 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1662 while (tptr
< pptr
+ len
) {
1664 * If we do not find a valid segment type, our guess might be wrong.
1666 if (GET_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| GET_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1669 tptr
+= 2 + GET_U_1(tptr
+ 1) * 2;
1673 * If we correctly reached end of the AS path attribute data content,
1674 * then most likely ASs were indeed encoded as 2 bytes.
1676 if (tptr
== pptr
+ len
) {
1683 * We can come here, either we did not have enough data, or if we
1684 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1685 * so that calller can try to decode each AS as of 4 bytes. If indeed
1686 * there was not enough data, it will crib and end the parse anyways.
1692 * The only way to know that a BGP UPDATE message is using add path is
1693 * by checking if the capability is in the OPEN message which we may have missed.
1694 * So this function checks if it is possible that the update could contain add path
1695 * and if so it checks that standard BGP doesn't make sense.
1698 check_add_path(netdissect_options
*ndo
, const u_char
*pptr
, u_int length
,
1699 u_int max_prefix_length
)
1701 u_int offset
, prefix_length
;
1708 * Scan through the NLRI information under the assumpetion that
1709 * it doesn't have path IDs.
1711 for (offset
= 0; offset
< length
;) {
1713 if (!ND_TTEST_1(pptr
+ offset
)) {
1714 /* We ran out of captured data; quit scanning. */
1717 prefix_length
= GET_U_1(pptr
+ offset
);
1719 * Add 4 to cover the path id
1720 * and check the prefix length isn't greater than 32/128.
1722 if (prefix_length
> max_prefix_length
) {
1725 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1726 offset
+= 1 + ((prefix_length
+ 7) / 8);
1728 /* check we haven't gone past the end of the section */
1729 if (offset
> length
) {
1733 /* check it's not standard BGP */
1734 for (offset
= 0; offset
< length
; ) {
1735 if (!ND_TTEST_1(pptr
+ offset
)) {
1736 /* We ran out of captured data; quit scanning. */
1739 prefix_length
= GET_U_1(pptr
+ offset
);
1741 * If the prefix_length is zero (0.0.0.0/0)
1742 * and since it's not the only address (length >= 5)
1743 * then it is add-path
1745 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1748 offset
+= 1 + ((prefix_length
+ 7) / 8);
1750 if (offset
> length
) {
1754 /* assume not add-path by default */
1759 bgp_mp_af_print(netdissect_options
*ndo
,
1760 const u_char
*tptr
, u_int tlen
,
1761 uint16_t *afp
, uint8_t *safip
)
1766 af
= GET_BE_U_2(tptr
);
1768 safi
= GET_U_1(tptr
+ 2);
1771 ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1772 tok2str(af_values
, "Unknown AFI", af
),
1774 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1775 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1778 switch(af
<<8 | safi
) {
1779 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
1780 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
1781 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
1782 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
1783 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
1784 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
1785 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
1786 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1787 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
):
1788 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
1789 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
1790 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
1791 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
1792 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
1793 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
1794 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
1795 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1796 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1797 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1798 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1799 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1800 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1801 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1802 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1803 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1804 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1805 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1808 ND_TCHECK_LEN(tptr
, tlen
);
1809 ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af
, safi
);
1810 if (ndo
->ndo_vflag
<= 1)
1811 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1820 bgp_nlri_print(netdissect_options
*ndo
, uint16_t af
, uint8_t safi
,
1821 const u_char
*tptr
, u_int len
,
1822 char *buf
, size_t buflen
,
1823 int add_path4
, int add_path6
)
1828 switch (af
<<8 | safi
) {
1829 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
1830 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
1831 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
1833 path_id
= GET_BE_U_4(tptr
);
1836 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1838 ND_PRINT("\n\t (illegal prefix length)");
1839 else if (advance
== -2)
1840 break; /* bytes left, but not enough */
1842 ND_PRINT("\n\t %s", buf
);
1844 ND_PRINT(" Path Id: %u", path_id
);
1848 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
1849 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1851 ND_PRINT("\n\t (illegal prefix length)");
1852 else if (advance
== -2)
1854 else if (advance
== -3)
1855 break; /* bytes left, but not enough */
1857 ND_PRINT("\n\t %s", buf
);
1859 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
1860 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
1861 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1862 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, buflen
);
1864 ND_PRINT("\n\t (illegal prefix length)");
1866 ND_PRINT("\n\t %s", buf
);
1868 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
1869 advance
= decode_rt_routing_info(ndo
, tptr
);
1871 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1872 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST_VPN
):
1873 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, buflen
);
1875 ND_PRINT("\n\t (illegal prefix length)");
1876 else if (advance
== -2)
1879 ND_PRINT("\n\t %s", buf
);
1882 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
1883 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, buflen
);
1885 ND_PRINT("\n\t (illegal prefix length)");
1886 else if (advance
== -2)
1889 ND_PRINT("\n\t %s", buf
);
1891 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
1892 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
1893 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
1895 path_id
= GET_BE_U_4(tptr
);
1898 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1900 ND_PRINT("\n\t (illegal prefix length)");
1901 else if (advance
== -2)
1902 break; /* bytes left, but not enough */
1904 ND_PRINT("\n\t %s", buf
);
1906 ND_PRINT(" Path Id: %u", path_id
);
1910 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
1911 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1913 ND_PRINT("\n\t (illegal prefix length)");
1914 else if (advance
== -2)
1916 else if (advance
== -3)
1917 break; /* bytes left, but not enough */
1919 ND_PRINT("\n\t %s", buf
);
1921 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
1922 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
1923 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1924 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, buflen
);
1926 ND_PRINT("\n\t (illegal prefix length)");
1928 ND_PRINT("\n\t %s", buf
);
1930 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1931 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1932 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1933 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1934 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, buflen
);
1936 ND_PRINT("\n\t (illegal length)");
1937 else if (advance
== -2)
1940 ND_PRINT("\n\t %s", buf
);
1942 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1943 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1944 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1945 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1947 ND_PRINT("\n\t (illegal prefix length)");
1949 ND_PRINT("\n\t %s", buf
);
1951 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1952 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1953 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1954 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1956 ND_PRINT("\n\t (illegal prefix length)");
1958 ND_PRINT("\n\t %s", buf
);
1962 * This should not happen, we should have been protected
1963 * by bgp_mp_af_print()'s return value.
1965 ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af
, safi
);
1970 trunc
: /* we rely on the caller to recognize -2 return value */
1974 static const struct tok bgp_flags
[] = {
1983 bgp_attr_print(netdissect_options
*ndo
,
1984 uint8_t atype
, const u_char
*pptr
, u_int len
,
1985 const unsigned attr_set_level
)
1987 /* allocate space for the largest possible string */
1988 char astostr
[AS_STR_SIZE
];
1991 uint8_t safi
, snpa
, nhlen
;
1995 char buf
[MAXHOSTNAMELEN
+ 100];
1997 int add_path4
, add_path6
;
2004 case BGPTYPE_ORIGIN
:
2006 ND_PRINT("invalid len");
2008 ND_PRINT("%s", tok2str(bgp_origin_values
,
2009 "Unknown Origin Typecode",
2015 * Process AS4 byte path and AS2 byte path attributes here.
2017 case BGPTYPE_AS4_PATH
:
2018 case BGPTYPE_AS_PATH
:
2020 ND_PRINT("invalid len");
2029 * BGP updates exchanged between New speakers that support 4
2030 * byte AS, ASs are always encoded in 4 bytes. There is no
2031 * definitive way to find this, just by the packet's
2032 * contents. So, check for packet's TLV's sanity assuming
2033 * 2 bytes first, and it does not pass, assume that ASs are
2034 * encoded in 4 bytes format and move on.
2036 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
2038 while (tptr
< pptr
+ len
) {
2039 ND_PRINT("%s", tok2str(bgp_as_path_segment_open_values
,
2040 "?", GET_U_1(tptr
)));
2041 for (i
= 0; i
< GET_U_1(tptr
+ 1) * as_size
; i
+= as_size
) {
2042 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
2044 as_printf(ndo
, astostr
, sizeof(astostr
),
2046 GET_BE_U_2(tptr
+ i
+ 2) :
2047 GET_BE_U_4(tptr
+ i
+ 2)));
2049 ND_PRINT("%s", tok2str(bgp_as_path_segment_close_values
,
2050 "?", GET_U_1(tptr
)));
2051 tptr
+= 2 + GET_U_1(tptr
+ 1) * as_size
;
2054 case BGPTYPE_NEXT_HOP
:
2056 ND_PRINT("invalid len");
2058 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
2061 case BGPTYPE_MULTI_EXIT_DISC
:
2062 case BGPTYPE_LOCAL_PREF
:
2064 ND_PRINT("invalid len");
2066 ND_PRINT("%u", GET_BE_U_4(tptr
));
2069 case BGPTYPE_ATOMIC_AGGREGATE
:
2071 ND_PRINT("invalid len");
2073 case BGPTYPE_AGGREGATOR
:
2076 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
2077 * the length of this PA can be either 6 bytes or 8 bytes.
2079 if (len
!= 6 && len
!= 8) {
2080 ND_PRINT("invalid len");
2083 ND_TCHECK_LEN(tptr
, len
);
2085 ND_PRINT(" AS #%s, origin %s",
2086 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(tptr
)),
2087 GET_IPADDR_STRING(tptr
+ 2));
2089 ND_PRINT(" AS #%s, origin %s",
2090 as_printf(ndo
, astostr
, sizeof(astostr
),
2091 GET_BE_U_4(tptr
)), GET_IPADDR_STRING(tptr
+ 4));
2094 case BGPTYPE_AGGREGATOR4
:
2096 ND_PRINT("invalid len");
2099 ND_PRINT(" AS #%s, origin %s",
2100 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)),
2101 GET_IPADDR_STRING(tptr
+ 4));
2103 case BGPTYPE_COMMUNITIES
:
2105 ND_PRINT("invalid len");
2113 comm
= GET_BE_U_4(tptr
);
2115 case BGP_COMMUNITY_NO_EXPORT
:
2116 ND_PRINT(" NO_EXPORT");
2118 case BGP_COMMUNITY_NO_ADVERT
:
2119 ND_PRINT(" NO_ADVERTISE");
2121 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
2122 ND_PRINT(" NO_EXPORT_SUBCONFED");
2126 (comm
>> 16) & 0xffff,
2128 (tlen
>4) ? ", " : "");
2135 case BGPTYPE_ORIGINATOR_ID
:
2137 ND_PRINT("invalid len");
2140 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2142 case BGPTYPE_CLUSTER_LIST
:
2144 ND_PRINT("invalid len");
2151 GET_IPADDR_STRING(tptr
),
2152 (tlen
>4) ? ", " : "");
2157 case BGPTYPE_MP_REACH_NLRI
:
2161 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2173 nhlen
= GET_U_1(tptr
);
2179 uint8_t tnhlen
= nhlen
;
2182 ND_PRINT("\n\t nexthop: ");
2183 while (tnhlen
!= 0) {
2187 switch(af
<<8 | safi
) {
2188 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
2189 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
2190 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
2191 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
2192 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
2193 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
):
2194 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
2195 if (tnhlen
< sizeof(nd_ipv4
)) {
2196 ND_PRINT("invalid len");
2201 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2202 tptr
+= sizeof(nd_ipv4
);
2203 tnhlen
-= sizeof(nd_ipv4
);
2204 tlen
-= sizeof(nd_ipv4
);
2207 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
2208 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
2209 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2210 if (tnhlen
< sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
) {
2211 ND_PRINT("invalid len");
2216 ND_PRINT("RD: %s, %s",
2217 bgp_vpn_rd_print(ndo
, tptr
),
2218 GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2219 tptr
+= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2220 tlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2221 tnhlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2224 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
2225 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
2226 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
2227 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
2228 if (tnhlen
< sizeof(nd_ipv6
)) {
2229 ND_PRINT("invalid len");
2234 ND_PRINT("%s", GET_IP6ADDR_STRING(tptr
));
2235 tptr
+= sizeof(nd_ipv6
);
2236 tlen
-= sizeof(nd_ipv6
);
2237 tnhlen
-= sizeof(nd_ipv6
);
2240 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
2241 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
2242 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2243 if (tnhlen
< sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
) {
2244 ND_PRINT("invalid len");
2249 ND_PRINT("RD: %s, %s",
2250 bgp_vpn_rd_print(ndo
, tptr
),
2251 GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2252 tptr
+= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2253 tlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2254 tnhlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2257 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2258 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2259 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2260 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2261 if (tnhlen
< sizeof(nd_ipv4
)) {
2262 ND_PRINT("invalid len");
2267 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
2268 tptr
+= (sizeof(nd_ipv4
));
2269 tlen
-= (sizeof(nd_ipv4
));
2270 tnhlen
-= (sizeof(nd_ipv4
));
2273 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2274 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2275 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2276 ND_PRINT("%s", GET_ISONSAP_STRING(tptr
, tnhlen
));
2282 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2283 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2284 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2285 if (tnhlen
< BGP_VPN_RD_LEN
+1) {
2286 ND_PRINT("invalid len");
2291 ND_TCHECK_LEN(tptr
, tnhlen
);
2292 ND_PRINT("RD: %s, %s",
2293 bgp_vpn_rd_print(ndo
, tptr
),
2294 GET_ISONSAP_STRING(tptr
+BGP_VPN_RD_LEN
,tnhlen
-BGP_VPN_RD_LEN
));
2295 /* rfc986 mapped IPv4 address ? */
2296 if (GET_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
2297 ND_PRINT(" = %s", GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
+4));
2298 /* rfc1888 mapped IPv6 address ? */
2299 else if (GET_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
2300 ND_PRINT(" = %s", GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
+3));
2308 * bgp_mp_af_print() should have saved us from
2309 * an unsupported AFI/SAFI.
2311 ND_PRINT("ERROR: no AFI %u/SAFI %u nexthop decoder", af
, safi
);
2320 ND_PRINT(", nh-length: %u", nhlen
);
2322 /* As per RFC 2858; this is reserved in RFC 4760 */
2325 snpa
= GET_U_1(tptr
);
2330 ND_PRINT("\n\t %u SNPA", snpa
);
2331 for (/*nothing*/; snpa
!= 0; snpa
--) {
2335 snpalen
= GET_U_1(tptr
);
2336 ND_PRINT("\n\t %u bytes", snpalen
);
2341 ND_TCHECK_LEN(tptr
, snpalen
);
2346 ND_PRINT(", no SNPA");
2349 add_path4
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 32);
2350 add_path6
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 128);
2352 while (tptr
< pptr
+ len
) {
2353 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2354 add_path4
, add_path6
);
2363 case BGPTYPE_MP_UNREACH_NLRI
:
2364 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
2365 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2371 if (len
== BGP_MP_NLRI_MINSIZE
)
2372 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2376 add_path4
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 32);
2377 add_path6
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 128);
2379 while (tptr
< pptr
+ len
) {
2380 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2381 add_path4
, add_path6
);
2389 case BGPTYPE_EXTD_COMMUNITIES
:
2391 ND_PRINT("invalid len");
2400 extd_comm
=GET_BE_U_2(tptr
);
2402 ND_PRINT("\n\t %s (0x%04x), Flags [%s]",
2403 tok2str(bgp_extd_comm_subtype_values
,
2404 "unknown extd community typecode",
2407 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
2413 bgp_extended_community_print(ndo
, tptr
);
2419 case BGPTYPE_PMSI_TUNNEL
:
2421 uint8_t tunnel_type
, flags
;
2426 flags
= GET_U_1(tptr
);
2427 tunnel_type
= GET_U_1(tptr
+ 1);
2429 ND_PRINT("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2430 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2432 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2433 GET_BE_U_3(tptr
+ 2)>>4);
2438 switch (tunnel_type
) {
2439 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2440 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2441 ND_PRINT("\n\t Sender %s, P-Group %s",
2442 GET_IPADDR_STRING(tptr
),
2443 GET_IPADDR_STRING(tptr
+4));
2446 case BGP_PMSI_TUNNEL_PIM_SSM
:
2447 ND_PRINT("\n\t Root-Node %s, P-Group %s",
2448 GET_IPADDR_STRING(tptr
),
2449 GET_IPADDR_STRING(tptr
+4));
2451 case BGP_PMSI_TUNNEL_INGRESS
:
2452 ND_PRINT("\n\t Tunnel-Endpoint %s",
2453 GET_IPADDR_STRING(tptr
));
2455 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2456 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2457 ND_PRINT("\n\t Root-Node %s, LSP-ID 0x%08x",
2458 GET_IPADDR_STRING(tptr
),
2459 GET_BE_U_4(tptr
+ 4));
2461 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2462 ND_PRINT("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2463 GET_IPADDR_STRING(tptr
),
2464 GET_BE_U_4(tptr
+ 4));
2467 if (ndo
->ndo_vflag
<= 1) {
2468 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2479 type
= GET_U_1(tptr
);
2480 length
= GET_BE_U_2(tptr
+ 1);
2484 ND_PRINT("\n\t %s TLV (%u), length %u",
2485 tok2str(bgp_aigp_values
, "Unknown", type
),
2493 * Check if we can read the TLV data.
2503 ND_PRINT(", metric %" PRIu64
,
2508 if (ndo
->ndo_vflag
<= 1) {
2509 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2518 case BGPTYPE_ATTR_SET
:
2522 ND_PRINT("\n\t Origin AS: %s",
2523 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)));
2528 u_int aflags
, alenlen
, alen
;
2532 ND_PRINT(" [path attr too short]");
2536 aflags
= GET_U_1(tptr
);
2537 atype
= GET_U_1(tptr
+ 1);
2540 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2541 ND_TCHECK_LEN(tptr
, alenlen
);
2542 if (len
< alenlen
) {
2543 ND_PRINT(" [path attr too short]");
2547 alen
= bgp_attr_len(aflags
, tptr
);
2551 ND_PRINT("\n\t %s (%u), length: %u",
2552 tok2str(bgp_attr_values
,
2553 "Unknown Attribute", atype
),
2558 ND_PRINT(", Flags [%s",
2559 bittok2str_nosep(bgp_flags
, "", aflags
));
2561 ND_PRINT("+%x", aflags
& 0xf);
2566 ND_PRINT(" [path attr too short]");
2571 * The protocol encoding per se allows ATTR_SET to be nested
2572 * as many times as the message can accommodate. This printer
2573 * used to be able to recurse into ATTR_SET contents until the
2574 * stack exhaustion, but now there is a limit on that (if live
2575 * protocol exchange goes that many levels deep, something is
2576 * probably wrong anyway). Feel free to refine this value if
2577 * you can find the spec with respective normative text.
2579 if (attr_set_level
== 10)
2580 ND_PRINT("(too many nested levels, not recursing)");
2581 else if (!bgp_attr_print(ndo
, atype
, tptr
, alen
, attr_set_level
+ 1))
2588 case BGPTYPE_LARGE_COMMUNITY
:
2589 if (len
== 0 || len
% 12) {
2590 ND_PRINT("invalid len");
2595 ND_PRINT("%u:%u:%u%s",
2597 GET_BE_U_4(tptr
+ 4),
2598 GET_BE_U_4(tptr
+ 8),
2599 (len
> 12) ? ", " : "");
2602 * len will always be a multiple of 12, as per the above,
2603 * so this will never underflow.
2608 case BGPTYPE_BGPSEC_PATH
:
2610 uint16_t sblen
, splen
;
2612 splen
= GET_BE_U_2(tptr
);
2615 * A secure path has a minimum length of 8 bytes:
2616 * 2 bytes length field
2617 * 6 bytes per secure path segment
2619 ND_ICHECKMSG_U("secure path length", splen
, <, 8);
2621 ND_PRINT("\n\t Secure Path Length: %u", splen
);
2625 /* Make sure the secure path length does not signal trailing bytes */
2627 ND_PRINT(" [total segments length %u != N x 6]", splen
);
2631 /* Parse secure path segments */
2632 while (splen
!= 0) {
2633 uint8_t pcount
= GET_U_1(tptr
);
2634 uint8_t flags
= GET_U_1(tptr
+ 1);
2635 uint32_t asn
= GET_BE_U_4(tptr
+ 2);
2636 ND_PRINT("\n\t Secure Path Segment: pCount: %u, Flags: [%s] (0x%02x), AS: %u",
2638 bittok2str(bgp_bgpsec_bitmap_str
, "none", flags
),
2645 sblen
= GET_BE_U_2(tptr
);
2647 ND_PRINT("\n\t Signature Block: Length: %u, Algo ID: %u",
2653 /* Parse signature segments */
2657 ND_PRINT("\n\t Signature Segment:\n\t SKI: ");
2658 ND_ICHECKMSG_U("remaining length", sblen
, <, 20);
2659 hex_print(ndo
, "\n\t ", tptr
, 20);
2662 ND_ICHECKMSG_U("remaining length", sblen
, <, 2);
2663 siglen
= GET_BE_U_2(tptr
);
2667 ND_PRINT("\n\t Length: %u", siglen
);
2668 ND_ICHECKMSG_U("remaining length", sblen
, <, siglen
);
2669 ND_PRINT("\n\t Signature:");
2670 hex_print(ndo
, "\n\t ", tptr
, siglen
);
2679 ND_PRINT("invalid len");
2682 ND_PRINT("\n\t OTC %u", GET_BE_U_4(pptr
));
2686 ND_TCHECK_LEN(pptr
, len
);
2687 ND_PRINT("\n\t no Attribute %u decoder", atype
); /* we have no decoder for the attribute */
2688 if (ndo
->ndo_vflag
<= 1)
2689 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2693 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2694 ND_TCHECK_LEN(pptr
, len
);
2695 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2700 nd_print_invalid(ndo
);
2708 bgp_capabilities_print(netdissect_options
*ndo
,
2709 const u_char
*opt
, u_int caps_len
)
2711 /* allocate space for the largest possible string */
2712 char astostr
[AS_STR_SIZE
];
2713 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2716 while (i
< caps_len
) {
2717 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2718 cap_type
=GET_U_1(opt
+ i
);
2719 cap_len
=GET_U_1(opt
+ i
+ 1);
2720 ND_PRINT("\n\t %s (%u), length: %u",
2721 tok2str(bgp_capcode_values
, "Unknown", cap_type
),
2724 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2726 case BGP_CAPCODE_MP
:
2727 /* AFI (16 bits), Reserved (8 bits), SAFI (8 bits) */
2729 ND_PRINT(" (too short, < 4)");
2732 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u)",
2733 tok2str(af_values
, "Unknown", GET_BE_U_2(opt
+ i
+ 2)),
2734 GET_BE_U_2(opt
+ i
+ 2),
2735 tok2str(bgp_safi_values
, "Unknown", GET_U_1(opt
+ i
+ 5)),
2736 GET_U_1(opt
+ i
+ 5));
2738 case BGP_CAPCODE_BGPSEC
:
2739 /* Version (4 bits), Direction (1 bit), Flags (3 bits), AFI (16 bits) */
2741 /* The capability length [...] MUST be set to 3. */
2743 ND_PRINT(" [%u != 3]", cap_len
);
2747 ND_PRINT("\n\t\tVersion %u, Direction %s (%u), AFI %s (%u)",
2748 GET_U_1(opt
+ i
+ 2)&0xf0,
2749 (GET_U_1(opt
+ i
+ 2)&0x08) ? "Send" : "Receive",
2750 (GET_U_1(opt
+ i
+ 2)&0x08)>>3,
2751 bittok2str(af_values
, "Unknown",
2752 GET_BE_U_2(opt
+ i
+ cap_offset
+ 2)),
2753 GET_BE_U_2(opt
+ i
+ cap_offset
+ 2));
2755 case BGP_CAPCODE_ML
:
2758 while (tcap_len
>= 4) {
2759 ND_PRINT( "\n\t\tAFI %s (%u), SAFI %s (%u), Count: %u",
2760 tok2str(af_values
, "Unknown",
2761 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2762 GET_BE_U_2(opt
+ i
+ cap_offset
),
2763 tok2str(bgp_safi_values
, "Unknown",
2764 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2765 GET_U_1(opt
+ i
+ cap_offset
+ 2),
2766 GET_U_1(opt
+ i
+ cap_offset
+ 3));
2771 case BGP_CAPCODE_RESTART
:
2772 /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */
2774 ND_PRINT(" (too short, < 2)");
2778 ND_PRINT("\n\t\tRestart Flags: [%s], Restart Time %us",
2779 bittok2str(bgp_graceful_restart_comm_flag_values
,
2780 "none", GET_U_1(opt
+ i
+ 2) >> 4),
2781 GET_BE_U_2(opt
+ i
+ 2)&0xfff);
2784 while(tcap_len
>=4) {
2785 ND_PRINT("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2786 tok2str(af_values
,"Unknown",
2787 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2788 GET_BE_U_2(opt
+ i
+ cap_offset
),
2789 tok2str(bgp_safi_values
,"Unknown",
2790 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2791 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2792 ((GET_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" );
2797 case BGP_CAPCODE_ROLE
:
2799 ND_PRINT(" (too short, < 1)");
2802 ND_PRINT("\n\t\tRole name %s (%u)",
2803 tok2str(bgp_role_values
, "Unassigned",
2804 GET_U_1(opt
+ i
+ 2)), GET_U_1(opt
+ i
+ 2));
2806 case BGP_CAPCODE_RR
:
2807 case BGP_CAPCODE_LLGR
:
2808 case BGP_CAPCODE_RR_CISCO
:
2809 case BGP_CAPCODE_EXT_MSG
:
2810 case BGP_CAPCODE_ENH_RR
:
2812 case BGP_CAPCODE_AS_NEW
:
2814 * Extract the 4 byte AS number encoded.
2817 ND_PRINT(" (too short, < 4)");
2820 ND_PRINT("\n\t\t 4 Byte AS %s",
2821 as_printf(ndo
, astostr
, sizeof(astostr
),
2822 GET_BE_U_4(opt
+ i
+ 2)));
2824 case BGP_CAPCODE_ADD_PATH
:
2826 ND_PRINT(" (bogus)"); /* length */
2831 while (tcap_len
!= 0) {
2833 nd_print_invalid(ndo
);
2836 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2837 tok2str(af_values
,"Unknown",GET_BE_U_2(opt
+ i
+ cap_offset
)),
2838 GET_BE_U_2(opt
+ i
+ cap_offset
),
2839 tok2str(bgp_safi_values
,"Unknown",GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2840 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2841 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",GET_U_1(opt
+ i
+ cap_offset
+ 3))
2848 ND_PRINT("\n\t\tno decoder for Capability %u",
2850 if (ndo
->ndo_vflag
<= 1)
2851 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2855 if (ndo
->ndo_vflag
> 1 && cap_len
!= 0) {
2856 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2858 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2863 nd_print_trunc(ndo
);
2867 bgp_open_print(netdissect_options
*ndo
,
2868 const u_char
*dat
, u_int length
)
2870 /* allocate space for the largest possible string */
2871 char astostr
[AS_STR_SIZE
];
2872 const struct bgp_open
*bgp_open_header
;
2875 const struct bgp_opt
*bgpopt
;
2878 uint8_t extended_opt_params
= 0;
2879 u_int open_size
= BGP_OPEN_SIZE
;
2880 u_int opt_size
= BGP_OPT_SIZE
;
2882 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2883 if (length
< BGP_OPEN_SIZE
)
2886 bgp_open_header
= (const struct bgp_open
*)dat
;
2888 ND_PRINT("\n\t Version %u, ",
2889 GET_U_1(bgp_open_header
->bgpo_version
));
2890 ND_PRINT("my AS %s, ",
2891 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(bgp_open_header
->bgpo_myas
)));
2892 ND_PRINT("Holdtime %us, ",
2893 GET_BE_U_2(bgp_open_header
->bgpo_holdtime
));
2894 ND_PRINT("ID %s", GET_IPADDR_STRING(bgp_open_header
->bgpo_id
));
2895 optslen
= GET_U_1(bgp_open_header
->bgpo_optlen
);
2896 opsttype
= GET_U_1(bgp_open_header
->bgpo_opttype
);
2897 if (opsttype
== BGP_OPEN_NON_EXT_OPT_TYPE_EXTENDED_LENGTH
) {
2898 optslen
= GET_BE_U_2(bgp_open_header
->bgpo_optlen_extended
);
2899 extended_opt_params
= 1;
2903 ND_PRINT("\n\t Optional parameters%s, length: %u",
2904 extended_opt_params
? " (Extended)" : "", optslen
);
2906 opt
= dat
+ open_size
;
2907 length
-= open_size
;
2910 while (i
< optslen
) {
2914 ND_TCHECK_LEN(opt
+ i
, opt_size
);
2915 if (length
< opt_size
+ i
)
2917 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2918 opt_type
= GET_U_1(bgpopt
->bgpopt_type
);
2919 opt_len
= extended_opt_params
? GET_BE_U_2(bgpopt
->bgpopt_len
)
2920 : GET_U_1(bgpopt
->bgpopt_len
);
2921 if (opt_size
+ i
+ opt_len
> optslen
) {
2922 ND_PRINT("\n\t Option %u, length: %u, goes past the end of the options",
2927 ND_PRINT("\n\t Option %s (%u), length: %u",
2928 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2932 /* now let's decode the options we know*/
2936 bgp_capabilities_print(ndo
, opt
+ opt_size
+ i
,
2942 ND_PRINT("\n\t no decoder for option %u",
2946 i
+= opt_size
+ opt_len
;
2950 nd_print_trunc(ndo
);
2954 bgp_update_print(netdissect_options
*ndo
,
2955 const u_char
*dat
, u_int length
)
2958 u_int withdrawn_routes_len
;
2959 char buf
[MAXHOSTNAMELEN
+ 100];
2966 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2967 if (length
< BGP_SIZE
)
2972 /* Unfeasible routes */
2976 withdrawn_routes_len
= GET_BE_U_2(p
);
2979 if (withdrawn_routes_len
> 1) {
2981 * Without keeping state from the original NLRI message,
2982 * it's not possible to tell if this a v4 or v6 route,
2983 * so only try to decode it if we're not v6 enabled.
2985 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2986 if (length
< withdrawn_routes_len
)
2988 ND_PRINT("\n\t Withdrawn routes:");
2989 add_path
= check_add_path(ndo
, p
, withdrawn_routes_len
, 32);
2990 while (withdrawn_routes_len
!= 0) {
2992 if (withdrawn_routes_len
< 4) {
2993 p
+= withdrawn_routes_len
;
2994 length
-= withdrawn_routes_len
;
2997 path_id
= GET_BE_U_4(p
);
3000 withdrawn_routes_len
-= 4;
3002 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
3004 ND_PRINT("\n\t (illegal prefix length)");
3006 } else if (wpfx
== -2)
3007 goto trunc
; /* bytes left, but not enough */
3009 ND_PRINT("\n\t %s", buf
);
3011 ND_PRINT(" Path Id: %u", path_id
);
3015 withdrawn_routes_len
-= wpfx
;
3019 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
3020 if (length
< withdrawn_routes_len
)
3022 p
+= withdrawn_routes_len
;
3023 length
-= withdrawn_routes_len
;
3029 len
= GET_BE_U_2(p
);
3033 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
3034 /* No withdrawn routes, no path attributes, no NLRI */
3035 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
3040 /* Make sure the path attributes don't go past the end of the packet */
3043 /* do something more useful!*/
3045 uint8_t aflags
, atype
, alenlen
;
3052 ND_PRINT("\n\t [path attrs too short]");
3057 aflags
= GET_U_1(p
);
3058 atype
= GET_U_1(p
+ 1);
3062 alenlen
= bgp_attr_lenlen(aflags
, p
);
3063 ND_TCHECK_LEN(p
, alenlen
);
3064 if (length
< alenlen
)
3066 if (len
< alenlen
) {
3067 ND_PRINT("\n\t [path attrs too short]");
3072 alen
= bgp_attr_len(aflags
, p
);
3077 ND_PRINT("\n\t %s (%u), length: %u",
3078 tok2str(bgp_attr_values
, "Unknown Attribute", atype
),
3083 ND_PRINT(", Flags [%s",
3084 bittok2str_nosep(bgp_flags
, "", aflags
));
3086 ND_PRINT("+%x", aflags
& 0xf);
3090 ND_PRINT(" [path attrs too short]");
3097 if (!bgp_attr_print(ndo
, atype
, p
, alen
, 0))
3106 add_path
= check_add_path(ndo
, p
, length
, 32);
3107 ND_PRINT("\n\t Updated routes:");
3108 while (length
!= 0) {
3113 path_id
= GET_BE_U_4(p
);
3117 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
3119 ND_PRINT("\n\t (illegal prefix length)");
3122 goto trunc
; /* bytes left, but not enough */
3124 ND_PRINT("\n\t %s", buf
);
3126 ND_PRINT(" Path Id: %u", path_id
);
3135 nd_print_trunc(ndo
);
3139 bgp_notification_print_code(netdissect_options
*ndo
,
3140 const u_char
*dat
, u_int length
,
3141 uint8_t bgpn_major
, uint8_t bgpn_minor
)
3143 ND_PRINT(", %s (%u)",
3144 tok2str(bgp_notify_major_values
, "Unknown Error",
3148 switch (bgpn_major
) {
3150 case BGP_NOTIFY_MAJOR_MSG
:
3151 ND_PRINT(", subcode %s (%u)",
3152 tok2str(bgp_notify_minor_msg_values
, "Unknown",
3156 case BGP_NOTIFY_MAJOR_OPEN
:
3157 ND_PRINT(", subcode %s (%u)",
3158 tok2str(bgp_notify_minor_open_values
, "Unknown",
3162 case BGP_NOTIFY_MAJOR_UPDATE
:
3163 ND_PRINT(", subcode %s (%u)",
3164 tok2str(bgp_notify_minor_update_values
, "Unknown",
3168 case BGP_NOTIFY_MAJOR_FSM
:
3169 ND_PRINT(" subcode %s (%u)",
3170 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
3174 case BGP_NOTIFY_MAJOR_CAP
:
3175 ND_PRINT(" subcode %s (%u)",
3176 tok2str(bgp_notify_minor_cap_values
, "Unknown",
3180 case BGP_NOTIFY_MAJOR_CEASE
:
3181 ND_PRINT(", subcode %s (%u)",
3182 tok2str(bgp_notify_minor_cease_values
, "Unknown",
3186 /* RFC 4486 mentions optionally 7 bytes
3187 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
3189 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= 7) {
3190 ND_PRINT(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
3191 tok2str(af_values
, "Unknown", GET_BE_U_2(dat
)),
3193 tok2str(bgp_safi_values
, "Unknown", GET_U_1((dat
+ 2))),
3195 GET_BE_U_4(dat
+ 3));
3198 * RFC 9003 describes a method to send a communication
3199 * intended for human consumption regarding the Administrative Shutdown
3201 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
3202 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
3204 uint8_t shutdown_comm_length
= GET_U_1(dat
);
3205 uint8_t remainder_offset
= 0;
3206 /* garbage, hexdump it all */
3207 if (shutdown_comm_length
> length
- 1) {
3208 ND_PRINT(", invalid Shutdown Communication length");
3210 else if (shutdown_comm_length
== 0) {
3211 ND_PRINT(", empty Shutdown Communication");
3212 remainder_offset
+= 1;
3214 /* a proper shutdown communication */
3216 ND_PRINT(", Shutdown Communication (length: %u): \"", shutdown_comm_length
);
3217 nd_printjn(ndo
, dat
+1, shutdown_comm_length
);
3219 remainder_offset
+= shutdown_comm_length
+ 1;
3221 /* if there is trailing data, hexdump it */
3222 if(length
- remainder_offset
> 0) {
3223 ND_PRINT(", Data: (length: %u)", length
- remainder_offset
);
3224 hex_print(ndo
, "\n\t\t", dat
+ remainder_offset
, length
- remainder_offset
);
3228 * RFC8538 describes the Hard Reset cease subcode, which contains another
3229 * notification code and subcode.
3231 if (bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_HARDRESET
&& length
>= 2) {
3232 bgpn_major
= GET_U_1(dat
++);
3233 bgpn_minor
= GET_U_1(dat
++);
3235 bgp_notification_print_code(ndo
, dat
, length
, bgpn_major
, bgpn_minor
);
3239 if (bgpn_minor
!= 0) {
3240 ND_PRINT(", subcode %u", bgpn_minor
);
3249 bgp_notification_print(netdissect_options
*ndo
,
3250 const u_char
*dat
, u_int length
)
3252 const struct bgp_notification
*bgp_notification_header
;
3253 uint8_t bgpn_major
, bgpn_minor
;
3255 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
3256 if (length
<BGP_NOTIFICATION_SIZE
)
3259 bgp_notification_header
= (const struct bgp_notification
*)dat
;
3260 bgpn_major
= GET_U_1(bgp_notification_header
->bgpn_major
);
3261 bgpn_minor
= GET_U_1(bgp_notification_header
->bgpn_minor
);
3262 bgp_notification_print_code(ndo
, dat
+ BGP_NOTIFICATION_SIZE
,
3263 length
- BGP_NOTIFICATION_SIZE
, bgpn_major
, bgpn_minor
);
3266 nd_print_trunc(ndo
);
3270 bgp_route_refresh_print(netdissect_options
*ndo
,
3271 const u_char
*pptr
, u_int len
)
3273 const struct bgp_route_refresh
*bgp_route_refresh_header
;
3275 /* some little sanity checking */
3276 if (len
<BGP_ROUTE_REFRESH_SIZE
)
3279 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
3281 ND_PRINT("\n\t AFI %s (%u), SAFI %s (%u), Subtype %s (%u)",
3282 tok2str(af_values
, "Unknown",
3283 GET_BE_U_2(bgp_route_refresh_header
->afi
)),
3284 GET_BE_U_2(bgp_route_refresh_header
->afi
),
3285 tok2str(bgp_safi_values
, "Unknown",
3286 GET_U_1(bgp_route_refresh_header
->safi
)),
3287 GET_U_1(bgp_route_refresh_header
->safi
),
3288 tok2str(bgp_route_refresh_subtype_values
, "Unknown",
3289 GET_U_1(bgp_route_refresh_header
->subtype
)),
3290 GET_U_1(bgp_route_refresh_header
->subtype
));
3293 if (len
>= BGP_ROUTE_REFRESH_SIZE_ORF
) {
3294 const struct bgp_route_refresh_orf
*orf_header
;
3297 (const struct bgp_route_refresh_orf
*)(pptr
+ BGP_ROUTE_REFRESH_SIZE
);
3299 ND_PRINT("\n\t ORF refresh %s (%u), ORF type %s (%u), ORF length %u",
3300 tok2str(bgp_orf_refresh_type
, "Unknown",
3301 GET_U_1(orf_header
->refresh
)),
3302 GET_U_1(orf_header
->refresh
),
3303 tok2str(bgp_orf_type
, "Unknown", GET_U_1(orf_header
->type
)),
3304 GET_U_1(orf_header
->type
), GET_BE_U_2(orf_header
->len
));
3307 if (ndo
->ndo_vflag
> 1) {
3308 ND_TCHECK_LEN(pptr
, len
);
3309 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
3314 nd_print_trunc(ndo
);
3318 bgp_pdu_print(netdissect_options
*ndo
,
3319 const u_char
*dat
, u_int length
)
3321 const struct bgp
*bgp_header
;
3324 ND_TCHECK_LEN(dat
, BGP_SIZE
);
3325 bgp_header
= (const struct bgp
*)dat
;
3326 bgp_type
= GET_U_1(bgp_header
->bgp_type
);
3328 ND_PRINT("\n\t%s Message (%u), length: %u",
3329 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
3335 bgp_open_print(ndo
, dat
, length
);
3338 bgp_update_print(ndo
, dat
, length
);
3340 case BGP_NOTIFICATION
:
3341 bgp_notification_print(ndo
, dat
, length
);
3345 case BGP_ROUTE_REFRESH
:
3346 bgp_route_refresh_print(ndo
, dat
, length
);
3349 /* we have no decoder for the BGP message */
3350 ND_TCHECK_LEN(dat
, length
);
3351 ND_PRINT("\n\t no Message %u decoder", bgp_type
);
3352 print_unknown_data(ndo
, dat
, "\n\t ", length
);
3357 nd_print_trunc(ndo
);
3362 bgp_print(netdissect_options
*ndo
,
3363 const u_char
*dat
, u_int length _U_
)
3366 const u_char
*ep
= ndo
->ndo_snapend
;
3367 const u_char
*start
;
3368 const u_char marker
[] = {
3369 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3370 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3372 const struct bgp
*bgp_header
;
3375 ndo
->ndo_protocol
= "bgp";
3378 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
3386 if (GET_U_1(p
) != 0xff) {
3391 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
3393 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
3398 /* found BGP header */
3399 ND_TCHECK_LEN(p
, BGP_SIZE
);
3400 bgp_header
= (const struct bgp
*)p
;
3403 nd_print_trunc(ndo
);
3405 hlen
= GET_BE_U_2(bgp_header
->bgp_len
);
3406 if (hlen
< BGP_SIZE
) {
3407 ND_PRINT("\nmessage length %u < %u", hlen
, BGP_SIZE
);
3408 nd_print_invalid(ndo
);
3412 if (ND_TTEST_LEN(p
, hlen
)) {
3413 if (!bgp_pdu_print(ndo
, p
, hlen
))
3418 ND_PRINT("\n[|BGP %s]",
3419 tok2str(bgp_msg_values
,
3420 "Unknown Message Type",
3421 GET_U_1(bgp_header
->bgp_type
)));
3429 nd_print_trunc(ndo
);