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
{
107 nd_byte bgp_marker
[16];
109 nd_uint8_t type
; /* No padding after this; afi is, in fact, not aligned */
114 #define BGP_ROUTE_REFRESH_SIZE 23
115 #define BGP_ROUTE_REFRESH_SUBTYPE_NORMAL 0
116 #define BGP_ROUTE_REFRESH_SUBTYPE_BORR 1
117 #define BGP_ROUTE_REFRESH_SUBTYPE_EORR 2
118 #define BGP_ROUTE_REFRESH_SUBTYPE_RESERVED 255
120 static const struct tok bgp_route_refresh_subtype_values
[] = {
121 {BGP_ROUTE_REFRESH_SUBTYPE_NORMAL
, "Normal route refresh request"},
122 {BGP_ROUTE_REFRESH_SUBTYPE_BORR
,
123 "Demarcation of the beginning of a route refresh"},
124 {BGP_ROUTE_REFRESH_SUBTYPE_EORR
,
125 "Demarcation of the ending of a route refresh"},
128 #define bgp_attr_lenlen(flags, p) \
129 (((flags) & 0x10) ? 2U : 1U)
130 #define bgp_attr_len(flags, p) \
131 (((flags) & 0x10) ? GET_BE_U_2(p) : GET_U_1(p))
133 #define BGPTYPE_ORIGIN 1
134 #define BGPTYPE_AS_PATH 2
135 #define BGPTYPE_NEXT_HOP 3
136 #define BGPTYPE_MULTI_EXIT_DISC 4
137 #define BGPTYPE_LOCAL_PREF 5
138 #define BGPTYPE_ATOMIC_AGGREGATE 6
139 #define BGPTYPE_AGGREGATOR 7
140 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
141 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC4456 */
142 #define BGPTYPE_CLUSTER_LIST 10 /* RFC4456 */
143 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */
144 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */
145 #define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */
146 #define BGPTYPE_AS4_PATH 17 /* RFC6793 */
147 #define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */
148 #define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */
149 #define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */
150 #define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */
151 #define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */
152 #define BGPTYPE_AIGP 26 /* RFC7311 */
153 #define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */
154 #define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */
155 #define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */
156 #define BGPTYPE_ATTR_SET 128 /* RFC6368 */
158 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
160 static const struct tok bgp_attr_values
[] = {
161 { BGPTYPE_ORIGIN
, "Origin"},
162 { BGPTYPE_AS_PATH
, "AS Path"},
163 { BGPTYPE_AS4_PATH
, "AS4 Path"},
164 { BGPTYPE_NEXT_HOP
, "Next Hop"},
165 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
166 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
167 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
168 { BGPTYPE_AGGREGATOR
, "Aggregator"},
169 { BGPTYPE_AGGREGATOR4
, "Aggregator4"},
170 { BGPTYPE_COMMUNITIES
, "Community"},
171 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
172 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
173 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
174 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
175 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
176 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
177 { BGPTYPE_TUNNEL_ENCAP
, "Tunnel Encapsulation"},
178 { BGPTYPE_TRAFFIC_ENG
, "Traffic Engineering"},
179 { BGPTYPE_IPV6_EXTD_COMMUNITIES
, "IPv6 Extended Community"},
180 { BGPTYPE_AIGP
, "Accumulated IGP Metric"},
181 { BGPTYPE_PE_DISTINGUISHER_LABEL
, "PE Distinguisher Label"},
182 { BGPTYPE_ENTROPY_LABEL
, "Entropy Label"},
183 { BGPTYPE_LARGE_COMMUNITY
, "Large Community"},
184 { BGPTYPE_ATTR_SET
, "Attribute Set"},
185 { 255, "Reserved for development"},
190 #define BGP_AS_SEQUENCE 2
191 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
192 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
194 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
195 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
197 static const struct tok bgp_as_path_segment_open_values
[] = {
198 { BGP_AS_SEQUENCE
, ""},
200 { BGP_CONFED_AS_SEQUENCE
, "( "},
201 { BGP_CONFED_AS_SET
, "({ "},
205 static const struct tok bgp_as_path_segment_close_values
[] = {
206 { BGP_AS_SEQUENCE
, ""},
208 { BGP_CONFED_AS_SEQUENCE
, ")"},
209 { BGP_CONFED_AS_SET
, "})"},
213 #define BGP_OPT_AUTH 1
214 #define BGP_OPT_CAP 2
216 static const struct tok bgp_opt_values
[] = {
217 { BGP_OPT_AUTH
, "Authentication Information"},
218 { BGP_OPT_CAP
, "Capabilities Advertisement"},
222 #define BGP_CAPCODE_MP 1 /* RFC2858 */
223 #define BGP_CAPCODE_RR 2 /* RFC2918 */
224 #define BGP_CAPCODE_ORF 3 /* RFC5291 */
225 #define BGP_CAPCODE_MR 4 /* RFC3107 */
226 #define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */
227 #define BGP_CAPCODE_EXT_MSG 6 /* RFC8654 */
228 #define BGP_CAPCODE_ML 8 /* RFC8277 */
229 #define BGP_CAPCODE_RESTART 64 /* RFC4724 */
230 #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */
231 #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */
232 #define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */
233 #define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */
234 #define BGP_CAPCODE_ENH_RR 70 /* RFC7313 */
235 #define BGP_CAPCODE_LLGR 71 /* draft-uttaro-idr-bgp-persistence-05 */
236 #define BGP_CAPCODE_RR_CISCO 128
238 static const struct tok bgp_capcode_values
[] = {
239 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
240 { BGP_CAPCODE_RR
, "Route Refresh"},
241 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
242 { BGP_CAPCODE_MR
, "Multiple Routes to a Destination"},
243 { BGP_CAPCODE_EXT_NH
, "Extended Next Hop Encoding"},
244 { BGP_CAPCODE_EXT_MSG
, "BGP Extended Message"},
245 { BGP_CAPCODE_ML
, "Multiple Labels"},
246 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
247 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
248 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
249 { BGP_CAPCODE_MULTISESS
, "Multisession BGP"},
250 { BGP_CAPCODE_ADD_PATH
, "Multiple Paths"},
251 { BGP_CAPCODE_ENH_RR
, "Enhanced Route Refresh"},
252 { BGP_CAPCODE_LLGR
, "Long-lived Graceful Restart"},
253 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
257 #define BGP_NOTIFY_MAJOR_MSG 1
258 #define BGP_NOTIFY_MAJOR_OPEN 2
259 #define BGP_NOTIFY_MAJOR_UPDATE 3
260 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
261 #define BGP_NOTIFY_MAJOR_FSM 5
262 #define BGP_NOTIFY_MAJOR_CEASE 6
263 #define BGP_NOTIFY_MAJOR_CAP 7
265 static const struct tok bgp_notify_major_values
[] = {
266 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
267 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
268 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
269 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
270 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
271 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
272 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
277 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
278 #define BGP_NOTIFY_MINOR_CEASE_SHUT 2
279 #define BGP_NOTIFY_MINOR_CEASE_RESET 4
280 static const struct tok bgp_notify_minor_cease_values
[] = {
281 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
282 { BGP_NOTIFY_MINOR_CEASE_SHUT
, "Administrative Shutdown"},
283 { 3, "Peer Unconfigured"},
284 { BGP_NOTIFY_MINOR_CEASE_RESET
, "Administrative Reset"},
285 { 5, "Connection Rejected"},
286 { 6, "Other Configuration Change"},
287 { 7, "Connection Collision Resolution"},
291 static const struct tok bgp_notify_minor_msg_values
[] = {
292 { 1, "Connection Not Synchronized"},
293 { 2, "Bad Message Length"},
294 { 3, "Bad Message Type"},
298 static const struct tok bgp_notify_minor_open_values
[] = {
299 { 1, "Unsupported Version Number"},
301 { 3, "Bad BGP Identifier"},
302 { 4, "Unsupported Optional Parameter"},
303 { 5, "Authentication Failure"},
304 { 6, "Unacceptable Hold Time"},
305 { 7, "Capability Message Error"},
309 static const struct tok bgp_notify_minor_update_values
[] = {
310 { 1, "Malformed Attribute List"},
311 { 2, "Unrecognized Well-known Attribute"},
312 { 3, "Missing Well-known Attribute"},
313 { 4, "Attribute Flags Error"},
314 { 5, "Attribute Length Error"},
315 { 6, "Invalid ORIGIN Attribute"},
316 { 7, "AS Routing Loop"},
317 { 8, "Invalid NEXT_HOP Attribute"},
318 { 9, "Optional Attribute Error"},
319 { 10, "Invalid Network Field"},
320 { 11, "Malformed AS_PATH"},
324 static const struct tok bgp_notify_minor_fsm_values
[] = {
325 { 0, "Unspecified Error"},
326 { 1, "In OpenSent State"},
327 { 2, "In OpenConfirm State"},
328 { 3, "In Established State"},
332 static const struct tok bgp_notify_minor_cap_values
[] = {
333 { 1, "Invalid Action Value" },
334 { 2, "Invalid Capability Length" },
335 { 3, "Malformed Capability Value" },
336 { 4, "Unsupported Capability Code" },
340 static const struct tok bgp_origin_values
[] = {
347 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
348 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
349 #define BGP_PMSI_TUNNEL_PIM_SSM 3
350 #define BGP_PMSI_TUNNEL_PIM_SM 4
351 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
352 #define BGP_PMSI_TUNNEL_INGRESS 6
353 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
355 static const struct tok bgp_pmsi_tunnel_values
[] = {
356 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
357 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
358 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
359 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
360 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
361 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
362 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
366 static const struct tok bgp_pmsi_flag_values
[] = {
367 { 0x01, "Leaf Information required"},
371 #define BGP_AIGP_TLV 1
373 static const struct tok bgp_aigp_values
[] = {
374 { BGP_AIGP_TLV
, "AIGP"},
378 /* Subsequent address family identifier, RFC2283 section 7 */
380 #define SAFNUM_UNICAST 1
381 #define SAFNUM_MULTICAST 2
382 #define SAFNUM_UNIMULTICAST 3 /* deprecated now */
383 /* labeled BGP RFC3107 */
384 #define SAFNUM_LABUNICAST 4
386 #define SAFNUM_MULTICAST_VPN 5
387 /* draft-nalawade-kapoor-tunnel-safi */
388 #define SAFNUM_TUNNEL 64
390 #define SAFNUM_VPLS 65
392 #define SAFNUM_MDT 66
394 #define SAFNUM_EVPN 70
396 #define SAFNUM_VPNUNICAST 128
398 #define SAFNUM_VPNMULTICAST 129
399 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
401 #define SAFNUM_RT_ROUTING_INFO 132
403 #define BGP_VPN_RD_LEN 8
405 static const struct tok bgp_safi_values
[] = {
406 { SAFNUM_RES
, "Reserved"},
407 { SAFNUM_UNICAST
, "Unicast"},
408 { SAFNUM_MULTICAST
, "Multicast"},
409 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
410 { SAFNUM_LABUNICAST
, "labeled Unicast"},
411 { SAFNUM_TUNNEL
, "Tunnel"},
412 { SAFNUM_VPLS
, "VPLS"},
413 { SAFNUM_MDT
, "MDT"},
414 { SAFNUM_EVPN
, "EVPN"},
415 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
416 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
417 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
418 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
419 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
423 /* well-known community */
424 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
425 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
426 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
428 /* Extended community type - RFC 4360 */
429 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
430 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
431 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
432 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
433 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
434 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
435 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
436 /* rfc2547 bgp-mpls-vpns */
437 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
438 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatibility */
439 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatibility */
440 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatibility */
442 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
443 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatibility */
444 #define BGP_EXT_COM_ENCAP 0x030c /* rfc5512 */
446 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
447 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatibility */
449 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
451 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
452 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
453 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
454 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
456 /* https://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
457 #define BGP_EXT_COM_EIGRP_GEN 0x8800
458 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
459 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
460 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
461 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
462 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
464 /* Optional Parameters */
465 #define BGP_OPEN_NON_EXT_OPT_TYPE_EXTENDED_LENGTH 255 /* Non-Ext OP Type */
467 static const struct tok bgp_extd_comm_flag_values
[] = {
468 { 0x8000, "vendor-specific"},
469 { 0x4000, "non-transitive"},
473 static const struct tok bgp_extd_comm_subtype_values
[] = {
474 { BGP_EXT_COM_RT_0
, "target"},
475 { BGP_EXT_COM_RT_1
, "target"},
476 { BGP_EXT_COM_RT_2
, "target"},
477 { BGP_EXT_COM_RO_0
, "origin"},
478 { BGP_EXT_COM_RO_1
, "origin"},
479 { BGP_EXT_COM_RO_2
, "origin"},
480 { BGP_EXT_COM_LINKBAND
, "link-BW"},
481 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
482 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
483 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
484 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
485 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
486 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
487 { BGP_EXT_COM_ENCAP
, "encapsulation"},
488 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
489 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
490 { BGP_EXT_COM_L2INFO
, "layer2-info"},
491 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
492 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
493 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
494 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
495 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
496 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
497 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
498 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
499 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
500 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
504 /* RFC RFC5512 BGP Tunnel Encapsulation Attribute Tunnel Types */
505 #define BGP_ENCAP_TUNNEL_L2TPV3_IP 1
506 #define BGP_ENCAP_TUNNEL_GRE 2
507 #define BGP_ENCAP_TUNNEL_TRANSMIT 3
508 #define BGP_ENCAP_TUNNEL_IPSEC 4
509 #define BGP_ENCAP_TUNNEL_IP_IPSEC 5
510 #define BGP_ENCAP_TUNNEL_MPLS_IP 6
511 #define BGP_ENCAP_TUNNEL_IP_IP 7
512 #define BGP_ENCAP_TUNNEL_VXLAN 8
513 #define BGP_ENCAP_TUNNEL_NVGRE 9
514 #define BGP_ENCAP_TUNNEL_MPLS 10
515 #define BGP_ENCAP_TUNNEL_MPLS_GRE 11
516 #define BGP_ENCAP_TUNNEL_VXLAN_GPE 12
517 #define BGP_ENCAP_TUNNEL_MPLS_UDP 13
518 #define BGP_ENCAP_TUNNEL_IPV6 14
519 #define BGP_ENCAP_TUNNEL_SR_TE 15
520 #define BGP_ENCAP_TUNNEL_BARE 16
521 #define BGP_ENCAP_TUNNEL_SR 17
523 static const struct tok bgp_extd_comm_encap_tunnel_values
[] = {
524 { BGP_ENCAP_TUNNEL_L2TPV3_IP
, "L2TPv3 over IP"},
525 { BGP_ENCAP_TUNNEL_GRE
, "GRE"},
526 { BGP_ENCAP_TUNNEL_TRANSMIT
, "Transmit Tunnel"},
527 { BGP_ENCAP_TUNNEL_IPSEC
, "IPsec"},
528 { BGP_ENCAP_TUNNEL_IP_IPSEC
, "IP in IP with IPsec"},
529 { BGP_ENCAP_TUNNEL_MPLS_IP
, "MPLS in IP with IPsec"},
530 { BGP_ENCAP_TUNNEL_IP_IP
, "IP in IP"},
531 { BGP_ENCAP_TUNNEL_VXLAN
, "VXLAN"},
532 { BGP_ENCAP_TUNNEL_NVGRE
, "NVGRE"},
533 { BGP_ENCAP_TUNNEL_MPLS
, "MPLS"},
534 { BGP_ENCAP_TUNNEL_MPLS_GRE
, "MPLS in GRE"},
535 { BGP_ENCAP_TUNNEL_VXLAN_GPE
, "VXLAN GPE"},
536 { BGP_ENCAP_TUNNEL_MPLS_UDP
, "MPLS in UDP"},
537 { BGP_ENCAP_TUNNEL_IPV6
, "IPv6"},
538 { BGP_ENCAP_TUNNEL_SR_TE
, "SR TE"},
539 { BGP_ENCAP_TUNNEL_BARE
, "Bare"},
540 { BGP_ENCAP_TUNNEL_SR
, "SR"},
544 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
545 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
546 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
547 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
548 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
549 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
550 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
551 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
553 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
554 { BGP_OSPF_RTYPE_RTR
, "Router" },
555 { BGP_OSPF_RTYPE_NET
, "Network" },
556 { BGP_OSPF_RTYPE_SUM
, "Summary" },
557 { BGP_OSPF_RTYPE_EXT
, "External" },
558 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
559 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
563 /* ADD-PATH Send/Receive field values */
564 static const struct tok bgp_add_path_recvsend
[] = {
571 #define AS_STR_SIZE sizeof("xxxxx.xxxxx")
576 * Convert an AS number into a string and return string pointer.
578 * Depending on bflag is set or not, AS number is converted into ASDOT notation
579 * or plain number notation.
583 as_printf(netdissect_options
*ndo
,
584 char *str
, size_t size
, u_int asnum
)
586 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
587 snprintf(str
, size
, "%u", asnum
);
589 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
594 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
597 decode_prefix4(netdissect_options
*ndo
,
598 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
601 u_int plen
, plenbytes
;
604 plen
= GET_U_1(pptr
);
609 memset(&addr
, 0, sizeof(addr
));
610 plenbytes
= (plen
+ 7) / 8;
611 ITEMCHECK(plenbytes
);
612 GET_CPY_BYTES(&addr
, pptr
+ 1, plenbytes
);
614 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
616 snprintf(buf
, buflen
, "%s/%u", ipaddr_string(ndo
, (const u_char
*)&addr
), plen
);
617 return 1 + plenbytes
;
624 decode_labeled_prefix4(netdissect_options
*ndo
,
625 const u_char
*pptr
, u_int itemlen
, char *buf
,
629 u_int plen
, plenbytes
;
631 /* prefix length and label = 4 bytes */
634 plen
= GET_U_1(pptr
); /* get prefix length */
636 /* this is one of the weirdnesses of rfc3107
637 the label length (actually the label + COS bits)
638 is added to the prefix length;
639 we also do only read out just one label -
640 there is no real application for advertisement of
641 stacked labels in a single BGP message
647 plen
-=24; /* adjust prefixlen - labellength */
653 memset(&addr
, 0, sizeof(addr
));
654 plenbytes
= (plen
+ 7) / 8;
655 ITEMCHECK(plenbytes
);
656 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
658 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
660 /* the label may get offsetted by 4 bits so lets shift it right */
661 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
662 ipaddr_string(ndo
, (const u_char
*)&addr
),
664 GET_BE_U_3(pptr
+ 1)>>4,
665 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
667 return 4 + plenbytes
;
679 * print an ipv4 or ipv6 address into a buffer dependent on address length.
682 bgp_vpn_ip_print(netdissect_options
*ndo
,
683 const u_char
*pptr
, u_int addr_length
)
686 /* worst case string is s fully formatted v6 address */
687 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
690 switch(addr_length
) {
691 case (sizeof(nd_ipv4
) << 3): /* 32 */
692 snprintf(pos
, sizeof(addr
), "%s", GET_IPADDR_STRING(pptr
));
694 case (sizeof(nd_ipv6
) << 3): /* 128 */
695 snprintf(pos
, sizeof(addr
), "%s", GET_IP6ADDR_STRING(pptr
));
698 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
710 * print an multicast s,g entry into a buffer.
711 * the s,g entry is encoded like this.
713 * +-----------------------------------+
714 * | Multicast Source Length (1 octet) |
715 * +-----------------------------------+
716 * | Multicast Source (Variable) |
717 * +-----------------------------------+
718 * | Multicast Group Length (1 octet) |
719 * +-----------------------------------+
720 * | Multicast Group (Variable) |
721 * +-----------------------------------+
723 * return the number of bytes read from the wire.
726 bgp_vpn_sg_print(netdissect_options
*ndo
,
727 const u_char
*pptr
, char *buf
, size_t buflen
)
730 u_int total_length
, offset
;
734 /* Source address length, encoded in bits */
735 addr_length
= GET_U_1(pptr
);
739 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
740 total_length
+= (addr_length
>> 3) + 1;
741 offset
= (u_int
)strlen(buf
);
743 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
744 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
745 pptr
+= (addr_length
>> 3);
748 /* Group address length, encoded in bits */
749 addr_length
= GET_U_1(pptr
);
753 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
754 total_length
+= (addr_length
>> 3) + 1;
755 offset
= (u_int
)strlen(buf
);
757 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
758 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
759 pptr
+= (addr_length
>> 3);
763 return (total_length
);
766 /* Print an RFC 4364 Route Distinguisher */
768 bgp_vpn_rd_print(netdissect_options
*ndo
,
771 /* allocate space for the largest possible string */
772 static char rd
[sizeof("xxxxx.xxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
774 /* allocate space for the largest possible string */
775 char astostr
[AS_STR_SIZE
];
777 /* ok lets load the RD format */
778 switch (GET_BE_U_2(pptr
)) {
781 /* 2-byte-AS:number fmt */
782 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
783 GET_BE_U_2(pptr
+ 2),
784 GET_BE_U_4(pptr
+ 4),
785 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
786 GET_U_1(pptr
+ 6), GET_U_1(pptr
+ 7));
790 /* IP-address:AS fmt */
791 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
792 GET_U_1(pptr
+ 2), GET_U_1(pptr
+ 3),
793 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
794 GET_BE_U_2(pptr
+ 6));
798 /* 4-byte-AS:number fmt */
799 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
800 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 2)),
801 GET_BE_U_2(pptr
+ 6), GET_U_1(pptr
+ 2),
802 GET_U_1(pptr
+ 3), GET_U_1(pptr
+ 4),
803 GET_U_1(pptr
+ 5), GET_BE_U_2(pptr
+ 6));
806 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
815 * Print an RFC 4360 Extended Community.
818 bgp_extended_community_print(netdissect_options
*ndo
,
821 union { /* copy buffer for bandwidth values */
825 /* allocate space for the largest possible string */
826 char astostr
[AS_STR_SIZE
];
828 switch (GET_BE_U_2(pptr
)) {
830 case BGP_EXT_COM_RT_0
:
831 case BGP_EXT_COM_RO_0
:
832 case BGP_EXT_COM_L2VPN_RT_0
:
833 ND_PRINT("%u:%u (= %s)",
834 GET_BE_U_2(pptr
+ 2),
835 GET_BE_U_4(pptr
+ 4),
836 GET_IPADDR_STRING(pptr
+4));
839 case BGP_EXT_COM_RT_1
:
840 case BGP_EXT_COM_RO_1
:
841 case BGP_EXT_COM_L2VPN_RT_1
:
842 case BGP_EXT_COM_VRF_RT_IMP
:
844 GET_IPADDR_STRING(pptr
+2),
845 GET_BE_U_2(pptr
+ 6));
848 case BGP_EXT_COM_RT_2
:
849 case BGP_EXT_COM_RO_2
:
851 as_printf(ndo
, astostr
, sizeof(astostr
),
852 GET_BE_U_4(pptr
+ 2)), GET_BE_U_2(pptr
+ 6));
855 case BGP_EXT_COM_LINKBAND
:
856 bw
.i
= GET_BE_U_4(pptr
+ 4);
857 ND_PRINT("bandwidth: %.3f Mbps",
861 case BGP_EXT_COM_VPN_ORIGIN
:
862 case BGP_EXT_COM_VPN_ORIGIN2
:
863 case BGP_EXT_COM_VPN_ORIGIN3
:
864 case BGP_EXT_COM_VPN_ORIGIN4
:
865 case BGP_EXT_COM_OSPF_RID
:
866 case BGP_EXT_COM_OSPF_RID2
:
867 ND_PRINT("%s", GET_IPADDR_STRING(pptr
+2));
870 case BGP_EXT_COM_OSPF_RTYPE
:
871 case BGP_EXT_COM_OSPF_RTYPE2
:
872 ND_PRINT("area:%s, router-type:%s, metric-type:%s%s",
873 GET_IPADDR_STRING(pptr
+2),
874 tok2str(bgp_extd_comm_ospf_rtype_values
,
876 GET_U_1((pptr
+ 6))),
877 (GET_U_1(pptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
878 ((GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
881 case BGP_EXT_COM_L2INFO
:
882 ND_PRINT("%s Control Flags [0x%02x]:MTU %u",
883 tok2str(l2vpn_encaps_values
,
885 GET_U_1((pptr
+ 2))),
887 GET_BE_U_2(pptr
+ 4));
890 case BGP_EXT_COM_SOURCE_AS
:
891 ND_PRINT("AS %u", GET_BE_U_2(pptr
+ 2));
894 case BGP_EXT_COM_ENCAP
:
895 ND_PRINT("Tunnel type: %s", tok2str(bgp_extd_comm_encap_tunnel_values
,
897 GET_BE_U_2(pptr
+ 6)));
901 ND_PRINT("%02x%02x%02x%02x%02x%02x",
913 * RFC4684 (Section 4)/RFC2858 (Section 4).
914 * RTC membership prefix is structured as follows
915 * [prefix-len] [origin-as] [route-target]
916 * The route-target is encoded as RT ext-comms.
917 * Prefix-len may be 0, 32..96
919 * Note that pptr is not packet data - it is
920 * a buffer owned by our caller - therefore GET_*
921 * macros can not be used.
924 bgp_rt_prefix_print(netdissect_options
*ndo
,
928 /* allocate space for the largest possible string */
929 char rtc_prefix_in_hex
[sizeof("0000 0000 0000 0000")] = "";
930 u_int rtc_prefix_in_hex_len
= 0;
931 static char output
[61]; /* max response string */
932 /* allocate space for the largest possible string */
933 char astostr
[AS_STR_SIZE
];
934 uint16_t ec_type
= 0;
939 snprintf(output
, sizeof(output
), "route-target: 0:0/0");
943 /* hex representation of the prefix */
944 octet_count
= (plen
+7)/8;
945 for (i
=0; i
<octet_count
; i
++) {
946 rtc_prefix_in_hex_len
+= snprintf(rtc_prefix_in_hex
+rtc_prefix_in_hex_len
,
947 sizeof(rtc_prefix_in_hex
)-rtc_prefix_in_hex_len
,
949 ((i
%2 == 1) && (i
<octet_count
-1)) ? " " : "");
954 * The prefix is too short to include the full ext-comm type,
955 * so we have no way to parse it further.
957 snprintf(output
, sizeof(output
), "route-target: partial-type: (%s/%d)",
958 rtc_prefix_in_hex
, plen
);
963 * get the ext-comm type
964 * Note: pptr references a static 8 octet buffer with unused bits set to 0,
965 * hense EXTRACT_*() macros are safe.
967 ec_type
= EXTRACT_BE_U_2(pptr
);
969 case BGP_EXT_COM_RT_0
:
970 /* 2-byte-AS:number fmt */
971 snprintf(output
, sizeof(output
), "route-target: %u:%u/%d (%s)",
972 EXTRACT_BE_U_2(pptr
+2),
973 EXTRACT_BE_U_4(pptr
+4),
974 plen
, rtc_prefix_in_hex
);
977 case BGP_EXT_COM_RT_1
:
978 /* IP-address:AS fmt */
979 snprintf(output
, sizeof(output
), "route-target: %u.%u.%u.%u:%u/%d (%s)",
980 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5),
981 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
984 case BGP_EXT_COM_RT_2
:
985 /* 4-byte-AS:number fmt */
986 snprintf(output
, sizeof(output
), "route-target: %s:%u/%d (%s)",
987 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(pptr
+2)),
988 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
992 snprintf(output
, sizeof(output
), "route target: unknown-type(%04x) (%s/%d)",
994 rtc_prefix_in_hex
, plen
);
1002 decode_rt_routing_info(netdissect_options
*ndo
,
1005 uint8_t route_target
[8];
1007 /* allocate space for the largest possible string */
1008 char astostr
[AS_STR_SIZE
];
1011 /* NLRI "prefix length" from RFC 2858 Section 4. */
1012 plen
= GET_U_1(pptr
); /* get prefix length */
1014 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
1015 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
1016 * target" fields inside the "prefix" depending on its length.
1019 /* Without "origin AS", without "route target". */
1020 ND_PRINT("\n\t default route target");
1025 ND_PRINT("\n\t (illegal prefix length)");
1029 /* With at least "origin AS", possibly with "route target". */
1030 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 1));
1032 plen
-= 32; /* adjust prefix length */
1035 ND_PRINT("\n\t (illegal prefix length)");
1039 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
1040 * and gives the number of octets in the variable-length "route
1041 * target" field inside this NLRI "prefix". Look for it.
1043 memset(&route_target
, 0, sizeof(route_target
));
1044 num_octets
= (plen
+ 7) / 8;
1045 GET_CPY_BYTES(&route_target
, pptr
+ 5, num_octets
);
1046 /* If mask-len is not on octet boundary, ensure all extra bits are 0 */
1048 ((u_char
*)&route_target
)[num_octets
- 1] &=
1049 ((0xff00 >> (plen
% 8)) & 0xff);
1051 ND_PRINT("\n\t origin AS: %s, %s",
1053 bgp_rt_prefix_print(ndo
, (u_char
*)&route_target
, plen
));
1055 return 5 + num_octets
;
1059 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
1060 const u_char
*pptr
, char *buf
, size_t buflen
)
1065 plen
= GET_U_1(pptr
); /* get prefix length */
1070 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1075 memset(&addr
, 0, sizeof(addr
));
1076 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1078 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
1079 ((0xff00 >> (plen
% 8)) & 0xff);
1081 /* the label may get offsetted by 4 bits so lets shift it right */
1082 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1083 bgp_vpn_rd_print(ndo
, pptr
+4),
1084 ipaddr_string(ndo
, (const u_char
*)&addr
),
1086 GET_BE_U_3(pptr
+ 1)>>4,
1087 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1089 return 12 + (plen
+ 7) / 8;
1093 * +-------------------------------+
1095 * | RD:IPv4-address (12 octets) |
1097 * +-------------------------------+
1098 * | MDT Group-address (4 octets) |
1099 * +-------------------------------+
1102 #define MDT_VPN_NLRI_LEN 16
1105 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
1106 const u_char
*pptr
, char *buf
, size_t buflen
)
1109 const u_char
*vpn_ip
;
1111 /* if the NLRI is not predefined length, quit.*/
1112 if (GET_U_1(pptr
) != MDT_VPN_NLRI_LEN
* 8)
1123 pptr
+= sizeof(nd_ipv4
);
1125 /* MDT Group Address */
1126 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
1127 bgp_vpn_rd_print(ndo
, rd
), GET_IPADDR_STRING(vpn_ip
), GET_IPADDR_STRING(pptr
));
1129 return MDT_VPN_NLRI_LEN
+ 1;
1135 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
1136 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
1137 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
1138 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
1139 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
1140 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
1141 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
1143 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
1144 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
1145 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
1146 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
1147 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
1148 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
1149 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
1150 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
1155 decode_multicast_vpn(netdissect_options
*ndo
,
1156 const u_char
*pptr
, char *buf
, size_t buflen
)
1158 /* allocate space for the largest possible string */
1159 char astostr
[AS_STR_SIZE
];
1160 uint8_t route_type
, route_length
;
1161 u_int addr_length
, sg_length
;
1164 route_type
= GET_U_1(pptr
);
1166 route_length
= GET_U_1(pptr
);
1169 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
1170 tok2str(bgp_multicast_vpn_route_type_values
,
1171 "Unknown", route_type
),
1172 route_type
, route_length
);
1174 switch(route_type
) {
1175 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
1176 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1177 offset
= (u_int
)strlen(buf
);
1178 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
1179 bgp_vpn_rd_print(ndo
, pptr
),
1180 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
1181 (route_length
- BGP_VPN_RD_LEN
) << 3));
1183 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
1184 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1185 offset
= (u_int
)strlen(buf
);
1186 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1187 bgp_vpn_rd_print(ndo
, pptr
),
1188 as_printf(ndo
, astostr
, sizeof(astostr
),
1189 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1192 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
1193 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1194 offset
= (u_int
)strlen(buf
);
1195 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1196 bgp_vpn_rd_print(ndo
, pptr
));
1197 pptr
+= BGP_VPN_RD_LEN
;
1199 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1200 addr_length
= route_length
- sg_length
;
1202 ND_TCHECK_LEN(pptr
, addr_length
);
1203 offset
= (u_int
)strlen(buf
);
1204 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
1205 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
1208 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
1209 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1210 offset
= (u_int
)strlen(buf
);
1211 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1212 bgp_vpn_rd_print(ndo
, pptr
));
1213 pptr
+= BGP_VPN_RD_LEN
;
1215 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1218 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
1219 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
1220 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1221 offset
= (u_int
)strlen(buf
);
1222 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1223 bgp_vpn_rd_print(ndo
, pptr
),
1224 as_printf(ndo
, astostr
, sizeof(astostr
),
1225 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1226 pptr
+= BGP_VPN_RD_LEN
+ 4;
1228 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1232 * no per route-type printing yet.
1234 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1239 return route_length
+ 2;
1246 * As I remember, some versions of systems have an snprintf() that
1247 * returns -1 if the buffer would have overflowed. If the return
1248 * value is negative, set buflen to 0, to indicate that we've filled
1251 * If the return value is greater than buflen, that means that
1252 * the buffer would have overflowed; again, set buflen to 0 in
1255 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1258 else if ((u_int)stringlen>buflen) \
1261 buflen-=stringlen; \
1266 decode_labeled_vpn_l2(netdissect_options
*ndo
,
1267 const u_char
*pptr
, char *buf
, size_t buflen
)
1269 u_int plen
, tlen
, tlv_type
, tlv_len
, ttlv_len
;
1272 plen
= GET_BE_U_2(pptr
);
1275 /* Old and new L2VPN NLRI share AFI/SAFI
1276 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1277 * and > 17 as old format. Complain for the middle case
1280 /* assume AD-only with RD, BGPNH */
1281 ND_TCHECK_LEN(pptr
, 12);
1283 stringlen
= snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
1284 bgp_vpn_rd_print(ndo
, pptr
),
1285 GET_IPADDR_STRING(pptr
+8));
1286 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1290 } else if (plen
> 17) {
1291 /* assume old format */
1292 /* RD, ID, LBLKOFF, LBLBASE */
1294 ND_TCHECK_LEN(pptr
, 15);
1296 stringlen
= snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1297 bgp_vpn_rd_print(ndo
, pptr
),
1298 GET_BE_U_2(pptr
+ 8),
1299 GET_BE_U_2(pptr
+ 10),
1300 GET_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1301 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1305 /* ok now the variable part - lets read out TLVs*/
1309 stringlen
=snprintf(buf
,buflen
, "\n\t\tran past the end");
1310 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1314 tlv_type
= GET_U_1(pptr
);
1316 tlv_len
= GET_BE_U_2(pptr
); /* length, in *bits* */
1317 ttlv_len
= (tlv_len
+ 7)/8; /* length, in *bytes* */
1323 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1326 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1328 while (ttlv_len
!= 0) {
1331 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1332 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1338 stringlen
=snprintf(buf
,buflen
, "%02x",
1341 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1349 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1352 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1354 if (tlen
< ttlv_len
) {
1356 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1357 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1367 /* complain bitterly ? */
1377 decode_prefix6(netdissect_options
*ndo
,
1378 const u_char
*pd
, u_int itemlen
, char *buf
, size_t buflen
)
1381 u_int plen
, plenbytes
;
1389 memset(&addr
, 0, sizeof(addr
));
1390 plenbytes
= (plen
+ 7) / 8;
1391 ITEMCHECK(plenbytes
);
1392 GET_CPY_BYTES(&addr
, pd
+ 1, plenbytes
);
1394 addr
[plenbytes
- 1] &=
1395 ((0xff00 >> (plen
% 8)) & 0xff);
1397 snprintf(buf
, buflen
, "%s/%u", ip6addr_string(ndo
, (const u_char
*)&addr
), plen
);
1398 return 1 + plenbytes
;
1405 decode_labeled_prefix6(netdissect_options
*ndo
,
1406 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
1409 u_int plen
, plenbytes
;
1411 /* prefix length and label = 4 bytes */
1414 plen
= GET_U_1(pptr
); /* get prefix length */
1419 plen
-= 24; /* adjust prefixlen - labellength */
1425 memset(&addr
, 0, sizeof(addr
));
1426 plenbytes
= (plen
+ 7) / 8;
1427 GET_CPY_BYTES(&addr
, pptr
+ 4, plenbytes
);
1429 addr
[plenbytes
- 1] &=
1430 ((0xff00 >> (plen
% 8)) & 0xff);
1432 /* the label may get offsetted by 4 bits so lets shift it right */
1433 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
1434 ip6addr_string(ndo
, (const u_char
*)&addr
),
1436 GET_BE_U_3(pptr
+ 1)>>4,
1437 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1439 return 4 + plenbytes
;
1449 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1450 const u_char
*pptr
, char *buf
, size_t buflen
)
1455 plen
= GET_U_1(pptr
); /* get prefix length */
1460 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1465 memset(&addr
, 0, sizeof(addr
));
1466 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1468 addr
[(plen
+ 7) / 8 - 1] &=
1469 ((0xff00 >> (plen
% 8)) & 0xff);
1471 /* the label may get offsetted by 4 bits so lets shift it right */
1472 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1473 bgp_vpn_rd_print(ndo
, pptr
+4),
1474 ip6addr_string(ndo
, (const u_char
*)&addr
),
1476 GET_BE_U_3(pptr
+ 1)>>4,
1477 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1479 return 12 + (plen
+ 7) / 8;
1483 decode_clnp_prefix(netdissect_options
*ndo
,
1484 const u_char
*pptr
, char *buf
, size_t buflen
)
1489 plen
= GET_U_1(pptr
); /* get prefix length */
1494 memset(&addr
, 0, sizeof(addr
));
1495 GET_CPY_BYTES(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1497 addr
[(plen
+ 7) / 8 - 1] &=
1498 ((0xff00 >> (plen
% 8)) & 0xff);
1500 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1501 snprintf(buf
, buflen
, "%s/%u",
1502 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1505 return 1 + (plen
+ 7) / 8;
1509 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1510 const u_char
*pptr
, char *buf
, size_t buflen
)
1515 plen
= GET_U_1(pptr
); /* get prefix length */
1520 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1525 memset(&addr
, 0, sizeof(addr
));
1526 GET_CPY_BYTES(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1528 addr
[(plen
+ 7) / 8 - 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
1530 /* the label may get offsetted by 4 bits so lets shift it right */
1531 /* Cannot use GET_ISONSAP_STRING (not packet buffer pointer) */
1532 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1533 bgp_vpn_rd_print(ndo
, pptr
+4),
1534 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1536 GET_BE_U_3(pptr
+ 1)>>4,
1537 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1539 return 12 + (plen
+ 7) / 8;
1543 * bgp_attr_get_as_size
1545 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1546 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1547 * support, exchange AS-Path with the same path-attribute type value 0x02.
1550 bgp_attr_get_as_size(netdissect_options
*ndo
,
1551 uint8_t bgpa_type
, const u_char
*pptr
, u_int len
)
1553 const u_char
*tptr
= pptr
;
1556 * If the path attribute is the optional AS4 path type, then we already
1557 * know, that ASs must be encoded in 4 byte format.
1559 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1564 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1565 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1568 while (tptr
< pptr
+ len
) {
1570 * If we do not find a valid segment type, our guess might be wrong.
1572 if (GET_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| GET_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1575 tptr
+= 2 + GET_U_1(tptr
+ 1) * 2;
1579 * If we correctly reached end of the AS path attribute data content,
1580 * then most likely ASs were indeed encoded as 2 bytes.
1582 if (tptr
== pptr
+ len
) {
1589 * We can come here, either we did not have enough data, or if we
1590 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1591 * so that calller can try to decode each AS as of 4 bytes. If indeed
1592 * there was not enough data, it will crib and end the parse anyways.
1598 * The only way to know that a BGP UPDATE message is using add path is
1599 * by checking if the capability is in the OPEN message which we may have missed.
1600 * So this function checks if it is possible that the update could contain add path
1601 * and if so it checks that standard BGP doesn't make sense.
1604 check_add_path(netdissect_options
*ndo
, const u_char
*pptr
, u_int length
,
1605 u_int max_prefix_length
)
1607 u_int offset
, prefix_length
;
1614 * Scan through the NLRI information under the assumpetion that
1615 * it doesn't have path IDs.
1617 for (offset
= 0; offset
< length
;) {
1619 if (!ND_TTEST_1(pptr
+ offset
)) {
1620 /* We ran out of captured data; quit scanning. */
1623 prefix_length
= GET_U_1(pptr
+ offset
);
1625 * Add 4 to cover the path id
1626 * and check the prefix length isn't greater than 32/128.
1628 if (prefix_length
> max_prefix_length
) {
1631 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1632 offset
+= 1 + ((prefix_length
+ 7) / 8);
1634 /* check we haven't gone past the end of the section */
1635 if (offset
> length
) {
1639 /* check it's not standard BGP */
1640 for (offset
= 0; offset
< length
; ) {
1641 if (!ND_TTEST_1(pptr
+ offset
)) {
1642 /* We ran out of captured data; quit scanning. */
1645 prefix_length
= GET_U_1(pptr
+ offset
);
1647 * If the prefix_length is zero (0.0.0.0/0)
1648 * and since it's not the only address (length >= 5)
1649 * then it is add-path
1651 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1654 offset
+= 1 + ((prefix_length
+ 7) / 8);
1656 if (offset
> length
) {
1660 /* assume not add-path by default */
1665 bgp_mp_af_print(netdissect_options
*ndo
,
1666 const u_char
*tptr
, u_int tlen
,
1667 uint16_t *afp
, uint8_t *safip
)
1672 af
= GET_BE_U_2(tptr
);
1674 safi
= GET_U_1(tptr
+ 2);
1677 ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1678 tok2str(af_values
, "Unknown AFI", af
),
1680 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1681 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1684 switch(af
<<8 | safi
) {
1685 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1686 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1687 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1688 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1689 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1690 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1691 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1692 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1693 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1694 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1695 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1696 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1697 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1698 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1699 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1700 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1701 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1702 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1703 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1704 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1705 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1706 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1707 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1708 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1709 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1710 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1711 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1714 ND_TCHECK_LEN(tptr
, tlen
);
1715 ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af
, safi
);
1716 if (ndo
->ndo_vflag
<= 1)
1717 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1726 bgp_nlri_print(netdissect_options
*ndo
, uint16_t af
, uint8_t safi
,
1727 const u_char
*tptr
, u_int len
,
1728 char *buf
, size_t buflen
,
1729 int add_path4
, int add_path6
)
1734 switch (af
<<8 | safi
) {
1735 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1736 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1737 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1739 path_id
= GET_BE_U_4(tptr
);
1742 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1744 ND_PRINT("\n\t (illegal prefix length)");
1745 else if (advance
== -2)
1746 break; /* bytes left, but not enough */
1748 ND_PRINT("\n\t %s", buf
);
1750 ND_PRINT(" Path Id: %u", path_id
);
1754 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1755 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1757 ND_PRINT("\n\t (illegal prefix length)");
1758 else if (advance
== -2)
1760 else if (advance
== -3)
1761 break; /* bytes left, but not enough */
1763 ND_PRINT("\n\t %s", buf
);
1765 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1766 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1767 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1768 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, buflen
);
1770 ND_PRINT("\n\t (illegal prefix length)");
1772 ND_PRINT("\n\t %s", buf
);
1774 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1775 advance
= decode_rt_routing_info(ndo
, tptr
);
1777 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1778 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1779 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, buflen
);
1781 ND_PRINT("\n\t (illegal prefix length)");
1782 else if (advance
== -2)
1785 ND_PRINT("\n\t %s", buf
);
1788 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1789 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, buflen
);
1791 ND_PRINT("\n\t (illegal prefix length)");
1792 else if (advance
== -2)
1795 ND_PRINT("\n\t %s", buf
);
1797 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1798 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1799 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1801 path_id
= GET_BE_U_4(tptr
);
1804 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1806 ND_PRINT("\n\t (illegal prefix length)");
1807 else if (advance
== -2)
1808 break; /* bytes left, but not enough */
1810 ND_PRINT("\n\t %s", buf
);
1812 ND_PRINT(" Path Id: %u", path_id
);
1816 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1817 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1819 ND_PRINT("\n\t (illegal prefix length)");
1820 else if (advance
== -2)
1822 else if (advance
== -3)
1823 break; /* bytes left, but not enough */
1825 ND_PRINT("\n\t %s", buf
);
1827 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1828 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1829 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1830 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, buflen
);
1832 ND_PRINT("\n\t (illegal prefix length)");
1834 ND_PRINT("\n\t %s", buf
);
1836 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1837 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1838 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1839 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1840 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, buflen
);
1842 ND_PRINT("\n\t (illegal length)");
1843 else if (advance
== -2)
1846 ND_PRINT("\n\t %s", buf
);
1848 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1849 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1850 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1851 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1853 ND_PRINT("\n\t (illegal prefix length)");
1855 ND_PRINT("\n\t %s", buf
);
1857 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1858 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1859 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1860 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1862 ND_PRINT("\n\t (illegal prefix length)");
1864 ND_PRINT("\n\t %s", buf
);
1868 * This should not happen, we should have been protected
1869 * by bgp_mp_af_print()'s return value.
1871 ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af
, safi
);
1876 trunc
: /* we rely on the caller to recognize -2 return value */
1881 bgp_attr_print(netdissect_options
*ndo
,
1882 uint8_t atype
, const u_char
*pptr
, u_int len
,
1883 const unsigned attr_set_level
)
1885 /* allocate space for the largest possible string */
1886 char astostr
[AS_STR_SIZE
];
1889 uint8_t safi
, snpa
, nhlen
;
1893 char buf
[MAXHOSTNAMELEN
+ 100];
1895 int add_path4
, add_path6
;
1902 case BGPTYPE_ORIGIN
:
1904 ND_PRINT("invalid len");
1906 ND_PRINT("%s", tok2str(bgp_origin_values
,
1907 "Unknown Origin Typecode",
1913 * Process AS4 byte path and AS2 byte path attributes here.
1915 case BGPTYPE_AS4_PATH
:
1916 case BGPTYPE_AS_PATH
:
1918 ND_PRINT("invalid len");
1927 * BGP updates exchanged between New speakers that support 4
1928 * byte AS, ASs are always encoded in 4 bytes. There is no
1929 * definitive way to find this, just by the packet's
1930 * contents. So, check for packet's TLV's sanity assuming
1931 * 2 bytes first, and it does not pass, assume that ASs are
1932 * encoded in 4 bytes format and move on.
1934 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1936 while (tptr
< pptr
+ len
) {
1937 ND_PRINT("%s", tok2str(bgp_as_path_segment_open_values
,
1938 "?", GET_U_1(tptr
)));
1939 for (i
= 0; i
< GET_U_1(tptr
+ 1) * as_size
; i
+= as_size
) {
1940 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
1942 as_printf(ndo
, astostr
, sizeof(astostr
),
1944 GET_BE_U_2(tptr
+ i
+ 2) :
1945 GET_BE_U_4(tptr
+ i
+ 2)));
1947 ND_PRINT("%s", tok2str(bgp_as_path_segment_close_values
,
1948 "?", GET_U_1(tptr
)));
1949 tptr
+= 2 + GET_U_1(tptr
+ 1) * as_size
;
1952 case BGPTYPE_NEXT_HOP
:
1954 ND_PRINT("invalid len");
1956 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
1959 case BGPTYPE_MULTI_EXIT_DISC
:
1960 case BGPTYPE_LOCAL_PREF
:
1962 ND_PRINT("invalid len");
1964 ND_PRINT("%u", GET_BE_U_4(tptr
));
1967 case BGPTYPE_ATOMIC_AGGREGATE
:
1969 ND_PRINT("invalid len");
1971 case BGPTYPE_AGGREGATOR
:
1974 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1975 * the length of this PA can be either 6 bytes or 8 bytes.
1977 if (len
!= 6 && len
!= 8) {
1978 ND_PRINT("invalid len");
1981 ND_TCHECK_LEN(tptr
, len
);
1983 ND_PRINT(" AS #%s, origin %s",
1984 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(tptr
)),
1985 GET_IPADDR_STRING(tptr
+ 2));
1987 ND_PRINT(" AS #%s, origin %s",
1988 as_printf(ndo
, astostr
, sizeof(astostr
),
1989 GET_BE_U_4(tptr
)), GET_IPADDR_STRING(tptr
+ 4));
1992 case BGPTYPE_AGGREGATOR4
:
1994 ND_PRINT("invalid len");
1997 ND_PRINT(" AS #%s, origin %s",
1998 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)),
1999 GET_IPADDR_STRING(tptr
+ 4));
2001 case BGPTYPE_COMMUNITIES
:
2003 ND_PRINT("invalid len");
2011 comm
= GET_BE_U_4(tptr
);
2013 case BGP_COMMUNITY_NO_EXPORT
:
2014 ND_PRINT(" NO_EXPORT");
2016 case BGP_COMMUNITY_NO_ADVERT
:
2017 ND_PRINT(" NO_ADVERTISE");
2019 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
2020 ND_PRINT(" NO_EXPORT_SUBCONFED");
2024 (comm
>> 16) & 0xffff,
2026 (tlen
>4) ? ", " : "");
2033 case BGPTYPE_ORIGINATOR_ID
:
2035 ND_PRINT("invalid len");
2038 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2040 case BGPTYPE_CLUSTER_LIST
:
2042 ND_PRINT("invalid len");
2049 GET_IPADDR_STRING(tptr
),
2050 (tlen
>4) ? ", " : "");
2055 case BGPTYPE_MP_REACH_NLRI
:
2059 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2071 nhlen
= GET_U_1(tptr
);
2077 uint8_t tnhlen
= nhlen
;
2080 ND_PRINT("\n\t nexthop: ");
2081 while (tnhlen
!= 0) {
2085 switch(af
<<8 | safi
) {
2086 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
2087 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
2088 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
2089 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
2090 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
2091 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
2092 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
2093 if (tnhlen
< sizeof(nd_ipv4
)) {
2094 ND_PRINT("invalid len");
2099 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2100 tptr
+= sizeof(nd_ipv4
);
2101 tnhlen
-= sizeof(nd_ipv4
);
2102 tlen
-= sizeof(nd_ipv4
);
2105 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
2106 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
2107 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
2108 if (tnhlen
< sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
) {
2109 ND_PRINT("invalid len");
2114 ND_PRINT("RD: %s, %s",
2115 bgp_vpn_rd_print(ndo
, tptr
),
2116 GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2117 tptr
+= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2118 tlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2119 tnhlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2122 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
2123 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
2124 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
2125 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
2126 if (tnhlen
< sizeof(nd_ipv6
)) {
2127 ND_PRINT("invalid len");
2132 ND_PRINT("%s", GET_IP6ADDR_STRING(tptr
));
2133 tptr
+= sizeof(nd_ipv6
);
2134 tlen
-= sizeof(nd_ipv6
);
2135 tnhlen
-= sizeof(nd_ipv6
);
2138 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
2139 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
2140 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2141 if (tnhlen
< sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
) {
2142 ND_PRINT("invalid len");
2147 ND_PRINT("RD: %s, %s",
2148 bgp_vpn_rd_print(ndo
, tptr
),
2149 GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2150 tptr
+= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2151 tlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2152 tnhlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2155 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2156 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2157 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2158 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2159 if (tnhlen
< sizeof(nd_ipv4
)) {
2160 ND_PRINT("invalid len");
2165 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
2166 tptr
+= (sizeof(nd_ipv4
));
2167 tlen
-= (sizeof(nd_ipv4
));
2168 tnhlen
-= (sizeof(nd_ipv4
));
2171 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2172 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2173 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2174 ND_PRINT("%s", GET_ISONSAP_STRING(tptr
, tnhlen
));
2180 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2181 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2182 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2183 if (tnhlen
< BGP_VPN_RD_LEN
+1) {
2184 ND_PRINT("invalid len");
2189 ND_TCHECK_LEN(tptr
, tnhlen
);
2190 ND_PRINT("RD: %s, %s",
2191 bgp_vpn_rd_print(ndo
, tptr
),
2192 GET_ISONSAP_STRING(tptr
+BGP_VPN_RD_LEN
,tnhlen
-BGP_VPN_RD_LEN
));
2193 /* rfc986 mapped IPv4 address ? */
2194 if (GET_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
2195 ND_PRINT(" = %s", GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
+4));
2196 /* rfc1888 mapped IPv6 address ? */
2197 else if (GET_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
2198 ND_PRINT(" = %s", GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
+3));
2206 * bgp_mp_af_print() should have saved us from
2207 * an unsupported AFI/SAFI.
2209 ND_PRINT("ERROR: no AFI %u/SAFI %u nexthop decoder", af
, safi
);
2218 ND_PRINT(", nh-length: %u", nhlen
);
2220 /* As per RFC 2858; this is reserved in RFC 4760 */
2223 snpa
= GET_U_1(tptr
);
2228 ND_PRINT("\n\t %u SNPA", snpa
);
2229 for (/*nothing*/; snpa
!= 0; snpa
--) {
2233 snpalen
= GET_U_1(tptr
);
2234 ND_PRINT("\n\t %u bytes", snpalen
);
2239 ND_TCHECK_LEN(tptr
, snpalen
);
2244 ND_PRINT(", no SNPA");
2247 add_path4
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 32);
2248 add_path6
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 128);
2250 while (tptr
< pptr
+ len
) {
2251 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2252 add_path4
, add_path6
);
2261 case BGPTYPE_MP_UNREACH_NLRI
:
2262 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
2263 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2269 if (len
== BGP_MP_NLRI_MINSIZE
)
2270 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2274 add_path4
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 32);
2275 add_path6
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 128);
2277 while (tptr
< pptr
+ len
) {
2278 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2279 add_path4
, add_path6
);
2287 case BGPTYPE_EXTD_COMMUNITIES
:
2289 ND_PRINT("invalid len");
2298 extd_comm
=GET_BE_U_2(tptr
);
2300 ND_PRINT("\n\t %s (0x%04x), Flags [%s]",
2301 tok2str(bgp_extd_comm_subtype_values
,
2302 "unknown extd community typecode",
2305 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
2311 bgp_extended_community_print(ndo
, tptr
);
2317 case BGPTYPE_PMSI_TUNNEL
:
2319 uint8_t tunnel_type
, flags
;
2324 flags
= GET_U_1(tptr
);
2325 tunnel_type
= GET_U_1(tptr
+ 1);
2327 ND_PRINT("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2328 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2330 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2331 GET_BE_U_3(tptr
+ 2)>>4);
2336 switch (tunnel_type
) {
2337 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2338 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2339 ND_PRINT("\n\t Sender %s, P-Group %s",
2340 GET_IPADDR_STRING(tptr
),
2341 GET_IPADDR_STRING(tptr
+4));
2344 case BGP_PMSI_TUNNEL_PIM_SSM
:
2345 ND_PRINT("\n\t Root-Node %s, P-Group %s",
2346 GET_IPADDR_STRING(tptr
),
2347 GET_IPADDR_STRING(tptr
+4));
2349 case BGP_PMSI_TUNNEL_INGRESS
:
2350 ND_PRINT("\n\t Tunnel-Endpoint %s",
2351 GET_IPADDR_STRING(tptr
));
2353 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2354 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2355 ND_PRINT("\n\t Root-Node %s, LSP-ID 0x%08x",
2356 GET_IPADDR_STRING(tptr
),
2357 GET_BE_U_4(tptr
+ 4));
2359 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2360 ND_PRINT("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2361 GET_IPADDR_STRING(tptr
),
2362 GET_BE_U_4(tptr
+ 4));
2365 if (ndo
->ndo_vflag
<= 1) {
2366 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2377 type
= GET_U_1(tptr
);
2378 length
= GET_BE_U_2(tptr
+ 1);
2382 ND_PRINT("\n\t %s TLV (%u), length %u",
2383 tok2str(bgp_aigp_values
, "Unknown", type
),
2391 * Check if we can read the TLV data.
2401 ND_PRINT(", metric %" PRIu64
,
2406 if (ndo
->ndo_vflag
<= 1) {
2407 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2416 case BGPTYPE_ATTR_SET
:
2420 ND_PRINT("\n\t Origin AS: %s",
2421 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)));
2426 u_int aflags
, alenlen
, alen
;
2430 ND_PRINT(" [path attr too short]");
2434 aflags
= GET_U_1(tptr
);
2435 atype
= GET_U_1(tptr
+ 1);
2438 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2439 ND_TCHECK_LEN(tptr
, alenlen
);
2440 if (len
< alenlen
) {
2441 ND_PRINT(" [path attr too short]");
2445 alen
= bgp_attr_len(aflags
, tptr
);
2449 ND_PRINT("\n\t %s (%u), length: %u",
2450 tok2str(bgp_attr_values
,
2451 "Unknown Attribute", atype
),
2456 ND_PRINT(", Flags [%s%s%s%s",
2457 aflags
& 0x80 ? "O" : "",
2458 aflags
& 0x40 ? "T" : "",
2459 aflags
& 0x20 ? "P" : "",
2460 aflags
& 0x10 ? "E" : "");
2462 ND_PRINT("+%x", aflags
& 0xf);
2467 ND_PRINT(" [path attr too short]");
2472 * The protocol encoding per se allows ATTR_SET to be nested
2473 * as many times as the message can accommodate. This printer
2474 * used to be able to recurse into ATTR_SET contents until the
2475 * stack exhaustion, but now there is a limit on that (if live
2476 * protocol exchange goes that many levels deep, something is
2477 * probably wrong anyway). Feel free to refine this value if
2478 * you can find the spec with respective normative text.
2480 if (attr_set_level
== 10)
2481 ND_PRINT("(too many nested levels, not recursing)");
2482 else if (!bgp_attr_print(ndo
, atype
, tptr
, alen
, attr_set_level
+ 1))
2489 case BGPTYPE_LARGE_COMMUNITY
:
2490 if (len
== 0 || len
% 12) {
2491 ND_PRINT("invalid len");
2496 ND_PRINT("%u:%u:%u%s",
2498 GET_BE_U_4(tptr
+ 4),
2499 GET_BE_U_4(tptr
+ 8),
2500 (len
> 12) ? ", " : "");
2503 * len will always be a multiple of 12, as per the above,
2504 * so this will never underflow.
2510 ND_TCHECK_LEN(pptr
, len
);
2511 ND_PRINT("\n\t no Attribute %u decoder", atype
); /* we have no decoder for the attribute */
2512 if (ndo
->ndo_vflag
<= 1)
2513 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2517 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2518 ND_TCHECK_LEN(pptr
, len
);
2519 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2528 bgp_capabilities_print(netdissect_options
*ndo
,
2529 const u_char
*opt
, u_int caps_len
)
2531 /* allocate space for the largest possible string */
2532 char astostr
[AS_STR_SIZE
];
2533 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2536 while (i
< caps_len
) {
2537 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2538 cap_type
=GET_U_1(opt
+ i
);
2539 cap_len
=GET_U_1(opt
+ i
+ 1);
2540 ND_PRINT("\n\t %s (%u), length: %u",
2541 tok2str(bgp_capcode_values
, "Unknown", cap_type
),
2544 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2546 case BGP_CAPCODE_MP
:
2547 /* AFI (16 bits), Reserved (8 bits), SAFI (8 bits) */
2549 ND_PRINT(" (too short, < 4)");
2552 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u)",
2553 tok2str(af_values
, "Unknown", GET_BE_U_2(opt
+ i
+ 2)),
2554 GET_BE_U_2(opt
+ i
+ 2),
2555 tok2str(bgp_safi_values
, "Unknown", GET_U_1(opt
+ i
+ 5)),
2556 GET_U_1(opt
+ i
+ 5));
2558 case BGP_CAPCODE_ML
:
2561 while (tcap_len
>= 4) {
2562 ND_PRINT( "\n\t\tAFI %s (%u), SAFI %s (%u), Count: %u",
2563 tok2str(af_values
, "Unknown",
2564 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2565 GET_BE_U_2(opt
+ i
+ cap_offset
),
2566 tok2str(bgp_safi_values
, "Unknown",
2567 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2568 GET_U_1(opt
+ i
+ cap_offset
+ 2),
2569 GET_U_1(opt
+ i
+ cap_offset
+ 3));
2574 case BGP_CAPCODE_RESTART
:
2575 /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */
2577 ND_PRINT(" (too short, < 2)");
2581 ND_PRINT("\n\t\tRestart Flags: [%s], Restart Time %us",
2582 ((GET_U_1(opt
+ i
+ 2))&0x80) ? "R" : "none",
2583 GET_BE_U_2(opt
+ i
+ 2)&0xfff);
2586 while(tcap_len
>=4) {
2587 ND_PRINT("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2588 tok2str(af_values
,"Unknown",
2589 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2590 GET_BE_U_2(opt
+ i
+ cap_offset
),
2591 tok2str(bgp_safi_values
,"Unknown",
2592 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2593 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2594 ((GET_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" );
2599 case BGP_CAPCODE_RR
:
2600 case BGP_CAPCODE_LLGR
:
2601 case BGP_CAPCODE_RR_CISCO
:
2602 case BGP_CAPCODE_EXT_MSG
:
2603 case BGP_CAPCODE_ENH_RR
:
2605 case BGP_CAPCODE_AS_NEW
:
2607 * Extract the 4 byte AS number encoded.
2610 ND_PRINT(" (too short, < 4)");
2613 ND_PRINT("\n\t\t 4 Byte AS %s",
2614 as_printf(ndo
, astostr
, sizeof(astostr
),
2615 GET_BE_U_4(opt
+ i
+ 2)));
2617 case BGP_CAPCODE_ADD_PATH
:
2619 ND_PRINT(" (bogus)"); /* length */
2624 while (tcap_len
!= 0) {
2626 nd_print_invalid(ndo
);
2629 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2630 tok2str(af_values
,"Unknown",GET_BE_U_2(opt
+ i
+ cap_offset
)),
2631 GET_BE_U_2(opt
+ i
+ cap_offset
),
2632 tok2str(bgp_safi_values
,"Unknown",GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2633 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2634 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",GET_U_1(opt
+ i
+ cap_offset
+ 3))
2641 ND_PRINT("\n\t\tno decoder for Capability %u",
2643 if (ndo
->ndo_vflag
<= 1)
2644 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2648 if (ndo
->ndo_vflag
> 1 && cap_len
!= 0) {
2649 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2651 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2656 nd_print_trunc(ndo
);
2660 bgp_open_print(netdissect_options
*ndo
,
2661 const u_char
*dat
, u_int length
)
2663 /* allocate space for the largest possible string */
2664 char astostr
[AS_STR_SIZE
];
2665 const struct bgp_open
*bgp_open_header
;
2668 const struct bgp_opt
*bgpopt
;
2671 uint8_t extended_opt_params
= 0;
2672 u_int open_size
= BGP_OPEN_SIZE
;
2673 u_int opt_size
= BGP_OPT_SIZE
;
2675 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2676 if (length
< BGP_OPEN_SIZE
)
2679 bgp_open_header
= (const struct bgp_open
*)dat
;
2681 ND_PRINT("\n\t Version %u, ",
2682 GET_U_1(bgp_open_header
->bgpo_version
));
2683 ND_PRINT("my AS %s, ",
2684 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(bgp_open_header
->bgpo_myas
)));
2685 ND_PRINT("Holdtime %us, ",
2686 GET_BE_U_2(bgp_open_header
->bgpo_holdtime
));
2687 ND_PRINT("ID %s", GET_IPADDR_STRING(bgp_open_header
->bgpo_id
));
2688 optslen
= GET_U_1(bgp_open_header
->bgpo_optlen
);
2689 opsttype
= GET_U_1(bgp_open_header
->bgpo_opttype
);
2690 if (opsttype
== BGP_OPEN_NON_EXT_OPT_TYPE_EXTENDED_LENGTH
) {
2691 optslen
= GET_BE_U_2(bgp_open_header
->bgpo_optlen_extended
);
2692 extended_opt_params
= 1;
2696 ND_PRINT("\n\t Optional parameters%s, length: %u",
2697 extended_opt_params
? " (Extended)" : "", optslen
);
2699 opt
= dat
+ open_size
;
2700 length
-= open_size
;
2703 while (i
< optslen
) {
2707 ND_TCHECK_LEN(opt
+ i
, opt_size
);
2708 if (length
< opt_size
+ i
)
2710 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2711 opt_type
= GET_U_1(bgpopt
->bgpopt_type
);
2712 opt_len
= extended_opt_params
? GET_BE_U_2(bgpopt
->bgpopt_len
)
2713 : GET_U_1(bgpopt
->bgpopt_len
);
2714 if (opt_size
+ i
+ opt_len
> optslen
) {
2715 ND_PRINT("\n\t Option %u, length: %u, goes past the end of the options",
2720 ND_PRINT("\n\t Option %s (%u), length: %u",
2721 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2725 /* now let's decode the options we know*/
2729 bgp_capabilities_print(ndo
, opt
+ opt_size
+ i
,
2735 ND_PRINT("\n\t no decoder for option %u",
2739 i
+= opt_size
+ opt_len
;
2743 nd_print_trunc(ndo
);
2747 bgp_update_print(netdissect_options
*ndo
,
2748 const u_char
*dat
, u_int length
)
2751 u_int withdrawn_routes_len
;
2752 char buf
[MAXHOSTNAMELEN
+ 100];
2759 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2760 if (length
< BGP_SIZE
)
2765 /* Unfeasible routes */
2769 withdrawn_routes_len
= GET_BE_U_2(p
);
2772 if (withdrawn_routes_len
> 1) {
2774 * Without keeping state from the original NLRI message,
2775 * it's not possible to tell if this a v4 or v6 route,
2776 * so only try to decode it if we're not v6 enabled.
2778 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2779 if (length
< withdrawn_routes_len
)
2781 ND_PRINT("\n\t Withdrawn routes:");
2782 add_path
= check_add_path(ndo
, p
, withdrawn_routes_len
, 32);
2783 while (withdrawn_routes_len
!= 0) {
2785 if (withdrawn_routes_len
< 4) {
2786 p
+= withdrawn_routes_len
;
2787 length
-= withdrawn_routes_len
;
2790 path_id
= GET_BE_U_4(p
);
2793 withdrawn_routes_len
-= 4;
2795 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2797 ND_PRINT("\n\t (illegal prefix length)");
2799 } else if (wpfx
== -2)
2800 goto trunc
; /* bytes left, but not enough */
2802 ND_PRINT("\n\t %s", buf
);
2804 ND_PRINT(" Path Id: %u", path_id
);
2808 withdrawn_routes_len
-= wpfx
;
2812 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2813 if (length
< withdrawn_routes_len
)
2815 p
+= withdrawn_routes_len
;
2816 length
-= withdrawn_routes_len
;
2822 len
= GET_BE_U_2(p
);
2826 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2827 /* No withdrawn routes, no path attributes, no NLRI */
2828 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2833 /* Make sure the path attributes don't go past the end of the packet */
2836 /* do something more useful!*/
2838 uint8_t aflags
, atype
, alenlen
;
2845 ND_PRINT("\n\t [path attrs too short]");
2850 aflags
= GET_U_1(p
);
2851 atype
= GET_U_1(p
+ 1);
2855 alenlen
= bgp_attr_lenlen(aflags
, p
);
2856 ND_TCHECK_LEN(p
, alenlen
);
2857 if (length
< alenlen
)
2859 if (len
< alenlen
) {
2860 ND_PRINT("\n\t [path attrs too short]");
2865 alen
= bgp_attr_len(aflags
, p
);
2870 ND_PRINT("\n\t %s (%u), length: %u",
2871 tok2str(bgp_attr_values
, "Unknown Attribute", atype
),
2876 ND_PRINT(", Flags [%s%s%s%s",
2877 aflags
& 0x80 ? "O" : "",
2878 aflags
& 0x40 ? "T" : "",
2879 aflags
& 0x20 ? "P" : "",
2880 aflags
& 0x10 ? "E" : "");
2882 ND_PRINT("+%x", aflags
& 0xf);
2886 ND_PRINT(" [path attrs too short]");
2893 if (!bgp_attr_print(ndo
, atype
, p
, alen
, 0))
2902 add_path
= check_add_path(ndo
, p
, length
, 32);
2903 ND_PRINT("\n\t Updated routes:");
2904 while (length
!= 0) {
2909 path_id
= GET_BE_U_4(p
);
2913 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2915 ND_PRINT("\n\t (illegal prefix length)");
2918 goto trunc
; /* bytes left, but not enough */
2920 ND_PRINT("\n\t %s", buf
);
2922 ND_PRINT(" Path Id: %u", path_id
);
2931 nd_print_trunc(ndo
);
2935 bgp_notification_print(netdissect_options
*ndo
,
2936 const u_char
*dat
, u_int length
)
2938 const struct bgp_notification
*bgp_notification_header
;
2940 uint8_t bgpn_major
, bgpn_minor
;
2942 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
2943 if (length
<BGP_NOTIFICATION_SIZE
)
2946 bgp_notification_header
= (const struct bgp_notification
*)dat
;
2947 bgpn_major
= GET_U_1(bgp_notification_header
->bgpn_major
);
2948 bgpn_minor
= GET_U_1(bgp_notification_header
->bgpn_minor
);
2950 ND_PRINT(", %s (%u)",
2951 tok2str(bgp_notify_major_values
, "Unknown Error",
2955 switch (bgpn_major
) {
2957 case BGP_NOTIFY_MAJOR_MSG
:
2958 ND_PRINT(", subcode %s (%u)",
2959 tok2str(bgp_notify_minor_msg_values
, "Unknown",
2963 case BGP_NOTIFY_MAJOR_OPEN
:
2964 ND_PRINT(", subcode %s (%u)",
2965 tok2str(bgp_notify_minor_open_values
, "Unknown",
2969 case BGP_NOTIFY_MAJOR_UPDATE
:
2970 ND_PRINT(", subcode %s (%u)",
2971 tok2str(bgp_notify_minor_update_values
, "Unknown",
2975 case BGP_NOTIFY_MAJOR_FSM
:
2976 ND_PRINT(" subcode %s (%u)",
2977 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
2981 case BGP_NOTIFY_MAJOR_CAP
:
2982 ND_PRINT(" subcode %s (%u)",
2983 tok2str(bgp_notify_minor_cap_values
, "Unknown",
2987 case BGP_NOTIFY_MAJOR_CEASE
:
2988 ND_PRINT(", subcode %s (%u)",
2989 tok2str(bgp_notify_minor_cease_values
, "Unknown",
2993 /* RFC 4486 mentions optionally 7 bytes
2994 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2996 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2997 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2998 ND_PRINT(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2999 tok2str(af_values
, "Unknown", GET_BE_U_2(tptr
)),
3001 tok2str(bgp_safi_values
, "Unknown", GET_U_1((tptr
+ 2))),
3002 GET_U_1((tptr
+ 2)),
3003 GET_BE_U_4(tptr
+ 3));
3006 * RFC 9003 describes a method to send a communication
3007 * intended for human consumption regarding the Administrative Shutdown
3009 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
3010 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
3011 length
>= BGP_NOTIFICATION_SIZE
+ 1) {
3012 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
3013 uint8_t shutdown_comm_length
= GET_U_1(tptr
);
3014 uint8_t remainder_offset
= 0;
3015 /* garbage, hexdump it all */
3016 if (shutdown_comm_length
> length
- (BGP_NOTIFICATION_SIZE
+ 1)) {
3017 ND_PRINT(", invalid Shutdown Communication length");
3019 else if (shutdown_comm_length
== 0) {
3020 ND_PRINT(", empty Shutdown Communication");
3021 remainder_offset
+= 1;
3023 /* a proper shutdown communication */
3025 ND_PRINT(", Shutdown Communication (length: %u): \"", shutdown_comm_length
);
3026 nd_printjn(ndo
, tptr
+1, shutdown_comm_length
);
3028 remainder_offset
+= shutdown_comm_length
+ 1;
3030 /* if there is trailing data, hexdump it */
3031 if(length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
) > 0) {
3032 ND_PRINT(", Data: (length: %u)", length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
3033 hex_print(ndo
, "\n\t\t", tptr
+ remainder_offset
, length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
3043 nd_print_trunc(ndo
);
3047 bgp_route_refresh_print(netdissect_options
*ndo
,
3048 const u_char
*pptr
, u_int len
)
3050 const struct bgp_route_refresh
*bgp_route_refresh_header
;
3052 ND_TCHECK_LEN(pptr
, BGP_ROUTE_REFRESH_SIZE
);
3054 /* some little sanity checking */
3055 if (len
<BGP_ROUTE_REFRESH_SIZE
)
3058 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
3060 ND_PRINT("\n\t AFI %s (%u), SAFI %s (%u), Subtype %s (%u)",
3061 tok2str(af_values
, "Unknown",
3062 GET_BE_U_2(bgp_route_refresh_header
->afi
)),
3063 GET_BE_U_2(bgp_route_refresh_header
->afi
),
3064 tok2str(bgp_safi_values
, "Unknown",
3065 GET_U_1(bgp_route_refresh_header
->safi
)),
3066 GET_U_1(bgp_route_refresh_header
->safi
),
3067 tok2str(bgp_route_refresh_subtype_values
, "Unknown",
3068 GET_U_1(bgp_route_refresh_header
->subtype
)),
3069 GET_U_1(bgp_route_refresh_header
->subtype
));
3071 if (ndo
->ndo_vflag
> 1) {
3072 ND_TCHECK_LEN(pptr
, len
);
3073 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
3078 nd_print_trunc(ndo
);
3082 bgp_pdu_print(netdissect_options
*ndo
,
3083 const u_char
*dat
, u_int length
)
3085 const struct bgp
*bgp_header
;
3088 ND_TCHECK_LEN(dat
, BGP_SIZE
);
3089 bgp_header
= (const struct bgp
*)dat
;
3090 bgp_type
= GET_U_1(bgp_header
->bgp_type
);
3092 ND_PRINT("\n\t%s Message (%u), length: %u",
3093 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
3099 bgp_open_print(ndo
, dat
, length
);
3102 bgp_update_print(ndo
, dat
, length
);
3104 case BGP_NOTIFICATION
:
3105 bgp_notification_print(ndo
, dat
, length
);
3109 case BGP_ROUTE_REFRESH
:
3110 bgp_route_refresh_print(ndo
, dat
, length
);
3113 /* we have no decoder for the BGP message */
3114 ND_TCHECK_LEN(dat
, length
);
3115 ND_PRINT("\n\t no Message %u decoder", bgp_type
);
3116 print_unknown_data(ndo
, dat
, "\n\t ", length
);
3121 nd_print_trunc(ndo
);
3126 bgp_print(netdissect_options
*ndo
,
3127 const u_char
*dat
, u_int length _U_
)
3130 const u_char
*ep
= ndo
->ndo_snapend
;
3131 const u_char
*start
;
3132 const u_char marker
[] = {
3133 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3134 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3136 const struct bgp
*bgp_header
;
3139 ndo
->ndo_protocol
= "bgp";
3142 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
3150 if (GET_U_1(p
) != 0xff) {
3155 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
3157 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
3162 /* found BGP header */
3163 ND_TCHECK_LEN(p
, BGP_SIZE
);
3164 bgp_header
= (const struct bgp
*)p
;
3167 nd_print_trunc(ndo
);
3169 hlen
= GET_BE_U_2(bgp_header
->bgp_len
);
3170 if (hlen
< BGP_SIZE
) {
3171 ND_PRINT("\nmessage length %u < %u", hlen
, BGP_SIZE
);
3172 nd_print_invalid(ndo
);
3176 if (ND_TTEST_LEN(p
, hlen
)) {
3177 if (!bgp_pdu_print(ndo
, p
, hlen
))
3182 ND_PRINT("\n[|BGP %s]",
3183 tok2str(bgp_msg_values
,
3184 "Unknown Message Type",
3185 GET_U_1(bgp_header
->bgp_type
)));
3193 nd_print_trunc(ndo
);