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 */
39 #include <netdissect-stdinc.h>
44 #include "netdissect.h"
45 #include "addrtoname.h"
51 nd_byte bgp_marker
[16];
55 #define BGP_SIZE 19 /* unaligned */
59 #define BGP_NOTIFICATION 3
60 #define BGP_KEEPALIVE 4
61 #define BGP_ROUTE_REFRESH 5
63 static const struct tok bgp_msg_values
[] = {
65 { BGP_UPDATE
, "Update"},
66 { BGP_NOTIFICATION
, "Notification"},
67 { BGP_KEEPALIVE
, "Keepalive"},
68 { BGP_ROUTE_REFRESH
, "Route Refresh"},
73 nd_byte bgpo_marker
[16];
76 nd_uint8_t bgpo_version
;
77 nd_uint16_t bgpo_myas
;
78 nd_uint16_t bgpo_holdtime
;
80 nd_uint8_t bgpo_optlen
;
81 /* options should follow */
83 #define BGP_OPEN_SIZE 29 /* unaligned */
86 nd_uint8_t bgpopt_type
;
87 nd_uint8_t bgpopt_len
;
90 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
91 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
93 struct bgp_notification
{
94 nd_byte bgpn_marker
[16];
97 nd_uint8_t bgpn_major
;
98 nd_uint8_t bgpn_minor
;
100 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
102 struct bgp_route_refresh
{
103 nd_byte bgp_marker
[16];
105 nd_uint8_t type
; /* No padding after this; afi is, in fact, not aligned */
110 #define BGP_ROUTE_REFRESH_SIZE 23
112 #define bgp_attr_lenlen(flags, p) \
113 (((flags) & 0x10) ? 2 : 1)
114 #define bgp_attr_len(flags, p) \
115 (((flags) & 0x10) ? EXTRACT_BE_U_2(p) : EXTRACT_U_1(p))
117 #define BGPTYPE_ORIGIN 1
118 #define BGPTYPE_AS_PATH 2
119 #define BGPTYPE_NEXT_HOP 3
120 #define BGPTYPE_MULTI_EXIT_DISC 4
121 #define BGPTYPE_LOCAL_PREF 5
122 #define BGPTYPE_ATOMIC_AGGREGATE 6
123 #define BGPTYPE_AGGREGATOR 7
124 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
125 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC4456 */
126 #define BGPTYPE_CLUSTER_LIST 10 /* RFC4456 */
127 #define BGPTYPE_DPA 11 /* deprecated, draft-ietf-idr-bgp-dpa */
128 #define BGPTYPE_ADVERTISERS 12 /* deprecated RFC1863 */
129 #define BGPTYPE_RCID_PATH 13 /* deprecated RFC1863 */
130 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */
131 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */
132 #define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */
133 #define BGPTYPE_AS4_PATH 17 /* RFC6793 */
134 #define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */
135 #define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */
136 #define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */
137 #define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */
138 #define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */
139 #define BGPTYPE_AIGP 26 /* RFC7311 */
140 #define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */
141 #define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */
142 #define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */
143 #define BGPTYPE_ATTR_SET 128 /* RFC6368 */
145 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
147 static const struct tok bgp_attr_values
[] = {
148 { BGPTYPE_ORIGIN
, "Origin"},
149 { BGPTYPE_AS_PATH
, "AS Path"},
150 { BGPTYPE_AS4_PATH
, "AS4 Path"},
151 { BGPTYPE_NEXT_HOP
, "Next Hop"},
152 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
153 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
154 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
155 { BGPTYPE_AGGREGATOR
, "Aggregator"},
156 { BGPTYPE_AGGREGATOR4
, "Aggregator4"},
157 { BGPTYPE_COMMUNITIES
, "Community"},
158 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
159 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
160 { BGPTYPE_DPA
, "DPA"},
161 { BGPTYPE_ADVERTISERS
, "Advertisers"},
162 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
163 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
164 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
165 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
166 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
167 { BGPTYPE_TUNNEL_ENCAP
, "Tunnel Encapsulation"},
168 { BGPTYPE_TRAFFIC_ENG
, "Traffic Engineering"},
169 { BGPTYPE_IPV6_EXTD_COMMUNITIES
, "IPv6 Extended Community"},
170 { BGPTYPE_AIGP
, "Accumulated IGP Metric"},
171 { BGPTYPE_PE_DISTINGUISHER_LABEL
, "PE Distinguisher Label"},
172 { BGPTYPE_ENTROPY_LABEL
, "Entropy Label"},
173 { BGPTYPE_LARGE_COMMUNITY
, "Large Community"},
174 { BGPTYPE_ATTR_SET
, "Attribute Set"},
175 { 255, "Reserved for development"},
180 #define BGP_AS_SEQUENCE 2
181 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
182 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
184 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
185 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
187 static const struct tok bgp_as_path_segment_open_values
[] = {
188 { BGP_AS_SEQUENCE
, ""},
190 { BGP_CONFED_AS_SEQUENCE
, "( "},
191 { BGP_CONFED_AS_SET
, "({ "},
195 static const struct tok bgp_as_path_segment_close_values
[] = {
196 { BGP_AS_SEQUENCE
, ""},
198 { BGP_CONFED_AS_SEQUENCE
, ")"},
199 { BGP_CONFED_AS_SET
, "})"},
203 #define BGP_OPT_AUTH 1
204 #define BGP_OPT_CAP 2
206 static const struct tok bgp_opt_values
[] = {
207 { BGP_OPT_AUTH
, "Authentication Information"},
208 { BGP_OPT_CAP
, "Capabilities Advertisement"},
212 #define BGP_CAPCODE_MP 1 /* RFC2858 */
213 #define BGP_CAPCODE_RR 2 /* RFC2918 */
214 #define BGP_CAPCODE_ORF 3 /* RFC5291 */
215 #define BGP_CAPCODE_MR 4 /* RFC3107 */
216 #define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */
217 #define BGP_CAPCODE_RESTART 64 /* RFC4724 */
218 #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */
219 #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */
220 #define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */
221 #define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */
222 #define BGP_CAPCODE_ENH_RR 70 /* draft-keyur-bgp-enhanced-route-refresh */
223 #define BGP_CAPCODE_RR_CISCO 128
225 static const struct tok bgp_capcode_values
[] = {
226 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
227 { BGP_CAPCODE_RR
, "Route Refresh"},
228 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
229 { BGP_CAPCODE_MR
, "Multiple Routes to a Destination"},
230 { BGP_CAPCODE_EXT_NH
, "Extended Next Hop Encoding"},
231 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
232 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
233 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
234 { BGP_CAPCODE_MULTISESS
, "Multisession BGP"},
235 { BGP_CAPCODE_ADD_PATH
, "Multiple Paths"},
236 { BGP_CAPCODE_ENH_RR
, "Enhanced Route Refresh"},
237 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
241 #define BGP_NOTIFY_MAJOR_MSG 1
242 #define BGP_NOTIFY_MAJOR_OPEN 2
243 #define BGP_NOTIFY_MAJOR_UPDATE 3
244 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
245 #define BGP_NOTIFY_MAJOR_FSM 5
246 #define BGP_NOTIFY_MAJOR_CEASE 6
247 #define BGP_NOTIFY_MAJOR_CAP 7
249 static const struct tok bgp_notify_major_values
[] = {
250 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
251 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
252 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
253 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
254 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
255 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
256 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
260 /* draft-ietf-idr-cease-subcode-02 */
261 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
262 /* draft-ietf-idr-shutdown-07 */
263 #define BGP_NOTIFY_MINOR_CEASE_SHUT 2
264 #define BGP_NOTIFY_MINOR_CEASE_RESET 4
265 #define BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN 128
266 static const struct tok bgp_notify_minor_cease_values
[] = {
267 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
268 { BGP_NOTIFY_MINOR_CEASE_SHUT
, "Administrative Shutdown"},
269 { 3, "Peer Unconfigured"},
270 { BGP_NOTIFY_MINOR_CEASE_RESET
, "Administrative Reset"},
271 { 5, "Connection Rejected"},
272 { 6, "Other Configuration Change"},
273 { 7, "Connection Collision Resolution"},
277 static const struct tok bgp_notify_minor_msg_values
[] = {
278 { 1, "Connection Not Synchronized"},
279 { 2, "Bad Message Length"},
280 { 3, "Bad Message Type"},
284 static const struct tok bgp_notify_minor_open_values
[] = {
285 { 1, "Unsupported Version Number"},
287 { 3, "Bad BGP Identifier"},
288 { 4, "Unsupported Optional Parameter"},
289 { 5, "Authentication Failure"},
290 { 6, "Unacceptable Hold Time"},
291 { 7, "Capability Message Error"},
295 static const struct tok bgp_notify_minor_update_values
[] = {
296 { 1, "Malformed Attribute List"},
297 { 2, "Unrecognized Well-known Attribute"},
298 { 3, "Missing Well-known Attribute"},
299 { 4, "Attribute Flags Error"},
300 { 5, "Attribute Length Error"},
301 { 6, "Invalid ORIGIN Attribute"},
302 { 7, "AS Routing Loop"},
303 { 8, "Invalid NEXT_HOP Attribute"},
304 { 9, "Optional Attribute Error"},
305 { 10, "Invalid Network Field"},
306 { 11, "Malformed AS_PATH"},
310 static const struct tok bgp_notify_minor_fsm_values
[] = {
311 { 0, "Unspecified Error"},
312 { 1, "In OpenSent State"},
313 { 2, "In OpenConfirm State"},
314 { 3, "In Established State"},
318 static const struct tok bgp_notify_minor_cap_values
[] = {
319 { 1, "Invalid Action Value" },
320 { 2, "Invalid Capability Length" },
321 { 3, "Malformed Capability Value" },
322 { 4, "Unsupported Capability Code" },
326 static const struct tok bgp_origin_values
[] = {
333 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
334 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
335 #define BGP_PMSI_TUNNEL_PIM_SSM 3
336 #define BGP_PMSI_TUNNEL_PIM_SM 4
337 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
338 #define BGP_PMSI_TUNNEL_INGRESS 6
339 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
341 static const struct tok bgp_pmsi_tunnel_values
[] = {
342 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
343 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
344 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
345 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
346 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
347 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
348 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
352 static const struct tok bgp_pmsi_flag_values
[] = {
353 { 0x01, "Leaf Information required"},
357 #define BGP_AIGP_TLV 1
359 static const struct tok bgp_aigp_values
[] = {
360 { BGP_AIGP_TLV
, "AIGP"},
364 /* Subsequent address family identifier, RFC2283 section 7 */
366 #define SAFNUM_UNICAST 1
367 #define SAFNUM_MULTICAST 2
368 #define SAFNUM_UNIMULTICAST 3 /* deprecated now */
369 /* labeled BGP RFC3107 */
370 #define SAFNUM_LABUNICAST 4
372 #define SAFNUM_MULTICAST_VPN 5
373 /* draft-nalawade-kapoor-tunnel-safi */
374 #define SAFNUM_TUNNEL 64
376 #define SAFNUM_VPLS 65
378 #define SAFNUM_MDT 66
380 #define SAFNUM_VPNUNICAST 128
382 #define SAFNUM_VPNMULTICAST 129
383 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
385 #define SAFNUM_RT_ROUTING_INFO 132
387 #define BGP_VPN_RD_LEN 8
389 static const struct tok bgp_safi_values
[] = {
390 { SAFNUM_RES
, "Reserved"},
391 { SAFNUM_UNICAST
, "Unicast"},
392 { SAFNUM_MULTICAST
, "Multicast"},
393 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
394 { SAFNUM_LABUNICAST
, "labeled Unicast"},
395 { SAFNUM_TUNNEL
, "Tunnel"},
396 { SAFNUM_VPLS
, "VPLS"},
397 { SAFNUM_MDT
, "MDT"},
398 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
399 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
400 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
401 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
402 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
406 /* well-known community */
407 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
408 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
409 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
411 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
412 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
413 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
414 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
415 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
416 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
417 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
418 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
419 /* rfc2547 bgp-mpls-vpns */
420 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
421 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatibility */
422 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatibility */
423 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatibility */
425 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
426 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatibility */
428 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
429 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatibility */
431 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
433 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
434 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
435 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
436 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
438 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
439 #define BGP_EXT_COM_EIGRP_GEN 0x8800
440 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
441 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
442 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
443 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
444 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
446 static const struct tok bgp_extd_comm_flag_values
[] = {
447 { 0x8000, "vendor-specific"},
448 { 0x4000, "non-transitive"},
452 static const struct tok bgp_extd_comm_subtype_values
[] = {
453 { BGP_EXT_COM_RT_0
, "target"},
454 { BGP_EXT_COM_RT_1
, "target"},
455 { BGP_EXT_COM_RT_2
, "target"},
456 { BGP_EXT_COM_RO_0
, "origin"},
457 { BGP_EXT_COM_RO_1
, "origin"},
458 { BGP_EXT_COM_RO_2
, "origin"},
459 { BGP_EXT_COM_LINKBAND
, "link-BW"},
460 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
461 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
462 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
463 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
464 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
465 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
466 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
467 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
468 { BGP_EXT_COM_L2INFO
, "layer2-info"},
469 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
470 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
471 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
472 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
473 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
474 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
475 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
476 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
477 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
478 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
482 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
483 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
484 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
485 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
486 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
487 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
488 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
489 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
491 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
492 { BGP_OSPF_RTYPE_RTR
, "Router" },
493 { BGP_OSPF_RTYPE_NET
, "Network" },
494 { BGP_OSPF_RTYPE_SUM
, "Summary" },
495 { BGP_OSPF_RTYPE_EXT
, "External" },
496 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
497 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
501 /* ADD-PATH Send/Receive field values */
502 static const struct tok bgp_add_path_recvsend
[] = {
509 static char astostr
[20];
514 * Convert an AS number into a string and return string pointer.
516 * Depending on bflag is set or not, AS number is converted into ASDOT notation
517 * or plain number notation.
521 as_printf(netdissect_options
*ndo
,
522 char *str
, int size
, u_int asnum
)
524 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
525 snprintf(str
, size
, "%u", asnum
);
527 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
532 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
535 decode_prefix4(netdissect_options
*ndo
,
536 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
539 u_int plen
, plenbytes
;
543 plen
= EXTRACT_U_1(pptr
);
548 memset(&addr
, 0, sizeof(addr
));
549 plenbytes
= (plen
+ 7) / 8;
550 ND_TCHECK_LEN(pptr
+ 1, plenbytes
);
551 ITEMCHECK(plenbytes
);
552 memcpy(&addr
, pptr
+ 1, plenbytes
);
554 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
556 snprintf(buf
, buflen
, "%s/%d", ipaddr_string(ndo
, &addr
), plen
);
557 return 1 + plenbytes
;
567 decode_labeled_prefix4(netdissect_options
*ndo
,
568 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
571 u_int plen
, plenbytes
;
573 /* prefix length and label = 4 bytes */
576 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
578 /* this is one of the weirdnesses of rfc3107
579 the label length (actually the label + COS bits)
580 is added to the prefix length;
581 we also do only read out just one label -
582 there is no real application for advertisement of
583 stacked labels in a single BGP message
589 plen
-=24; /* adjust prefixlen - labellength */
595 memset(&addr
, 0, sizeof(addr
));
596 plenbytes
= (plen
+ 7) / 8;
597 ND_TCHECK_LEN(pptr
+ 4, plenbytes
);
598 ITEMCHECK(plenbytes
);
599 memcpy(&addr
, pptr
+ 4, plenbytes
);
601 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
603 /* the label may get offsetted by 4 bits so lets shift it right */
604 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
605 ipaddr_string(ndo
, &addr
),
607 EXTRACT_BE_U_3(pptr
+ 1)>>4,
608 ((EXTRACT_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
610 return 4 + plenbytes
;
622 * print an ipv4 or ipv6 address into a buffer dependend on address length.
625 bgp_vpn_ip_print(netdissect_options
*ndo
,
626 const u_char
*pptr
, u_int addr_length
)
629 /* worst case string is s fully formatted v6 address */
630 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
633 switch(addr_length
) {
634 case (sizeof(struct in_addr
) << 3): /* 32 */
635 ND_TCHECK_LEN(pptr
, sizeof(struct in_addr
));
636 snprintf(pos
, sizeof(addr
), "%s", ipaddr_string(ndo
, pptr
));
638 case (sizeof(struct in6_addr
) << 3): /* 128 */
639 ND_TCHECK_LEN(pptr
, sizeof(struct in6_addr
));
640 snprintf(pos
, sizeof(addr
), "%s", ip6addr_string(ndo
, pptr
));
643 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
656 * print an multicast s,g entry into a buffer.
657 * the s,g entry is encoded like this.
659 * +-----------------------------------+
660 * | Multicast Source Length (1 octet) |
661 * +-----------------------------------+
662 * | Multicast Source (Variable) |
663 * +-----------------------------------+
664 * | Multicast Group Length (1 octet) |
665 * +-----------------------------------+
666 * | Multicast Group (Variable) |
667 * +-----------------------------------+
669 * return the number of bytes read from the wire.
672 bgp_vpn_sg_print(netdissect_options
*ndo
,
673 const u_char
*pptr
, char *buf
, u_int buflen
)
676 u_int total_length
, offset
;
680 /* Source address length, encoded in bits */
682 addr_length
= EXTRACT_U_1(pptr
);
686 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
687 total_length
+= (addr_length
>> 3) + 1;
688 offset
= strlen(buf
);
690 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
691 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
692 pptr
+= (addr_length
>> 3);
695 /* Group address length, encoded in bits */
697 addr_length
= EXTRACT_U_1(pptr
);
701 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
702 total_length
+= (addr_length
>> 3) + 1;
703 offset
= strlen(buf
);
705 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
706 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
707 pptr
+= (addr_length
>> 3);
711 return (total_length
);
714 /* RDs and RTs share the same semantics
715 * we use bgp_vpn_rd_print for
716 * printing route targets inside a NLRI */
718 bgp_vpn_rd_print(netdissect_options
*ndo
,
721 /* allocate space for the largest possible string */
722 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
725 /* ok lets load the RD format */
726 switch (EXTRACT_BE_U_2(pptr
)) {
728 /* 2-byte-AS:number fmt*/
730 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
731 EXTRACT_BE_U_2(pptr
+ 2),
732 EXTRACT_BE_U_4(pptr
+ 4),
733 EXTRACT_U_1(pptr
+ 4), EXTRACT_U_1(pptr
+ 5),
734 EXTRACT_U_1(pptr
+ 6), EXTRACT_U_1(pptr
+ 7));
736 /* IP-address:AS fmt*/
739 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
740 EXTRACT_U_1(pptr
+ 2), EXTRACT_U_1(pptr
+ 3),
741 EXTRACT_U_1(pptr
+ 4), EXTRACT_U_1(pptr
+ 5),
742 EXTRACT_BE_U_2(pptr
+ 6));
745 /* 4-byte-AS:number fmt*/
747 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
748 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(pptr
+ 2)),
749 EXTRACT_BE_U_2(pptr
+ 6), EXTRACT_U_1(pptr
+ 2),
750 EXTRACT_U_1(pptr
+ 3), EXTRACT_U_1(pptr
+ 4),
751 EXTRACT_U_1(pptr
+ 5), EXTRACT_BE_U_2(pptr
+ 6));
754 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
763 decode_rt_routing_info(netdissect_options
*ndo
,
764 const u_char
*pptr
, char *buf
, u_int buflen
)
766 uint8_t route_target
[8];
768 char asbuf
[sizeof(astostr
)]; /* bgp_vpn_rd_print() overwrites astostr */
770 /* NLRI "prefix length" from RFC 2858 Section 4. */
772 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
774 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
775 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
776 * target" fields inside the "prefix" depending on its length.
779 /* Without "origin AS", without "route target". */
780 snprintf(buf
, buflen
, "default route target");
787 /* With at least "origin AS", possibly with "route target". */
788 ND_TCHECK_4(pptr
+ 1);
789 as_printf(ndo
, asbuf
, sizeof(asbuf
), EXTRACT_BE_U_4(pptr
+ 1));
791 plen
-= 32; /* adjust prefix length */
796 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
797 * and gives the number of octets in the variable-length "route
798 * target" field inside this NLRI "prefix". Look for it.
800 memset(&route_target
, 0, sizeof(route_target
));
801 ND_TCHECK_LEN(pptr
+ 5, (plen
+ 7) / 8);
802 memcpy(&route_target
, pptr
+ 5, (plen
+ 7) / 8);
803 /* Which specification says to do this? */
805 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
806 ((0xff00 >> (plen
% 8)) & 0xff);
808 snprintf(buf
, buflen
, "origin AS: %s, route target %s",
810 bgp_vpn_rd_print(ndo
, (u_char
*)&route_target
));
812 return 5 + (plen
+ 7) / 8;
819 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
820 const u_char
*pptr
, char *buf
, u_int buflen
)
826 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
831 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
836 memset(&addr
, 0, sizeof(addr
));
837 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
838 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
840 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
841 ((0xff00 >> (plen
% 8)) & 0xff);
843 /* the label may get offsetted by 4 bits so lets shift it right */
844 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
845 bgp_vpn_rd_print(ndo
, pptr
+4),
846 ipaddr_string(ndo
, &addr
),
848 EXTRACT_BE_U_3(pptr
+ 1)>>4,
849 ((EXTRACT_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
851 return 12 + (plen
+ 7) / 8;
858 * +-------------------------------+
860 * | RD:IPv4-address (12 octets) |
862 * +-------------------------------+
863 * | MDT Group-address (4 octets) |
864 * +-------------------------------+
867 #define MDT_VPN_NLRI_LEN 16
870 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
871 const u_char
*pptr
, char *buf
, u_int buflen
)
874 const u_char
*vpn_ip
;
878 /* if the NLRI is not predefined length, quit.*/
879 if (EXTRACT_U_1(pptr
) != MDT_VPN_NLRI_LEN
* 8)
889 ND_TCHECK_LEN(pptr
, sizeof(struct in_addr
));
891 pptr
+= sizeof(struct in_addr
);
893 /* MDT Group Address */
894 ND_TCHECK_LEN(pptr
, sizeof(struct in_addr
));
896 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
897 bgp_vpn_rd_print(ndo
, rd
), ipaddr_string(ndo
, vpn_ip
), ipaddr_string(ndo
, pptr
));
899 return MDT_VPN_NLRI_LEN
+ 1;
905 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
906 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
907 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
908 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
909 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
910 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
911 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
913 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
914 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
915 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
916 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
917 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
918 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
919 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
920 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
925 decode_multicast_vpn(netdissect_options
*ndo
,
926 const u_char
*pptr
, char *buf
, u_int buflen
)
928 uint8_t route_type
, route_length
, addr_length
, sg_length
;
932 route_type
= EXTRACT_U_1(pptr
);
934 route_length
= EXTRACT_U_1(pptr
);
937 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
938 tok2str(bgp_multicast_vpn_route_type_values
,
939 "Unknown", route_type
),
940 route_type
, route_length
);
943 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
944 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
945 offset
= strlen(buf
);
946 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
947 bgp_vpn_rd_print(ndo
, pptr
),
948 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
949 (route_length
- BGP_VPN_RD_LEN
) << 3));
951 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
952 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
953 offset
= strlen(buf
);
954 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
955 bgp_vpn_rd_print(ndo
, pptr
),
956 as_printf(ndo
, astostr
, sizeof(astostr
),
957 EXTRACT_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
960 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
961 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
962 offset
= strlen(buf
);
963 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
964 bgp_vpn_rd_print(ndo
, pptr
));
965 pptr
+= BGP_VPN_RD_LEN
;
967 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
968 addr_length
= route_length
- sg_length
;
970 ND_TCHECK_LEN(pptr
, addr_length
);
971 offset
= strlen(buf
);
972 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
973 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
976 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
977 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
978 offset
= strlen(buf
);
979 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
980 bgp_vpn_rd_print(ndo
, pptr
));
981 pptr
+= BGP_VPN_RD_LEN
;
983 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
986 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
987 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
988 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
989 offset
= strlen(buf
);
990 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
991 bgp_vpn_rd_print(ndo
, pptr
),
992 as_printf(ndo
, astostr
, sizeof(astostr
),
993 EXTRACT_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
994 pptr
+= BGP_VPN_RD_LEN
+ 4;
996 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1000 * no per route-type printing yet.
1002 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1007 return route_length
+ 2;
1014 * As I remember, some versions of systems have an snprintf() that
1015 * returns -1 if the buffer would have overflowed. If the return
1016 * value is negative, set buflen to 0, to indicate that we've filled
1019 * If the return value is greater than buflen, that means that
1020 * the buffer would have overflowed; again, set buflen to 0 in
1023 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1026 else if ((u_int)stringlen>buflen) \
1029 buflen-=stringlen; \
1034 decode_labeled_vpn_l2(netdissect_options
*ndo
,
1035 const u_char
*pptr
, char *buf
, u_int buflen
)
1037 int plen
,tlen
,stringlen
,tlv_type
,tlv_len
,ttlv_len
;
1040 plen
=EXTRACT_BE_U_2(pptr
);
1043 /* Old and new L2VPN NLRI share AFI/SAFI
1044 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1045 * and > 17 as old format. Complain for the middle case
1048 /* assume AD-only with RD, BGPNH */
1049 ND_TCHECK_LEN(pptr
, 12);
1051 stringlen
=snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
1052 bgp_vpn_rd_print(ndo
, pptr
),
1053 ipaddr_string(ndo
, pptr
+8)
1055 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1059 } else if (plen
>17) {
1060 /* assume old format */
1061 /* RD, ID, LBLKOFF, LBLBASE */
1063 ND_TCHECK_LEN(pptr
, 15);
1065 stringlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1066 bgp_vpn_rd_print(ndo
, pptr
),
1067 EXTRACT_BE_U_2(pptr
+ 8),
1068 EXTRACT_BE_U_2(pptr
+ 10),
1069 EXTRACT_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1070 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1074 /* ok now the variable part - lets read out TLVs*/
1079 tlv_type
=EXTRACT_U_1(pptr
);
1081 tlv_len
=EXTRACT_BE_U_2(pptr
);
1088 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1091 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1093 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
1094 while (ttlv_len
>0) {
1097 stringlen
=snprintf(buf
,buflen
, "%02x",
1100 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1107 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1110 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1114 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
1119 /* complain bitterly ? */
1129 decode_prefix6(netdissect_options
*ndo
,
1130 const u_char
*pd
, u_int itemlen
, char *buf
, u_int buflen
)
1132 struct in6_addr addr
;
1133 u_int plen
, plenbytes
;
1137 plen
= EXTRACT_U_1(pd
);
1142 memset(&addr
, 0, sizeof(addr
));
1143 plenbytes
= (plen
+ 7) / 8;
1144 ND_TCHECK_LEN(pd
+ 1, plenbytes
);
1145 ITEMCHECK(plenbytes
);
1146 memcpy(&addr
, pd
+ 1, plenbytes
);
1148 addr
.s6_addr
[plenbytes
- 1] &=
1149 ((0xff00 >> (plen
% 8)) & 0xff);
1151 snprintf(buf
, buflen
, "%s/%d", ip6addr_string(ndo
, &addr
), plen
);
1152 return 1 + plenbytes
;
1162 decode_labeled_prefix6(netdissect_options
*ndo
,
1163 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
1165 struct in6_addr addr
;
1166 u_int plen
, plenbytes
;
1168 /* prefix length and label = 4 bytes */
1171 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
1176 plen
-= 24; /* adjust prefixlen - labellength */
1182 memset(&addr
, 0, sizeof(addr
));
1183 plenbytes
= (plen
+ 7) / 8;
1184 ND_TCHECK_LEN(pptr
+ 4, plenbytes
);
1185 memcpy(&addr
, pptr
+ 4, plenbytes
);
1187 addr
.s6_addr
[plenbytes
- 1] &=
1188 ((0xff00 >> (plen
% 8)) & 0xff);
1190 /* the label may get offsetted by 4 bits so lets shift it right */
1191 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
1192 ip6addr_string(ndo
, &addr
),
1194 EXTRACT_BE_U_3(pptr
+ 1)>>4,
1195 ((EXTRACT_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1197 return 4 + plenbytes
;
1207 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1208 const u_char
*pptr
, char *buf
, u_int buflen
)
1210 struct in6_addr addr
;
1214 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
1219 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1224 memset(&addr
, 0, sizeof(addr
));
1225 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
1226 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1228 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1229 ((0xff00 >> (plen
% 8)) & 0xff);
1231 /* the label may get offsetted by 4 bits so lets shift it right */
1232 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1233 bgp_vpn_rd_print(ndo
, pptr
+4),
1234 ip6addr_string(ndo
, &addr
),
1236 EXTRACT_BE_U_3(pptr
+ 1)>>4,
1237 ((EXTRACT_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1239 return 12 + (plen
+ 7) / 8;
1246 decode_clnp_prefix(netdissect_options
*ndo
,
1247 const u_char
*pptr
, char *buf
, u_int buflen
)
1253 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
1258 memset(&addr
, 0, sizeof(addr
));
1259 ND_TCHECK_LEN(pptr
+ 4, (plen
+ 7) / 8);
1260 memcpy(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1262 addr
[(plen
+ 7) / 8 - 1] &=
1263 ((0xff00 >> (plen
% 8)) & 0xff);
1265 snprintf(buf
, buflen
, "%s/%d",
1266 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1269 return 1 + (plen
+ 7) / 8;
1276 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1277 const u_char
*pptr
, char *buf
, u_int buflen
)
1283 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
1288 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1293 memset(&addr
, 0, sizeof(addr
));
1294 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
1295 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1297 addr
[(plen
+ 7) / 8 - 1] &=
1298 ((0xff00 >> (plen
% 8)) & 0xff);
1300 /* the label may get offsetted by 4 bits so lets shift it right */
1301 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1302 bgp_vpn_rd_print(ndo
, pptr
+4),
1303 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1305 EXTRACT_BE_U_3(pptr
+ 1)>>4,
1306 ((EXTRACT_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1308 return 12 + (plen
+ 7) / 8;
1315 * bgp_attr_get_as_size
1317 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1318 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1319 * support, exchange AS-Path with the same path-attribute type value 0x02.
1322 bgp_attr_get_as_size(netdissect_options
*ndo
,
1323 uint8_t bgpa_type
, const u_char
*pptr
, int len
)
1325 const u_char
*tptr
= pptr
;
1328 * If the path attribute is the optional AS4 path type, then we already
1329 * know, that ASs must be encoded in 4 byte format.
1331 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1336 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1337 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1340 while (tptr
< pptr
+ len
) {
1344 * If we do not find a valid segment type, our guess might be wrong.
1346 if (EXTRACT_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| EXTRACT_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1349 ND_TCHECK_1(tptr
+ 1);
1350 tptr
+= 2 + EXTRACT_U_1(tptr
+ 1) * 2;
1354 * If we correctly reached end of the AS path attribute data content,
1355 * then most likely ASs were indeed encoded as 2 bytes.
1357 if (tptr
== pptr
+ len
) {
1364 * We can come here, either we did not have enough data, or if we
1365 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1366 * so that calller can try to decode each AS as of 4 bytes. If indeed
1367 * there was not enough data, it will crib and end the parse anyways.
1373 * The only way to know that a BGP UPDATE message is using add path is
1374 * by checking if the capability is in the OPEN message which we may have missed.
1375 * So this function checks if it is possible that the update could contain add path
1376 * and if so it checks that standard BGP doesn't make sense.
1379 check_add_path(const u_char
*pptr
, u_int length
, u_int max_prefix_length
)
1381 u_int offset
, prefix_length
;
1386 /* check if it could be add path */
1387 for (offset
= 0; offset
< length
;) {
1389 prefix_length
= EXTRACT_U_1(pptr
+ offset
);
1391 * Add 4 to cover the path id
1392 * and check the prefix length isn't greater than 32/128.
1394 if (prefix_length
> max_prefix_length
) {
1397 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1398 offset
+= 1 + ((prefix_length
+ 7) / 8);
1400 /* check we haven't gone past the end of the section */
1401 if (offset
> length
) {
1405 /* check it's not standard BGP */
1406 for (offset
= 0; offset
< length
; ) {
1407 prefix_length
= EXTRACT_U_1(pptr
+ offset
);
1409 * If the prefix_length is zero (0.0.0.0/0)
1410 * and since it's not the only address (length >= 5)
1411 * then it is add-path
1413 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1416 offset
+= 1 + ((prefix_length
+ 7) / 8);
1418 if (offset
> length
) {
1422 /* assume not add-path by default */
1427 bgp_attr_print(netdissect_options
*ndo
,
1428 u_int atype
, const u_char
*pptr
, u_int len
)
1432 uint8_t safi
, snpa
, nhlen
;
1433 union { /* copy buffer for bandwidth values */
1440 char buf
[MAXHOSTNAMELEN
+ 100];
1442 int add_path4
, add_path6
, path_id
;
1448 case BGPTYPE_ORIGIN
:
1450 ND_PRINT((ndo
, "invalid len"));
1453 ND_PRINT((ndo
, "%s", tok2str(bgp_origin_values
,
1454 "Unknown Origin Typecode",
1455 EXTRACT_U_1(tptr
))));
1460 * Process AS4 byte path and AS2 byte path attributes here.
1462 case BGPTYPE_AS4_PATH
:
1463 case BGPTYPE_AS_PATH
:
1465 ND_PRINT((ndo
, "invalid len"));
1469 ND_PRINT((ndo
, "empty"));
1474 * BGP updates exchanged between New speakers that support 4
1475 * byte AS, ASs are always encoded in 4 bytes. There is no
1476 * definitive way to find this, just by the packet's
1477 * contents. So, check for packet's TLV's sanity assuming
1478 * 2 bytes first, and it does not pass, assume that ASs are
1479 * encoded in 4 bytes format and move on.
1481 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1483 while (tptr
< pptr
+ len
) {
1485 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_open_values
,
1486 "?", EXTRACT_U_1(tptr
))));
1487 ND_TCHECK_1(tptr
+ 1);
1488 for (i
= 0; i
< EXTRACT_U_1(tptr
+ 1) * as_size
; i
+= as_size
) {
1489 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
1490 ND_PRINT((ndo
, "%s ",
1491 as_printf(ndo
, astostr
, sizeof(astostr
),
1493 EXTRACT_BE_U_2(tptr
+ i
+ 2) :
1494 EXTRACT_BE_U_4(tptr
+ i
+ 2))));
1497 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_close_values
,
1498 "?", EXTRACT_U_1(tptr
))));
1499 ND_TCHECK_1(tptr
+ 1);
1500 tptr
+= 2 + EXTRACT_U_1(tptr
+ 1) * as_size
;
1503 case BGPTYPE_NEXT_HOP
:
1505 ND_PRINT((ndo
, "invalid len"));
1508 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1511 case BGPTYPE_MULTI_EXIT_DISC
:
1512 case BGPTYPE_LOCAL_PREF
:
1514 ND_PRINT((ndo
, "invalid len"));
1517 ND_PRINT((ndo
, "%u", EXTRACT_BE_U_4(tptr
)));
1520 case BGPTYPE_ATOMIC_AGGREGATE
:
1522 ND_PRINT((ndo
, "invalid len"));
1524 case BGPTYPE_AGGREGATOR
:
1527 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1528 * the length of this PA can be either 6 bytes or 8 bytes.
1530 if (len
!= 6 && len
!= 8) {
1531 ND_PRINT((ndo
, "invalid len"));
1534 ND_TCHECK_LEN(tptr
, len
);
1536 ND_PRINT((ndo
, " AS #%s, origin %s",
1537 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_2(tptr
)),
1538 ipaddr_string(ndo
, tptr
+ 2)));
1540 ND_PRINT((ndo
, " AS #%s, origin %s",
1541 as_printf(ndo
, astostr
, sizeof(astostr
),
1542 EXTRACT_BE_U_4(tptr
)), ipaddr_string(ndo
, tptr
+ 4)));
1545 case BGPTYPE_AGGREGATOR4
:
1547 ND_PRINT((ndo
, "invalid len"));
1551 ND_PRINT((ndo
, " AS #%s, origin %s",
1552 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(tptr
)),
1553 ipaddr_string(ndo
, tptr
+ 4)));
1555 case BGPTYPE_COMMUNITIES
:
1557 ND_PRINT((ndo
, "invalid len"));
1563 comm
= EXTRACT_BE_U_4(tptr
);
1565 case BGP_COMMUNITY_NO_EXPORT
:
1566 ND_PRINT((ndo
, " NO_EXPORT"));
1568 case BGP_COMMUNITY_NO_ADVERT
:
1569 ND_PRINT((ndo
, " NO_ADVERTISE"));
1571 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1572 ND_PRINT((ndo
, " NO_EXPORT_SUBCONFED"));
1575 ND_PRINT((ndo
, "%u:%u%s",
1576 (comm
>> 16) & 0xffff,
1578 (tlen
>4) ? ", " : ""));
1585 case BGPTYPE_ORIGINATOR_ID
:
1587 ND_PRINT((ndo
, "invalid len"));
1591 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1593 case BGPTYPE_CLUSTER_LIST
:
1595 ND_PRINT((ndo
, "invalid len"));
1600 ND_PRINT((ndo
, "%s%s",
1601 ipaddr_string(ndo
, tptr
),
1602 (tlen
>4) ? ", " : ""));
1607 case BGPTYPE_MP_REACH_NLRI
:
1609 af
= EXTRACT_BE_U_2(tptr
);
1610 safi
= EXTRACT_U_1(tptr
+ 2);
1612 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1613 tok2str(af_values
, "Unknown AFI", af
),
1615 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1616 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1619 switch(af
<<8 | safi
) {
1620 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1621 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1622 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1623 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1624 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1625 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1626 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1627 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1628 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1629 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1630 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1631 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1632 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1633 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1634 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1635 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1636 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1637 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1638 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1639 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1640 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1641 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1642 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1643 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1644 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1645 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1646 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1649 ND_TCHECK_LEN(tptr
, tlen
);
1650 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1651 if (ndo
->ndo_vflag
<= 1)
1652 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1660 nhlen
= EXTRACT_U_1(tptr
);
1666 ND_PRINT((ndo
, "\n\t nexthop: "));
1669 ND_PRINT((ndo
, ", " ));
1671 switch(af
<<8 | safi
) {
1672 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1673 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1674 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1675 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1676 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1677 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1678 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1679 if (tlen
< sizeof(struct in_addr
)) {
1680 ND_PRINT((ndo
, "invalid len"));
1683 ND_TCHECK_LEN(tptr
, sizeof(struct in_addr
));
1684 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1685 tlen
-= sizeof(struct in_addr
);
1686 tptr
+= sizeof(struct in_addr
);
1689 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1690 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1691 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1692 if (tlen
< sizeof(struct in_addr
)+BGP_VPN_RD_LEN
) {
1693 ND_PRINT((ndo
, "invalid len"));
1697 sizeof(struct in_addr
) + BGP_VPN_RD_LEN
);
1698 ND_PRINT((ndo
, "RD: %s, %s",
1699 bgp_vpn_rd_print(ndo
, tptr
),
1700 ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1701 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1702 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1705 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1706 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1707 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1708 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1709 if (tlen
< sizeof(struct in6_addr
)) {
1710 ND_PRINT((ndo
, "invalid len"));
1713 ND_TCHECK_LEN(tptr
, sizeof(struct in6_addr
));
1714 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, tptr
)));
1715 tlen
-= sizeof(struct in6_addr
);
1716 tptr
+= sizeof(struct in6_addr
);
1719 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1720 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1721 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1722 if (tlen
< sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
) {
1723 ND_PRINT((ndo
, "invalid len"));
1727 sizeof(struct in6_addr
) + BGP_VPN_RD_LEN
);
1728 ND_PRINT((ndo
, "RD: %s, %s",
1729 bgp_vpn_rd_print(ndo
, tptr
),
1730 ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1731 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1732 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1735 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1736 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1737 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1738 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1739 if (tlen
< sizeof(struct in_addr
)) {
1740 ND_PRINT((ndo
, "invalid len"));
1743 ND_TCHECK_LEN(tptr
, sizeof(struct in_addr
));
1744 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1745 tlen
-= (sizeof(struct in_addr
));
1746 tptr
+= (sizeof(struct in_addr
));
1749 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1750 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1751 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1752 ND_TCHECK_LEN(tptr
, tlen
);
1753 ND_PRINT((ndo
, "%s", isonsap_string(ndo
, tptr
, tlen
)));
1758 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1759 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1760 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1761 if (tlen
< BGP_VPN_RD_LEN
+1) {
1762 ND_PRINT((ndo
, "invalid len"));
1765 ND_TCHECK_LEN(tptr
, tlen
);
1766 ND_PRINT((ndo
, "RD: %s, %s",
1767 bgp_vpn_rd_print(ndo
, tptr
),
1768 isonsap_string(ndo
, tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
)));
1769 /* rfc986 mapped IPv4 address ? */
1770 if (EXTRACT_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
1771 ND_PRINT((ndo
, " = %s", ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+4)));
1772 /* rfc1888 mapped IPv6 address ? */
1773 else if (EXTRACT_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
1774 ND_PRINT((ndo
, " = %s", ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+3)));
1780 ND_TCHECK_LEN(tptr
, tlen
);
1781 ND_PRINT((ndo
, "no AFI %u/SAFI %u decoder", af
, safi
));
1782 if (ndo
->ndo_vflag
<= 1)
1783 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1791 ND_PRINT((ndo
, ", nh-length: %u", nhlen
));
1795 snpa
= EXTRACT_U_1(tptr
);
1799 ND_PRINT((ndo
, "\n\t %u SNPA", snpa
));
1800 for (/*nothing*/; snpa
> 0; snpa
--) {
1802 ND_PRINT((ndo
, "\n\t %d bytes", EXTRACT_U_1(tptr
)));
1803 tptr
+= EXTRACT_U_1(tptr
) + 1;
1806 ND_PRINT((ndo
, ", no SNPA"));
1809 add_path4
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 32);
1810 add_path6
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 128);
1812 while (tptr
< pptr
+ len
) {
1813 switch (af
<<8 | safi
) {
1814 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1815 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1816 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1818 path_id
= EXTRACT_BE_U_4(tptr
);
1821 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1823 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1824 else if (advance
== -2)
1826 else if (advance
== -3)
1827 break; /* bytes left, but not enough */
1829 ND_PRINT((ndo
, "\n\t %s", buf
));
1831 ND_PRINT((ndo
, " Path Id: %d", path_id
));
1834 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1835 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1837 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1838 else if (advance
== -2)
1840 else if (advance
== -3)
1841 break; /* bytes left, but not enough */
1843 ND_PRINT((ndo
, "\n\t %s", buf
));
1845 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1846 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1847 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1848 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1850 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1851 else if (advance
== -2)
1854 ND_PRINT((ndo
, "\n\t %s", buf
));
1856 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1857 advance
= decode_rt_routing_info(ndo
, tptr
, buf
, sizeof(buf
));
1859 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1860 else if (advance
== -2)
1863 ND_PRINT((ndo
, "\n\t %s", buf
));
1865 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1866 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1867 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1869 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1870 else if (advance
== -2)
1873 ND_PRINT((ndo
, "\n\t %s", buf
));
1876 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1877 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
1879 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1880 else if (advance
== -2)
1883 ND_PRINT((ndo
, "\n\t %s", buf
));
1885 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1886 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1887 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1889 path_id
= EXTRACT_BE_U_4(tptr
);
1892 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1894 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1895 else if (advance
== -2)
1897 else if (advance
== -3)
1898 break; /* bytes left, but not enough */
1900 ND_PRINT((ndo
, "\n\t %s", buf
));
1902 ND_PRINT((ndo
, " Path Id: %d", path_id
));
1905 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1906 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1908 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1909 else if (advance
== -2)
1911 else if (advance
== -3)
1912 break; /* bytes left, but not enough */
1914 ND_PRINT((ndo
, "\n\t %s", buf
));
1916 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1917 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1918 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1919 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1921 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1922 else if (advance
== -2)
1925 ND_PRINT((ndo
, "\n\t %s", buf
));
1927 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1928 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1929 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1930 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1931 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1933 ND_PRINT((ndo
, "\n\t (illegal length)"));
1934 else if (advance
== -2)
1937 ND_PRINT((ndo
, "\n\t %s", buf
));
1939 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1940 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1941 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1942 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1944 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1945 else if (advance
== -2)
1948 ND_PRINT((ndo
, "\n\t %s", buf
));
1950 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1951 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1952 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1953 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1955 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1956 else if (advance
== -2)
1959 ND_PRINT((ndo
, "\n\t %s", buf
));
1962 ND_TCHECK_LEN(tptr
, tlen
);
1963 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1964 if (ndo
->ndo_vflag
<= 1)
1965 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1977 case BGPTYPE_MP_UNREACH_NLRI
:
1978 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
1979 af
= EXTRACT_BE_U_2(tptr
);
1980 safi
= EXTRACT_U_1(tptr
+ 2);
1982 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1983 tok2str(af_values
, "Unknown AFI", af
),
1985 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1986 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1989 if (len
== BGP_MP_NLRI_MINSIZE
)
1990 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
1994 add_path4
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 32);
1995 add_path6
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 128);
1997 while (tptr
< pptr
+ len
) {
1998 switch (af
<<8 | safi
) {
1999 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
2000 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
2001 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
2003 path_id
= EXTRACT_BE_U_4(tptr
);
2006 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
2008 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2009 else if (advance
== -2)
2011 else if (advance
== -3)
2012 break; /* bytes left, but not enough */
2014 ND_PRINT((ndo
, "\n\t %s", buf
));
2016 ND_PRINT((ndo
, " Path Id: %d", path_id
));
2019 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
2020 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
2022 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2023 else if (advance
== -2)
2025 else if (advance
== -3)
2026 break; /* bytes left, but not enough */
2028 ND_PRINT((ndo
, "\n\t %s", buf
));
2030 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
2031 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
2032 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
2033 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
2035 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2036 else if (advance
== -2)
2039 ND_PRINT((ndo
, "\n\t %s", buf
));
2041 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
2042 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
2043 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
2045 path_id
= EXTRACT_BE_U_4(tptr
);
2048 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
2050 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2051 else if (advance
== -2)
2053 else if (advance
== -3)
2054 break; /* bytes left, but not enough */
2056 ND_PRINT((ndo
, "\n\t %s", buf
));
2058 ND_PRINT((ndo
, " Path Id: %d", path_id
));
2061 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
2062 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
2064 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2065 else if (advance
== -2)
2067 else if (advance
== -3)
2068 break; /* bytes left, but not enough */
2070 ND_PRINT((ndo
, "\n\t %s", buf
));
2072 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
2073 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
2074 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2075 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
2077 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2078 else if (advance
== -2)
2081 ND_PRINT((ndo
, "\n\t %s", buf
));
2083 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2084 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2085 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2086 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2087 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
2089 ND_PRINT((ndo
, "\n\t (illegal length)"));
2090 else if (advance
== -2)
2093 ND_PRINT((ndo
, "\n\t %s", buf
));
2095 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2096 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2097 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2098 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2100 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2101 else if (advance
== -2)
2104 ND_PRINT((ndo
, "\n\t %s", buf
));
2106 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2107 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2108 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2109 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2111 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2112 else if (advance
== -2)
2115 ND_PRINT((ndo
, "\n\t %s", buf
));
2117 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
2118 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
2120 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2121 else if (advance
== -2)
2124 ND_PRINT((ndo
, "\n\t %s", buf
));
2126 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
2127 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
2128 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
2130 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2131 else if (advance
== -2)
2134 ND_PRINT((ndo
, "\n\t %s", buf
));
2137 ND_TCHECK_LEN(tptr
- 3, tlen
);
2138 ND_PRINT((ndo
, "no AFI %u / SAFI %u decoder", af
, safi
));
2139 if (ndo
->ndo_vflag
<= 1)
2140 print_unknown_data(ndo
, tptr
-3, "\n\t ", tlen
);
2150 case BGPTYPE_EXTD_COMMUNITIES
:
2152 ND_PRINT((ndo
, "invalid len"));
2159 extd_comm
=EXTRACT_BE_U_2(tptr
);
2161 ND_PRINT((ndo
, "\n\t %s (0x%04x), Flags [%s]",
2162 tok2str(bgp_extd_comm_subtype_values
,
2163 "unknown extd community typecode",
2166 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
)));
2168 ND_TCHECK_6(tptr
+ 2);
2170 case BGP_EXT_COM_RT_0
:
2171 case BGP_EXT_COM_RO_0
:
2172 case BGP_EXT_COM_L2VPN_RT_0
:
2173 ND_PRINT((ndo
, ": %u:%u (= %s)",
2174 EXTRACT_BE_U_2(tptr
+ 2),
2175 EXTRACT_BE_U_4(tptr
+ 4),
2176 ipaddr_string(ndo
, tptr
+4)));
2178 case BGP_EXT_COM_RT_1
:
2179 case BGP_EXT_COM_RO_1
:
2180 case BGP_EXT_COM_L2VPN_RT_1
:
2181 case BGP_EXT_COM_VRF_RT_IMP
:
2182 ND_PRINT((ndo
, ": %s:%u",
2183 ipaddr_string(ndo
, tptr
+2),
2184 EXTRACT_BE_U_2(tptr
+ 6)));
2186 case BGP_EXT_COM_RT_2
:
2187 case BGP_EXT_COM_RO_2
:
2188 ND_PRINT((ndo
, ": %s:%u",
2189 as_printf(ndo
, astostr
, sizeof(astostr
),
2190 EXTRACT_BE_U_4(tptr
+ 2)), EXTRACT_BE_U_2(tptr
+ 6)));
2192 case BGP_EXT_COM_LINKBAND
:
2193 bw
.i
= EXTRACT_BE_U_4(tptr
+ 2);
2194 ND_PRINT((ndo
, ": bandwidth: %.3f Mbps",
2197 case BGP_EXT_COM_VPN_ORIGIN
:
2198 case BGP_EXT_COM_VPN_ORIGIN2
:
2199 case BGP_EXT_COM_VPN_ORIGIN3
:
2200 case BGP_EXT_COM_VPN_ORIGIN4
:
2201 case BGP_EXT_COM_OSPF_RID
:
2202 case BGP_EXT_COM_OSPF_RID2
:
2203 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
+2)));
2205 case BGP_EXT_COM_OSPF_RTYPE
:
2206 case BGP_EXT_COM_OSPF_RTYPE2
:
2207 ND_PRINT((ndo
, ": area:%s, router-type:%s, metric-type:%s%s",
2208 ipaddr_string(ndo
, tptr
+2),
2209 tok2str(bgp_extd_comm_ospf_rtype_values
,
2211 EXTRACT_U_1((tptr
+ 6))),
2212 (EXTRACT_U_1(tptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
2213 ((EXTRACT_U_1(tptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (EXTRACT_U_1(tptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : ""));
2215 case BGP_EXT_COM_L2INFO
:
2216 ND_PRINT((ndo
, ": %s Control Flags [0x%02x]:MTU %u",
2217 tok2str(l2vpn_encaps_values
,
2219 EXTRACT_U_1((tptr
+ 2))),
2220 EXTRACT_U_1((tptr
+ 3)),
2221 EXTRACT_BE_U_2(tptr
+ 4)));
2223 case BGP_EXT_COM_SOURCE_AS
:
2224 ND_PRINT((ndo
, ": AS %u", EXTRACT_BE_U_2(tptr
+ 2)));
2228 print_unknown_data(ndo
, tptr
, "\n\t ", 8);
2236 case BGPTYPE_PMSI_TUNNEL
:
2238 uint8_t tunnel_type
, flags
;
2241 flags
= EXTRACT_U_1(tptr
);
2242 tunnel_type
= EXTRACT_U_1(tptr
+ 1);
2245 ND_PRINT((ndo
, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2246 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2248 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2249 EXTRACT_BE_U_3(tptr
+ 2)>>4));
2254 switch (tunnel_type
) {
2255 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2256 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2258 ND_PRINT((ndo
, "\n\t Sender %s, P-Group %s",
2259 ipaddr_string(ndo
, tptr
),
2260 ipaddr_string(ndo
, tptr
+4)));
2263 case BGP_PMSI_TUNNEL_PIM_SSM
:
2265 ND_PRINT((ndo
, "\n\t Root-Node %s, P-Group %s",
2266 ipaddr_string(ndo
, tptr
),
2267 ipaddr_string(ndo
, tptr
+4)));
2269 case BGP_PMSI_TUNNEL_INGRESS
:
2271 ND_PRINT((ndo
, "\n\t Tunnel-Endpoint %s",
2272 ipaddr_string(ndo
, tptr
)));
2274 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2275 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2277 ND_PRINT((ndo
, "\n\t Root-Node %s, LSP-ID 0x%08x",
2278 ipaddr_string(ndo
, tptr
),
2279 EXTRACT_BE_U_4(tptr
+ 4)));
2281 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2283 ND_PRINT((ndo
, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2284 ipaddr_string(ndo
, tptr
),
2285 EXTRACT_BE_U_4(tptr
+ 4)));
2288 if (ndo
->ndo_vflag
<= 1) {
2289 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2305 type
= EXTRACT_U_1(tptr
);
2306 length
= EXTRACT_BE_U_2(tptr
+ 1);
2310 ND_PRINT((ndo
, "\n\t %s TLV (%u), length %u",
2311 tok2str(bgp_aigp_values
, "Unknown", type
),
2319 * Check if we can read the TLV data.
2321 ND_TCHECK_LEN(tptr
+ 3, length
);
2328 ND_PRINT((ndo
, ", metric %" PRIu64
,
2329 EXTRACT_BE_U_8(tptr
)));
2333 if (ndo
->ndo_vflag
<= 1) {
2334 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2343 case BGPTYPE_ATTR_SET
:
2347 ND_PRINT((ndo
, "\n\t Origin AS: %s",
2348 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(tptr
))));
2353 u_int aflags
, alenlen
, alen
;
2358 aflags
= EXTRACT_U_1(tptr
);
2359 atype
= EXTRACT_U_1(tptr
+ 1);
2362 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2363 ND_TCHECK_LEN(tptr
, alenlen
);
2366 alen
= bgp_attr_len(aflags
, tptr
);
2370 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2371 tok2str(bgp_attr_values
,
2372 "Unknown Attribute", atype
),
2377 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2378 aflags
& 0x80 ? "O" : "",
2379 aflags
& 0x40 ? "T" : "",
2380 aflags
& 0x20 ? "P" : "",
2381 aflags
& 0x10 ? "E" : ""));
2383 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2384 ND_PRINT((ndo
, "]: "));
2386 /* FIXME check for recursion */
2387 if (!bgp_attr_print(ndo
, atype
, tptr
, alen
))
2394 case BGPTYPE_LARGE_COMMUNITY
:
2395 if (len
== 0 || len
% 12) {
2396 ND_PRINT((ndo
, "invalid len"));
2399 ND_PRINT((ndo
, "\n\t "));
2401 ND_TCHECK_LEN(tptr
, 12);
2402 ND_PRINT((ndo
, "%u:%u:%u%s",
2403 EXTRACT_BE_U_4(tptr
),
2404 EXTRACT_BE_U_4(tptr
+ 4),
2405 EXTRACT_BE_U_4(tptr
+ 8),
2406 (len
> 12) ? ", " : ""));
2412 ND_TCHECK_LEN(pptr
, len
);
2413 ND_PRINT((ndo
, "\n\t no Attribute %u decoder", atype
)); /* we have no decoder for the attribute */
2414 if (ndo
->ndo_vflag
<= 1)
2415 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2418 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2419 ND_TCHECK_LEN(pptr
, len
);
2420 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2429 bgp_capabilities_print(netdissect_options
*ndo
,
2430 const u_char
*opt
, u_int caps_len
)
2432 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2435 while (i
< caps_len
) {
2436 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2437 cap_type
=EXTRACT_U_1(opt
+ i
);
2438 cap_len
=EXTRACT_U_1(opt
+ i
+ 1);
2440 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2441 tok2str(bgp_capcode_values
, "Unknown", cap_type
),
2444 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2446 case BGP_CAPCODE_MP
:
2447 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u)",
2448 tok2str(af_values
, "Unknown", EXTRACT_BE_U_2(opt
+ i
+ 2)),
2449 EXTRACT_BE_U_2(opt
+ i
+ 2),
2450 tok2str(bgp_safi_values
, "Unknown", EXTRACT_U_1(opt
+ i
+ 5)),
2451 EXTRACT_U_1(opt
+ i
+ 5)));
2453 case BGP_CAPCODE_RESTART
:
2454 ND_PRINT((ndo
, "\n\t\tRestart Flags: [%s], Restart Time %us",
2455 ((EXTRACT_U_1(opt
+ i
+ 2))&0x80) ? "R" : "none",
2456 EXTRACT_BE_U_2(opt
+ i
+ 2)&0xfff));
2459 while(tcap_len
>=4) {
2460 ND_PRINT((ndo
, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2461 tok2str(af_values
,"Unknown",
2462 EXTRACT_BE_U_2(opt
+ i
+ cap_offset
)),
2463 EXTRACT_BE_U_2(opt
+ i
+ cap_offset
),
2464 tok2str(bgp_safi_values
,"Unknown",
2465 EXTRACT_U_1(opt
+ i
+ cap_offset
+ 2)),
2466 EXTRACT_U_1(opt
+ (i
+ cap_offset
+ 2)),
2467 ((EXTRACT_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" ));
2472 case BGP_CAPCODE_RR
:
2473 case BGP_CAPCODE_RR_CISCO
:
2475 case BGP_CAPCODE_AS_NEW
:
2478 * Extract the 4 byte AS number encoded.
2481 ND_PRINT((ndo
, "\n\t\t 4 Byte AS %s",
2482 as_printf(ndo
, astostr
, sizeof(astostr
),
2483 EXTRACT_BE_U_4(opt
+ i
+ 2))));
2486 case BGP_CAPCODE_ADD_PATH
:
2488 if (tcap_len
== 0) {
2489 ND_PRINT((ndo
, " (bogus)")); /* length */
2492 while (tcap_len
> 0) {
2494 ND_PRINT((ndo
, "\n\t\t(invalid)"));
2497 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2498 tok2str(af_values
,"Unknown",EXTRACT_BE_U_2(opt
+ i
+ cap_offset
)),
2499 EXTRACT_BE_U_2(opt
+ i
+ cap_offset
),
2500 tok2str(bgp_safi_values
,"Unknown",EXTRACT_U_1(opt
+ i
+ cap_offset
+ 2)),
2501 EXTRACT_U_1(opt
+ (i
+ cap_offset
+ 2)),
2502 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",EXTRACT_U_1(opt
+ i
+ cap_offset
+ 3))
2509 ND_PRINT((ndo
, "\n\t\tno decoder for Capability %u",
2511 if (ndo
->ndo_vflag
<= 1)
2512 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2516 if (ndo
->ndo_vflag
> 1 && cap_len
> 0) {
2517 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2519 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2524 ND_PRINT((ndo
, "[|BGP]"));
2528 bgp_open_print(netdissect_options
*ndo
,
2529 const u_char
*dat
, u_int length
)
2531 const struct bgp_open
*bgp_open_header
;
2533 const struct bgp_opt
*bgpopt
;
2537 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2538 if (length
< BGP_OPEN_SIZE
)
2541 bgp_open_header
= (const struct bgp_open
*)dat
;
2543 ND_PRINT((ndo
, "\n\t Version %u, ",
2544 EXTRACT_U_1(bgp_open_header
->bgpo_version
)));
2545 ND_PRINT((ndo
, "my AS %s, ",
2546 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_2(bgp_open_header
->bgpo_myas
))));
2547 ND_PRINT((ndo
, "Holdtime %us, ",
2548 EXTRACT_BE_U_2(bgp_open_header
->bgpo_holdtime
)));
2549 ND_PRINT((ndo
, "ID %s", ipaddr_string(ndo
, &bgp_open_header
->bgpo_id
)));
2550 optslen
= EXTRACT_U_1(bgp_open_header
->bgpo_optlen
);
2551 ND_PRINT((ndo
, "\n\t Optional parameters, length: %u", optslen
));
2553 opt
= dat
+ BGP_OPEN_SIZE
;
2554 length
-= BGP_OPEN_SIZE
;
2557 while (i
< optslen
) {
2558 uint8_t opt_type
, opt_len
;
2560 ND_TCHECK_LEN(opt
+ i
, BGP_OPT_SIZE
);
2561 if (length
< BGP_OPT_SIZE
+ i
)
2563 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2564 opt_type
= EXTRACT_U_1(bgpopt
->bgpopt_type
);
2565 opt_len
= EXTRACT_U_1(bgpopt
->bgpopt_len
);
2566 if (BGP_OPT_SIZE
+ i
+ opt_len
> optslen
) {
2567 ND_PRINT((ndo
, "\n\t Option %u, length: %u, goes past the end of the options",
2568 opt_type
, opt_len
));
2572 ND_PRINT((ndo
, "\n\t Option %s (%u), length: %u",
2573 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2577 /* now let's decode the options we know*/
2581 bgp_capabilities_print(ndo
, opt
+ BGP_OPT_SIZE
+ i
,
2587 ND_PRINT((ndo
, "\n\t no decoder for option %u",
2591 i
+= BGP_OPT_SIZE
+ opt_len
;
2595 ND_PRINT((ndo
, "[|BGP]"));
2599 bgp_update_print(netdissect_options
*ndo
,
2600 const u_char
*dat
, int length
)
2602 const struct bgp
*bgp_header
;
2604 int withdrawn_routes_len
;
2605 char buf
[MAXHOSTNAMELEN
+ 100];
2612 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2613 if (length
< BGP_SIZE
)
2615 bgp_header
= (const struct bgp
*)dat
;
2619 /* Unfeasible routes */
2623 withdrawn_routes_len
= EXTRACT_BE_U_2(p
);
2626 if (withdrawn_routes_len
> 1) {
2628 * Without keeping state from the original NLRI message,
2629 * it's not possible to tell if this a v4 or v6 route,
2630 * so only try to decode it if we're not v6 enabled.
2632 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2633 if (length
< withdrawn_routes_len
)
2635 ND_PRINT((ndo
, "\n\t Withdrawn routes:"));
2636 add_path
= check_add_path(p
, withdrawn_routes_len
, 32);
2637 while (withdrawn_routes_len
> 0) {
2639 path_id
= EXTRACT_BE_U_4(p
);
2642 withdrawn_routes_len
-= 4;
2644 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2646 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2648 } else if (wpfx
== -2)
2650 else if (wpfx
== -3)
2651 goto trunc
; /* bytes left, but not enough */
2653 ND_PRINT((ndo
, "\n\t %s", buf
));
2655 ND_PRINT((ndo
, " Path Id: %d", path_id
));
2659 withdrawn_routes_len
-= wpfx
;
2663 p
+= withdrawn_routes_len
;
2664 length
-= withdrawn_routes_len
;
2670 len
= EXTRACT_BE_U_2(p
);
2674 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2675 /* No withdrawn routes, no path attributes, no NLRI */
2676 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
2681 /* do something more useful!*/
2683 int aflags
, atype
, alenlen
, alen
;
2690 aflags
= EXTRACT_U_1(p
);
2691 atype
= EXTRACT_U_1(p
+ 1);
2695 alenlen
= bgp_attr_lenlen(aflags
, p
);
2696 ND_TCHECK_LEN(p
, alenlen
);
2699 if (length
< alenlen
)
2701 alen
= bgp_attr_len(aflags
, p
);
2706 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2707 tok2str(bgp_attr_values
, "Unknown Attribute", atype
),
2712 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2713 aflags
& 0x80 ? "O" : "",
2714 aflags
& 0x40 ? "T" : "",
2715 aflags
& 0x20 ? "P" : "",
2716 aflags
& 0x10 ? "E" : ""));
2718 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2719 ND_PRINT((ndo
, "]: "));
2725 if (!bgp_attr_print(ndo
, atype
, p
, alen
))
2734 add_path
= check_add_path(p
, length
, 32);
2735 ND_PRINT((ndo
, "\n\t Updated routes:"));
2736 while (length
> 0) {
2738 path_id
= EXTRACT_BE_U_4(p
);
2742 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2744 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2749 goto trunc
; /* bytes left, but not enough */
2751 ND_PRINT((ndo
, "\n\t %s", buf
));
2753 ND_PRINT((ndo
, " Path Id: %d", path_id
));
2762 ND_PRINT((ndo
, "[|BGP]"));
2766 bgp_notification_print(netdissect_options
*ndo
,
2767 const u_char
*dat
, int length
)
2769 const struct bgp_notification
*bgp_notification_header
;
2771 uint8_t bgpn_major
, bgpn_minor
;
2772 uint8_t shutdown_comm_length
;
2773 uint8_t remainder_offset
;
2775 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
2776 if (length
<BGP_NOTIFICATION_SIZE
)
2779 bgp_notification_header
= (const struct bgp_notification
*)dat
;
2780 bgpn_major
= EXTRACT_U_1(bgp_notification_header
->bgpn_major
);
2781 bgpn_minor
= EXTRACT_U_1(bgp_notification_header
->bgpn_minor
);
2783 ND_PRINT((ndo
, ", %s (%u)",
2784 tok2str(bgp_notify_major_values
, "Unknown Error",
2788 switch (bgpn_major
) {
2790 case BGP_NOTIFY_MAJOR_MSG
:
2791 ND_PRINT((ndo
, ", subcode %s (%u)",
2792 tok2str(bgp_notify_minor_msg_values
, "Unknown",
2796 case BGP_NOTIFY_MAJOR_OPEN
:
2797 ND_PRINT((ndo
, ", subcode %s (%u)",
2798 tok2str(bgp_notify_minor_open_values
, "Unknown",
2802 case BGP_NOTIFY_MAJOR_UPDATE
:
2803 ND_PRINT((ndo
, ", subcode %s (%u)",
2804 tok2str(bgp_notify_minor_update_values
, "Unknown",
2808 case BGP_NOTIFY_MAJOR_FSM
:
2809 ND_PRINT((ndo
, " subcode %s (%u)",
2810 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
2814 case BGP_NOTIFY_MAJOR_CAP
:
2815 ND_PRINT((ndo
, " subcode %s (%u)",
2816 tok2str(bgp_notify_minor_cap_values
, "Unknown",
2820 case BGP_NOTIFY_MAJOR_CEASE
:
2821 ND_PRINT((ndo
, ", subcode %s (%u)",
2822 tok2str(bgp_notify_minor_cease_values
, "Unknown",
2826 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2827 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2829 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2830 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2832 ND_PRINT((ndo
, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2833 tok2str(af_values
, "Unknown", EXTRACT_BE_U_2(tptr
)),
2834 EXTRACT_BE_U_2(tptr
),
2835 tok2str(bgp_safi_values
, "Unknown", EXTRACT_U_1((tptr
+ 2))),
2836 EXTRACT_U_1((tptr
+ 2)),
2837 EXTRACT_BE_U_4(tptr
+ 3)));
2840 * draft-ietf-idr-shutdown describes a method to send a communication
2841 * intended for human consumption regarding the Administrative Shutdown
2843 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
2844 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
2845 length
>= BGP_NOTIFICATION_SIZE
+ 1) {
2846 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2848 shutdown_comm_length
= EXTRACT_U_1(tptr
);
2849 remainder_offset
= 0;
2850 /* garbage, hexdump it all */
2851 if (shutdown_comm_length
> BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN
||
2852 shutdown_comm_length
> length
- (BGP_NOTIFICATION_SIZE
+ 1)) {
2853 ND_PRINT((ndo
, ", invalid Shutdown Communication length"));
2855 else if (shutdown_comm_length
== 0) {
2856 ND_PRINT((ndo
, ", empty Shutdown Communication"));
2857 remainder_offset
+= 1;
2859 /* a proper shutdown communication */
2861 ND_TCHECK_LEN(tptr
+ 1, shutdown_comm_length
);
2862 ND_PRINT((ndo
, ", Shutdown Communication (length: %u): \"", shutdown_comm_length
));
2863 (void)fn_printn(ndo
, tptr
+1, shutdown_comm_length
, NULL
);
2864 ND_PRINT((ndo
, "\""));
2865 remainder_offset
+= shutdown_comm_length
+ 1;
2867 /* if there is trailing data, hexdump it */
2868 if(length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
) > 0) {
2869 ND_PRINT((ndo
, ", Data: (length: %u)", length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
)));
2870 hex_print(ndo
, "\n\t\t", tptr
+ remainder_offset
, length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
2880 ND_PRINT((ndo
, "[|BGP]"));
2884 bgp_route_refresh_print(netdissect_options
*ndo
,
2885 const u_char
*pptr
, int len
)
2887 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2889 ND_TCHECK_LEN(pptr
, BGP_ROUTE_REFRESH_SIZE
);
2891 /* some little sanity checking */
2892 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2895 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2897 ND_PRINT((ndo
, "\n\t AFI %s (%u), SAFI %s (%u)",
2898 tok2str(af_values
,"Unknown",
2899 EXTRACT_BE_U_2(bgp_route_refresh_header
->afi
)),
2900 EXTRACT_BE_U_2(bgp_route_refresh_header
->afi
),
2901 tok2str(bgp_safi_values
,"Unknown",
2902 EXTRACT_U_1(bgp_route_refresh_header
->safi
)),
2903 EXTRACT_U_1(bgp_route_refresh_header
->safi
)));
2905 if (ndo
->ndo_vflag
> 1) {
2906 ND_TCHECK_LEN(pptr
, len
);
2907 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2912 ND_PRINT((ndo
, "[|BGP]"));
2916 bgp_pdu_print(netdissect_options
*ndo
,
2917 const u_char
*dat
, u_int length
)
2919 const struct bgp
*bgp_header
;
2922 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2923 bgp_header
= (const struct bgp
*)dat
;
2924 bgp_type
= EXTRACT_U_1(bgp_header
->bgp_type
);
2926 ND_PRINT((ndo
, "\n\t%s Message (%u), length: %u",
2927 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
2933 bgp_open_print(ndo
, dat
, length
);
2936 bgp_update_print(ndo
, dat
, length
);
2938 case BGP_NOTIFICATION
:
2939 bgp_notification_print(ndo
, dat
, length
);
2943 case BGP_ROUTE_REFRESH
:
2944 bgp_route_refresh_print(ndo
, dat
, length
);
2947 /* we have no decoder for the BGP message */
2948 ND_TCHECK_LEN(dat
, length
);
2949 ND_PRINT((ndo
, "\n\t no Message %u decoder", bgp_type
));
2950 print_unknown_data(ndo
, dat
, "\n\t ", length
);
2955 ND_PRINT((ndo
, "[|BGP]"));
2960 bgp_print(netdissect_options
*ndo
,
2961 const u_char
*dat
, int length
)
2965 const u_char
*start
;
2966 const u_char marker
[] = {
2967 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2968 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2970 const struct bgp
*bgp_header
;
2974 if (ndo
->ndo_snapend
< dat
+ length
)
2975 ep
= ndo
->ndo_snapend
;
2977 ND_PRINT((ndo
, ": BGP"));
2979 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
2987 if (EXTRACT_U_1(p
) != 0xff) {
2992 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
2994 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2999 /* found BGP header */
3000 ND_TCHECK_LEN(p
, BGP_SIZE
);
3001 bgp_header
= (const struct bgp
*)p
;
3004 ND_PRINT((ndo
, " [|BGP]"));
3006 hlen
= EXTRACT_BE_U_2(bgp_header
->bgp_len
);
3007 if (hlen
< BGP_SIZE
) {
3008 ND_PRINT((ndo
, "\n[|BGP Bogus header length %u < %u]", hlen
,
3013 if (ND_TTEST_LEN(p
, hlen
)) {
3014 if (!bgp_pdu_print(ndo
, p
, hlen
))
3019 ND_PRINT((ndo
, "\n[|BGP %s]",
3020 tok2str(bgp_msg_values
,
3021 "Unknown Message Type",
3022 EXTRACT_U_1(bgp_header
->bgp_type
))));
3030 ND_PRINT((ndo
, " [|BGP]"));
3035 * c-style: whitesmith