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 4771 */
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) ? EXTRACT_BE_U_2(p) : EXTRACT_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_RESTART 64 /* RFC4724 */
220 #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */
221 #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */
222 #define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */
223 #define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */
224 #define BGP_CAPCODE_ENH_RR 70 /* draft-keyur-bgp-enhanced-route-refresh */
225 #define BGP_CAPCODE_RR_CISCO 128
227 static const struct tok bgp_capcode_values
[] = {
228 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
229 { BGP_CAPCODE_RR
, "Route Refresh"},
230 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
231 { BGP_CAPCODE_MR
, "Multiple Routes to a Destination"},
232 { BGP_CAPCODE_EXT_NH
, "Extended Next Hop Encoding"},
233 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
234 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
235 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
236 { BGP_CAPCODE_MULTISESS
, "Multisession BGP"},
237 { BGP_CAPCODE_ADD_PATH
, "Multiple Paths"},
238 { BGP_CAPCODE_ENH_RR
, "Enhanced Route Refresh"},
239 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
243 #define BGP_NOTIFY_MAJOR_MSG 1
244 #define BGP_NOTIFY_MAJOR_OPEN 2
245 #define BGP_NOTIFY_MAJOR_UPDATE 3
246 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
247 #define BGP_NOTIFY_MAJOR_FSM 5
248 #define BGP_NOTIFY_MAJOR_CEASE 6
249 #define BGP_NOTIFY_MAJOR_CAP 7
251 static const struct tok bgp_notify_major_values
[] = {
252 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
253 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
254 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
255 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
256 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
257 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
258 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
262 /* draft-ietf-idr-cease-subcode-02 */
263 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
264 /* draft-ietf-idr-shutdown-07 */
265 #define BGP_NOTIFY_MINOR_CEASE_SHUT 2
266 #define BGP_NOTIFY_MINOR_CEASE_RESET 4
267 #define BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN 128
268 static const struct tok bgp_notify_minor_cease_values
[] = {
269 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
270 { BGP_NOTIFY_MINOR_CEASE_SHUT
, "Administrative Shutdown"},
271 { 3, "Peer Unconfigured"},
272 { BGP_NOTIFY_MINOR_CEASE_RESET
, "Administrative Reset"},
273 { 5, "Connection Rejected"},
274 { 6, "Other Configuration Change"},
275 { 7, "Connection Collision Resolution"},
279 static const struct tok bgp_notify_minor_msg_values
[] = {
280 { 1, "Connection Not Synchronized"},
281 { 2, "Bad Message Length"},
282 { 3, "Bad Message Type"},
286 static const struct tok bgp_notify_minor_open_values
[] = {
287 { 1, "Unsupported Version Number"},
289 { 3, "Bad BGP Identifier"},
290 { 4, "Unsupported Optional Parameter"},
291 { 5, "Authentication Failure"},
292 { 6, "Unacceptable Hold Time"},
293 { 7, "Capability Message Error"},
297 static const struct tok bgp_notify_minor_update_values
[] = {
298 { 1, "Malformed Attribute List"},
299 { 2, "Unrecognized Well-known Attribute"},
300 { 3, "Missing Well-known Attribute"},
301 { 4, "Attribute Flags Error"},
302 { 5, "Attribute Length Error"},
303 { 6, "Invalid ORIGIN Attribute"},
304 { 7, "AS Routing Loop"},
305 { 8, "Invalid NEXT_HOP Attribute"},
306 { 9, "Optional Attribute Error"},
307 { 10, "Invalid Network Field"},
308 { 11, "Malformed AS_PATH"},
312 static const struct tok bgp_notify_minor_fsm_values
[] = {
313 { 0, "Unspecified Error"},
314 { 1, "In OpenSent State"},
315 { 2, "In OpenConfirm State"},
316 { 3, "In Established State"},
320 static const struct tok bgp_notify_minor_cap_values
[] = {
321 { 1, "Invalid Action Value" },
322 { 2, "Invalid Capability Length" },
323 { 3, "Malformed Capability Value" },
324 { 4, "Unsupported Capability Code" },
328 static const struct tok bgp_origin_values
[] = {
335 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
336 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
337 #define BGP_PMSI_TUNNEL_PIM_SSM 3
338 #define BGP_PMSI_TUNNEL_PIM_SM 4
339 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
340 #define BGP_PMSI_TUNNEL_INGRESS 6
341 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
343 static const struct tok bgp_pmsi_tunnel_values
[] = {
344 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
345 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
346 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
347 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
348 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
349 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
350 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
354 static const struct tok bgp_pmsi_flag_values
[] = {
355 { 0x01, "Leaf Information required"},
359 #define BGP_AIGP_TLV 1
361 static const struct tok bgp_aigp_values
[] = {
362 { BGP_AIGP_TLV
, "AIGP"},
366 /* Subsequent address family identifier, RFC2283 section 7 */
368 #define SAFNUM_UNICAST 1
369 #define SAFNUM_MULTICAST 2
370 #define SAFNUM_UNIMULTICAST 3 /* deprecated now */
371 /* labeled BGP RFC3107 */
372 #define SAFNUM_LABUNICAST 4
374 #define SAFNUM_MULTICAST_VPN 5
375 /* draft-nalawade-kapoor-tunnel-safi */
376 #define SAFNUM_TUNNEL 64
378 #define SAFNUM_VPLS 65
380 #define SAFNUM_MDT 66
382 #define SAFNUM_VPNUNICAST 128
384 #define SAFNUM_VPNMULTICAST 129
385 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
387 #define SAFNUM_RT_ROUTING_INFO 132
389 #define BGP_VPN_RD_LEN 8
391 static const struct tok bgp_safi_values
[] = {
392 { SAFNUM_RES
, "Reserved"},
393 { SAFNUM_UNICAST
, "Unicast"},
394 { SAFNUM_MULTICAST
, "Multicast"},
395 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
396 { SAFNUM_LABUNICAST
, "labeled Unicast"},
397 { SAFNUM_TUNNEL
, "Tunnel"},
398 { SAFNUM_VPLS
, "VPLS"},
399 { SAFNUM_MDT
, "MDT"},
400 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
401 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
402 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
403 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
404 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
408 /* well-known community */
409 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
410 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
411 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
413 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
414 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
415 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
416 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
417 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
418 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
419 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
420 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
421 /* rfc2547 bgp-mpls-vpns */
422 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
423 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatibility */
424 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatibility */
425 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatibility */
427 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
428 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatibility */
430 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
431 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatibility */
433 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
435 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
436 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
437 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
438 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
440 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
441 #define BGP_EXT_COM_EIGRP_GEN 0x8800
442 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
443 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
444 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
445 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
446 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
448 static const struct tok bgp_extd_comm_flag_values
[] = {
449 { 0x8000, "vendor-specific"},
450 { 0x4000, "non-transitive"},
454 static const struct tok bgp_extd_comm_subtype_values
[] = {
455 { BGP_EXT_COM_RT_0
, "target"},
456 { BGP_EXT_COM_RT_1
, "target"},
457 { BGP_EXT_COM_RT_2
, "target"},
458 { BGP_EXT_COM_RO_0
, "origin"},
459 { BGP_EXT_COM_RO_1
, "origin"},
460 { BGP_EXT_COM_RO_2
, "origin"},
461 { BGP_EXT_COM_LINKBAND
, "link-BW"},
462 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
463 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
464 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
465 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
466 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
467 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
468 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
469 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
470 { BGP_EXT_COM_L2INFO
, "layer2-info"},
471 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
472 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
473 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
474 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
475 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
476 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
477 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
478 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
479 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
480 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
484 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
485 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
486 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
487 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
488 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
489 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
490 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
491 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
493 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
494 { BGP_OSPF_RTYPE_RTR
, "Router" },
495 { BGP_OSPF_RTYPE_NET
, "Network" },
496 { BGP_OSPF_RTYPE_SUM
, "Summary" },
497 { BGP_OSPF_RTYPE_EXT
, "External" },
498 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
499 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
503 /* ADD-PATH Send/Receive field values */
504 static const struct tok bgp_add_path_recvsend
[] = {
511 static char astostr
[20];
516 * Convert an AS number into a string and return string pointer.
518 * Depending on bflag is set or not, AS number is converted into ASDOT notation
519 * or plain number notation.
523 as_printf(netdissect_options
*ndo
,
524 char *str
, size_t size
, u_int asnum
)
526 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
527 snprintf(str
, size
, "%u", asnum
);
529 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
534 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
537 decode_prefix4(netdissect_options
*ndo
,
538 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
541 u_int plen
, plenbytes
;
545 plen
= EXTRACT_U_1(pptr
);
550 memset(&addr
, 0, sizeof(addr
));
551 plenbytes
= (plen
+ 7) / 8;
552 ND_TCHECK_LEN(pptr
+ 1, plenbytes
);
553 ITEMCHECK(plenbytes
);
554 memcpy(&addr
, pptr
+ 1, plenbytes
);
556 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
558 snprintf(buf
, buflen
, "%s/%u", ipaddr_string(ndo
, &addr
), plen
);
559 return 1 + plenbytes
;
569 decode_labeled_prefix4(netdissect_options
*ndo
,
570 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
573 u_int plen
, plenbytes
;
575 /* prefix length and label = 4 bytes */
578 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
580 /* this is one of the weirdnesses of rfc3107
581 the label length (actually the label + COS bits)
582 is added to the prefix length;
583 we also do only read out just one label -
584 there is no real application for advertisement of
585 stacked labels in a single BGP message
591 plen
-=24; /* adjust prefixlen - labellength */
597 memset(&addr
, 0, sizeof(addr
));
598 plenbytes
= (plen
+ 7) / 8;
599 ND_TCHECK_LEN(pptr
+ 4, plenbytes
);
600 ITEMCHECK(plenbytes
);
601 memcpy(&addr
, pptr
+ 4, plenbytes
);
603 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
605 /* the label may get offsetted by 4 bits so lets shift it right */
606 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
607 ipaddr_string(ndo
, &addr
),
609 EXTRACT_BE_U_3(pptr
+ 1)>>4,
610 ((EXTRACT_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
612 return 4 + plenbytes
;
624 * print an ipv4 or ipv6 address into a buffer dependend on address length.
627 bgp_vpn_ip_print(netdissect_options
*ndo
,
628 const u_char
*pptr
, u_int addr_length
)
631 /* worst case string is s fully formatted v6 address */
632 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
635 switch(addr_length
) {
636 case (sizeof(struct in_addr
) << 3): /* 32 */
637 ND_TCHECK_LEN(pptr
, sizeof(struct in_addr
));
638 snprintf(pos
, sizeof(addr
), "%s", ipaddr_string(ndo
, pptr
));
640 case (sizeof(struct in6_addr
) << 3): /* 128 */
641 ND_TCHECK_LEN(pptr
, sizeof(struct in6_addr
));
642 snprintf(pos
, sizeof(addr
), "%s", ip6addr_string(ndo
, pptr
));
645 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
658 * print an multicast s,g entry into a buffer.
659 * the s,g entry is encoded like this.
661 * +-----------------------------------+
662 * | Multicast Source Length (1 octet) |
663 * +-----------------------------------+
664 * | Multicast Source (Variable) |
665 * +-----------------------------------+
666 * | Multicast Group Length (1 octet) |
667 * +-----------------------------------+
668 * | Multicast Group (Variable) |
669 * +-----------------------------------+
671 * return the number of bytes read from the wire.
674 bgp_vpn_sg_print(netdissect_options
*ndo
,
675 const u_char
*pptr
, char *buf
, u_int buflen
)
678 u_int total_length
, offset
;
682 /* Source address length, encoded in bits */
684 addr_length
= EXTRACT_U_1(pptr
);
688 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
689 total_length
+= (addr_length
>> 3) + 1;
690 offset
= strlen(buf
);
692 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
693 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
694 pptr
+= (addr_length
>> 3);
697 /* Group address length, encoded in bits */
699 addr_length
= EXTRACT_U_1(pptr
);
703 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
704 total_length
+= (addr_length
>> 3) + 1;
705 offset
= strlen(buf
);
707 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
708 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
709 pptr
+= (addr_length
>> 3);
713 return (total_length
);
716 /* RDs and RTs share the same semantics
717 * we use bgp_vpn_rd_print for
718 * printing route targets inside a NLRI */
720 bgp_vpn_rd_print(netdissect_options
*ndo
,
723 /* allocate space for the largest possible string */
724 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
727 /* ok lets load the RD format */
728 switch (EXTRACT_BE_U_2(pptr
)) {
730 /* 2-byte-AS:number fmt*/
732 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
733 EXTRACT_BE_U_2(pptr
+ 2),
734 EXTRACT_BE_U_4(pptr
+ 4),
735 EXTRACT_U_1(pptr
+ 4), EXTRACT_U_1(pptr
+ 5),
736 EXTRACT_U_1(pptr
+ 6), EXTRACT_U_1(pptr
+ 7));
738 /* IP-address:AS fmt*/
741 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
742 EXTRACT_U_1(pptr
+ 2), EXTRACT_U_1(pptr
+ 3),
743 EXTRACT_U_1(pptr
+ 4), EXTRACT_U_1(pptr
+ 5),
744 EXTRACT_BE_U_2(pptr
+ 6));
747 /* 4-byte-AS:number fmt*/
749 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
750 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(pptr
+ 2)),
751 EXTRACT_BE_U_2(pptr
+ 6), EXTRACT_U_1(pptr
+ 2),
752 EXTRACT_U_1(pptr
+ 3), EXTRACT_U_1(pptr
+ 4),
753 EXTRACT_U_1(pptr
+ 5), EXTRACT_BE_U_2(pptr
+ 6));
756 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
765 decode_rt_routing_info(netdissect_options
*ndo
,
766 const u_char
*pptr
, char *buf
, u_int buflen
)
768 uint8_t route_target
[8];
770 char asbuf
[sizeof(astostr
)]; /* bgp_vpn_rd_print() overwrites astostr */
772 /* NLRI "prefix length" from RFC 2858 Section 4. */
774 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
776 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
777 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
778 * target" fields inside the "prefix" depending on its length.
781 /* Without "origin AS", without "route target". */
782 snprintf(buf
, buflen
, "default route target");
789 /* With at least "origin AS", possibly with "route target". */
790 ND_TCHECK_4(pptr
+ 1);
791 as_printf(ndo
, asbuf
, sizeof(asbuf
), EXTRACT_BE_U_4(pptr
+ 1));
793 plen
-= 32; /* adjust prefix length */
798 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
799 * and gives the number of octets in the variable-length "route
800 * target" field inside this NLRI "prefix". Look for it.
802 memset(&route_target
, 0, sizeof(route_target
));
803 ND_TCHECK_LEN(pptr
+ 5, (plen
+ 7) / 8);
804 memcpy(&route_target
, pptr
+ 5, (plen
+ 7) / 8);
805 /* Which specification says to do this? */
807 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
808 ((0xff00 >> (plen
% 8)) & 0xff);
810 snprintf(buf
, buflen
, "origin AS: %s, route target %s",
812 bgp_vpn_rd_print(ndo
, (u_char
*)&route_target
));
814 return 5 + (plen
+ 7) / 8;
821 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
822 const u_char
*pptr
, char *buf
, u_int buflen
)
828 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
833 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
838 memset(&addr
, 0, sizeof(addr
));
839 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
840 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
842 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
843 ((0xff00 >> (plen
% 8)) & 0xff);
845 /* the label may get offsetted by 4 bits so lets shift it right */
846 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
847 bgp_vpn_rd_print(ndo
, pptr
+4),
848 ipaddr_string(ndo
, &addr
),
850 EXTRACT_BE_U_3(pptr
+ 1)>>4,
851 ((EXTRACT_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
853 return 12 + (plen
+ 7) / 8;
860 * +-------------------------------+
862 * | RD:IPv4-address (12 octets) |
864 * +-------------------------------+
865 * | MDT Group-address (4 octets) |
866 * +-------------------------------+
869 #define MDT_VPN_NLRI_LEN 16
872 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
873 const u_char
*pptr
, char *buf
, u_int buflen
)
876 const u_char
*vpn_ip
;
880 /* if the NLRI is not predefined length, quit.*/
881 if (EXTRACT_U_1(pptr
) != MDT_VPN_NLRI_LEN
* 8)
891 ND_TCHECK_LEN(pptr
, sizeof(struct in_addr
));
893 pptr
+= sizeof(struct in_addr
);
895 /* MDT Group Address */
896 ND_TCHECK_LEN(pptr
, sizeof(struct in_addr
));
898 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
899 bgp_vpn_rd_print(ndo
, rd
), ipaddr_string(ndo
, vpn_ip
), ipaddr_string(ndo
, pptr
));
901 return MDT_VPN_NLRI_LEN
+ 1;
907 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
908 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
909 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
910 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
911 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
912 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
913 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
915 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
916 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
917 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
918 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
919 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
920 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
921 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
922 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
927 decode_multicast_vpn(netdissect_options
*ndo
,
928 const u_char
*pptr
, char *buf
, size_t buflen
)
930 uint8_t route_type
, route_length
, addr_length
;
935 route_type
= EXTRACT_U_1(pptr
);
937 route_length
= EXTRACT_U_1(pptr
);
940 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
941 tok2str(bgp_multicast_vpn_route_type_values
,
942 "Unknown", route_type
),
943 route_type
, route_length
);
946 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
947 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
948 offset
= strlen(buf
);
949 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
950 bgp_vpn_rd_print(ndo
, pptr
),
951 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
952 (route_length
- BGP_VPN_RD_LEN
) << 3));
954 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
955 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
956 offset
= strlen(buf
);
957 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
958 bgp_vpn_rd_print(ndo
, pptr
),
959 as_printf(ndo
, astostr
, sizeof(astostr
),
960 EXTRACT_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
963 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
964 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
965 offset
= strlen(buf
);
966 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
967 bgp_vpn_rd_print(ndo
, pptr
));
968 pptr
+= BGP_VPN_RD_LEN
;
970 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
971 addr_length
= route_length
- sg_length
;
973 ND_TCHECK_LEN(pptr
, addr_length
);
974 offset
= strlen(buf
);
975 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
976 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
979 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
980 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
981 offset
= strlen(buf
);
982 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
983 bgp_vpn_rd_print(ndo
, pptr
));
984 pptr
+= BGP_VPN_RD_LEN
;
986 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
989 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
990 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
991 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
992 offset
= strlen(buf
);
993 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
994 bgp_vpn_rd_print(ndo
, pptr
),
995 as_printf(ndo
, astostr
, sizeof(astostr
),
996 EXTRACT_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
997 pptr
+= BGP_VPN_RD_LEN
+ 4;
999 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1003 * no per route-type printing yet.
1005 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1010 return route_length
+ 2;
1017 * As I remember, some versions of systems have an snprintf() that
1018 * returns -1 if the buffer would have overflowed. If the return
1019 * value is negative, set buflen to 0, to indicate that we've filled
1022 * If the return value is greater than buflen, that means that
1023 * the buffer would have overflowed; again, set buflen to 0 in
1026 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1029 else if ((u_int)stringlen>buflen) \
1032 buflen-=stringlen; \
1037 decode_labeled_vpn_l2(netdissect_options
*ndo
,
1038 const u_char
*pptr
, char *buf
, u_int buflen
)
1040 u_int plen
, tlen
, tlv_type
, tlv_len
, ttlv_len
;
1044 plen
= EXTRACT_BE_U_2(pptr
);
1047 /* Old and new L2VPN NLRI share AFI/SAFI
1048 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1049 * and > 17 as old format. Complain for the middle case
1052 /* assume AD-only with RD, BGPNH */
1053 ND_TCHECK_LEN(pptr
, 12);
1055 stringlen
= snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
1056 bgp_vpn_rd_print(ndo
, pptr
),
1057 ipaddr_string(ndo
, pptr
+8));
1058 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1062 } else if (plen
> 17) {
1063 /* assume old format */
1064 /* RD, ID, LBLKOFF, LBLBASE */
1066 ND_TCHECK_LEN(pptr
, 15);
1068 stringlen
= snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1069 bgp_vpn_rd_print(ndo
, pptr
),
1070 EXTRACT_BE_U_2(pptr
+ 8),
1071 EXTRACT_BE_U_2(pptr
+ 10),
1072 EXTRACT_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1073 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1077 /* ok now the variable part - lets read out TLVs*/
1081 stringlen
=snprintf(buf
,buflen
, "\n\t\tran past the end");
1082 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1087 tlv_type
= EXTRACT_U_1(pptr
);
1089 tlv_len
= EXTRACT_BE_U_2(pptr
); /* length, in *bits* */
1090 ttlv_len
= (tlv_len
+ 7)/8; /* length, in *bytes* */
1096 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1099 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1101 while (ttlv_len
!= 0) {
1104 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1105 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1111 stringlen
=snprintf(buf
,buflen
, "%02x",
1114 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1122 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1125 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1127 if (tlen
< ttlv_len
) {
1129 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1130 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1140 /* complain bitterly ? */
1150 decode_prefix6(netdissect_options
*ndo
,
1151 const u_char
*pd
, u_int itemlen
, char *buf
, u_int buflen
)
1153 struct in6_addr addr
;
1154 u_int plen
, plenbytes
;
1158 plen
= EXTRACT_U_1(pd
);
1163 memset(&addr
, 0, sizeof(addr
));
1164 plenbytes
= (plen
+ 7) / 8;
1165 ND_TCHECK_LEN(pd
+ 1, plenbytes
);
1166 ITEMCHECK(plenbytes
);
1167 memcpy(&addr
, pd
+ 1, plenbytes
);
1169 addr
.s6_addr
[plenbytes
- 1] &=
1170 ((0xff00 >> (plen
% 8)) & 0xff);
1172 snprintf(buf
, buflen
, "%s/%u", ip6addr_string(ndo
, &addr
), plen
);
1173 return 1 + plenbytes
;
1183 decode_labeled_prefix6(netdissect_options
*ndo
,
1184 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
1186 struct in6_addr addr
;
1187 u_int plen
, plenbytes
;
1189 /* prefix length and label = 4 bytes */
1192 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
1197 plen
-= 24; /* adjust prefixlen - labellength */
1203 memset(&addr
, 0, sizeof(addr
));
1204 plenbytes
= (plen
+ 7) / 8;
1205 ND_TCHECK_LEN(pptr
+ 4, plenbytes
);
1206 memcpy(&addr
, pptr
+ 4, plenbytes
);
1208 addr
.s6_addr
[plenbytes
- 1] &=
1209 ((0xff00 >> (plen
% 8)) & 0xff);
1211 /* the label may get offsetted by 4 bits so lets shift it right */
1212 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
1213 ip6addr_string(ndo
, &addr
),
1215 EXTRACT_BE_U_3(pptr
+ 1)>>4,
1216 ((EXTRACT_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1218 return 4 + plenbytes
;
1228 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1229 const u_char
*pptr
, char *buf
, u_int buflen
)
1231 struct in6_addr addr
;
1235 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
1240 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1245 memset(&addr
, 0, sizeof(addr
));
1246 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
1247 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1249 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1250 ((0xff00 >> (plen
% 8)) & 0xff);
1252 /* the label may get offsetted by 4 bits so lets shift it right */
1253 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1254 bgp_vpn_rd_print(ndo
, pptr
+4),
1255 ip6addr_string(ndo
, &addr
),
1257 EXTRACT_BE_U_3(pptr
+ 1)>>4,
1258 ((EXTRACT_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1260 return 12 + (plen
+ 7) / 8;
1267 decode_clnp_prefix(netdissect_options
*ndo
,
1268 const u_char
*pptr
, char *buf
, u_int buflen
)
1274 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
1279 memset(&addr
, 0, sizeof(addr
));
1280 ND_TCHECK_LEN(pptr
+ 4, (plen
+ 7) / 8);
1281 memcpy(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1283 addr
[(plen
+ 7) / 8 - 1] &=
1284 ((0xff00 >> (plen
% 8)) & 0xff);
1286 snprintf(buf
, buflen
, "%s/%u",
1287 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1290 return 1 + (plen
+ 7) / 8;
1297 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1298 const u_char
*pptr
, char *buf
, u_int buflen
)
1304 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
1309 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1314 memset(&addr
, 0, sizeof(addr
));
1315 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
1316 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1318 addr
[(plen
+ 7) / 8 - 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
1320 /* the label may get offsetted by 4 bits so lets shift it right */
1321 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1322 bgp_vpn_rd_print(ndo
, pptr
+4),
1323 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1325 EXTRACT_BE_U_3(pptr
+ 1)>>4,
1326 ((EXTRACT_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1328 return 12 + (plen
+ 7) / 8;
1335 * bgp_attr_get_as_size
1337 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1338 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1339 * support, exchange AS-Path with the same path-attribute type value 0x02.
1342 bgp_attr_get_as_size(netdissect_options
*ndo
,
1343 uint8_t bgpa_type
, const u_char
*pptr
, u_int len
)
1345 const u_char
*tptr
= pptr
;
1348 * If the path attribute is the optional AS4 path type, then we already
1349 * know, that ASs must be encoded in 4 byte format.
1351 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1356 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1357 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1360 while (tptr
< pptr
+ len
) {
1364 * If we do not find a valid segment type, our guess might be wrong.
1366 if (EXTRACT_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| EXTRACT_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1369 ND_TCHECK_1(tptr
+ 1);
1370 tptr
+= 2 + EXTRACT_U_1(tptr
+ 1) * 2;
1374 * If we correctly reached end of the AS path attribute data content,
1375 * then most likely ASs were indeed encoded as 2 bytes.
1377 if (tptr
== pptr
+ len
) {
1384 * We can come here, either we did not have enough data, or if we
1385 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1386 * so that calller can try to decode each AS as of 4 bytes. If indeed
1387 * there was not enough data, it will crib and end the parse anyways.
1393 * The only way to know that a BGP UPDATE message is using add path is
1394 * by checking if the capability is in the OPEN message which we may have missed.
1395 * So this function checks if it is possible that the update could contain add path
1396 * and if so it checks that standard BGP doesn't make sense.
1399 check_add_path(const u_char
*pptr
, u_int length
, u_int max_prefix_length
)
1401 u_int offset
, prefix_length
;
1407 /* check if it could be add path */
1408 for (offset
= 0; offset
< length
;) {
1410 prefix_length
= EXTRACT_U_1(pptr
+ offset
);
1412 * Add 4 to cover the path id
1413 * and check the prefix length isn't greater than 32/128.
1415 if (prefix_length
> max_prefix_length
) {
1418 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1419 offset
+= 1 + ((prefix_length
+ 7) / 8);
1421 /* check we haven't gone past the end of the section */
1422 if (offset
> length
) {
1426 /* check it's not standard BGP */
1427 for (offset
= 0; offset
< length
; ) {
1428 prefix_length
= EXTRACT_U_1(pptr
+ offset
);
1430 * If the prefix_length is zero (0.0.0.0/0)
1431 * and since it's not the only address (length >= 5)
1432 * then it is add-path
1434 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1437 offset
+= 1 + ((prefix_length
+ 7) / 8);
1439 if (offset
> length
) {
1443 /* assume not add-path by default */
1448 bgp_attr_print(netdissect_options
*ndo
,
1449 u_int atype
, const u_char
*pptr
, u_int len
)
1453 uint8_t safi
, snpa
, nhlen
;
1454 union { /* copy buffer for bandwidth values */
1461 char buf
[MAXHOSTNAMELEN
+ 100];
1463 int add_path4
, add_path6
;
1470 case BGPTYPE_ORIGIN
:
1472 ND_PRINT((ndo
, "invalid len"));
1475 ND_PRINT((ndo
, "%s", tok2str(bgp_origin_values
,
1476 "Unknown Origin Typecode",
1477 EXTRACT_U_1(tptr
))));
1482 * Process AS4 byte path and AS2 byte path attributes here.
1484 case BGPTYPE_AS4_PATH
:
1485 case BGPTYPE_AS_PATH
:
1487 ND_PRINT((ndo
, "invalid len"));
1491 ND_PRINT((ndo
, "empty"));
1496 * BGP updates exchanged between New speakers that support 4
1497 * byte AS, ASs are always encoded in 4 bytes. There is no
1498 * definitive way to find this, just by the packet's
1499 * contents. So, check for packet's TLV's sanity assuming
1500 * 2 bytes first, and it does not pass, assume that ASs are
1501 * encoded in 4 bytes format and move on.
1503 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1505 while (tptr
< pptr
+ len
) {
1507 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_open_values
,
1508 "?", EXTRACT_U_1(tptr
))));
1509 ND_TCHECK_1(tptr
+ 1);
1510 for (i
= 0; i
< EXTRACT_U_1(tptr
+ 1) * as_size
; i
+= as_size
) {
1511 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
1512 ND_PRINT((ndo
, "%s ",
1513 as_printf(ndo
, astostr
, sizeof(astostr
),
1515 EXTRACT_BE_U_2(tptr
+ i
+ 2) :
1516 EXTRACT_BE_U_4(tptr
+ i
+ 2))));
1519 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_close_values
,
1520 "?", EXTRACT_U_1(tptr
))));
1521 ND_TCHECK_1(tptr
+ 1);
1522 tptr
+= 2 + EXTRACT_U_1(tptr
+ 1) * as_size
;
1525 case BGPTYPE_NEXT_HOP
:
1527 ND_PRINT((ndo
, "invalid len"));
1530 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1533 case BGPTYPE_MULTI_EXIT_DISC
:
1534 case BGPTYPE_LOCAL_PREF
:
1536 ND_PRINT((ndo
, "invalid len"));
1539 ND_PRINT((ndo
, "%u", EXTRACT_BE_U_4(tptr
)));
1542 case BGPTYPE_ATOMIC_AGGREGATE
:
1544 ND_PRINT((ndo
, "invalid len"));
1546 case BGPTYPE_AGGREGATOR
:
1549 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1550 * the length of this PA can be either 6 bytes or 8 bytes.
1552 if (len
!= 6 && len
!= 8) {
1553 ND_PRINT((ndo
, "invalid len"));
1556 ND_TCHECK_LEN(tptr
, len
);
1558 ND_PRINT((ndo
, " AS #%s, origin %s",
1559 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_2(tptr
)),
1560 ipaddr_string(ndo
, tptr
+ 2)));
1562 ND_PRINT((ndo
, " AS #%s, origin %s",
1563 as_printf(ndo
, astostr
, sizeof(astostr
),
1564 EXTRACT_BE_U_4(tptr
)), ipaddr_string(ndo
, tptr
+ 4)));
1567 case BGPTYPE_AGGREGATOR4
:
1569 ND_PRINT((ndo
, "invalid len"));
1573 ND_PRINT((ndo
, " AS #%s, origin %s",
1574 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(tptr
)),
1575 ipaddr_string(ndo
, tptr
+ 4)));
1577 case BGPTYPE_COMMUNITIES
:
1579 ND_PRINT((ndo
, "invalid len"));
1587 comm
= EXTRACT_BE_U_4(tptr
);
1589 case BGP_COMMUNITY_NO_EXPORT
:
1590 ND_PRINT((ndo
, " NO_EXPORT"));
1592 case BGP_COMMUNITY_NO_ADVERT
:
1593 ND_PRINT((ndo
, " NO_ADVERTISE"));
1595 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1596 ND_PRINT((ndo
, " NO_EXPORT_SUBCONFED"));
1599 ND_PRINT((ndo
, "%u:%u%s",
1600 (comm
>> 16) & 0xffff,
1602 (tlen
>4) ? ", " : ""));
1609 case BGPTYPE_ORIGINATOR_ID
:
1611 ND_PRINT((ndo
, "invalid len"));
1615 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1617 case BGPTYPE_CLUSTER_LIST
:
1619 ND_PRINT((ndo
, "invalid len"));
1626 ND_PRINT((ndo
, "%s%s",
1627 ipaddr_string(ndo
, tptr
),
1628 (tlen
>4) ? ", " : ""));
1633 case BGPTYPE_MP_REACH_NLRI
:
1635 af
= EXTRACT_BE_U_2(tptr
);
1636 safi
= EXTRACT_U_1(tptr
+ 2);
1638 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1639 tok2str(af_values
, "Unknown AFI", af
),
1641 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1642 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1645 switch(af
<<8 | safi
) {
1646 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1647 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1648 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1649 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1650 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1651 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1652 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1653 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1654 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1655 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1656 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1657 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1658 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1659 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1660 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1661 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1662 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1663 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1664 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1665 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1666 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1667 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1668 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1669 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1670 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1671 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1672 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1675 ND_TCHECK_LEN(tptr
, tlen
);
1676 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1677 if (ndo
->ndo_vflag
<= 1)
1678 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1686 nhlen
= EXTRACT_U_1(tptr
);
1692 ND_PRINT((ndo
, "\n\t nexthop: "));
1695 ND_PRINT((ndo
, ", " ));
1697 switch(af
<<8 | safi
) {
1698 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1699 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1700 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1701 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1702 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1703 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1704 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1705 if (tlen
< sizeof(struct in_addr
)) {
1706 ND_PRINT((ndo
, "invalid len"));
1709 ND_TCHECK_LEN(tptr
, sizeof(struct in_addr
));
1710 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1711 tlen
-= sizeof(struct in_addr
);
1712 tptr
+= sizeof(struct in_addr
);
1715 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1716 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1717 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1718 if (tlen
< sizeof(struct in_addr
)+BGP_VPN_RD_LEN
) {
1719 ND_PRINT((ndo
, "invalid len"));
1723 sizeof(struct in_addr
) + BGP_VPN_RD_LEN
);
1724 ND_PRINT((ndo
, "RD: %s, %s",
1725 bgp_vpn_rd_print(ndo
, tptr
),
1726 ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1727 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1728 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1731 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1732 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1733 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1734 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1735 if (tlen
< sizeof(struct in6_addr
)) {
1736 ND_PRINT((ndo
, "invalid len"));
1739 ND_TCHECK_LEN(tptr
, sizeof(struct in6_addr
));
1740 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, tptr
)));
1741 tlen
-= sizeof(struct in6_addr
);
1742 tptr
+= sizeof(struct in6_addr
);
1745 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1746 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1747 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1748 if (tlen
< sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
) {
1749 ND_PRINT((ndo
, "invalid len"));
1753 sizeof(struct in6_addr
) + BGP_VPN_RD_LEN
);
1754 ND_PRINT((ndo
, "RD: %s, %s",
1755 bgp_vpn_rd_print(ndo
, tptr
),
1756 ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1757 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1758 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1761 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1762 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1763 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1764 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1765 if (tlen
< sizeof(struct in_addr
)) {
1766 ND_PRINT((ndo
, "invalid len"));
1769 ND_TCHECK_LEN(tptr
, sizeof(struct in_addr
));
1770 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1771 tlen
-= (sizeof(struct in_addr
));
1772 tptr
+= (sizeof(struct in_addr
));
1775 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1776 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1777 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1778 ND_TCHECK_LEN(tptr
, tlen
);
1779 ND_PRINT((ndo
, "%s", isonsap_string(ndo
, tptr
, tlen
)));
1784 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1785 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1786 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1787 if (tlen
< BGP_VPN_RD_LEN
+1) {
1788 ND_PRINT((ndo
, "invalid len"));
1791 ND_TCHECK_LEN(tptr
, tlen
);
1792 ND_PRINT((ndo
, "RD: %s, %s",
1793 bgp_vpn_rd_print(ndo
, tptr
),
1794 isonsap_string(ndo
, tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
)));
1795 /* rfc986 mapped IPv4 address ? */
1796 if (EXTRACT_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
1797 ND_PRINT((ndo
, " = %s", ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+4)));
1798 /* rfc1888 mapped IPv6 address ? */
1799 else if (EXTRACT_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
1800 ND_PRINT((ndo
, " = %s", ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+3)));
1806 ND_TCHECK_LEN(tptr
, tlen
);
1807 ND_PRINT((ndo
, "no AFI %u/SAFI %u decoder", af
, safi
));
1808 if (ndo
->ndo_vflag
<= 1)
1809 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1817 ND_PRINT((ndo
, ", nh-length: %u", nhlen
));
1821 snpa
= EXTRACT_U_1(tptr
);
1825 ND_PRINT((ndo
, "\n\t %u SNPA", snpa
));
1826 for (/*nothing*/; snpa
!= 0; snpa
--) {
1828 ND_PRINT((ndo
, "\n\t %u bytes", EXTRACT_U_1(tptr
)));
1829 tptr
+= EXTRACT_U_1(tptr
) + 1;
1832 ND_PRINT((ndo
, ", no SNPA"));
1835 add_path4
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 32);
1836 add_path6
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 128);
1838 while (tptr
< pptr
+ len
) {
1839 switch (af
<<8 | safi
) {
1840 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1841 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1842 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1844 path_id
= EXTRACT_BE_U_4(tptr
);
1847 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1849 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1850 else if (advance
== -2)
1852 else if (advance
== -3)
1853 break; /* bytes left, but not enough */
1855 ND_PRINT((ndo
, "\n\t %s", buf
));
1857 ND_PRINT((ndo
, " Path Id: %u", path_id
));
1860 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1861 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1863 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1864 else if (advance
== -2)
1866 else if (advance
== -3)
1867 break; /* bytes left, but not enough */
1869 ND_PRINT((ndo
, "\n\t %s", buf
));
1871 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1872 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1873 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1874 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1876 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1877 else if (advance
== -2)
1880 ND_PRINT((ndo
, "\n\t %s", buf
));
1882 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1883 advance
= decode_rt_routing_info(ndo
, tptr
, buf
, sizeof(buf
));
1885 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1886 else if (advance
== -2)
1889 ND_PRINT((ndo
, "\n\t %s", buf
));
1891 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1892 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1893 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1895 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1896 else if (advance
== -2)
1899 ND_PRINT((ndo
, "\n\t %s", buf
));
1902 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1903 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
1905 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1906 else if (advance
== -2)
1909 ND_PRINT((ndo
, "\n\t %s", buf
));
1911 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1912 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1913 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1915 path_id
= EXTRACT_BE_U_4(tptr
);
1918 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1920 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1921 else if (advance
== -2)
1923 else if (advance
== -3)
1924 break; /* bytes left, but not enough */
1926 ND_PRINT((ndo
, "\n\t %s", buf
));
1928 ND_PRINT((ndo
, " Path Id: %u", path_id
));
1931 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1932 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1934 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1935 else if (advance
== -2)
1937 else if (advance
== -3)
1938 break; /* bytes left, but not enough */
1940 ND_PRINT((ndo
, "\n\t %s", buf
));
1942 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1943 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1944 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1945 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1947 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1948 else if (advance
== -2)
1951 ND_PRINT((ndo
, "\n\t %s", buf
));
1953 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1954 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1955 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1956 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1957 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1959 ND_PRINT((ndo
, "\n\t (illegal length)"));
1960 else if (advance
== -2)
1963 ND_PRINT((ndo
, "\n\t %s", buf
));
1965 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1966 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1967 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1968 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1970 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1971 else if (advance
== -2)
1974 ND_PRINT((ndo
, "\n\t %s", buf
));
1976 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1977 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1978 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1979 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1981 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1982 else if (advance
== -2)
1985 ND_PRINT((ndo
, "\n\t %s", buf
));
1988 ND_TCHECK_LEN(tptr
, tlen
);
1989 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1990 if (ndo
->ndo_vflag
<= 1)
1991 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2003 case BGPTYPE_MP_UNREACH_NLRI
:
2004 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
2005 af
= EXTRACT_BE_U_2(tptr
);
2006 safi
= EXTRACT_U_1(tptr
+ 2);
2008 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
2009 tok2str(af_values
, "Unknown AFI", af
),
2011 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
2012 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
2015 if (len
== BGP_MP_NLRI_MINSIZE
)
2016 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
2020 add_path4
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 32);
2021 add_path6
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 128);
2023 while (tptr
< pptr
+ len
) {
2024 switch (af
<<8 | safi
) {
2025 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
2026 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
2027 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
2029 path_id
= EXTRACT_BE_U_4(tptr
);
2032 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
2034 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2035 else if (advance
== -2)
2037 else if (advance
== -3)
2038 break; /* bytes left, but not enough */
2040 ND_PRINT((ndo
, "\n\t %s", buf
));
2042 ND_PRINT((ndo
, " Path Id: %u", path_id
));
2045 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
2046 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
2048 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2049 else if (advance
== -2)
2051 else if (advance
== -3)
2052 break; /* bytes left, but not enough */
2054 ND_PRINT((ndo
, "\n\t %s", buf
));
2056 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
2057 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
2058 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
2059 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
2061 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2062 else if (advance
== -2)
2065 ND_PRINT((ndo
, "\n\t %s", buf
));
2067 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
2068 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
2069 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
2071 path_id
= EXTRACT_BE_U_4(tptr
);
2074 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
2076 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2077 else if (advance
== -2)
2079 else if (advance
== -3)
2080 break; /* bytes left, but not enough */
2082 ND_PRINT((ndo
, "\n\t %s", buf
));
2084 ND_PRINT((ndo
, " Path Id: %u", path_id
));
2087 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
2088 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
2090 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2091 else if (advance
== -2)
2093 else if (advance
== -3)
2094 break; /* bytes left, but not enough */
2096 ND_PRINT((ndo
, "\n\t %s", buf
));
2098 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
2099 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
2100 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2101 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
2103 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2104 else if (advance
== -2)
2107 ND_PRINT((ndo
, "\n\t %s", buf
));
2109 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2110 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2111 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2112 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2113 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
2115 ND_PRINT((ndo
, "\n\t (illegal length)"));
2116 else if (advance
== -2)
2119 ND_PRINT((ndo
, "\n\t %s", buf
));
2121 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2122 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2123 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2124 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2126 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2127 else if (advance
== -2)
2130 ND_PRINT((ndo
, "\n\t %s", buf
));
2132 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2133 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2134 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2135 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2137 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2138 else if (advance
== -2)
2141 ND_PRINT((ndo
, "\n\t %s", buf
));
2143 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
2144 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
2146 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2147 else if (advance
== -2)
2150 ND_PRINT((ndo
, "\n\t %s", buf
));
2152 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
2153 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
2154 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
2156 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2157 else if (advance
== -2)
2160 ND_PRINT((ndo
, "\n\t %s", buf
));
2163 ND_TCHECK_LEN(tptr
- 3, tlen
);
2164 ND_PRINT((ndo
, "no AFI %u / SAFI %u decoder", af
, safi
));
2165 if (ndo
->ndo_vflag
<= 1)
2166 print_unknown_data(ndo
, tptr
-3, "\n\t ", tlen
);
2176 case BGPTYPE_EXTD_COMMUNITIES
:
2178 ND_PRINT((ndo
, "invalid len"));
2187 extd_comm
=EXTRACT_BE_U_2(tptr
);
2189 ND_PRINT((ndo
, "\n\t %s (0x%04x), Flags [%s]",
2190 tok2str(bgp_extd_comm_subtype_values
,
2191 "unknown extd community typecode",
2194 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
)));
2196 ND_TCHECK_6(tptr
+ 2);
2200 case BGP_EXT_COM_RT_0
:
2201 case BGP_EXT_COM_RO_0
:
2202 case BGP_EXT_COM_L2VPN_RT_0
:
2203 ND_PRINT((ndo
, ": %u:%u (= %s)",
2204 EXTRACT_BE_U_2(tptr
+ 2),
2205 EXTRACT_BE_U_4(tptr
+ 4),
2206 ipaddr_string(ndo
, tptr
+4)));
2208 case BGP_EXT_COM_RT_1
:
2209 case BGP_EXT_COM_RO_1
:
2210 case BGP_EXT_COM_L2VPN_RT_1
:
2211 case BGP_EXT_COM_VRF_RT_IMP
:
2212 ND_PRINT((ndo
, ": %s:%u",
2213 ipaddr_string(ndo
, tptr
+2),
2214 EXTRACT_BE_U_2(tptr
+ 6)));
2216 case BGP_EXT_COM_RT_2
:
2217 case BGP_EXT_COM_RO_2
:
2218 ND_PRINT((ndo
, ": %s:%u",
2219 as_printf(ndo
, astostr
, sizeof(astostr
),
2220 EXTRACT_BE_U_4(tptr
+ 2)), EXTRACT_BE_U_2(tptr
+ 6)));
2222 case BGP_EXT_COM_LINKBAND
:
2223 bw
.i
= EXTRACT_BE_U_4(tptr
+ 2);
2224 ND_PRINT((ndo
, ": bandwidth: %.3f Mbps",
2227 case BGP_EXT_COM_VPN_ORIGIN
:
2228 case BGP_EXT_COM_VPN_ORIGIN2
:
2229 case BGP_EXT_COM_VPN_ORIGIN3
:
2230 case BGP_EXT_COM_VPN_ORIGIN4
:
2231 case BGP_EXT_COM_OSPF_RID
:
2232 case BGP_EXT_COM_OSPF_RID2
:
2233 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
+2)));
2235 case BGP_EXT_COM_OSPF_RTYPE
:
2236 case BGP_EXT_COM_OSPF_RTYPE2
:
2237 ND_PRINT((ndo
, ": area:%s, router-type:%s, metric-type:%s%s",
2238 ipaddr_string(ndo
, tptr
+2),
2239 tok2str(bgp_extd_comm_ospf_rtype_values
,
2241 EXTRACT_U_1((tptr
+ 6))),
2242 (EXTRACT_U_1(tptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
2243 ((EXTRACT_U_1(tptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (EXTRACT_U_1(tptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : ""));
2245 case BGP_EXT_COM_L2INFO
:
2246 ND_PRINT((ndo
, ": %s Control Flags [0x%02x]:MTU %u",
2247 tok2str(l2vpn_encaps_values
,
2249 EXTRACT_U_1((tptr
+ 2))),
2250 EXTRACT_U_1((tptr
+ 3)),
2251 EXTRACT_BE_U_2(tptr
+ 4)));
2253 case BGP_EXT_COM_SOURCE_AS
:
2254 ND_PRINT((ndo
, ": AS %u", EXTRACT_BE_U_2(tptr
+ 2)));
2258 print_unknown_data(ndo
, tptr
, "\n\t ", 8);
2266 case BGPTYPE_PMSI_TUNNEL
:
2268 uint8_t tunnel_type
, flags
;
2271 flags
= EXTRACT_U_1(tptr
);
2272 tunnel_type
= EXTRACT_U_1(tptr
+ 1);
2275 ND_PRINT((ndo
, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2276 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2278 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2279 EXTRACT_BE_U_3(tptr
+ 2)>>4));
2284 switch (tunnel_type
) {
2285 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2286 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2288 ND_PRINT((ndo
, "\n\t Sender %s, P-Group %s",
2289 ipaddr_string(ndo
, tptr
),
2290 ipaddr_string(ndo
, tptr
+4)));
2293 case BGP_PMSI_TUNNEL_PIM_SSM
:
2295 ND_PRINT((ndo
, "\n\t Root-Node %s, P-Group %s",
2296 ipaddr_string(ndo
, tptr
),
2297 ipaddr_string(ndo
, tptr
+4)));
2299 case BGP_PMSI_TUNNEL_INGRESS
:
2301 ND_PRINT((ndo
, "\n\t Tunnel-Endpoint %s",
2302 ipaddr_string(ndo
, tptr
)));
2304 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2305 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2307 ND_PRINT((ndo
, "\n\t Root-Node %s, LSP-ID 0x%08x",
2308 ipaddr_string(ndo
, tptr
),
2309 EXTRACT_BE_U_4(tptr
+ 4)));
2311 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2313 ND_PRINT((ndo
, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2314 ipaddr_string(ndo
, tptr
),
2315 EXTRACT_BE_U_4(tptr
+ 4)));
2318 if (ndo
->ndo_vflag
<= 1) {
2319 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2335 type
= EXTRACT_U_1(tptr
);
2336 length
= EXTRACT_BE_U_2(tptr
+ 1);
2340 ND_PRINT((ndo
, "\n\t %s TLV (%u), length %u",
2341 tok2str(bgp_aigp_values
, "Unknown", type
),
2349 * Check if we can read the TLV data.
2351 ND_TCHECK_LEN(tptr
+ 3, length
);
2358 ND_PRINT((ndo
, ", metric %" PRIu64
,
2359 EXTRACT_BE_U_8(tptr
)));
2363 if (ndo
->ndo_vflag
<= 1) {
2364 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2373 case BGPTYPE_ATTR_SET
:
2377 ND_PRINT((ndo
, "\n\t Origin AS: %s",
2378 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(tptr
))));
2383 u_int aflags
, alenlen
, alen
;
2388 aflags
= EXTRACT_U_1(tptr
);
2389 atype
= EXTRACT_U_1(tptr
+ 1);
2392 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2393 ND_TCHECK_LEN(tptr
, alenlen
);
2396 alen
= bgp_attr_len(aflags
, tptr
);
2400 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2401 tok2str(bgp_attr_values
,
2402 "Unknown Attribute", atype
),
2407 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2408 aflags
& 0x80 ? "O" : "",
2409 aflags
& 0x40 ? "T" : "",
2410 aflags
& 0x20 ? "P" : "",
2411 aflags
& 0x10 ? "E" : ""));
2413 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2414 ND_PRINT((ndo
, "]: "));
2416 /* FIXME check for recursion */
2417 if (!bgp_attr_print(ndo
, atype
, tptr
, alen
))
2424 case BGPTYPE_LARGE_COMMUNITY
:
2425 if (len
== 0 || len
% 12) {
2426 ND_PRINT((ndo
, "invalid len"));
2429 ND_PRINT((ndo
, "\n\t "));
2431 ND_TCHECK_LEN(tptr
, 12);
2432 ND_PRINT((ndo
, "%u:%u:%u%s",
2433 EXTRACT_BE_U_4(tptr
),
2434 EXTRACT_BE_U_4(tptr
+ 4),
2435 EXTRACT_BE_U_4(tptr
+ 8),
2436 (len
> 12) ? ", " : ""));
2439 * len will always be a multiple of 12, as per the above,
2440 * so this will never underflow.
2446 ND_TCHECK_LEN(pptr
, len
);
2447 ND_PRINT((ndo
, "\n\t no Attribute %u decoder", atype
)); /* we have no decoder for the attribute */
2448 if (ndo
->ndo_vflag
<= 1)
2449 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2452 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2453 ND_TCHECK_LEN(pptr
, len
);
2454 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2463 bgp_capabilities_print(netdissect_options
*ndo
,
2464 const u_char
*opt
, u_int caps_len
)
2466 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2469 while (i
< caps_len
) {
2470 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2471 cap_type
=EXTRACT_U_1(opt
+ i
);
2472 cap_len
=EXTRACT_U_1(opt
+ i
+ 1);
2474 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2475 tok2str(bgp_capcode_values
, "Unknown", cap_type
),
2478 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2480 case BGP_CAPCODE_MP
:
2481 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u)",
2482 tok2str(af_values
, "Unknown", EXTRACT_BE_U_2(opt
+ i
+ 2)),
2483 EXTRACT_BE_U_2(opt
+ i
+ 2),
2484 tok2str(bgp_safi_values
, "Unknown", EXTRACT_U_1(opt
+ i
+ 5)),
2485 EXTRACT_U_1(opt
+ i
+ 5)));
2487 case BGP_CAPCODE_RESTART
:
2488 ND_PRINT((ndo
, "\n\t\tRestart Flags: [%s], Restart Time %us",
2489 ((EXTRACT_U_1(opt
+ i
+ 2))&0x80) ? "R" : "none",
2490 EXTRACT_BE_U_2(opt
+ i
+ 2)&0xfff));
2493 while(tcap_len
>=4) {
2494 ND_PRINT((ndo
, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2495 tok2str(af_values
,"Unknown",
2496 EXTRACT_BE_U_2(opt
+ i
+ cap_offset
)),
2497 EXTRACT_BE_U_2(opt
+ i
+ cap_offset
),
2498 tok2str(bgp_safi_values
,"Unknown",
2499 EXTRACT_U_1(opt
+ i
+ cap_offset
+ 2)),
2500 EXTRACT_U_1(opt
+ (i
+ cap_offset
+ 2)),
2501 ((EXTRACT_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" ));
2506 case BGP_CAPCODE_RR
:
2507 case BGP_CAPCODE_RR_CISCO
:
2509 case BGP_CAPCODE_AS_NEW
:
2512 * Extract the 4 byte AS number encoded.
2515 ND_PRINT((ndo
, "\n\t\t 4 Byte AS %s",
2516 as_printf(ndo
, astostr
, sizeof(astostr
),
2517 EXTRACT_BE_U_4(opt
+ i
+ 2))));
2520 case BGP_CAPCODE_ADD_PATH
:
2522 if (tcap_len
== 0) {
2523 ND_PRINT((ndo
, " (bogus)")); /* length */
2526 while (tcap_len
!= 0) {
2528 ND_PRINT((ndo
, "\n\t\t(invalid)"));
2531 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2532 tok2str(af_values
,"Unknown",EXTRACT_BE_U_2(opt
+ i
+ cap_offset
)),
2533 EXTRACT_BE_U_2(opt
+ i
+ cap_offset
),
2534 tok2str(bgp_safi_values
,"Unknown",EXTRACT_U_1(opt
+ i
+ cap_offset
+ 2)),
2535 EXTRACT_U_1(opt
+ (i
+ cap_offset
+ 2)),
2536 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",EXTRACT_U_1(opt
+ i
+ cap_offset
+ 3))
2543 ND_PRINT((ndo
, "\n\t\tno decoder for Capability %u",
2545 if (ndo
->ndo_vflag
<= 1)
2546 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2550 if (ndo
->ndo_vflag
> 1 && cap_len
!= 0) {
2551 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2553 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2558 ND_PRINT((ndo
, "[|BGP]"));
2562 bgp_open_print(netdissect_options
*ndo
,
2563 const u_char
*dat
, u_int length
)
2565 const struct bgp_open
*bgp_open_header
;
2567 const struct bgp_opt
*bgpopt
;
2571 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2572 if (length
< BGP_OPEN_SIZE
)
2575 bgp_open_header
= (const struct bgp_open
*)dat
;
2577 ND_PRINT((ndo
, "\n\t Version %u, ",
2578 EXTRACT_U_1(bgp_open_header
->bgpo_version
)));
2579 ND_PRINT((ndo
, "my AS %s, ",
2580 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_2(bgp_open_header
->bgpo_myas
))));
2581 ND_PRINT((ndo
, "Holdtime %us, ",
2582 EXTRACT_BE_U_2(bgp_open_header
->bgpo_holdtime
)));
2583 ND_PRINT((ndo
, "ID %s", ipaddr_string(ndo
, &bgp_open_header
->bgpo_id
)));
2584 optslen
= EXTRACT_U_1(bgp_open_header
->bgpo_optlen
);
2585 ND_PRINT((ndo
, "\n\t Optional parameters, length: %u", optslen
));
2587 opt
= dat
+ BGP_OPEN_SIZE
;
2588 length
-= BGP_OPEN_SIZE
;
2591 while (i
< optslen
) {
2592 uint8_t opt_type
, opt_len
;
2594 ND_TCHECK_LEN(opt
+ i
, BGP_OPT_SIZE
);
2595 if (length
< BGP_OPT_SIZE
+ i
)
2597 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2598 opt_type
= EXTRACT_U_1(bgpopt
->bgpopt_type
);
2599 opt_len
= EXTRACT_U_1(bgpopt
->bgpopt_len
);
2600 if (BGP_OPT_SIZE
+ i
+ opt_len
> optslen
) {
2601 ND_PRINT((ndo
, "\n\t Option %u, length: %u, goes past the end of the options",
2602 opt_type
, opt_len
));
2606 ND_PRINT((ndo
, "\n\t Option %s (%u), length: %u",
2607 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2611 /* now let's decode the options we know*/
2615 bgp_capabilities_print(ndo
, opt
+ BGP_OPT_SIZE
+ i
,
2621 ND_PRINT((ndo
, "\n\t no decoder for option %u",
2625 i
+= BGP_OPT_SIZE
+ opt_len
;
2629 ND_PRINT((ndo
, "[|BGP]"));
2633 bgp_update_print(netdissect_options
*ndo
,
2634 const u_char
*dat
, u_int length
)
2637 u_int withdrawn_routes_len
;
2638 char buf
[MAXHOSTNAMELEN
+ 100];
2645 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2646 if (length
< BGP_SIZE
)
2651 /* Unfeasible routes */
2655 withdrawn_routes_len
= EXTRACT_BE_U_2(p
);
2658 if (withdrawn_routes_len
> 1) {
2660 * Without keeping state from the original NLRI message,
2661 * it's not possible to tell if this a v4 or v6 route,
2662 * so only try to decode it if we're not v6 enabled.
2664 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2665 if (length
< withdrawn_routes_len
)
2667 ND_PRINT((ndo
, "\n\t Withdrawn routes:"));
2668 add_path
= check_add_path(p
, withdrawn_routes_len
, 32);
2669 while (withdrawn_routes_len
!= 0) {
2671 if (withdrawn_routes_len
< 4) {
2672 p
+= withdrawn_routes_len
;
2673 length
-= withdrawn_routes_len
;
2676 path_id
= EXTRACT_BE_U_4(p
);
2679 withdrawn_routes_len
-= 4;
2681 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2683 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2685 } else if (wpfx
== -2)
2687 else if (wpfx
== -3)
2688 goto trunc
; /* bytes left, but not enough */
2690 ND_PRINT((ndo
, "\n\t %s", buf
));
2692 ND_PRINT((ndo
, " Path Id: %u", path_id
));
2696 withdrawn_routes_len
-= wpfx
;
2700 p
+= withdrawn_routes_len
;
2701 length
-= withdrawn_routes_len
;
2707 len
= EXTRACT_BE_U_2(p
);
2711 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2712 /* No withdrawn routes, no path attributes, no NLRI */
2713 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
2718 /* do something more useful!*/
2720 u_int aflags
, atype
, alenlen
, alen
;
2727 aflags
= EXTRACT_U_1(p
);
2728 atype
= EXTRACT_U_1(p
+ 1);
2732 alenlen
= bgp_attr_lenlen(aflags
, p
);
2733 ND_TCHECK_LEN(p
, alenlen
);
2736 if (length
< alenlen
)
2738 alen
= bgp_attr_len(aflags
, p
);
2743 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2744 tok2str(bgp_attr_values
, "Unknown Attribute", atype
),
2749 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2750 aflags
& 0x80 ? "O" : "",
2751 aflags
& 0x40 ? "T" : "",
2752 aflags
& 0x20 ? "P" : "",
2753 aflags
& 0x10 ? "E" : ""));
2755 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2756 ND_PRINT((ndo
, "]: "));
2762 if (!bgp_attr_print(ndo
, atype
, p
, alen
))
2771 add_path
= check_add_path(p
, length
, 32);
2772 ND_PRINT((ndo
, "\n\t Updated routes:"));
2773 while (length
!= 0) {
2775 path_id
= EXTRACT_BE_U_4(p
);
2779 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2781 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2786 goto trunc
; /* bytes left, but not enough */
2788 ND_PRINT((ndo
, "\n\t %s", buf
));
2790 ND_PRINT((ndo
, " Path Id: %u", path_id
));
2799 ND_PRINT((ndo
, "[|BGP]"));
2803 bgp_notification_print(netdissect_options
*ndo
,
2804 const u_char
*dat
, u_int length
)
2806 const struct bgp_notification
*bgp_notification_header
;
2808 uint8_t bgpn_major
, bgpn_minor
;
2809 uint8_t shutdown_comm_length
;
2810 uint8_t remainder_offset
;
2812 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
2813 if (length
<BGP_NOTIFICATION_SIZE
)
2816 bgp_notification_header
= (const struct bgp_notification
*)dat
;
2817 bgpn_major
= EXTRACT_U_1(bgp_notification_header
->bgpn_major
);
2818 bgpn_minor
= EXTRACT_U_1(bgp_notification_header
->bgpn_minor
);
2820 ND_PRINT((ndo
, ", %s (%u)",
2821 tok2str(bgp_notify_major_values
, "Unknown Error",
2825 switch (bgpn_major
) {
2827 case BGP_NOTIFY_MAJOR_MSG
:
2828 ND_PRINT((ndo
, ", subcode %s (%u)",
2829 tok2str(bgp_notify_minor_msg_values
, "Unknown",
2833 case BGP_NOTIFY_MAJOR_OPEN
:
2834 ND_PRINT((ndo
, ", subcode %s (%u)",
2835 tok2str(bgp_notify_minor_open_values
, "Unknown",
2839 case BGP_NOTIFY_MAJOR_UPDATE
:
2840 ND_PRINT((ndo
, ", subcode %s (%u)",
2841 tok2str(bgp_notify_minor_update_values
, "Unknown",
2845 case BGP_NOTIFY_MAJOR_FSM
:
2846 ND_PRINT((ndo
, " subcode %s (%u)",
2847 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
2851 case BGP_NOTIFY_MAJOR_CAP
:
2852 ND_PRINT((ndo
, " subcode %s (%u)",
2853 tok2str(bgp_notify_minor_cap_values
, "Unknown",
2857 case BGP_NOTIFY_MAJOR_CEASE
:
2858 ND_PRINT((ndo
, ", subcode %s (%u)",
2859 tok2str(bgp_notify_minor_cease_values
, "Unknown",
2863 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2864 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2866 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2867 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2869 ND_PRINT((ndo
, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2870 tok2str(af_values
, "Unknown", EXTRACT_BE_U_2(tptr
)),
2871 EXTRACT_BE_U_2(tptr
),
2872 tok2str(bgp_safi_values
, "Unknown", EXTRACT_U_1((tptr
+ 2))),
2873 EXTRACT_U_1((tptr
+ 2)),
2874 EXTRACT_BE_U_4(tptr
+ 3)));
2877 * draft-ietf-idr-shutdown describes a method to send a communication
2878 * intended for human consumption regarding the Administrative Shutdown
2880 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
2881 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
2882 length
>= BGP_NOTIFICATION_SIZE
+ 1) {
2883 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2885 shutdown_comm_length
= EXTRACT_U_1(tptr
);
2886 remainder_offset
= 0;
2887 /* garbage, hexdump it all */
2888 if (shutdown_comm_length
> BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN
||
2889 shutdown_comm_length
> length
- (BGP_NOTIFICATION_SIZE
+ 1)) {
2890 ND_PRINT((ndo
, ", invalid Shutdown Communication length"));
2892 else if (shutdown_comm_length
== 0) {
2893 ND_PRINT((ndo
, ", empty Shutdown Communication"));
2894 remainder_offset
+= 1;
2896 /* a proper shutdown communication */
2898 ND_TCHECK_LEN(tptr
+ 1, shutdown_comm_length
);
2899 ND_PRINT((ndo
, ", Shutdown Communication (length: %u): \"", shutdown_comm_length
));
2900 (void)fn_printn(ndo
, tptr
+1, shutdown_comm_length
, NULL
);
2901 ND_PRINT((ndo
, "\""));
2902 remainder_offset
+= shutdown_comm_length
+ 1;
2904 /* if there is trailing data, hexdump it */
2905 if(length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
) > 0) {
2906 ND_PRINT((ndo
, ", Data: (length: %u)", length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
)));
2907 hex_print(ndo
, "\n\t\t", tptr
+ remainder_offset
, length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
2917 ND_PRINT((ndo
, "[|BGP]"));
2921 bgp_route_refresh_print(netdissect_options
*ndo
,
2922 const u_char
*pptr
, u_int len
)
2924 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2926 ND_TCHECK_LEN(pptr
, BGP_ROUTE_REFRESH_SIZE
);
2928 /* some little sanity checking */
2929 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2932 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2934 ND_PRINT((ndo
, "\n\t AFI %s (%u), SAFI %s (%u)",
2935 tok2str(af_values
,"Unknown",
2936 EXTRACT_BE_U_2(bgp_route_refresh_header
->afi
)),
2937 EXTRACT_BE_U_2(bgp_route_refresh_header
->afi
),
2938 tok2str(bgp_safi_values
,"Unknown",
2939 EXTRACT_U_1(bgp_route_refresh_header
->safi
)),
2940 EXTRACT_U_1(bgp_route_refresh_header
->safi
)));
2942 if (ndo
->ndo_vflag
> 1) {
2943 ND_TCHECK_LEN(pptr
, len
);
2944 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2949 ND_PRINT((ndo
, "[|BGP]"));
2953 bgp_pdu_print(netdissect_options
*ndo
,
2954 const u_char
*dat
, u_int length
)
2956 const struct bgp
*bgp_header
;
2959 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2960 bgp_header
= (const struct bgp
*)dat
;
2961 bgp_type
= EXTRACT_U_1(bgp_header
->bgp_type
);
2963 ND_PRINT((ndo
, "\n\t%s Message (%u), length: %u",
2964 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
2970 bgp_open_print(ndo
, dat
, length
);
2973 bgp_update_print(ndo
, dat
, length
);
2975 case BGP_NOTIFICATION
:
2976 bgp_notification_print(ndo
, dat
, length
);
2980 case BGP_ROUTE_REFRESH
:
2981 bgp_route_refresh_print(ndo
, dat
, length
);
2984 /* we have no decoder for the BGP message */
2985 ND_TCHECK_LEN(dat
, length
);
2986 ND_PRINT((ndo
, "\n\t no Message %u decoder", bgp_type
));
2987 print_unknown_data(ndo
, dat
, "\n\t ", length
);
2992 ND_PRINT((ndo
, "[|BGP]"));
2997 bgp_print(netdissect_options
*ndo
,
2998 const u_char
*dat
, u_int length
)
3002 const u_char
*start
;
3003 const u_char marker
[] = {
3004 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3005 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3007 const struct bgp
*bgp_header
;
3011 if (ndo
->ndo_snapend
< dat
+ length
)
3012 ep
= ndo
->ndo_snapend
;
3014 ND_PRINT((ndo
, ": BGP"));
3016 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
3024 if (EXTRACT_U_1(p
) != 0xff) {
3029 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
3031 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
3036 /* found BGP header */
3037 ND_TCHECK_LEN(p
, BGP_SIZE
);
3038 bgp_header
= (const struct bgp
*)p
;
3041 ND_PRINT((ndo
, " [|BGP]"));
3043 hlen
= EXTRACT_BE_U_2(bgp_header
->bgp_len
);
3044 if (hlen
< BGP_SIZE
) {
3045 ND_PRINT((ndo
, "\n[|BGP Bogus header length %u < %u]", hlen
,
3050 if (ND_TTEST_LEN(p
, hlen
)) {
3051 if (!bgp_pdu_print(ndo
, p
, hlen
))
3056 ND_PRINT((ndo
, "\n[|BGP %s]",
3057 tok2str(bgp_msg_values
,
3058 "Unknown Message Type",
3059 EXTRACT_U_1(bgp_header
->bgp_type
))));
3067 ND_PRINT((ndo
, " [|BGP]"));
3072 * c-style: whitesmith