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 if (route_length
< BGP_VPN_RD_LEN
)
1273 offset
= (u_int
)strlen(buf
);
1274 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
1275 bgp_vpn_rd_print(ndo
, pptr
),
1276 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
1277 (route_length
- BGP_VPN_RD_LEN
) << 3));
1279 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
1280 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1281 offset
= (u_int
)strlen(buf
);
1282 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1283 bgp_vpn_rd_print(ndo
, pptr
),
1284 as_printf(ndo
, astostr
, sizeof(astostr
),
1285 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1288 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
1289 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1290 offset
= (u_int
)strlen(buf
);
1291 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1292 bgp_vpn_rd_print(ndo
, pptr
));
1293 pptr
+= BGP_VPN_RD_LEN
;
1295 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1296 addr_length
= route_length
- sg_length
;
1298 ND_TCHECK_LEN(pptr
, addr_length
);
1299 offset
= (u_int
)strlen(buf
);
1300 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
1301 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
1304 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
1305 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1306 offset
= (u_int
)strlen(buf
);
1307 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1308 bgp_vpn_rd_print(ndo
, pptr
));
1309 pptr
+= BGP_VPN_RD_LEN
;
1311 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1314 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
1315 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
1316 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1317 offset
= (u_int
)strlen(buf
);
1318 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1319 bgp_vpn_rd_print(ndo
, pptr
),
1320 as_printf(ndo
, astostr
, sizeof(astostr
),
1321 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1322 pptr
+= BGP_VPN_RD_LEN
+ 4;
1324 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1328 * no per route-type printing yet.
1330 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1335 return route_length
+ 2;
1342 * As I remember, some versions of systems have an snprintf() that
1343 * returns -1 if the buffer would have overflowed. If the return
1344 * value is negative, set buflen to 0, to indicate that we've filled
1347 * If the return value is greater than buflen, that means that
1348 * the buffer would have overflowed; again, set buflen to 0 in
1351 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1354 else if ((u_int)stringlen>buflen) \
1357 buflen-=stringlen; \
1362 decode_labeled_vpn_l2(netdissect_options
*ndo
,
1363 const u_char
*pptr
, char *buf
, size_t buflen
)
1365 u_int plen
, tlen
, tlv_type
, tlv_len
, ttlv_len
;
1368 plen
= GET_BE_U_2(pptr
);
1371 /* Old and new L2VPN NLRI share AFI/SAFI
1372 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1373 * and > 17 as old format. Complain for the middle case
1376 /* assume AD-only with RD, BGPNH */
1377 ND_TCHECK_LEN(pptr
, 12);
1379 stringlen
= snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
1380 bgp_vpn_rd_print(ndo
, pptr
),
1381 GET_IPADDR_STRING(pptr
+8));
1382 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1386 } else if (plen
> 17) {
1387 /* assume old format */
1388 /* RD, ID, LBLKOFF, LBLBASE */
1390 ND_TCHECK_LEN(pptr
, 15);
1392 stringlen
= snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1393 bgp_vpn_rd_print(ndo
, pptr
),
1394 GET_BE_U_2(pptr
+ 8),
1395 GET_BE_U_2(pptr
+ 10),
1396 GET_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1397 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1401 /* ok now the variable part - lets read out TLVs*/
1405 stringlen
=snprintf(buf
,buflen
, "\n\t\tran past the end");
1406 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1410 tlv_type
= GET_U_1(pptr
);
1412 tlv_len
= GET_BE_U_2(pptr
); /* length, in *bits* */
1413 ttlv_len
= (tlv_len
+ 7)/8; /* length, in *bytes* */
1419 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1422 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1424 while (ttlv_len
!= 0) {
1427 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1428 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1434 stringlen
=snprintf(buf
,buflen
, "%02x",
1437 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1445 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1448 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1450 if (tlen
< ttlv_len
) {
1452 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1453 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1463 /* complain bitterly ? */
1473 decode_prefix6(netdissect_options
*ndo
,
1474 const u_char
*pd
, u_int itemlen
, char *buf
, size_t buflen
)
1477 u_int plen
, plenbytes
;
1485 memset(&addr
, 0, sizeof(addr
));
1486 plenbytes
= (plen
+ 7) / 8;
1487 ITEMCHECK(plenbytes
);
1488 GET_CPY_BYTES(&addr
, pd
+ 1, plenbytes
);
1490 addr
[plenbytes
- 1] &=
1491 ((0xff00 >> (plen
% 8)) & 0xff);
1493 snprintf(buf
, buflen
, "%s/%u", ip6addr_string(ndo
, (const u_char
*)&addr
), plen
);
1494 return 1 + plenbytes
;
1501 decode_labeled_prefix6(netdissect_options
*ndo
,
1502 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
1505 u_int plen
, plenbytes
;
1507 /* prefix length and label = 4 bytes */
1510 plen
= GET_U_1(pptr
); /* get prefix length */
1515 plen
-= 24; /* adjust prefixlen - labellength */
1521 memset(&addr
, 0, sizeof(addr
));
1522 plenbytes
= (plen
+ 7) / 8;
1523 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
1525 addr
[plenbytes
- 1] &=
1526 ((0xff00 >> (plen
% 8)) & 0xff);
1528 /* the label may get offsetted by 4 bits so lets shift it right */
1529 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
1530 ip6addr_string(ndo
, (const u_char
*)&addr
),
1532 GET_BE_U_3(pptr
+ 1)>>4,
1533 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1535 return 4 + plenbytes
;
1545 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1546 const u_char
*pptr
, char *buf
, size_t buflen
)
1551 plen
= GET_U_1(pptr
); /* get prefix length */
1556 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1561 memset(&addr
, 0, sizeof(addr
));
1562 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1564 addr
[(plen
+ 7) / 8 - 1] &=
1565 ((0xff00 >> (plen
% 8)) & 0xff);
1567 /* the label may get offsetted by 4 bits so lets shift it right */
1568 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1569 bgp_vpn_rd_print(ndo
, pptr
+4),
1570 ip6addr_string(ndo
, (const u_char
*)&addr
),
1572 GET_BE_U_3(pptr
+ 1)>>4,
1573 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1575 return 12 + (plen
+ 7) / 8;
1579 decode_clnp_prefix(netdissect_options
*ndo
,
1580 const u_char
*pptr
, char *buf
, size_t buflen
)
1585 plen
= GET_U_1(pptr
); /* get prefix length */
1590 memset(&addr
, 0, sizeof(addr
));
1591 GET_CPY_BYTES(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1593 addr
[(plen
+ 7) / 8 - 1] &=
1594 ((0xff00 >> (plen
% 8)) & 0xff);
1596 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1597 snprintf(buf
, buflen
, "%s/%u",
1598 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1601 return 1 + (plen
+ 7) / 8;
1605 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1606 const u_char
*pptr
, char *buf
, size_t buflen
)
1611 plen
= GET_U_1(pptr
); /* get prefix length */
1616 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1621 memset(&addr
, 0, sizeof(addr
));
1622 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1624 addr
[(plen
+ 7) / 8 - 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
1626 /* the label may get offsetted by 4 bits so lets shift it right */
1627 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1628 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1629 bgp_vpn_rd_print(ndo
, pptr
+4),
1630 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1632 GET_BE_U_3(pptr
+ 1)>>4,
1633 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1635 return 12 + (plen
+ 7) / 8;
1639 * bgp_attr_get_as_size
1641 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1642 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1643 * support, exchange AS-Path with the same path-attribute type value 0x02.
1646 bgp_attr_get_as_size(netdissect_options
*ndo
,
1647 uint8_t bgpa_type
, const u_char
*pptr
, u_int len
)
1649 const u_char
*tptr
= pptr
;
1652 * If the path attribute is the optional AS4 path type, then we already
1653 * know, that ASs must be encoded in 4 byte format.
1655 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1660 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1661 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1664 while (tptr
< pptr
+ len
) {
1666 * If we do not find a valid segment type, our guess might be wrong.
1668 if (GET_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| GET_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1671 tptr
+= 2 + GET_U_1(tptr
+ 1) * 2;
1675 * If we correctly reached end of the AS path attribute data content,
1676 * then most likely ASs were indeed encoded as 2 bytes.
1678 if (tptr
== pptr
+ len
) {
1685 * We can come here, either we did not have enough data, or if we
1686 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1687 * so that caller can try to decode each AS as of 4 bytes. If indeed
1688 * there was not enough data, it will crib and end the parse anyways.
1694 * The only way to know that a BGP UPDATE message is using add path is
1695 * by checking if the capability is in the OPEN message which we may have missed.
1696 * So this function checks if it is possible that the update could contain add path
1697 * and if so it checks that standard BGP doesn't make sense.
1700 check_add_path(netdissect_options
*ndo
, const u_char
*pptr
, u_int length
,
1701 u_int max_prefix_length
)
1703 u_int offset
, prefix_length
;
1710 * Scan through the NLRI information under the assumption that
1711 * it doesn't have path IDs.
1713 for (offset
= 0; offset
< length
;) {
1715 if (!ND_TTEST_1(pptr
+ offset
)) {
1716 /* We ran out of captured data; quit scanning. */
1719 prefix_length
= GET_U_1(pptr
+ offset
);
1721 * Add 4 to cover the path id
1722 * and check the prefix length isn't greater than 32/128.
1724 if (prefix_length
> max_prefix_length
) {
1727 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1728 offset
+= 1 + ((prefix_length
+ 7) / 8);
1730 /* check we haven't gone past the end of the section */
1731 if (offset
> length
) {
1735 /* check it's not standard BGP */
1736 for (offset
= 0; offset
< length
; ) {
1737 if (!ND_TTEST_1(pptr
+ offset
)) {
1738 /* We ran out of captured data; quit scanning. */
1741 prefix_length
= GET_U_1(pptr
+ offset
);
1743 * If the prefix_length is zero (0.0.0.0/0)
1744 * and since it's not the only address (length >= 5)
1745 * then it is add-path
1747 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1750 offset
+= 1 + ((prefix_length
+ 7) / 8);
1752 if (offset
> length
) {
1756 /* assume not add-path by default */
1761 bgp_mp_af_print(netdissect_options
*ndo
,
1762 const u_char
*tptr
, u_int tlen
,
1763 uint16_t *afp
, uint8_t *safip
)
1768 af
= GET_BE_U_2(tptr
);
1770 safi
= GET_U_1(tptr
+ 2);
1773 ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1774 tok2str(af_values
, "Unknown AFI", af
),
1776 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1777 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1780 switch(af
<<8 | safi
) {
1781 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
1782 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
1783 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
1784 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
1785 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
1786 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
1787 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
1788 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1789 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
):
1790 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
1791 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
1792 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
1793 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
1794 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
1795 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
1796 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
1797 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1798 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1799 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1800 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1801 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1802 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1803 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1804 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1805 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1806 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1807 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1810 ND_TCHECK_LEN(tptr
, tlen
);
1811 ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af
, safi
);
1812 if (ndo
->ndo_vflag
<= 1)
1813 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1822 bgp_nlri_print(netdissect_options
*ndo
, uint16_t af
, uint8_t safi
,
1823 const u_char
*tptr
, u_int len
,
1824 char *buf
, size_t buflen
,
1825 int add_path4
, int add_path6
)
1830 switch (af
<<8 | safi
) {
1831 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
1832 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
1833 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
1835 path_id
= GET_BE_U_4(tptr
);
1838 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1840 ND_PRINT("\n\t (illegal prefix length)");
1841 else if (advance
== -2)
1842 break; /* bytes left, but not enough */
1844 ND_PRINT("\n\t %s", buf
);
1846 ND_PRINT(" Path Id: %u", path_id
);
1850 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
1851 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1853 ND_PRINT("\n\t (illegal prefix length)");
1854 else if (advance
== -2)
1856 else if (advance
== -3)
1857 break; /* bytes left, but not enough */
1859 ND_PRINT("\n\t %s", buf
);
1861 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
1862 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
1863 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1864 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, buflen
);
1866 ND_PRINT("\n\t (illegal prefix length)");
1868 ND_PRINT("\n\t %s", buf
);
1870 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
1871 advance
= decode_rt_routing_info(ndo
, tptr
);
1873 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1874 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST_VPN
):
1875 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, buflen
);
1877 ND_PRINT("\n\t (illegal prefix length)");
1878 else if (advance
== -2)
1881 ND_PRINT("\n\t %s", buf
);
1884 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
1885 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, buflen
);
1887 ND_PRINT("\n\t (illegal prefix length)");
1888 else if (advance
== -2)
1891 ND_PRINT("\n\t %s", buf
);
1893 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
1894 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
1895 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
1897 path_id
= GET_BE_U_4(tptr
);
1900 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1902 ND_PRINT("\n\t (illegal prefix length)");
1903 else if (advance
== -2)
1904 break; /* bytes left, but not enough */
1906 ND_PRINT("\n\t %s", buf
);
1908 ND_PRINT(" Path Id: %u", path_id
);
1912 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
1913 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1915 ND_PRINT("\n\t (illegal prefix length)");
1916 else if (advance
== -2)
1918 else if (advance
== -3)
1919 break; /* bytes left, but not enough */
1921 ND_PRINT("\n\t %s", buf
);
1923 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
1924 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
1925 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1926 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, buflen
);
1928 ND_PRINT("\n\t (illegal prefix length)");
1930 ND_PRINT("\n\t %s", buf
);
1932 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1933 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1934 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1935 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1936 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, buflen
);
1938 ND_PRINT("\n\t (illegal length)");
1939 else if (advance
== -2)
1942 ND_PRINT("\n\t %s", buf
);
1944 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1945 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1946 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1947 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1949 ND_PRINT("\n\t (illegal prefix length)");
1951 ND_PRINT("\n\t %s", buf
);
1953 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1954 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1955 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1956 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1958 ND_PRINT("\n\t (illegal prefix length)");
1960 ND_PRINT("\n\t %s", buf
);
1964 * This should not happen, we should have been protected
1965 * by bgp_mp_af_print()'s return value.
1967 ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af
, safi
);
1972 trunc
: /* we rely on the caller to recognize -2 return value */
1976 static const struct tok bgp_flags
[] = {
1985 bgp_attr_print(netdissect_options
*ndo
,
1986 uint8_t atype
, const u_char
*pptr
, u_int len
,
1987 const unsigned attr_set_level
)
1989 /* allocate space for the largest possible string */
1990 char astostr
[AS_STR_SIZE
];
1993 uint8_t safi
, snpa
, nhlen
;
1999 int add_path4
, add_path6
;
2006 case BGPTYPE_ORIGIN
:
2008 ND_PRINT("invalid len");
2010 ND_PRINT("%s", tok2str(bgp_origin_values
,
2011 "Unknown Origin Typecode",
2017 * Process AS4 byte path and AS2 byte path attributes here.
2019 case BGPTYPE_AS4_PATH
:
2020 case BGPTYPE_AS_PATH
:
2022 ND_PRINT("invalid len");
2031 * BGP updates exchanged between New speakers that support 4
2032 * byte AS, ASs are always encoded in 4 bytes. There is no
2033 * definitive way to find this, just by the packet's
2034 * contents. So, check for packet's TLV's sanity assuming
2035 * 2 bytes first, and it does not pass, assume that ASs are
2036 * encoded in 4 bytes format and move on.
2038 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
2040 while (tptr
< pptr
+ len
) {
2041 ND_PRINT("%s", tok2str(bgp_as_path_segment_open_values
,
2042 "?", GET_U_1(tptr
)));
2043 for (i
= 0; i
< GET_U_1(tptr
+ 1) * as_size
; i
+= as_size
) {
2044 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
2046 as_printf(ndo
, astostr
, sizeof(astostr
),
2048 GET_BE_U_2(tptr
+ i
+ 2) :
2049 GET_BE_U_4(tptr
+ i
+ 2)));
2051 ND_PRINT("%s", tok2str(bgp_as_path_segment_close_values
,
2052 "?", GET_U_1(tptr
)));
2053 tptr
+= 2 + GET_U_1(tptr
+ 1) * as_size
;
2056 case BGPTYPE_NEXT_HOP
:
2058 ND_PRINT("invalid len");
2060 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
2063 case BGPTYPE_MULTI_EXIT_DISC
:
2064 case BGPTYPE_LOCAL_PREF
:
2066 ND_PRINT("invalid len");
2068 ND_PRINT("%u", GET_BE_U_4(tptr
));
2071 case BGPTYPE_ATOMIC_AGGREGATE
:
2073 ND_PRINT("invalid len");
2075 case BGPTYPE_AGGREGATOR
:
2078 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
2079 * the length of this PA can be either 6 bytes or 8 bytes.
2081 if (len
!= 6 && len
!= 8) {
2082 ND_PRINT("invalid len");
2085 ND_TCHECK_LEN(tptr
, len
);
2087 ND_PRINT(" AS #%s, origin %s",
2088 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(tptr
)),
2089 GET_IPADDR_STRING(tptr
+ 2));
2091 ND_PRINT(" AS #%s, origin %s",
2092 as_printf(ndo
, astostr
, sizeof(astostr
),
2093 GET_BE_U_4(tptr
)), GET_IPADDR_STRING(tptr
+ 4));
2096 case BGPTYPE_AGGREGATOR4
:
2098 ND_PRINT("invalid len");
2101 ND_PRINT(" AS #%s, origin %s",
2102 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)),
2103 GET_IPADDR_STRING(tptr
+ 4));
2105 case BGPTYPE_COMMUNITIES
:
2107 ND_PRINT("invalid len");
2115 comm
= GET_BE_U_4(tptr
);
2117 case BGP_COMMUNITY_NO_EXPORT
:
2118 ND_PRINT(" NO_EXPORT");
2120 case BGP_COMMUNITY_NO_ADVERT
:
2121 ND_PRINT(" NO_ADVERTISE");
2123 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
2124 ND_PRINT(" NO_EXPORT_SUBCONFED");
2128 (comm
>> 16) & 0xffff,
2130 (tlen
>4) ? ", " : "");
2137 case BGPTYPE_ORIGINATOR_ID
:
2139 ND_PRINT("invalid len");
2142 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2144 case BGPTYPE_CLUSTER_LIST
:
2146 ND_PRINT("invalid len");
2153 GET_IPADDR_STRING(tptr
),
2154 (tlen
>4) ? ", " : "");
2159 case BGPTYPE_MP_REACH_NLRI
:
2163 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2175 nhlen
= GET_U_1(tptr
);
2181 uint8_t tnhlen
= nhlen
;
2184 ND_PRINT("\n\t nexthop: ");
2185 while (tnhlen
!= 0) {
2189 switch(af
<<8 | safi
) {
2190 case (AFNUM_IP
<<8 | SAFNUM_UNICAST
):
2191 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST
):
2192 case (AFNUM_IP
<<8 | SAFNUM_UNIMULTICAST
):
2193 case (AFNUM_IP
<<8 | SAFNUM_LABUNICAST
):
2194 case (AFNUM_IP
<<8 | SAFNUM_RT_ROUTING_INFO
):
2195 case (AFNUM_IP
<<8 | SAFNUM_MULTICAST_VPN
):
2196 case (AFNUM_IP
<<8 | SAFNUM_MDT
):
2197 if (tnhlen
< sizeof(nd_ipv4
)) {
2198 ND_PRINT("invalid len");
2203 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2204 tptr
+= sizeof(nd_ipv4
);
2205 tnhlen
-= sizeof(nd_ipv4
);
2206 tlen
-= sizeof(nd_ipv4
);
2209 case (AFNUM_IP
<<8 | SAFNUM_VPNUNICAST
):
2210 case (AFNUM_IP
<<8 | SAFNUM_VPNMULTICAST
):
2211 case (AFNUM_IP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2212 if (tnhlen
< sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
) {
2213 ND_PRINT("invalid len");
2218 ND_PRINT("RD: %s, %s",
2219 bgp_vpn_rd_print(ndo
, tptr
),
2220 GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2221 tptr
+= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2222 tlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2223 tnhlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2226 case (AFNUM_IP6
<<8 | SAFNUM_UNICAST
):
2227 case (AFNUM_IP6
<<8 | SAFNUM_MULTICAST
):
2228 case (AFNUM_IP6
<<8 | SAFNUM_UNIMULTICAST
):
2229 case (AFNUM_IP6
<<8 | SAFNUM_LABUNICAST
):
2230 if (tnhlen
< sizeof(nd_ipv6
)) {
2231 ND_PRINT("invalid len");
2236 ND_PRINT("%s", GET_IP6ADDR_STRING(tptr
));
2237 tptr
+= sizeof(nd_ipv6
);
2238 tlen
-= sizeof(nd_ipv6
);
2239 tnhlen
-= sizeof(nd_ipv6
);
2242 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNICAST
):
2243 case (AFNUM_IP6
<<8 | SAFNUM_VPNMULTICAST
):
2244 case (AFNUM_IP6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2245 if (tnhlen
< sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
) {
2246 ND_PRINT("invalid len");
2251 ND_PRINT("RD: %s, %s",
2252 bgp_vpn_rd_print(ndo
, tptr
),
2253 GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2254 tptr
+= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2255 tlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2256 tnhlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2259 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2260 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2261 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2262 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2263 if (tnhlen
< sizeof(nd_ipv4
)) {
2264 ND_PRINT("invalid len");
2269 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
2270 tptr
+= (sizeof(nd_ipv4
));
2271 tlen
-= (sizeof(nd_ipv4
));
2272 tnhlen
-= (sizeof(nd_ipv4
));
2275 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2276 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2277 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2278 ND_PRINT("%s", GET_ISONSAP_STRING(tptr
, tnhlen
));
2284 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2285 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2286 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2287 if (tnhlen
< BGP_VPN_RD_LEN
+1) {
2288 ND_PRINT("invalid len");
2293 ND_TCHECK_LEN(tptr
, tnhlen
);
2294 ND_PRINT("RD: %s, %s",
2295 bgp_vpn_rd_print(ndo
, tptr
),
2296 GET_ISONSAP_STRING(tptr
+BGP_VPN_RD_LEN
,tnhlen
-BGP_VPN_RD_LEN
));
2297 /* rfc986 mapped IPv4 address ? */
2298 if (GET_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
2299 ND_PRINT(" = %s", GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
+4));
2300 /* rfc1888 mapped IPv6 address ? */
2301 else if (GET_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
2302 ND_PRINT(" = %s", GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
+3));
2310 * bgp_mp_af_print() should have saved us from
2311 * an unsupported AFI/SAFI.
2313 ND_PRINT("ERROR: no AFI %u/SAFI %u nexthop decoder", af
, safi
);
2322 ND_PRINT(", nh-length: %u", nhlen
);
2324 /* As per RFC 2858; this is reserved in RFC 4760 */
2327 snpa
= GET_U_1(tptr
);
2332 ND_PRINT("\n\t %u SNPA", snpa
);
2333 for (/*nothing*/; snpa
!= 0; snpa
--) {
2337 snpalen
= GET_U_1(tptr
);
2338 ND_PRINT("\n\t %u bytes", snpalen
);
2343 ND_TCHECK_LEN(tptr
, snpalen
);
2348 ND_PRINT(", no SNPA");
2351 add_path4
= check_add_path(ndo
, tptr
,
2352 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 32);
2353 add_path6
= check_add_path(ndo
, tptr
,
2354 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 128);
2356 while (tptr
< pptr
+ len
) {
2357 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2358 add_path4
, add_path6
);
2367 case BGPTYPE_MP_UNREACH_NLRI
:
2368 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
2369 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2375 if (len
== BGP_MP_NLRI_MINSIZE
)
2376 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2380 add_path4
= check_add_path(ndo
, tptr
,
2381 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 32);
2382 add_path6
= check_add_path(ndo
, tptr
,
2383 (len
-ND_BYTES_BETWEEN(pptr
, tptr
)), 128);
2385 while (tptr
< pptr
+ len
) {
2386 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2387 add_path4
, add_path6
);
2395 case BGPTYPE_EXTD_COMMUNITIES
:
2397 ND_PRINT("invalid len");
2406 extd_comm
=GET_BE_U_2(tptr
);
2408 ND_PRINT("\n\t %s (0x%04x), Flags [%s]",
2409 tok2str(bgp_extd_comm_subtype_values
,
2410 "unknown extd community typecode",
2413 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
2419 bgp_extended_community_print(ndo
, tptr
);
2425 case BGPTYPE_PMSI_TUNNEL
:
2427 uint8_t tunnel_type
, flags
;
2432 flags
= GET_U_1(tptr
);
2433 tunnel_type
= GET_U_1(tptr
+ 1);
2435 ND_PRINT("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2436 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2438 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2439 GET_BE_U_3(tptr
+ 2)>>4);
2444 switch (tunnel_type
) {
2445 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2446 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2447 ND_PRINT("\n\t Sender %s, P-Group %s",
2448 GET_IPADDR_STRING(tptr
),
2449 GET_IPADDR_STRING(tptr
+4));
2452 case BGP_PMSI_TUNNEL_PIM_SSM
:
2453 ND_PRINT("\n\t Root-Node %s, P-Group %s",
2454 GET_IPADDR_STRING(tptr
),
2455 GET_IPADDR_STRING(tptr
+4));
2457 case BGP_PMSI_TUNNEL_INGRESS
:
2458 ND_PRINT("\n\t Tunnel-Endpoint %s",
2459 GET_IPADDR_STRING(tptr
));
2461 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2462 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2463 ND_PRINT("\n\t Root-Node %s, LSP-ID 0x%08x",
2464 GET_IPADDR_STRING(tptr
),
2465 GET_BE_U_4(tptr
+ 4));
2467 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2468 ND_PRINT("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2469 GET_IPADDR_STRING(tptr
),
2470 GET_BE_U_4(tptr
+ 4));
2473 if (ndo
->ndo_vflag
<= 1) {
2474 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2485 type
= GET_U_1(tptr
);
2486 length
= GET_BE_U_2(tptr
+ 1);
2490 ND_PRINT("\n\t %s TLV (%u), length %u",
2491 tok2str(bgp_aigp_values
, "Unknown", type
),
2499 * Check if we can read the TLV data.
2509 ND_PRINT(", metric %" PRIu64
,
2514 if (ndo
->ndo_vflag
<= 1) {
2515 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2524 case BGPTYPE_ATTR_SET
:
2528 ND_PRINT("\n\t Origin AS: %s",
2529 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)));
2534 u_int aflags
, alenlen
, alen
;
2538 ND_PRINT(" [path attr too short]");
2542 aflags
= GET_U_1(tptr
);
2543 atype
= GET_U_1(tptr
+ 1);
2546 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2547 ND_TCHECK_LEN(tptr
, alenlen
);
2548 if (len
< alenlen
) {
2549 ND_PRINT(" [path attr too short]");
2553 alen
= bgp_attr_len(aflags
, tptr
);
2557 ND_PRINT("\n\t %s (%u), length: %u",
2558 tok2str(bgp_attr_values
,
2559 "Unknown Attribute", atype
),
2564 ND_PRINT(", Flags [%s",
2565 bittok2str_nosep(bgp_flags
, "", aflags
));
2567 ND_PRINT("+%x", aflags
& 0xf);
2572 ND_PRINT(" [path attr too short]");
2577 * The protocol encoding per se allows ATTR_SET to be nested
2578 * as many times as the message can accommodate. This printer
2579 * used to be able to recurse into ATTR_SET contents until the
2580 * stack exhaustion, but now there is a limit on that (if live
2581 * protocol exchange goes that many levels deep, something is
2582 * probably wrong anyway). Feel free to refine this value if
2583 * you can find the spec with respective normative text.
2585 if (attr_set_level
== 10)
2586 ND_PRINT("(too many nested levels, not recursing)");
2587 else if (!bgp_attr_print(ndo
, atype
, tptr
, alen
, attr_set_level
+ 1))
2594 case BGPTYPE_LARGE_COMMUNITY
:
2595 if (len
== 0 || len
% 12) {
2596 ND_PRINT("invalid len");
2601 ND_PRINT("%u:%u:%u%s",
2603 GET_BE_U_4(tptr
+ 4),
2604 GET_BE_U_4(tptr
+ 8),
2605 (len
> 12) ? ", " : "");
2608 * len will always be a multiple of 12, as per the above,
2609 * so this will never underflow.
2614 case BGPTYPE_BGPSEC_PATH
:
2616 uint16_t sblen
, splen
;
2618 splen
= GET_BE_U_2(tptr
);
2621 * A secure path has a minimum length of 8 bytes:
2622 * 2 bytes length field
2623 * 6 bytes per secure path segment
2625 ND_ICHECKMSG_U("secure path length", splen
, <, 8);
2627 ND_PRINT("\n\t Secure Path Length: %u", splen
);
2631 /* Make sure the secure path length does not signal trailing bytes */
2633 ND_PRINT(" [total segments length %u != N x 6]", splen
);
2637 /* Parse secure path segments */
2638 while (splen
!= 0) {
2639 uint8_t pcount
= GET_U_1(tptr
);
2640 uint8_t flags
= GET_U_1(tptr
+ 1);
2641 uint32_t asn
= GET_BE_U_4(tptr
+ 2);
2642 ND_PRINT("\n\t Secure Path Segment: pCount: %u, Flags: [%s] (0x%02x), AS: %u",
2644 bittok2str(bgp_bgpsec_bitmap_str
, "none", flags
),
2651 sblen
= GET_BE_U_2(tptr
);
2653 ND_PRINT("\n\t Signature Block: Length: %u, Algo ID: %u",
2659 /* Parse signature segments */
2663 ND_PRINT("\n\t Signature Segment:\n\t SKI: ");
2664 ND_ICHECKMSG_U("remaining length", sblen
, <, 20);
2665 hex_print(ndo
, "\n\t ", tptr
, 20);
2668 ND_ICHECKMSG_U("remaining length", sblen
, <, 2);
2669 siglen
= GET_BE_U_2(tptr
);
2673 ND_PRINT("\n\t Length: %u", siglen
);
2674 ND_ICHECKMSG_U("remaining length", sblen
, <, siglen
);
2675 ND_PRINT("\n\t Signature:");
2676 hex_print(ndo
, "\n\t ", tptr
, siglen
);
2685 ND_PRINT("invalid len");
2688 ND_PRINT("\n\t OTC %u", GET_BE_U_4(pptr
));
2692 ND_TCHECK_LEN(pptr
, len
);
2693 ND_PRINT("\n\t no Attribute %u decoder", atype
); /* we have no decoder for the attribute */
2694 if (ndo
->ndo_vflag
<= 1)
2695 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2699 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2700 ND_TCHECK_LEN(pptr
, len
);
2701 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2706 nd_print_invalid(ndo
);
2714 bgp_capabilities_print(netdissect_options
*ndo
,
2715 const u_char
*opt
, u_int caps_len
)
2717 /* allocate space for the largest possible string */
2718 char astostr
[AS_STR_SIZE
];
2719 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2722 while (i
< caps_len
) {
2723 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2724 cap_type
=GET_U_1(opt
+ i
);
2725 cap_len
=GET_U_1(opt
+ i
+ 1);
2726 ND_PRINT("\n\t %s (%u), length: %u",
2727 tok2str(bgp_capcode_values
, "Unknown", cap_type
),
2730 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2732 case BGP_CAPCODE_MP
:
2733 /* AFI (16 bits), Reserved (8 bits), SAFI (8 bits) */
2735 ND_PRINT(" (too short, < 4)");
2738 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u)",
2739 tok2str(af_values
, "Unknown", GET_BE_U_2(opt
+ i
+ 2)),
2740 GET_BE_U_2(opt
+ i
+ 2),
2741 tok2str(bgp_safi_values
, "Unknown", GET_U_1(opt
+ i
+ 5)),
2742 GET_U_1(opt
+ i
+ 5));
2744 case BGP_CAPCODE_BGPSEC
:
2745 /* Version (4 bits), Direction (1 bit), Flags (3 bits), AFI (16 bits) */
2747 /* The capability length [...] MUST be set to 3. */
2749 ND_PRINT(" [%u != 3]", cap_len
);
2753 ND_PRINT("\n\t\tVersion %u, Direction %s (%u), AFI %s (%u)",
2754 GET_U_1(opt
+ i
+ 2)&0xf0,
2755 (GET_U_1(opt
+ i
+ 2)&0x08) ? "Send" : "Receive",
2756 (GET_U_1(opt
+ i
+ 2)&0x08)>>3,
2757 bittok2str(af_values
, "Unknown",
2758 GET_BE_U_2(opt
+ i
+ cap_offset
+ 2)),
2759 GET_BE_U_2(opt
+ i
+ cap_offset
+ 2));
2761 case BGP_CAPCODE_ML
:
2764 while (tcap_len
>= 4) {
2765 ND_PRINT( "\n\t\tAFI %s (%u), SAFI %s (%u), Count: %u",
2766 tok2str(af_values
, "Unknown",
2767 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2768 GET_BE_U_2(opt
+ i
+ cap_offset
),
2769 tok2str(bgp_safi_values
, "Unknown",
2770 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2771 GET_U_1(opt
+ i
+ cap_offset
+ 2),
2772 GET_U_1(opt
+ i
+ cap_offset
+ 3));
2777 case BGP_CAPCODE_RESTART
:
2778 /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */
2780 ND_PRINT(" (too short, < 2)");
2784 ND_PRINT("\n\t\tRestart Flags: [%s], Restart Time %us",
2785 bittok2str(bgp_graceful_restart_comm_flag_values
,
2786 "none", GET_U_1(opt
+ i
+ 2) >> 4),
2787 GET_BE_U_2(opt
+ i
+ 2)&0xfff);
2790 while(tcap_len
>=4) {
2791 ND_PRINT("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2792 tok2str(af_values
,"Unknown",
2793 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2794 GET_BE_U_2(opt
+ i
+ cap_offset
),
2795 tok2str(bgp_safi_values
,"Unknown",
2796 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2797 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2798 ((GET_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" );
2803 case BGP_CAPCODE_ROLE
:
2805 ND_PRINT(" (too short, < 1)");
2808 ND_PRINT("\n\t\tRole name %s (%u)",
2809 tok2str(bgp_role_values
, "Unassigned",
2810 GET_U_1(opt
+ i
+ 2)), GET_U_1(opt
+ i
+ 2));
2812 case BGP_CAPCODE_RR
:
2813 case BGP_CAPCODE_LLGR
:
2814 case BGP_CAPCODE_RR_CISCO
:
2815 case BGP_CAPCODE_EXT_MSG
:
2816 case BGP_CAPCODE_ENH_RR
:
2818 case BGP_CAPCODE_AS_NEW
:
2820 * Extract the 4 byte AS number encoded.
2823 ND_PRINT(" (too short, < 4)");
2826 ND_PRINT("\n\t\t 4 Byte AS %s",
2827 as_printf(ndo
, astostr
, sizeof(astostr
),
2828 GET_BE_U_4(opt
+ i
+ 2)));
2830 case BGP_CAPCODE_ADD_PATH
:
2832 ND_PRINT(" (bogus)"); /* length */
2837 while (tcap_len
!= 0) {
2839 nd_print_invalid(ndo
);
2842 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2843 tok2str(af_values
,"Unknown",GET_BE_U_2(opt
+ i
+ cap_offset
)),
2844 GET_BE_U_2(opt
+ i
+ cap_offset
),
2845 tok2str(bgp_safi_values
,"Unknown",GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2846 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2847 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",GET_U_1(opt
+ i
+ cap_offset
+ 3))
2854 ND_PRINT("\n\t\tno decoder for Capability %u",
2856 if (ndo
->ndo_vflag
<= 1)
2857 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2861 if (ndo
->ndo_vflag
> 1 && cap_len
!= 0) {
2862 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2864 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2869 nd_print_trunc(ndo
);
2873 bgp_open_print(netdissect_options
*ndo
,
2874 const u_char
*dat
, u_int length
)
2876 /* allocate space for the largest possible string */
2877 char astostr
[AS_STR_SIZE
];
2878 const struct bgp_open
*bgp_open_header
;
2881 const struct bgp_opt
*bgpopt
;
2884 uint8_t extended_opt_params
= 0;
2885 u_int open_size
= BGP_OPEN_SIZE
;
2886 u_int opt_size
= BGP_OPT_SIZE
;
2888 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2889 if (length
< BGP_OPEN_SIZE
)
2892 bgp_open_header
= (const struct bgp_open
*)dat
;
2894 ND_PRINT("\n\t Version %u, ",
2895 GET_U_1(bgp_open_header
->bgpo_version
));
2896 ND_PRINT("my AS %s, ",
2897 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(bgp_open_header
->bgpo_myas
)));
2898 ND_PRINT("Holdtime %us, ",
2899 GET_BE_U_2(bgp_open_header
->bgpo_holdtime
));
2900 ND_PRINT("ID %s", GET_IPADDR_STRING(bgp_open_header
->bgpo_id
));
2901 optslen
= GET_U_1(bgp_open_header
->bgpo_optlen
);
2902 opsttype
= GET_U_1(bgp_open_header
->bgpo_opttype
);
2903 if (opsttype
== BGP_OPEN_NON_EXT_OPT_TYPE_EXTENDED_LENGTH
) {
2904 optslen
= GET_BE_U_2(bgp_open_header
->bgpo_optlen_extended
);
2905 extended_opt_params
= 1;
2909 ND_PRINT("\n\t Optional parameters%s, length: %u",
2910 extended_opt_params
? " (Extended)" : "", optslen
);
2912 opt
= dat
+ open_size
;
2913 length
-= open_size
;
2916 while (i
< optslen
) {
2920 ND_TCHECK_LEN(opt
+ i
, opt_size
);
2921 if (length
< opt_size
+ i
)
2923 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2924 opt_type
= GET_U_1(bgpopt
->bgpopt_type
);
2925 opt_len
= extended_opt_params
? GET_BE_U_2(bgpopt
->bgpopt_len
)
2926 : GET_U_1(bgpopt
->bgpopt_len
);
2927 if (opt_size
+ i
+ opt_len
> optslen
) {
2928 ND_PRINT("\n\t Option %u, length: %u, goes past the end of the options",
2933 ND_PRINT("\n\t Option %s (%u), length: %u",
2934 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2938 /* now let's decode the options we know*/
2942 bgp_capabilities_print(ndo
, opt
+ opt_size
+ i
,
2948 ND_PRINT("\n\t no decoder for option %u",
2952 i
+= opt_size
+ opt_len
;
2956 nd_print_trunc(ndo
);
2960 bgp_update_print(netdissect_options
*ndo
,
2961 const u_char
*dat
, u_int length
)
2964 u_int withdrawn_routes_len
;
2972 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2973 if (length
< BGP_SIZE
)
2978 /* Unfeasible routes */
2982 withdrawn_routes_len
= GET_BE_U_2(p
);
2985 if (withdrawn_routes_len
> 1) {
2987 * Without keeping state from the original NLRI message,
2988 * it's not possible to tell if this a v4 or v6 route,
2989 * so only try to decode it if we're not v6 enabled.
2991 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2992 if (length
< withdrawn_routes_len
)
2994 ND_PRINT("\n\t Withdrawn routes:");
2995 add_path
= check_add_path(ndo
, p
, withdrawn_routes_len
, 32);
2996 while (withdrawn_routes_len
!= 0) {
2998 if (withdrawn_routes_len
< 4) {
2999 p
+= withdrawn_routes_len
;
3000 length
-= withdrawn_routes_len
;
3003 path_id
= GET_BE_U_4(p
);
3006 withdrawn_routes_len
-= 4;
3008 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
3010 ND_PRINT("\n\t (illegal prefix length)");
3012 } else if (wpfx
== -2)
3013 goto trunc
; /* bytes left, but not enough */
3015 ND_PRINT("\n\t %s", buf
);
3017 ND_PRINT(" Path Id: %u", path_id
);
3021 withdrawn_routes_len
-= wpfx
;
3025 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
3026 if (length
< withdrawn_routes_len
)
3028 p
+= withdrawn_routes_len
;
3029 length
-= withdrawn_routes_len
;
3035 len
= GET_BE_U_2(p
);
3039 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
3040 /* No withdrawn routes, no path attributes, no NLRI */
3041 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
3046 /* Make sure the path attributes don't go past the end of the packet */
3049 /* do something more useful!*/
3051 uint8_t aflags
, atype
, alenlen
;
3058 ND_PRINT("\n\t [path attrs too short]");
3063 aflags
= GET_U_1(p
);
3064 atype
= GET_U_1(p
+ 1);
3068 alenlen
= bgp_attr_lenlen(aflags
, p
);
3069 ND_TCHECK_LEN(p
, alenlen
);
3070 if (length
< alenlen
)
3072 if (len
< alenlen
) {
3073 ND_PRINT("\n\t [path attrs too short]");
3078 alen
= bgp_attr_len(aflags
, p
);
3083 ND_PRINT("\n\t %s (%u), length: %u",
3084 tok2str(bgp_attr_values
, "Unknown Attribute", atype
),
3089 ND_PRINT(", Flags [%s",
3090 bittok2str_nosep(bgp_flags
, "", aflags
));
3092 ND_PRINT("+%x", aflags
& 0xf);
3096 ND_PRINT(" [path attrs too short]");
3103 if (!bgp_attr_print(ndo
, atype
, p
, alen
, 0))
3112 add_path
= check_add_path(ndo
, p
, length
, 32);
3113 ND_PRINT("\n\t Updated routes:");
3114 while (length
!= 0) {
3119 path_id
= GET_BE_U_4(p
);
3123 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
3125 ND_PRINT("\n\t (illegal prefix length)");
3128 goto trunc
; /* bytes left, but not enough */
3130 ND_PRINT("\n\t %s", buf
);
3132 ND_PRINT(" Path Id: %u", path_id
);
3141 nd_print_trunc(ndo
);
3145 bgp_notification_print_code(netdissect_options
*ndo
,
3146 const u_char
*dat
, u_int length
,
3147 uint8_t bgpn_major
, uint8_t bgpn_minor
)
3149 ND_PRINT(", %s (%u)",
3150 tok2str(bgp_notify_major_values
, "Unknown Error",
3154 switch (bgpn_major
) {
3156 case BGP_NOTIFY_MAJOR_MSG
:
3157 ND_PRINT(", subcode %s (%u)",
3158 tok2str(bgp_notify_minor_msg_values
, "Unknown",
3162 case BGP_NOTIFY_MAJOR_OPEN
:
3163 ND_PRINT(", subcode %s (%u)",
3164 tok2str(bgp_notify_minor_open_values
, "Unknown",
3168 case BGP_NOTIFY_MAJOR_UPDATE
:
3169 ND_PRINT(", subcode %s (%u)",
3170 tok2str(bgp_notify_minor_update_values
, "Unknown",
3174 case BGP_NOTIFY_MAJOR_FSM
:
3175 ND_PRINT(" subcode %s (%u)",
3176 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
3180 case BGP_NOTIFY_MAJOR_CAP
:
3181 ND_PRINT(" subcode %s (%u)",
3182 tok2str(bgp_notify_minor_cap_values
, "Unknown",
3186 case BGP_NOTIFY_MAJOR_CEASE
:
3187 ND_PRINT(", subcode %s (%u)",
3188 tok2str(bgp_notify_minor_cease_values
, "Unknown",
3192 /* RFC 4486 mentions optionally 7 bytes
3193 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
3195 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= 7) {
3196 ND_PRINT(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
3197 tok2str(af_values
, "Unknown", GET_BE_U_2(dat
)),
3199 tok2str(bgp_safi_values
, "Unknown", GET_U_1((dat
+ 2))),
3201 GET_BE_U_4(dat
+ 3));
3204 * RFC 9003 describes a method to send a communication
3205 * intended for human consumption regarding the Administrative Shutdown
3207 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
3208 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
3210 uint8_t shutdown_comm_length
= GET_U_1(dat
);
3211 uint8_t remainder_offset
= 0;
3212 /* garbage, hexdump it all */
3213 if (shutdown_comm_length
> length
- 1) {
3214 ND_PRINT(", invalid Shutdown Communication length");
3215 } else if (shutdown_comm_length
== 0) {
3216 ND_PRINT(", empty Shutdown Communication");
3217 remainder_offset
+= 1;
3219 /* a proper shutdown communication */
3221 ND_PRINT(", Shutdown Communication (length: %u): \"", shutdown_comm_length
);
3222 nd_printjn(ndo
, dat
+1, shutdown_comm_length
);
3224 remainder_offset
+= shutdown_comm_length
+ 1;
3226 /* if there is trailing data, hexdump it */
3227 if(length
- remainder_offset
> 0) {
3228 ND_PRINT(", Data: (length: %u)", length
- remainder_offset
);
3229 hex_print(ndo
, "\n\t\t", dat
+ remainder_offset
, length
- remainder_offset
);
3233 * RFC8538 describes the Hard Reset cease subcode, which contains another
3234 * notification code and subcode.
3236 if (bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_HARDRESET
&& length
>= 2) {
3237 bgpn_major
= GET_U_1(dat
++);
3238 bgpn_minor
= GET_U_1(dat
++);
3240 bgp_notification_print_code(ndo
, dat
, length
, bgpn_major
, bgpn_minor
);
3244 if (bgpn_minor
!= 0) {
3245 ND_PRINT(", subcode %u", bgpn_minor
);
3254 bgp_notification_print(netdissect_options
*ndo
,
3255 const u_char
*dat
, u_int length
)
3257 const struct bgp_notification
*bgp_notification_header
;
3258 uint8_t bgpn_major
, bgpn_minor
;
3260 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
3261 if (length
<BGP_NOTIFICATION_SIZE
)
3264 bgp_notification_header
= (const struct bgp_notification
*)dat
;
3265 bgpn_major
= GET_U_1(bgp_notification_header
->bgpn_major
);
3266 bgpn_minor
= GET_U_1(bgp_notification_header
->bgpn_minor
);
3267 bgp_notification_print_code(ndo
, dat
+ BGP_NOTIFICATION_SIZE
,
3268 length
- BGP_NOTIFICATION_SIZE
, bgpn_major
, bgpn_minor
);
3271 nd_print_trunc(ndo
);
3275 bgp_route_refresh_print(netdissect_options
*ndo
,
3276 const u_char
*pptr
, u_int len
)
3278 const struct bgp_route_refresh
*bgp_route_refresh_header
;
3280 /* some little sanity checking */
3281 if (len
<BGP_ROUTE_REFRESH_SIZE
)
3284 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
3286 ND_PRINT("\n\t AFI %s (%u), SAFI %s (%u), Subtype %s (%u)",
3287 tok2str(af_values
, "Unknown",
3288 GET_BE_U_2(bgp_route_refresh_header
->afi
)),
3289 GET_BE_U_2(bgp_route_refresh_header
->afi
),
3290 tok2str(bgp_safi_values
, "Unknown",
3291 GET_U_1(bgp_route_refresh_header
->safi
)),
3292 GET_U_1(bgp_route_refresh_header
->safi
),
3293 tok2str(bgp_route_refresh_subtype_values
, "Unknown",
3294 GET_U_1(bgp_route_refresh_header
->subtype
)),
3295 GET_U_1(bgp_route_refresh_header
->subtype
));
3298 if (len
>= BGP_ROUTE_REFRESH_SIZE_ORF
) {
3299 const struct bgp_route_refresh_orf
*orf_header
;
3302 (const struct bgp_route_refresh_orf
*)(pptr
+ BGP_ROUTE_REFRESH_SIZE
);
3304 ND_PRINT("\n\t ORF refresh %s (%u), ORF type %s (%u), ORF length %u",
3305 tok2str(bgp_orf_refresh_type
, "Unknown",
3306 GET_U_1(orf_header
->refresh
)),
3307 GET_U_1(orf_header
->refresh
),
3308 tok2str(bgp_orf_type
, "Unknown", GET_U_1(orf_header
->type
)),
3309 GET_U_1(orf_header
->type
), GET_BE_U_2(orf_header
->len
));
3312 if (ndo
->ndo_vflag
> 1) {
3313 ND_TCHECK_LEN(pptr
, len
);
3314 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
3319 nd_print_trunc(ndo
);
3323 bgp_pdu_print(netdissect_options
*ndo
,
3324 const u_char
*dat
, u_int length
)
3326 const struct bgp
*bgp_header
;
3329 ND_TCHECK_LEN(dat
, BGP_SIZE
);
3330 bgp_header
= (const struct bgp
*)dat
;
3331 bgp_type
= GET_U_1(bgp_header
->bgp_type
);
3333 ND_PRINT("\n\t%s Message (%u), length: %u",
3334 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
3340 bgp_open_print(ndo
, dat
, length
);
3343 bgp_update_print(ndo
, dat
, length
);
3345 case BGP_NOTIFICATION
:
3346 bgp_notification_print(ndo
, dat
, length
);
3350 case BGP_ROUTE_REFRESH
:
3351 bgp_route_refresh_print(ndo
, dat
, length
);
3354 /* we have no decoder for the BGP message */
3355 ND_TCHECK_LEN(dat
, length
);
3356 ND_PRINT("\n\t no Message %u decoder", bgp_type
);
3357 print_unknown_data(ndo
, dat
, "\n\t ", length
);
3362 nd_print_trunc(ndo
);
3367 bgp_print(netdissect_options
*ndo
,
3368 const u_char
*dat
, u_int length _U_
)
3371 const u_char
*ep
= ndo
->ndo_snapend
;
3372 const u_char
*start
;
3373 const u_char marker
[] = {
3374 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3375 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3377 const struct bgp
*bgp_header
;
3380 ndo
->ndo_protocol
= "bgp";
3383 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
3391 if (GET_U_1(p
) != 0xff) {
3396 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
3398 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
3403 /* found BGP header */
3404 ND_TCHECK_LEN(p
, BGP_SIZE
);
3405 bgp_header
= (const struct bgp
*)p
;
3408 nd_print_trunc(ndo
);
3410 hlen
= GET_BE_U_2(bgp_header
->bgp_len
);
3411 if (hlen
< BGP_SIZE
) {
3412 ND_PRINT("\nmessage length %u < %u", hlen
, BGP_SIZE
);
3413 nd_print_invalid(ndo
);
3417 if (ND_TTEST_LEN(p
, hlen
)) {
3418 if (!bgp_pdu_print(ndo
, p
, hlen
))
3423 ND_PRINT("\n[|BGP %s]",
3424 tok2str(bgp_msg_values
,
3425 "Unknown Message Type",
3426 GET_U_1(bgp_header
->bgp_type
)));
3434 nd_print_trunc(ndo
);