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 /* options should follow */
85 #define BGP_OPEN_SIZE 29 /* unaligned */
88 nd_uint8_t bgpopt_type
;
89 nd_uint8_t bgpopt_len
;
92 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
93 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
95 struct bgp_notification
{
96 nd_byte bgpn_marker
[16];
99 nd_uint8_t bgpn_major
;
100 nd_uint8_t bgpn_minor
;
102 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
104 struct bgp_route_refresh
{
105 nd_byte bgp_marker
[16];
107 nd_uint8_t type
; /* No padding after this; afi is, in fact, not aligned */
112 #define BGP_ROUTE_REFRESH_SIZE 23
114 #define bgp_attr_lenlen(flags, p) \
115 (((flags) & 0x10) ? 2U : 1U)
116 #define bgp_attr_len(flags, p) \
117 (((flags) & 0x10) ? GET_BE_U_2(p) : GET_U_1(p))
119 #define BGPTYPE_ORIGIN 1
120 #define BGPTYPE_AS_PATH 2
121 #define BGPTYPE_NEXT_HOP 3
122 #define BGPTYPE_MULTI_EXIT_DISC 4
123 #define BGPTYPE_LOCAL_PREF 5
124 #define BGPTYPE_ATOMIC_AGGREGATE 6
125 #define BGPTYPE_AGGREGATOR 7
126 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
127 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC4456 */
128 #define BGPTYPE_CLUSTER_LIST 10 /* RFC4456 */
129 #define BGPTYPE_DPA 11 /* deprecated, draft-ietf-idr-bgp-dpa */
130 #define BGPTYPE_ADVERTISERS 12 /* deprecated RFC1863 */
131 #define BGPTYPE_RCID_PATH 13 /* deprecated RFC1863 */
132 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */
133 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */
134 #define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */
135 #define BGPTYPE_AS4_PATH 17 /* RFC6793 */
136 #define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */
137 #define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */
138 #define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */
139 #define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */
140 #define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */
141 #define BGPTYPE_AIGP 26 /* RFC7311 */
142 #define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */
143 #define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */
144 #define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */
145 #define BGPTYPE_ATTR_SET 128 /* RFC6368 */
147 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
149 static const struct tok bgp_attr_values
[] = {
150 { BGPTYPE_ORIGIN
, "Origin"},
151 { BGPTYPE_AS_PATH
, "AS Path"},
152 { BGPTYPE_AS4_PATH
, "AS4 Path"},
153 { BGPTYPE_NEXT_HOP
, "Next Hop"},
154 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
155 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
156 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
157 { BGPTYPE_AGGREGATOR
, "Aggregator"},
158 { BGPTYPE_AGGREGATOR4
, "Aggregator4"},
159 { BGPTYPE_COMMUNITIES
, "Community"},
160 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
161 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
162 { BGPTYPE_DPA
, "DPA"},
163 { BGPTYPE_ADVERTISERS
, "Advertisers"},
164 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
165 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
166 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
167 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
168 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
169 { BGPTYPE_TUNNEL_ENCAP
, "Tunnel Encapsulation"},
170 { BGPTYPE_TRAFFIC_ENG
, "Traffic Engineering"},
171 { BGPTYPE_IPV6_EXTD_COMMUNITIES
, "IPv6 Extended Community"},
172 { BGPTYPE_AIGP
, "Accumulated IGP Metric"},
173 { BGPTYPE_PE_DISTINGUISHER_LABEL
, "PE Distinguisher Label"},
174 { BGPTYPE_ENTROPY_LABEL
, "Entropy Label"},
175 { BGPTYPE_LARGE_COMMUNITY
, "Large Community"},
176 { BGPTYPE_ATTR_SET
, "Attribute Set"},
177 { 255, "Reserved for development"},
182 #define BGP_AS_SEQUENCE 2
183 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
184 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
186 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
187 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
189 static const struct tok bgp_as_path_segment_open_values
[] = {
190 { BGP_AS_SEQUENCE
, ""},
192 { BGP_CONFED_AS_SEQUENCE
, "( "},
193 { BGP_CONFED_AS_SET
, "({ "},
197 static const struct tok bgp_as_path_segment_close_values
[] = {
198 { BGP_AS_SEQUENCE
, ""},
200 { BGP_CONFED_AS_SEQUENCE
, ")"},
201 { BGP_CONFED_AS_SET
, "})"},
205 #define BGP_OPT_AUTH 1
206 #define BGP_OPT_CAP 2
208 static const struct tok bgp_opt_values
[] = {
209 { BGP_OPT_AUTH
, "Authentication Information"},
210 { BGP_OPT_CAP
, "Capabilities Advertisement"},
214 #define BGP_CAPCODE_MP 1 /* RFC2858 */
215 #define BGP_CAPCODE_RR 2 /* RFC2918 */
216 #define BGP_CAPCODE_ORF 3 /* RFC5291 */
217 #define BGP_CAPCODE_MR 4 /* RFC3107 */
218 #define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */
219 #define BGP_CAPCODE_ML 8 /* RFC8277 */
220 #define BGP_CAPCODE_RESTART 64 /* RFC4724 */
221 #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */
222 #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */
223 #define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */
224 #define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */
225 #define BGP_CAPCODE_ENH_RR 70 /* draft-keyur-bgp-enhanced-route-refresh */
226 #define BGP_CAPCODE_LLGR 71 /* draft-uttaro-idr-bgp-persistence-05 */
227 #define BGP_CAPCODE_RR_CISCO 128
229 static const struct tok bgp_capcode_values
[] = {
230 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
231 { BGP_CAPCODE_RR
, "Route Refresh"},
232 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
233 { BGP_CAPCODE_MR
, "Multiple Routes to a Destination"},
234 { BGP_CAPCODE_EXT_NH
, "Extended Next Hop Encoding"},
235 { BGP_CAPCODE_ML
, "Multiple Labels"},
236 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
237 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
238 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
239 { BGP_CAPCODE_MULTISESS
, "Multisession BGP"},
240 { BGP_CAPCODE_ADD_PATH
, "Multiple Paths"},
241 { BGP_CAPCODE_ENH_RR
, "Enhanced Route Refresh"},
242 { BGP_CAPCODE_LLGR
, "Long-lived Graceful Restart"},
243 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
247 #define BGP_NOTIFY_MAJOR_MSG 1
248 #define BGP_NOTIFY_MAJOR_OPEN 2
249 #define BGP_NOTIFY_MAJOR_UPDATE 3
250 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
251 #define BGP_NOTIFY_MAJOR_FSM 5
252 #define BGP_NOTIFY_MAJOR_CEASE 6
253 #define BGP_NOTIFY_MAJOR_CAP 7
255 static const struct tok bgp_notify_major_values
[] = {
256 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
257 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
258 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
259 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
260 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
261 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
262 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
266 /* draft-ietf-idr-cease-subcode-02 */
267 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
268 /* draft-ietf-idr-shutdown-07 */
269 #define BGP_NOTIFY_MINOR_CEASE_SHUT 2
270 #define BGP_NOTIFY_MINOR_CEASE_RESET 4
271 #define BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN 128
272 static const struct tok bgp_notify_minor_cease_values
[] = {
273 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
274 { BGP_NOTIFY_MINOR_CEASE_SHUT
, "Administrative Shutdown"},
275 { 3, "Peer Unconfigured"},
276 { BGP_NOTIFY_MINOR_CEASE_RESET
, "Administrative Reset"},
277 { 5, "Connection Rejected"},
278 { 6, "Other Configuration Change"},
279 { 7, "Connection Collision Resolution"},
283 static const struct tok bgp_notify_minor_msg_values
[] = {
284 { 1, "Connection Not Synchronized"},
285 { 2, "Bad Message Length"},
286 { 3, "Bad Message Type"},
290 static const struct tok bgp_notify_minor_open_values
[] = {
291 { 1, "Unsupported Version Number"},
293 { 3, "Bad BGP Identifier"},
294 { 4, "Unsupported Optional Parameter"},
295 { 5, "Authentication Failure"},
296 { 6, "Unacceptable Hold Time"},
297 { 7, "Capability Message Error"},
301 static const struct tok bgp_notify_minor_update_values
[] = {
302 { 1, "Malformed Attribute List"},
303 { 2, "Unrecognized Well-known Attribute"},
304 { 3, "Missing Well-known Attribute"},
305 { 4, "Attribute Flags Error"},
306 { 5, "Attribute Length Error"},
307 { 6, "Invalid ORIGIN Attribute"},
308 { 7, "AS Routing Loop"},
309 { 8, "Invalid NEXT_HOP Attribute"},
310 { 9, "Optional Attribute Error"},
311 { 10, "Invalid Network Field"},
312 { 11, "Malformed AS_PATH"},
316 static const struct tok bgp_notify_minor_fsm_values
[] = {
317 { 0, "Unspecified Error"},
318 { 1, "In OpenSent State"},
319 { 2, "In OpenConfirm State"},
320 { 3, "In Established State"},
324 static const struct tok bgp_notify_minor_cap_values
[] = {
325 { 1, "Invalid Action Value" },
326 { 2, "Invalid Capability Length" },
327 { 3, "Malformed Capability Value" },
328 { 4, "Unsupported Capability Code" },
332 static const struct tok bgp_origin_values
[] = {
339 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
340 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
341 #define BGP_PMSI_TUNNEL_PIM_SSM 3
342 #define BGP_PMSI_TUNNEL_PIM_SM 4
343 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
344 #define BGP_PMSI_TUNNEL_INGRESS 6
345 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
347 static const struct tok bgp_pmsi_tunnel_values
[] = {
348 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
349 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
350 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
351 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
352 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
353 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
354 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
358 static const struct tok bgp_pmsi_flag_values
[] = {
359 { 0x01, "Leaf Information required"},
363 #define BGP_AIGP_TLV 1
365 static const struct tok bgp_aigp_values
[] = {
366 { BGP_AIGP_TLV
, "AIGP"},
370 /* Subsequent address family identifier, RFC2283 section 7 */
372 #define SAFNUM_UNICAST 1
373 #define SAFNUM_MULTICAST 2
374 #define SAFNUM_UNIMULTICAST 3 /* deprecated now */
375 /* labeled BGP RFC3107 */
376 #define SAFNUM_LABUNICAST 4
378 #define SAFNUM_MULTICAST_VPN 5
379 /* draft-nalawade-kapoor-tunnel-safi */
380 #define SAFNUM_TUNNEL 64
382 #define SAFNUM_VPLS 65
384 #define SAFNUM_MDT 66
386 #define SAFNUM_EVPN 70
388 #define SAFNUM_VPNUNICAST 128
390 #define SAFNUM_VPNMULTICAST 129
391 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
393 #define SAFNUM_RT_ROUTING_INFO 132
395 #define BGP_VPN_RD_LEN 8
397 static const struct tok bgp_safi_values
[] = {
398 { SAFNUM_RES
, "Reserved"},
399 { SAFNUM_UNICAST
, "Unicast"},
400 { SAFNUM_MULTICAST
, "Multicast"},
401 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
402 { SAFNUM_LABUNICAST
, "labeled Unicast"},
403 { SAFNUM_TUNNEL
, "Tunnel"},
404 { SAFNUM_VPLS
, "VPLS"},
405 { SAFNUM_MDT
, "MDT"},
406 { SAFNUM_EVPN
, "EVPN"},
407 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
408 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
409 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
410 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
411 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
415 /* well-known community */
416 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
417 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
418 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
420 /* Extended community type - RFC 4360 */
421 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
422 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
423 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
424 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
425 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
426 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
427 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
428 /* rfc2547 bgp-mpls-vpns */
429 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
430 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatibility */
431 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatibility */
432 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatibility */
434 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
435 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatibility */
436 #define BGP_EXT_COM_ENCAP 0x030c /* rfc5512 */
438 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
439 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatibility */
441 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
443 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
444 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
445 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
446 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
448 /* https://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
449 #define BGP_EXT_COM_EIGRP_GEN 0x8800
450 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
451 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
452 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
453 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
454 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
456 static const struct tok bgp_extd_comm_flag_values
[] = {
457 { 0x8000, "vendor-specific"},
458 { 0x4000, "non-transitive"},
462 static const struct tok bgp_extd_comm_subtype_values
[] = {
463 { BGP_EXT_COM_RT_0
, "target"},
464 { BGP_EXT_COM_RT_1
, "target"},
465 { BGP_EXT_COM_RT_2
, "target"},
466 { BGP_EXT_COM_RO_0
, "origin"},
467 { BGP_EXT_COM_RO_1
, "origin"},
468 { BGP_EXT_COM_RO_2
, "origin"},
469 { BGP_EXT_COM_LINKBAND
, "link-BW"},
470 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
471 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
472 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
473 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
474 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
475 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
476 { BGP_EXT_COM_ENCAP
, "encapsulation"},
477 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
478 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
479 { BGP_EXT_COM_L2INFO
, "layer2-info"},
480 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
481 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
482 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
483 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
484 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
485 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
486 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
487 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
488 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
489 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
493 /* RFC RFC5512 BGP Tunnel Encapsulation Attribute Tunnel Types */
494 #define BGP_ENCAP_TUNNEL_L2TPV3_IP 1
495 #define BGP_ENCAP_TUNNEL_GRE 2
496 #define BGP_ENCAP_TUNNEL_TRANSMIT 3
497 #define BGP_ENCAP_TUNNEL_IPSEC 4
498 #define BGP_ENCAP_TUNNEL_IP_IPSEC 5
499 #define BGP_ENCAP_TUNNEL_MPLS_IP 6
500 #define BGP_ENCAP_TUNNEL_IP_IP 7
501 #define BGP_ENCAP_TUNNEL_VXLAN 8
502 #define BGP_ENCAP_TUNNEL_NVGRE 9
503 #define BGP_ENCAP_TUNNEL_MPLS 10
504 #define BGP_ENCAP_TUNNEL_MPLS_GRE 11
505 #define BGP_ENCAP_TUNNEL_VXLAN_GPE 12
506 #define BGP_ENCAP_TUNNEL_MPLS_UDP 13
507 #define BGP_ENCAP_TUNNEL_IPV6 14
508 #define BGP_ENCAP_TUNNEL_SR_TE 15
509 #define BGP_ENCAP_TUNNEL_BARE 16
510 #define BGP_ENCAP_TUNNEL_SR 17
512 static const struct tok bgp_extd_comm_encap_tunnel_values
[] = {
513 { BGP_ENCAP_TUNNEL_L2TPV3_IP
, "L2TPv3 over IP"},
514 { BGP_ENCAP_TUNNEL_GRE
, "GRE"},
515 { BGP_ENCAP_TUNNEL_TRANSMIT
, "Transmit Tunnel"},
516 { BGP_ENCAP_TUNNEL_IPSEC
, "IPsec"},
517 { BGP_ENCAP_TUNNEL_IP_IPSEC
, "IP in IP with IPsec"},
518 { BGP_ENCAP_TUNNEL_MPLS_IP
, "MPLS in IP with IPsec"},
519 { BGP_ENCAP_TUNNEL_IP_IP
, "IP in IP"},
520 { BGP_ENCAP_TUNNEL_VXLAN
, "VXLAN"},
521 { BGP_ENCAP_TUNNEL_NVGRE
, "NVGRE"},
522 { BGP_ENCAP_TUNNEL_MPLS
, "MPLS"},
523 { BGP_ENCAP_TUNNEL_MPLS_GRE
, "MPLS in GRE"},
524 { BGP_ENCAP_TUNNEL_VXLAN_GPE
, "VXLAN GPE"},
525 { BGP_ENCAP_TUNNEL_MPLS_UDP
, "MPLS in UDP"},
526 { BGP_ENCAP_TUNNEL_IPV6
, "IPv6"},
527 { BGP_ENCAP_TUNNEL_SR_TE
, "SR TE"},
528 { BGP_ENCAP_TUNNEL_BARE
, "Bare"},
529 { BGP_ENCAP_TUNNEL_SR
, "SR"},
533 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
534 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
535 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
536 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
537 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
538 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
539 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
540 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
542 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
543 { BGP_OSPF_RTYPE_RTR
, "Router" },
544 { BGP_OSPF_RTYPE_NET
, "Network" },
545 { BGP_OSPF_RTYPE_SUM
, "Summary" },
546 { BGP_OSPF_RTYPE_EXT
, "External" },
547 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
548 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
552 /* ADD-PATH Send/Receive field values */
553 static const struct tok bgp_add_path_recvsend
[] = {
560 /* allocate space for the largest possible string */
561 static char astostr
[sizeof("xxxxx.xxxxx")];
566 * Convert an AS number into a string and return string pointer.
568 * Depending on bflag is set or not, AS number is converted into ASDOT notation
569 * or plain number notation.
573 as_printf(netdissect_options
*ndo
,
574 char *str
, size_t size
, u_int asnum
)
576 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
577 snprintf(str
, size
, "%u", asnum
);
579 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
584 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
587 decode_prefix4(netdissect_options
*ndo
,
588 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
591 u_int plen
, plenbytes
;
595 plen
= GET_U_1(pptr
);
600 memset(&addr
, 0, sizeof(addr
));
601 plenbytes
= (plen
+ 7) / 8;
602 ND_TCHECK_LEN(pptr
+ 1, plenbytes
);
603 ITEMCHECK(plenbytes
);
604 memcpy(&addr
, pptr
+ 1, plenbytes
);
606 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
608 snprintf(buf
, buflen
, "%s/%u", ipaddr_string(ndo
, (const u_char
*)&addr
), plen
);
609 return 1 + plenbytes
;
619 decode_labeled_prefix4(netdissect_options
*ndo
,
620 const u_char
*pptr
, u_int itemlen
, char *buf
,
624 u_int plen
, plenbytes
;
626 /* prefix length and label = 4 bytes */
629 plen
= GET_U_1(pptr
); /* get prefix length */
631 /* this is one of the weirdnesses of rfc3107
632 the label length (actually the label + COS bits)
633 is added to the prefix length;
634 we also do only read out just one label -
635 there is no real application for advertisement of
636 stacked labels in a single BGP message
642 plen
-=24; /* adjust prefixlen - labellength */
648 memset(&addr
, 0, sizeof(addr
));
649 plenbytes
= (plen
+ 7) / 8;
650 ND_TCHECK_LEN(pptr
+ 4, plenbytes
);
651 ITEMCHECK(plenbytes
);
652 memcpy(&addr
, pptr
+ 4, plenbytes
);
654 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
656 /* the label may get offsetted by 4 bits so lets shift it right */
657 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
658 ipaddr_string(ndo
, (const u_char
*)&addr
),
660 GET_BE_U_3(pptr
+ 1)>>4,
661 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
663 return 4 + plenbytes
;
675 * print an ipv4 or ipv6 address into a buffer dependend on address length.
678 bgp_vpn_ip_print(netdissect_options
*ndo
,
679 const u_char
*pptr
, u_int addr_length
)
682 /* worst case string is s fully formatted v6 address */
683 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
686 switch(addr_length
) {
687 case (sizeof(nd_ipv4
) << 3): /* 32 */
688 ND_TCHECK_LEN(pptr
, sizeof(nd_ipv4
));
689 snprintf(pos
, sizeof(addr
), "%s", GET_IPADDR_STRING(pptr
));
691 case (sizeof(nd_ipv6
) << 3): /* 128 */
692 ND_TCHECK_LEN(pptr
, sizeof(nd_ipv6
));
693 snprintf(pos
, sizeof(addr
), "%s", GET_IP6ADDR_STRING(pptr
));
696 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
709 * print an multicast s,g entry into a buffer.
710 * the s,g entry is encoded like this.
712 * +-----------------------------------+
713 * | Multicast Source Length (1 octet) |
714 * +-----------------------------------+
715 * | Multicast Source (Variable) |
716 * +-----------------------------------+
717 * | Multicast Group Length (1 octet) |
718 * +-----------------------------------+
719 * | Multicast Group (Variable) |
720 * +-----------------------------------+
722 * return the number of bytes read from the wire.
725 bgp_vpn_sg_print(netdissect_options
*ndo
,
726 const u_char
*pptr
, char *buf
, size_t buflen
)
729 u_int total_length
, offset
;
733 /* 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 */
750 addr_length
= GET_U_1(pptr
);
754 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
755 total_length
+= (addr_length
>> 3) + 1;
756 offset
= (u_int
)strlen(buf
);
758 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
759 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
760 pptr
+= (addr_length
>> 3);
764 return (total_length
);
767 /* Print an RFC 4364 Route Distinguisher */
769 bgp_vpn_rd_print(netdissect_options
*ndo
,
772 /* allocate space for the largest possible string */
773 static char rd
[sizeof("xxxxx.xxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
776 /* ok lets load the RD format */
777 switch (GET_BE_U_2(pptr
)) {
780 /* 2-byte-AS:number fmt */
781 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
782 GET_BE_U_2(pptr
+ 2),
783 GET_BE_U_4(pptr
+ 4),
784 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
785 GET_U_1(pptr
+ 6), GET_U_1(pptr
+ 7));
789 /* IP-address:AS fmt */
790 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
791 GET_U_1(pptr
+ 2), GET_U_1(pptr
+ 3),
792 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
793 GET_BE_U_2(pptr
+ 6));
797 /* 4-byte-AS:number fmt */
798 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
799 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 2)),
800 GET_BE_U_2(pptr
+ 6), GET_U_1(pptr
+ 2),
801 GET_U_1(pptr
+ 3), GET_U_1(pptr
+ 4),
802 GET_U_1(pptr
+ 5), GET_BE_U_2(pptr
+ 6));
805 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
814 * Print an RFC 4360 Extended Community.
817 bgp_extended_community_print(netdissect_options
*ndo
,
820 union { /* copy buffer for bandwidth values */
825 switch (GET_BE_U_2(pptr
)) {
827 case BGP_EXT_COM_RT_0
:
828 case BGP_EXT_COM_RO_0
:
829 case BGP_EXT_COM_L2VPN_RT_0
:
830 ND_PRINT("%u:%u (= %s)",
831 GET_BE_U_2(pptr
+ 2),
832 GET_BE_U_4(pptr
+ 4),
833 GET_IPADDR_STRING(pptr
+4));
836 case BGP_EXT_COM_RT_1
:
837 case BGP_EXT_COM_RO_1
:
838 case BGP_EXT_COM_L2VPN_RT_1
:
839 case BGP_EXT_COM_VRF_RT_IMP
:
841 GET_IPADDR_STRING(pptr
+2),
842 GET_BE_U_2(pptr
+ 6));
845 case BGP_EXT_COM_RT_2
:
846 case BGP_EXT_COM_RO_2
:
848 as_printf(ndo
, astostr
, sizeof(astostr
),
849 GET_BE_U_4(pptr
+ 2)), GET_BE_U_2(pptr
+ 6));
852 case BGP_EXT_COM_LINKBAND
:
853 bw
.i
= GET_BE_U_4(pptr
+ 2);
854 ND_PRINT("bandwidth: %.3f Mbps",
858 case BGP_EXT_COM_VPN_ORIGIN
:
859 case BGP_EXT_COM_VPN_ORIGIN2
:
860 case BGP_EXT_COM_VPN_ORIGIN3
:
861 case BGP_EXT_COM_VPN_ORIGIN4
:
862 case BGP_EXT_COM_OSPF_RID
:
863 case BGP_EXT_COM_OSPF_RID2
:
864 ND_PRINT("%s", GET_IPADDR_STRING(pptr
+2));
867 case BGP_EXT_COM_OSPF_RTYPE
:
868 case BGP_EXT_COM_OSPF_RTYPE2
:
869 ND_PRINT("area:%s, router-type:%s, metric-type:%s%s",
870 GET_IPADDR_STRING(pptr
+2),
871 tok2str(bgp_extd_comm_ospf_rtype_values
,
873 GET_U_1((pptr
+ 6))),
874 (GET_U_1(pptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
875 ((GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
878 case BGP_EXT_COM_L2INFO
:
879 ND_PRINT("%s Control Flags [0x%02x]:MTU %u",
880 tok2str(l2vpn_encaps_values
,
882 GET_U_1((pptr
+ 2))),
884 GET_BE_U_2(pptr
+ 4));
887 case BGP_EXT_COM_SOURCE_AS
:
888 ND_PRINT("AS %u", GET_BE_U_2(pptr
+ 2));
891 case BGP_EXT_COM_ENCAP
:
892 ND_PRINT("Tunnel type: %s", tok2str(bgp_extd_comm_encap_tunnel_values
,
894 GET_BE_U_2(pptr
+ 6)));
898 ND_PRINT("%02x%02x%02x%02x%02x%02x",
910 * RFC4684 (Section 4)/RFC2858 (Section 4).
911 * RTC membership prefix is structured as follows
912 * [prefix-len] [origin-as] [route-target]
913 * The route-target is encoded as RT ext-comms.
914 * Prefix-len may be 0, 32..96
916 * Note that pptr is not packet data - it is
917 * a buffer owned by our caller - therefore GET_*
918 * macros can not be used.
921 bgp_rt_prefix_print(netdissect_options
*ndo
,
925 /* allocate space for the largest possible string */
926 char rtc_prefix_in_hex
[20] = "";
927 u_int rtc_prefix_in_hex_len
= 0;
928 static char output
[61]; /* max response string */
929 uint16_t ec_type
= 0;
934 snprintf(output
, sizeof(output
), "route-target: 0:0/0");
938 /* hex representation of the prefix */
939 octet_count
= (plen
+7)/8;
940 for (i
=0; i
<octet_count
; i
++) {
941 rtc_prefix_in_hex_len
+= snprintf(rtc_prefix_in_hex
+rtc_prefix_in_hex_len
,
942 sizeof(rtc_prefix_in_hex
)-rtc_prefix_in_hex_len
,
944 ((i
%2 == 1) && (i
<octet_count
-1)) ? " " : "");
949 * The prefix is too short to include the full ext-comm type,
950 * so we have no way to parse it further.
952 snprintf(output
, sizeof(output
), "route-target: partial-type: (%s/%d)",
953 rtc_prefix_in_hex
, plen
);
958 * get the ext-comm type
959 * Note: pptr references a static 8 octet buffer with unused bits set to 0,
960 * hense EXTRACT_*() macros are safe.
962 ec_type
= EXTRACT_BE_U_2(pptr
);
964 case BGP_EXT_COM_RT_0
:
965 /* 2-byte-AS:number fmt */
966 snprintf(output
, sizeof(output
), "route-target: %u:%u/%d (%s)",
967 EXTRACT_BE_U_2(pptr
+2),
968 EXTRACT_BE_U_4(pptr
+4),
969 plen
, rtc_prefix_in_hex
);
972 case BGP_EXT_COM_RT_1
:
973 /* IP-address:AS fmt */
974 snprintf(output
, sizeof(output
), "route-target: %u.%u.%u.%u:%u/%d (%s)",
975 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5),
976 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
979 case BGP_EXT_COM_RT_2
:
980 /* 4-byte-AS:number fmt */
981 snprintf(output
, sizeof(output
), "route-target: %s:%u/%d (%s)",
982 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(pptr
+2)),
983 EXTRACT_BE_U_2(pptr
+6), plen
, rtc_prefix_in_hex
);
987 snprintf(output
, sizeof(output
), "route target: unknown-type(%04x) (%s/%d)",
989 rtc_prefix_in_hex
, plen
);
997 decode_rt_routing_info(netdissect_options
*ndo
,
1000 uint8_t route_target
[8];
1002 char asbuf
[sizeof(astostr
)]; /* bgp_vpn_rd_print() overwrites astostr */
1005 /* NLRI "prefix length" from RFC 2858 Section 4. */
1007 plen
= GET_U_1(pptr
); /* get prefix length */
1009 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
1010 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
1011 * target" fields inside the "prefix" depending on its length.
1014 /* Without "origin AS", without "route target". */
1015 ND_PRINT("\n\t default route target");
1020 ND_PRINT("\n\t (illegal prefix length)");
1024 /* With at least "origin AS", possibly with "route target". */
1025 ND_TCHECK_4(pptr
+ 1);
1026 as_printf(ndo
, asbuf
, sizeof(asbuf
), GET_BE_U_4(pptr
+ 1));
1028 plen
-= 32; /* adjust prefix length */
1031 ND_PRINT("\n\t (illegal prefix length)");
1035 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
1036 * and gives the number of octets in the variable-length "route
1037 * target" field inside this NLRI "prefix". Look for it.
1039 memset(&route_target
, 0, sizeof(route_target
));
1040 num_octets
= (plen
+ 7) / 8;
1041 ND_TCHECK_LEN(pptr
+ 5, num_octets
);
1042 memcpy(&route_target
, pptr
+ 5, num_octets
);
1043 /* If mask-len is not on octet boundary, ensure all extra bits are 0 */
1045 ((u_char
*)&route_target
)[num_octets
- 1] &=
1046 ((0xff00 >> (plen
% 8)) & 0xff);
1048 ND_PRINT("\n\t origin AS: %s, %s",
1050 bgp_rt_prefix_print(ndo
, (u_char
*)&route_target
, plen
));
1052 return 5 + num_octets
;
1058 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
1059 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 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
1077 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1079 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
1080 ((0xff00 >> (plen
% 8)) & 0xff);
1082 /* the label may get offsetted by 4 bits so lets shift it right */
1083 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1084 bgp_vpn_rd_print(ndo
, pptr
+4),
1085 ipaddr_string(ndo
, (const u_char
*)&addr
),
1087 GET_BE_U_3(pptr
+ 1)>>4,
1088 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1090 return 12 + (plen
+ 7) / 8;
1097 * +-------------------------------+
1099 * | RD:IPv4-address (12 octets) |
1101 * +-------------------------------+
1102 * | MDT Group-address (4 octets) |
1103 * +-------------------------------+
1106 #define MDT_VPN_NLRI_LEN 16
1109 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
1110 const u_char
*pptr
, char *buf
, size_t buflen
)
1113 const u_char
*vpn_ip
;
1117 /* if the NLRI is not predefined length, quit.*/
1118 if (GET_U_1(pptr
) != MDT_VPN_NLRI_LEN
* 8)
1128 ND_TCHECK_LEN(pptr
, sizeof(nd_ipv4
));
1130 pptr
+= sizeof(nd_ipv4
);
1132 /* MDT Group Address */
1133 ND_TCHECK_LEN(pptr
, sizeof(nd_ipv4
));
1135 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
1136 bgp_vpn_rd_print(ndo
, rd
), GET_IPADDR_STRING(vpn_ip
), GET_IPADDR_STRING(pptr
));
1138 return MDT_VPN_NLRI_LEN
+ 1;
1144 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
1145 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
1146 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
1147 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
1148 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
1149 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
1150 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
1152 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
1153 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
1154 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
1155 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
1156 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
1157 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
1158 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
1159 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
1164 decode_multicast_vpn(netdissect_options
*ndo
,
1165 const u_char
*pptr
, char *buf
, size_t buflen
)
1167 uint8_t route_type
, route_length
;
1168 u_int addr_length
, sg_length
;
1172 route_type
= GET_U_1(pptr
);
1174 route_length
= GET_U_1(pptr
);
1177 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
1178 tok2str(bgp_multicast_vpn_route_type_values
,
1179 "Unknown", route_type
),
1180 route_type
, route_length
);
1182 switch(route_type
) {
1183 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
1184 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1185 offset
= (u_int
)strlen(buf
);
1186 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
1187 bgp_vpn_rd_print(ndo
, pptr
),
1188 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
1189 (route_length
- BGP_VPN_RD_LEN
) << 3));
1191 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
1192 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1193 offset
= (u_int
)strlen(buf
);
1194 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1195 bgp_vpn_rd_print(ndo
, pptr
),
1196 as_printf(ndo
, astostr
, sizeof(astostr
),
1197 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1200 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
1201 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1202 offset
= (u_int
)strlen(buf
);
1203 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1204 bgp_vpn_rd_print(ndo
, pptr
));
1205 pptr
+= BGP_VPN_RD_LEN
;
1207 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1208 addr_length
= route_length
- sg_length
;
1210 ND_TCHECK_LEN(pptr
, addr_length
);
1211 offset
= (u_int
)strlen(buf
);
1212 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
1213 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
1216 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
1217 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1218 offset
= (u_int
)strlen(buf
);
1219 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1220 bgp_vpn_rd_print(ndo
, pptr
));
1221 pptr
+= BGP_VPN_RD_LEN
;
1223 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1226 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
1227 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
1228 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1229 offset
= (u_int
)strlen(buf
);
1230 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1231 bgp_vpn_rd_print(ndo
, pptr
),
1232 as_printf(ndo
, astostr
, sizeof(astostr
),
1233 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1234 pptr
+= BGP_VPN_RD_LEN
+ 4;
1236 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1240 * no per route-type printing yet.
1242 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1247 return route_length
+ 2;
1254 * As I remember, some versions of systems have an snprintf() that
1255 * returns -1 if the buffer would have overflowed. If the return
1256 * value is negative, set buflen to 0, to indicate that we've filled
1259 * If the return value is greater than buflen, that means that
1260 * the buffer would have overflowed; again, set buflen to 0 in
1263 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1266 else if ((u_int)stringlen>buflen) \
1269 buflen-=stringlen; \
1274 decode_labeled_vpn_l2(netdissect_options
*ndo
,
1275 const u_char
*pptr
, char *buf
, size_t buflen
)
1277 u_int plen
, tlen
, tlv_type
, tlv_len
, ttlv_len
;
1281 plen
= GET_BE_U_2(pptr
);
1284 /* Old and new L2VPN NLRI share AFI/SAFI
1285 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1286 * and > 17 as old format. Complain for the middle case
1289 /* assume AD-only with RD, BGPNH */
1290 ND_TCHECK_LEN(pptr
, 12);
1292 stringlen
= snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
1293 bgp_vpn_rd_print(ndo
, pptr
),
1294 GET_IPADDR_STRING(pptr
+8));
1295 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1299 } else if (plen
> 17) {
1300 /* assume old format */
1301 /* RD, ID, LBLKOFF, LBLBASE */
1303 ND_TCHECK_LEN(pptr
, 15);
1305 stringlen
= snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1306 bgp_vpn_rd_print(ndo
, pptr
),
1307 GET_BE_U_2(pptr
+ 8),
1308 GET_BE_U_2(pptr
+ 10),
1309 GET_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1310 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1314 /* ok now the variable part - lets read out TLVs*/
1318 stringlen
=snprintf(buf
,buflen
, "\n\t\tran past the end");
1319 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1324 tlv_type
= GET_U_1(pptr
);
1326 tlv_len
= GET_BE_U_2(pptr
); /* length, in *bits* */
1327 ttlv_len
= (tlv_len
+ 7)/8; /* length, in *bytes* */
1333 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1336 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1338 while (ttlv_len
!= 0) {
1341 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1342 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1348 stringlen
=snprintf(buf
,buflen
, "%02x",
1351 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1359 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1362 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1364 if (tlen
< ttlv_len
) {
1366 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1367 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1377 /* complain bitterly ? */
1387 decode_prefix6(netdissect_options
*ndo
,
1388 const u_char
*pd
, u_int itemlen
, char *buf
, size_t buflen
)
1391 u_int plen
, plenbytes
;
1400 memset(&addr
, 0, sizeof(addr
));
1401 plenbytes
= (plen
+ 7) / 8;
1402 ND_TCHECK_LEN(pd
+ 1, plenbytes
);
1403 ITEMCHECK(plenbytes
);
1404 memcpy(&addr
, pd
+ 1, plenbytes
);
1406 addr
[plenbytes
- 1] &=
1407 ((0xff00 >> (plen
% 8)) & 0xff);
1409 snprintf(buf
, buflen
, "%s/%u", ip6addr_string(ndo
, (const u_char
*)&addr
), plen
);
1410 return 1 + plenbytes
;
1420 decode_labeled_prefix6(netdissect_options
*ndo
,
1421 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
1424 u_int plen
, plenbytes
;
1426 /* prefix length and label = 4 bytes */
1429 plen
= GET_U_1(pptr
); /* get prefix length */
1434 plen
-= 24; /* adjust prefixlen - labellength */
1440 memset(&addr
, 0, sizeof(addr
));
1441 plenbytes
= (plen
+ 7) / 8;
1442 ND_TCHECK_LEN(pptr
+ 4, plenbytes
);
1443 memcpy(&addr
, pptr
+ 4, plenbytes
);
1445 addr
[plenbytes
- 1] &=
1446 ((0xff00 >> (plen
% 8)) & 0xff);
1448 /* the label may get offsetted by 4 bits so lets shift it right */
1449 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
1450 ip6addr_string(ndo
, (const u_char
*)&addr
),
1452 GET_BE_U_3(pptr
+ 1)>>4,
1453 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1455 return 4 + plenbytes
;
1465 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1466 const u_char
*pptr
, char *buf
, size_t buflen
)
1472 plen
= GET_U_1(pptr
); /* get prefix length */
1477 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1482 memset(&addr
, 0, sizeof(addr
));
1483 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
1484 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1486 addr
[(plen
+ 7) / 8 - 1] &=
1487 ((0xff00 >> (plen
% 8)) & 0xff);
1489 /* the label may get offsetted by 4 bits so lets shift it right */
1490 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1491 bgp_vpn_rd_print(ndo
, pptr
+4),
1492 ip6addr_string(ndo
, (const u_char
*)&addr
),
1494 GET_BE_U_3(pptr
+ 1)>>4,
1495 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1497 return 12 + (plen
+ 7) / 8;
1504 decode_clnp_prefix(netdissect_options
*ndo
,
1505 const u_char
*pptr
, char *buf
, size_t buflen
)
1511 plen
= GET_U_1(pptr
); /* get prefix length */
1516 memset(&addr
, 0, sizeof(addr
));
1517 ND_TCHECK_LEN(pptr
+ 4, (plen
+ 7) / 8);
1518 memcpy(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1520 addr
[(plen
+ 7) / 8 - 1] &=
1521 ((0xff00 >> (plen
% 8)) & 0xff);
1523 snprintf(buf
, buflen
, "%s/%u",
1524 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1527 return 1 + (plen
+ 7) / 8;
1534 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1535 const u_char
*pptr
, char *buf
, size_t buflen
)
1541 plen
= GET_U_1(pptr
); /* get prefix length */
1546 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1551 memset(&addr
, 0, sizeof(addr
));
1552 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
1553 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1555 addr
[(plen
+ 7) / 8 - 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
1557 /* the label may get offsetted by 4 bits so lets shift it right */
1558 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1559 bgp_vpn_rd_print(ndo
, pptr
+4),
1560 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1562 GET_BE_U_3(pptr
+ 1)>>4,
1563 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1565 return 12 + (plen
+ 7) / 8;
1572 * bgp_attr_get_as_size
1574 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1575 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1576 * support, exchange AS-Path with the same path-attribute type value 0x02.
1579 bgp_attr_get_as_size(netdissect_options
*ndo
,
1580 uint8_t bgpa_type
, const u_char
*pptr
, u_int len
)
1582 const u_char
*tptr
= pptr
;
1585 * If the path attribute is the optional AS4 path type, then we already
1586 * know, that ASs must be encoded in 4 byte format.
1588 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1593 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1594 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1597 while (tptr
< pptr
+ len
) {
1601 * If we do not find a valid segment type, our guess might be wrong.
1603 if (GET_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| GET_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1606 ND_TCHECK_1(tptr
+ 1);
1607 tptr
+= 2 + GET_U_1(tptr
+ 1) * 2;
1611 * If we correctly reached end of the AS path attribute data content,
1612 * then most likely ASs were indeed encoded as 2 bytes.
1614 if (tptr
== pptr
+ len
) {
1621 * We can come here, either we did not have enough data, or if we
1622 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1623 * so that calller can try to decode each AS as of 4 bytes. If indeed
1624 * there was not enough data, it will crib and end the parse anyways.
1630 * The only way to know that a BGP UPDATE message is using add path is
1631 * by checking if the capability is in the OPEN message which we may have missed.
1632 * So this function checks if it is possible that the update could contain add path
1633 * and if so it checks that standard BGP doesn't make sense.
1636 check_add_path(netdissect_options
*ndo
, const u_char
*pptr
, u_int length
,
1637 u_int max_prefix_length
)
1639 u_int offset
, prefix_length
;
1646 * Scan through the NLRI information under the assumpetion that
1647 * it doesn't have path IDs.
1649 for (offset
= 0; offset
< length
;) {
1651 if (!ND_TTEST_1(pptr
+ offset
)) {
1652 /* We ran out of captured data; quit scanning. */
1655 prefix_length
= GET_U_1(pptr
+ offset
);
1657 * Add 4 to cover the path id
1658 * and check the prefix length isn't greater than 32/128.
1660 if (prefix_length
> max_prefix_length
) {
1663 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1664 offset
+= 1 + ((prefix_length
+ 7) / 8);
1666 /* check we haven't gone past the end of the section */
1667 if (offset
> length
) {
1671 /* check it's not standard BGP */
1672 for (offset
= 0; offset
< length
; ) {
1673 if (!ND_TTEST_1(pptr
+ offset
)) {
1674 /* We ran out of captured data; quit scanning. */
1677 prefix_length
= GET_U_1(pptr
+ offset
);
1679 * If the prefix_length is zero (0.0.0.0/0)
1680 * and since it's not the only address (length >= 5)
1681 * then it is add-path
1683 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1686 offset
+= 1 + ((prefix_length
+ 7) / 8);
1688 if (offset
> length
) {
1692 /* assume not add-path by default */
1697 bgp_mp_af_print(netdissect_options
*ndo
,
1698 const u_char
*tptr
, u_int tlen
,
1699 uint16_t *afp
, uint8_t *safip
)
1704 af
= GET_BE_U_2(tptr
);
1706 safi
= GET_U_1(tptr
+ 2);
1709 ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1710 tok2str(af_values
, "Unknown AFI", af
),
1712 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1713 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1716 switch(af
<<8 | safi
) {
1717 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1718 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1719 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1720 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1721 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1722 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1723 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1724 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1725 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1726 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1727 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1728 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1729 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1730 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1731 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1732 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1733 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1734 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1735 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1736 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1737 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1738 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1739 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1740 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1741 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1742 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1743 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1746 ND_TCHECK_LEN(tptr
, tlen
);
1747 ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af
, safi
);
1748 if (ndo
->ndo_vflag
<= 1)
1749 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1758 bgp_nlri_print(netdissect_options
*ndo
, uint16_t af
, uint8_t safi
,
1759 const u_char
*tptr
, u_int len
,
1760 char *buf
, size_t buflen
,
1761 int add_path4
, int add_path6
)
1766 switch (af
<<8 | safi
) {
1767 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1768 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1769 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1771 path_id
= GET_BE_U_4(tptr
);
1774 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1776 ND_PRINT("\n\t (illegal prefix length)");
1777 else if (advance
== -2)
1779 else if (advance
== -3)
1780 break; /* bytes left, but not enough */
1782 ND_PRINT("\n\t %s", buf
);
1784 ND_PRINT(" Path Id: %u", path_id
);
1788 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1789 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1791 ND_PRINT("\n\t (illegal prefix length)");
1792 else if (advance
== -2)
1794 else if (advance
== -3)
1795 break; /* bytes left, but not enough */
1797 ND_PRINT("\n\t %s", buf
);
1799 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1800 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1801 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1802 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, buflen
);
1804 ND_PRINT("\n\t (illegal prefix length)");
1805 else if (advance
== -2)
1808 ND_PRINT("\n\t %s", buf
);
1810 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1811 advance
= decode_rt_routing_info(ndo
, tptr
);
1815 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1816 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1817 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, buflen
);
1819 ND_PRINT("\n\t (illegal prefix length)");
1820 else if (advance
== -2)
1823 ND_PRINT("\n\t %s", buf
);
1826 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1827 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, buflen
);
1829 ND_PRINT("\n\t (illegal prefix length)");
1830 else if (advance
== -2)
1833 ND_PRINT("\n\t %s", buf
);
1835 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1836 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1837 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1839 path_id
= GET_BE_U_4(tptr
);
1842 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1844 ND_PRINT("\n\t (illegal prefix length)");
1845 else if (advance
== -2)
1847 else if (advance
== -3)
1848 break; /* bytes left, but not enough */
1850 ND_PRINT("\n\t %s", buf
);
1852 ND_PRINT(" Path Id: %u", path_id
);
1856 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1857 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1859 ND_PRINT("\n\t (illegal prefix length)");
1860 else if (advance
== -2)
1862 else if (advance
== -3)
1863 break; /* bytes left, but not enough */
1865 ND_PRINT("\n\t %s", buf
);
1867 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1868 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1869 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1870 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, buflen
);
1872 ND_PRINT("\n\t (illegal prefix length)");
1873 else if (advance
== -2)
1876 ND_PRINT("\n\t %s", buf
);
1878 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1879 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1880 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1881 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1882 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, buflen
);
1884 ND_PRINT("\n\t (illegal length)");
1885 else if (advance
== -2)
1888 ND_PRINT("\n\t %s", buf
);
1890 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1891 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1892 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1893 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1895 ND_PRINT("\n\t (illegal prefix length)");
1896 else if (advance
== -2)
1899 ND_PRINT("\n\t %s", buf
);
1901 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1902 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1903 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1904 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1906 ND_PRINT("\n\t (illegal prefix length)");
1907 else if (advance
== -2)
1910 ND_PRINT("\n\t %s", buf
);
1914 * This should not happen, we should have been protected
1915 * by bgp_mp_af_print()'s return value.
1917 ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af
, safi
);
1922 trunc
: /* we rely on the caller to recognize -2 return value */
1927 bgp_attr_print(netdissect_options
*ndo
,
1928 uint8_t atype
, const u_char
*pptr
, u_int len
,
1929 const unsigned attr_set_level
)
1933 uint8_t safi
, snpa
, nhlen
;
1937 char buf
[MAXHOSTNAMELEN
+ 100];
1939 int add_path4
, add_path6
;
1946 case BGPTYPE_ORIGIN
:
1948 ND_PRINT("invalid len");
1951 ND_PRINT("%s", tok2str(bgp_origin_values
,
1952 "Unknown Origin Typecode",
1958 * Process AS4 byte path and AS2 byte path attributes here.
1960 case BGPTYPE_AS4_PATH
:
1961 case BGPTYPE_AS_PATH
:
1963 ND_PRINT("invalid len");
1972 * BGP updates exchanged between New speakers that support 4
1973 * byte AS, ASs are always encoded in 4 bytes. There is no
1974 * definitive way to find this, just by the packet's
1975 * contents. So, check for packet's TLV's sanity assuming
1976 * 2 bytes first, and it does not pass, assume that ASs are
1977 * encoded in 4 bytes format and move on.
1979 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1981 while (tptr
< pptr
+ len
) {
1983 ND_PRINT("%s", tok2str(bgp_as_path_segment_open_values
,
1984 "?", GET_U_1(tptr
)));
1985 ND_TCHECK_1(tptr
+ 1);
1986 for (i
= 0; i
< GET_U_1(tptr
+ 1) * as_size
; i
+= as_size
) {
1987 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
1989 as_printf(ndo
, astostr
, sizeof(astostr
),
1991 GET_BE_U_2(tptr
+ i
+ 2) :
1992 GET_BE_U_4(tptr
+ i
+ 2)));
1995 ND_PRINT("%s", tok2str(bgp_as_path_segment_close_values
,
1996 "?", GET_U_1(tptr
)));
1997 ND_TCHECK_1(tptr
+ 1);
1998 tptr
+= 2 + GET_U_1(tptr
+ 1) * as_size
;
2001 case BGPTYPE_NEXT_HOP
:
2003 ND_PRINT("invalid len");
2006 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
2009 case BGPTYPE_MULTI_EXIT_DISC
:
2010 case BGPTYPE_LOCAL_PREF
:
2012 ND_PRINT("invalid len");
2015 ND_PRINT("%u", GET_BE_U_4(tptr
));
2018 case BGPTYPE_ATOMIC_AGGREGATE
:
2020 ND_PRINT("invalid len");
2022 case BGPTYPE_AGGREGATOR
:
2025 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
2026 * the length of this PA can be either 6 bytes or 8 bytes.
2028 if (len
!= 6 && len
!= 8) {
2029 ND_PRINT("invalid len");
2032 ND_TCHECK_LEN(tptr
, len
);
2034 ND_PRINT(" AS #%s, origin %s",
2035 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(tptr
)),
2036 GET_IPADDR_STRING(tptr
+ 2));
2038 ND_PRINT(" AS #%s, origin %s",
2039 as_printf(ndo
, astostr
, sizeof(astostr
),
2040 GET_BE_U_4(tptr
)), GET_IPADDR_STRING(tptr
+ 4));
2043 case BGPTYPE_AGGREGATOR4
:
2045 ND_PRINT("invalid len");
2049 ND_PRINT(" AS #%s, origin %s",
2050 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)),
2051 GET_IPADDR_STRING(tptr
+ 4));
2053 case BGPTYPE_COMMUNITIES
:
2055 ND_PRINT("invalid len");
2063 comm
= GET_BE_U_4(tptr
);
2065 case BGP_COMMUNITY_NO_EXPORT
:
2066 ND_PRINT(" NO_EXPORT");
2068 case BGP_COMMUNITY_NO_ADVERT
:
2069 ND_PRINT(" NO_ADVERTISE");
2071 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
2072 ND_PRINT(" NO_EXPORT_SUBCONFED");
2076 (comm
>> 16) & 0xffff,
2078 (tlen
>4) ? ", " : "");
2085 case BGPTYPE_ORIGINATOR_ID
:
2087 ND_PRINT("invalid len");
2091 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2093 case BGPTYPE_CLUSTER_LIST
:
2095 ND_PRINT("invalid len");
2103 GET_IPADDR_STRING(tptr
),
2104 (tlen
>4) ? ", " : "");
2109 case BGPTYPE_MP_REACH_NLRI
:
2113 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2125 nhlen
= GET_U_1(tptr
);
2131 uint8_t tnhlen
= nhlen
;
2134 ND_PRINT("\n\t nexthop: ");
2135 while (tnhlen
!= 0) {
2139 switch(af
<<8 | safi
) {
2140 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
2141 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
2142 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
2143 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
2144 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
2145 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
2146 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
2147 if (tnhlen
< sizeof(nd_ipv4
)) {
2148 ND_PRINT("invalid len");
2153 ND_TCHECK_LEN(tptr
, sizeof(nd_ipv4
));
2154 ND_PRINT("%s",GET_IPADDR_STRING(tptr
));
2155 tptr
+= sizeof(nd_ipv4
);
2156 tnhlen
-= sizeof(nd_ipv4
);
2157 tlen
-= sizeof(nd_ipv4
);
2160 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
2161 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
2162 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
2163 if (tnhlen
< sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
) {
2164 ND_PRINT("invalid len");
2170 sizeof(nd_ipv4
) + BGP_VPN_RD_LEN
);
2171 ND_PRINT("RD: %s, %s",
2172 bgp_vpn_rd_print(ndo
, tptr
),
2173 GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2174 tptr
+= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2175 tlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2176 tnhlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2179 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
2180 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
2181 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
2182 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
2183 if (tnhlen
< sizeof(nd_ipv6
)) {
2184 ND_PRINT("invalid len");
2189 ND_TCHECK_LEN(tptr
, sizeof(nd_ipv6
));
2190 ND_PRINT("%s", GET_IP6ADDR_STRING(tptr
));
2191 tptr
+= sizeof(nd_ipv6
);
2192 tlen
-= sizeof(nd_ipv6
);
2193 tnhlen
-= sizeof(nd_ipv6
);
2196 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
2197 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
2198 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2199 if (tnhlen
< sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
) {
2200 ND_PRINT("invalid len");
2206 sizeof(nd_ipv6
) + BGP_VPN_RD_LEN
);
2207 ND_PRINT("RD: %s, %s",
2208 bgp_vpn_rd_print(ndo
, tptr
),
2209 GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
));
2210 tptr
+= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2211 tlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2212 tnhlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2215 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2216 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2217 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2218 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2219 if (tnhlen
< sizeof(nd_ipv4
)) {
2220 ND_PRINT("invalid len");
2225 ND_TCHECK_LEN(tptr
, sizeof(nd_ipv4
));
2226 ND_PRINT("%s", GET_IPADDR_STRING(tptr
));
2227 tptr
+= (sizeof(nd_ipv4
));
2228 tlen
-= (sizeof(nd_ipv4
));
2229 tnhlen
-= (sizeof(nd_ipv4
));
2232 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2233 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2234 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2235 ND_TCHECK_LEN(tptr
, tnhlen
);
2236 ND_PRINT("%s", GET_ISONSAP_STRING(tptr
, tnhlen
));
2242 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2243 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2244 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2245 if (tnhlen
< BGP_VPN_RD_LEN
+1) {
2246 ND_PRINT("invalid len");
2251 ND_TCHECK_LEN(tptr
, tnhlen
);
2252 ND_PRINT("RD: %s, %s",
2253 bgp_vpn_rd_print(ndo
, tptr
),
2254 GET_ISONSAP_STRING(tptr
+BGP_VPN_RD_LEN
,tnhlen
-BGP_VPN_RD_LEN
));
2255 /* rfc986 mapped IPv4 address ? */
2256 if (GET_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
2257 ND_PRINT(" = %s", GET_IPADDR_STRING(tptr
+BGP_VPN_RD_LEN
+4));
2258 /* rfc1888 mapped IPv6 address ? */
2259 else if (GET_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
2260 ND_PRINT(" = %s", GET_IP6ADDR_STRING(tptr
+BGP_VPN_RD_LEN
+3));
2268 * bgp_mp_af_print() should have saved us from
2269 * an unsupported AFI/SAFI.
2271 ND_PRINT("ERROR: no AFI %u/SAFI %u nexthop decoder", af
, safi
);
2280 ND_PRINT(", nh-length: %u", nhlen
);
2282 /* As per RFC 2858; this is reserved in RFC 4760 */
2286 snpa
= GET_U_1(tptr
);
2291 ND_PRINT("\n\t %u SNPA", snpa
);
2292 for (/*nothing*/; snpa
!= 0; snpa
--) {
2297 snpalen
= GET_U_1(tptr
);
2298 ND_PRINT("\n\t %u bytes", snpalen
);
2303 ND_TCHECK_LEN(tptr
, snpalen
);
2308 ND_PRINT(", no SNPA");
2311 add_path4
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 32);
2312 add_path6
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 128);
2314 while (tptr
< pptr
+ len
) {
2315 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2316 add_path4
, add_path6
);
2325 case BGPTYPE_MP_UNREACH_NLRI
:
2326 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
2327 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2333 if (len
== BGP_MP_NLRI_MINSIZE
)
2334 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2338 add_path4
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 32);
2339 add_path6
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 128);
2341 while (tptr
< pptr
+ len
) {
2342 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2343 add_path4
, add_path6
);
2351 case BGPTYPE_EXTD_COMMUNITIES
:
2353 ND_PRINT("invalid len");
2362 extd_comm
=GET_BE_U_2(tptr
);
2364 ND_PRINT("\n\t %s (0x%04x), Flags [%s]",
2365 tok2str(bgp_extd_comm_subtype_values
,
2366 "unknown extd community typecode",
2369 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
2375 bgp_extended_community_print(ndo
, tptr
);
2381 case BGPTYPE_PMSI_TUNNEL
:
2383 uint8_t tunnel_type
, flags
;
2388 flags
= GET_U_1(tptr
);
2389 tunnel_type
= GET_U_1(tptr
+ 1);
2391 ND_PRINT("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2392 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2394 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2395 GET_BE_U_3(tptr
+ 2)>>4);
2400 switch (tunnel_type
) {
2401 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2402 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2404 ND_PRINT("\n\t Sender %s, P-Group %s",
2405 GET_IPADDR_STRING(tptr
),
2406 GET_IPADDR_STRING(tptr
+4));
2409 case BGP_PMSI_TUNNEL_PIM_SSM
:
2411 ND_PRINT("\n\t Root-Node %s, P-Group %s",
2412 GET_IPADDR_STRING(tptr
),
2413 GET_IPADDR_STRING(tptr
+4));
2415 case BGP_PMSI_TUNNEL_INGRESS
:
2417 ND_PRINT("\n\t Tunnel-Endpoint %s",
2418 GET_IPADDR_STRING(tptr
));
2420 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2421 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2423 ND_PRINT("\n\t Root-Node %s, LSP-ID 0x%08x",
2424 GET_IPADDR_STRING(tptr
),
2425 GET_BE_U_4(tptr
+ 4));
2427 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2429 ND_PRINT("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2430 GET_IPADDR_STRING(tptr
),
2431 GET_BE_U_4(tptr
+ 4));
2434 if (ndo
->ndo_vflag
<= 1) {
2435 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2449 type
= GET_U_1(tptr
);
2450 length
= GET_BE_U_2(tptr
+ 1);
2454 ND_PRINT("\n\t %s TLV (%u), length %u",
2455 tok2str(bgp_aigp_values
, "Unknown", type
),
2463 * Check if we can read the TLV data.
2465 ND_TCHECK_LEN(tptr
+ 3, length
);
2474 ND_PRINT(", metric %" PRIu64
,
2479 if (ndo
->ndo_vflag
<= 1) {
2480 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2489 case BGPTYPE_ATTR_SET
:
2493 ND_PRINT("\n\t Origin AS: %s",
2494 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)));
2499 u_int aflags
, alenlen
, alen
;
2503 ND_PRINT(" [path attr too short]");
2507 aflags
= GET_U_1(tptr
);
2508 atype
= GET_U_1(tptr
+ 1);
2511 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2512 ND_TCHECK_LEN(tptr
, alenlen
);
2513 if (len
< alenlen
) {
2514 ND_PRINT(" [path attr too short]");
2518 alen
= bgp_attr_len(aflags
, tptr
);
2522 ND_PRINT("\n\t %s (%u), length: %u",
2523 tok2str(bgp_attr_values
,
2524 "Unknown Attribute", atype
),
2529 ND_PRINT(", Flags [%s%s%s%s",
2530 aflags
& 0x80 ? "O" : "",
2531 aflags
& 0x40 ? "T" : "",
2532 aflags
& 0x20 ? "P" : "",
2533 aflags
& 0x10 ? "E" : "");
2535 ND_PRINT("+%x", aflags
& 0xf);
2540 ND_PRINT(" [path attr too short]");
2545 * The protocol encoding per se allows ATTR_SET to be nested
2546 * as many times as the message can accommodate. This printer
2547 * used to be able to recurse into ATTR_SET contents until the
2548 * stack exhaustion, but now there is a limit on that (if live
2549 * protocol exchange goes that many levels deep, something is
2550 * probably wrong anyway). Feel free to refine this value if
2551 * you can find the spec with respective normative text.
2553 if (attr_set_level
== 10)
2554 ND_PRINT("(too many nested levels, not recursing)");
2555 else if (!bgp_attr_print(ndo
, atype
, tptr
, alen
, attr_set_level
+ 1))
2562 case BGPTYPE_LARGE_COMMUNITY
:
2563 if (len
== 0 || len
% 12) {
2564 ND_PRINT("invalid len");
2569 ND_TCHECK_LEN(tptr
, 12);
2570 ND_PRINT("%u:%u:%u%s",
2572 GET_BE_U_4(tptr
+ 4),
2573 GET_BE_U_4(tptr
+ 8),
2574 (len
> 12) ? ", " : "");
2577 * len will always be a multiple of 12, as per the above,
2578 * so this will never underflow.
2584 ND_TCHECK_LEN(pptr
, len
);
2585 ND_PRINT("\n\t no Attribute %u decoder", atype
); /* we have no decoder for the attribute */
2586 if (ndo
->ndo_vflag
<= 1)
2587 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2591 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2592 ND_TCHECK_LEN(pptr
, len
);
2593 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2602 bgp_capabilities_print(netdissect_options
*ndo
,
2603 const u_char
*opt
, u_int caps_len
)
2605 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2608 while (i
< caps_len
) {
2609 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2610 cap_type
=GET_U_1(opt
+ i
);
2611 cap_len
=GET_U_1(opt
+ i
+ 1);
2612 ND_PRINT("\n\t %s (%u), length: %u",
2613 tok2str(bgp_capcode_values
, "Unknown", cap_type
),
2616 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2618 case BGP_CAPCODE_MP
:
2619 /* AFI (16 bits), Reserved (8 bits), SAFI (8 bits) */
2621 ND_PRINT(" (too short, < 4)");
2624 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u)",
2625 tok2str(af_values
, "Unknown", GET_BE_U_2(opt
+ i
+ 2)),
2626 GET_BE_U_2(opt
+ i
+ 2),
2627 tok2str(bgp_safi_values
, "Unknown", GET_U_1(opt
+ i
+ 5)),
2628 GET_U_1(opt
+ i
+ 5));
2630 case BGP_CAPCODE_ML
:
2633 while (tcap_len
>= 4) {
2634 ND_PRINT( "\n\t\tAFI %s (%u), SAFI %s (%u), Count: %u",
2635 tok2str(af_values
, "Unknown",
2636 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2637 GET_BE_U_2(opt
+ i
+ cap_offset
),
2638 tok2str(bgp_safi_values
, "Unknown",
2639 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2640 GET_U_1(opt
+ i
+ cap_offset
+ 2),
2641 GET_U_1(opt
+ i
+ cap_offset
+ 3));
2646 case BGP_CAPCODE_RESTART
:
2647 /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */
2649 ND_PRINT(" (too short, < 2)");
2653 ND_PRINT("\n\t\tRestart Flags: [%s], Restart Time %us",
2654 ((GET_U_1(opt
+ i
+ 2))&0x80) ? "R" : "none",
2655 GET_BE_U_2(opt
+ i
+ 2)&0xfff);
2658 while(tcap_len
>=4) {
2659 ND_PRINT("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2660 tok2str(af_values
,"Unknown",
2661 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2662 GET_BE_U_2(opt
+ i
+ cap_offset
),
2663 tok2str(bgp_safi_values
,"Unknown",
2664 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2665 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2666 ((GET_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" );
2671 case BGP_CAPCODE_RR
:
2672 case BGP_CAPCODE_LLGR
:
2673 case BGP_CAPCODE_RR_CISCO
:
2675 case BGP_CAPCODE_AS_NEW
:
2677 * Extract the 4 byte AS number encoded.
2680 ND_PRINT(" (too short, < 4)");
2683 ND_PRINT("\n\t\t 4 Byte AS %s",
2684 as_printf(ndo
, astostr
, sizeof(astostr
),
2685 GET_BE_U_4(opt
+ i
+ 2)));
2687 case BGP_CAPCODE_ADD_PATH
:
2689 ND_PRINT(" (bogus)"); /* length */
2694 while (tcap_len
!= 0) {
2696 nd_print_invalid(ndo
);
2699 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2700 tok2str(af_values
,"Unknown",GET_BE_U_2(opt
+ i
+ cap_offset
)),
2701 GET_BE_U_2(opt
+ i
+ cap_offset
),
2702 tok2str(bgp_safi_values
,"Unknown",GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2703 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2704 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",GET_U_1(opt
+ i
+ cap_offset
+ 3))
2711 ND_PRINT("\n\t\tno decoder for Capability %u",
2713 if (ndo
->ndo_vflag
<= 1)
2714 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2718 if (ndo
->ndo_vflag
> 1 && cap_len
!= 0) {
2719 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2721 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2726 nd_print_trunc(ndo
);
2730 bgp_open_print(netdissect_options
*ndo
,
2731 const u_char
*dat
, u_int length
)
2733 const struct bgp_open
*bgp_open_header
;
2735 const struct bgp_opt
*bgpopt
;
2739 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2740 if (length
< BGP_OPEN_SIZE
)
2743 bgp_open_header
= (const struct bgp_open
*)dat
;
2745 ND_PRINT("\n\t Version %u, ",
2746 GET_U_1(bgp_open_header
->bgpo_version
));
2747 ND_PRINT("my AS %s, ",
2748 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(bgp_open_header
->bgpo_myas
)));
2749 ND_PRINT("Holdtime %us, ",
2750 GET_BE_U_2(bgp_open_header
->bgpo_holdtime
));
2751 ND_PRINT("ID %s", GET_IPADDR_STRING(bgp_open_header
->bgpo_id
));
2752 optslen
= GET_U_1(bgp_open_header
->bgpo_optlen
);
2753 ND_PRINT("\n\t Optional parameters, length: %u", optslen
);
2755 opt
= dat
+ BGP_OPEN_SIZE
;
2756 length
-= BGP_OPEN_SIZE
;
2759 while (i
< optslen
) {
2760 uint8_t opt_type
, opt_len
;
2762 ND_TCHECK_LEN(opt
+ i
, BGP_OPT_SIZE
);
2763 if (length
< BGP_OPT_SIZE
+ i
)
2765 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2766 opt_type
= GET_U_1(bgpopt
->bgpopt_type
);
2767 opt_len
= GET_U_1(bgpopt
->bgpopt_len
);
2768 if (BGP_OPT_SIZE
+ i
+ opt_len
> optslen
) {
2769 ND_PRINT("\n\t Option %u, length: %u, goes past the end of the options",
2774 ND_PRINT("\n\t Option %s (%u), length: %u",
2775 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2779 /* now let's decode the options we know*/
2783 bgp_capabilities_print(ndo
, opt
+ BGP_OPT_SIZE
+ i
,
2789 ND_PRINT("\n\t no decoder for option %u",
2793 i
+= BGP_OPT_SIZE
+ opt_len
;
2797 nd_print_trunc(ndo
);
2801 bgp_update_print(netdissect_options
*ndo
,
2802 const u_char
*dat
, u_int length
)
2805 u_int withdrawn_routes_len
;
2806 char buf
[MAXHOSTNAMELEN
+ 100];
2813 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2814 if (length
< BGP_SIZE
)
2819 /* Unfeasible routes */
2823 withdrawn_routes_len
= GET_BE_U_2(p
);
2826 if (withdrawn_routes_len
> 1) {
2828 * Without keeping state from the original NLRI message,
2829 * it's not possible to tell if this a v4 or v6 route,
2830 * so only try to decode it if we're not v6 enabled.
2832 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2833 if (length
< withdrawn_routes_len
)
2835 ND_PRINT("\n\t Withdrawn routes:");
2836 add_path
= check_add_path(ndo
, p
, withdrawn_routes_len
, 32);
2837 while (withdrawn_routes_len
!= 0) {
2839 if (withdrawn_routes_len
< 4) {
2840 p
+= withdrawn_routes_len
;
2841 length
-= withdrawn_routes_len
;
2844 path_id
= GET_BE_U_4(p
);
2847 withdrawn_routes_len
-= 4;
2849 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2851 ND_PRINT("\n\t (illegal prefix length)");
2853 } else if (wpfx
== -2)
2855 else if (wpfx
== -3)
2856 goto trunc
; /* bytes left, but not enough */
2858 ND_PRINT("\n\t %s", buf
);
2860 ND_PRINT(" Path Id: %u", path_id
);
2864 withdrawn_routes_len
-= wpfx
;
2868 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2869 if (length
< withdrawn_routes_len
)
2871 p
+= withdrawn_routes_len
;
2872 length
-= withdrawn_routes_len
;
2878 len
= GET_BE_U_2(p
);
2882 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2883 /* No withdrawn routes, no path attributes, no NLRI */
2884 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2889 /* do something more useful!*/
2891 uint8_t aflags
, atype
, alenlen
;
2898 ND_PRINT("\n\t [path attrs too short]");
2903 aflags
= GET_U_1(p
);
2904 atype
= GET_U_1(p
+ 1);
2908 alenlen
= bgp_attr_lenlen(aflags
, p
);
2909 ND_TCHECK_LEN(p
, alenlen
);
2910 if (length
< alenlen
)
2912 if (len
< alenlen
) {
2913 ND_PRINT("\n\t [path attrs too short]");
2918 alen
= bgp_attr_len(aflags
, p
);
2923 ND_PRINT("\n\t %s (%u), length: %u",
2924 tok2str(bgp_attr_values
, "Unknown Attribute", atype
),
2929 ND_PRINT(", Flags [%s%s%s%s",
2930 aflags
& 0x80 ? "O" : "",
2931 aflags
& 0x40 ? "T" : "",
2932 aflags
& 0x20 ? "P" : "",
2933 aflags
& 0x10 ? "E" : "");
2935 ND_PRINT("+%x", aflags
& 0xf);
2939 ND_PRINT(" [path attrs too short]");
2946 if (!bgp_attr_print(ndo
, atype
, p
, alen
, 0))
2955 add_path
= check_add_path(ndo
, p
, length
, 32);
2956 ND_PRINT("\n\t Updated routes:");
2957 while (length
!= 0) {
2962 path_id
= GET_BE_U_4(p
);
2966 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2968 ND_PRINT("\n\t (illegal prefix length)");
2973 goto trunc
; /* bytes left, but not enough */
2975 ND_PRINT("\n\t %s", buf
);
2977 ND_PRINT(" Path Id: %u", path_id
);
2986 nd_print_trunc(ndo
);
2990 bgp_notification_print(netdissect_options
*ndo
,
2991 const u_char
*dat
, u_int length
)
2993 const struct bgp_notification
*bgp_notification_header
;
2995 uint8_t bgpn_major
, bgpn_minor
;
2996 uint8_t shutdown_comm_length
;
2997 uint8_t remainder_offset
;
2999 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
3000 if (length
<BGP_NOTIFICATION_SIZE
)
3003 bgp_notification_header
= (const struct bgp_notification
*)dat
;
3004 bgpn_major
= GET_U_1(bgp_notification_header
->bgpn_major
);
3005 bgpn_minor
= GET_U_1(bgp_notification_header
->bgpn_minor
);
3007 ND_PRINT(", %s (%u)",
3008 tok2str(bgp_notify_major_values
, "Unknown Error",
3012 switch (bgpn_major
) {
3014 case BGP_NOTIFY_MAJOR_MSG
:
3015 ND_PRINT(", subcode %s (%u)",
3016 tok2str(bgp_notify_minor_msg_values
, "Unknown",
3020 case BGP_NOTIFY_MAJOR_OPEN
:
3021 ND_PRINT(", subcode %s (%u)",
3022 tok2str(bgp_notify_minor_open_values
, "Unknown",
3026 case BGP_NOTIFY_MAJOR_UPDATE
:
3027 ND_PRINT(", subcode %s (%u)",
3028 tok2str(bgp_notify_minor_update_values
, "Unknown",
3032 case BGP_NOTIFY_MAJOR_FSM
:
3033 ND_PRINT(" subcode %s (%u)",
3034 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
3038 case BGP_NOTIFY_MAJOR_CAP
:
3039 ND_PRINT(" subcode %s (%u)",
3040 tok2str(bgp_notify_minor_cap_values
, "Unknown",
3044 case BGP_NOTIFY_MAJOR_CEASE
:
3045 ND_PRINT(", subcode %s (%u)",
3046 tok2str(bgp_notify_minor_cease_values
, "Unknown",
3050 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
3051 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
3053 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
3054 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
3056 ND_PRINT(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
3057 tok2str(af_values
, "Unknown", GET_BE_U_2(tptr
)),
3059 tok2str(bgp_safi_values
, "Unknown", GET_U_1((tptr
+ 2))),
3060 GET_U_1((tptr
+ 2)),
3061 GET_BE_U_4(tptr
+ 3));
3064 * draft-ietf-idr-shutdown describes a method to send a communication
3065 * intended for human consumption regarding the Administrative Shutdown
3067 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
3068 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
3069 length
>= BGP_NOTIFICATION_SIZE
+ 1) {
3070 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
3072 shutdown_comm_length
= GET_U_1(tptr
);
3073 remainder_offset
= 0;
3074 /* garbage, hexdump it all */
3075 if (shutdown_comm_length
> BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN
||
3076 shutdown_comm_length
> length
- (BGP_NOTIFICATION_SIZE
+ 1)) {
3077 ND_PRINT(", invalid Shutdown Communication length");
3079 else if (shutdown_comm_length
== 0) {
3080 ND_PRINT(", empty Shutdown Communication");
3081 remainder_offset
+= 1;
3083 /* a proper shutdown communication */
3085 ND_TCHECK_LEN(tptr
+ 1, shutdown_comm_length
);
3086 ND_PRINT(", Shutdown Communication (length: %u): \"", shutdown_comm_length
);
3087 (void)nd_printn(ndo
, tptr
+1, shutdown_comm_length
, NULL
);
3089 remainder_offset
+= shutdown_comm_length
+ 1;
3091 /* if there is trailing data, hexdump it */
3092 if(length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
) > 0) {
3093 ND_PRINT(", Data: (length: %u)", length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
3094 hex_print(ndo
, "\n\t\t", tptr
+ remainder_offset
, length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
3104 nd_print_trunc(ndo
);
3108 bgp_route_refresh_print(netdissect_options
*ndo
,
3109 const u_char
*pptr
, u_int len
)
3111 const struct bgp_route_refresh
*bgp_route_refresh_header
;
3113 ND_TCHECK_LEN(pptr
, BGP_ROUTE_REFRESH_SIZE
);
3115 /* some little sanity checking */
3116 if (len
<BGP_ROUTE_REFRESH_SIZE
)
3119 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
3121 ND_PRINT("\n\t AFI %s (%u), SAFI %s (%u)",
3122 tok2str(af_values
,"Unknown",
3123 GET_BE_U_2(bgp_route_refresh_header
->afi
)),
3124 GET_BE_U_2(bgp_route_refresh_header
->afi
),
3125 tok2str(bgp_safi_values
,"Unknown",
3126 GET_U_1(bgp_route_refresh_header
->safi
)),
3127 GET_U_1(bgp_route_refresh_header
->safi
));
3129 if (ndo
->ndo_vflag
> 1) {
3130 ND_TCHECK_LEN(pptr
, len
);
3131 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
3136 nd_print_trunc(ndo
);
3140 bgp_pdu_print(netdissect_options
*ndo
,
3141 const u_char
*dat
, u_int length
)
3143 const struct bgp
*bgp_header
;
3146 ND_TCHECK_LEN(dat
, BGP_SIZE
);
3147 bgp_header
= (const struct bgp
*)dat
;
3148 bgp_type
= GET_U_1(bgp_header
->bgp_type
);
3150 ND_PRINT("\n\t%s Message (%u), length: %u",
3151 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
3157 bgp_open_print(ndo
, dat
, length
);
3160 bgp_update_print(ndo
, dat
, length
);
3162 case BGP_NOTIFICATION
:
3163 bgp_notification_print(ndo
, dat
, length
);
3167 case BGP_ROUTE_REFRESH
:
3168 bgp_route_refresh_print(ndo
, dat
, length
);
3171 /* we have no decoder for the BGP message */
3172 ND_TCHECK_LEN(dat
, length
);
3173 ND_PRINT("\n\t no Message %u decoder", bgp_type
);
3174 print_unknown_data(ndo
, dat
, "\n\t ", length
);
3179 nd_print_trunc(ndo
);
3184 bgp_print(netdissect_options
*ndo
,
3185 const u_char
*dat
, u_int length _U_
)
3188 const u_char
*ep
= ndo
->ndo_snapend
;
3189 const u_char
*start
;
3190 const u_char marker
[] = {
3191 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3192 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3194 const struct bgp
*bgp_header
;
3197 ndo
->ndo_protocol
= "bgp";
3200 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
3208 if (GET_U_1(p
) != 0xff) {
3213 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
3215 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
3220 /* found BGP header */
3221 ND_TCHECK_LEN(p
, BGP_SIZE
);
3222 bgp_header
= (const struct bgp
*)p
;
3225 nd_print_trunc(ndo
);
3227 hlen
= GET_BE_U_2(bgp_header
->bgp_len
);
3228 if (hlen
< BGP_SIZE
) {
3229 ND_PRINT("\nmessage length %u < %u", hlen
, BGP_SIZE
);
3230 nd_print_invalid(ndo
);
3234 if (ND_TTEST_LEN(p
, hlen
)) {
3235 if (!bgp_pdu_print(ndo
, p
, hlen
))
3240 ND_PRINT("\n[|BGP %s]",
3241 tok2str(bgp_msg_values
,
3242 "Unknown Message Type",
3243 GET_U_1(bgp_header
->bgp_type
)));
3251 nd_print_trunc(ndo
);