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] &=
555 ((0xff00 >> (plen
% 8)) & 0xff);
557 snprintf(buf
, buflen
, "%s/%d", ipaddr_string(ndo
, &addr
), plen
);
558 return 1 + plenbytes
;
568 decode_labeled_prefix4(netdissect_options
*ndo
,
569 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
572 u_int plen
, plenbytes
;
574 /* prefix length and label = 4 bytes */
577 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
579 /* this is one of the weirdnesses of rfc3107
580 the label length (actually the label + COS bits)
581 is added to the prefix length;
582 we also do only read out just one label -
583 there is no real application for advertisement of
584 stacked labels in a single BGP message
590 plen
-=24; /* adjust prefixlen - labellength */
596 memset(&addr
, 0, sizeof(addr
));
597 plenbytes
= (plen
+ 7) / 8;
598 ND_TCHECK_LEN(pptr
+ 4, plenbytes
);
599 ITEMCHECK(plenbytes
);
600 memcpy(&addr
, pptr
+ 4, plenbytes
);
602 ((u_char
*)&addr
)[plenbytes
- 1] &=
603 ((0xff00 >> (plen
% 8)) & 0xff);
605 /* the label may get offsetted by 4 bits so lets shift it right */
606 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
607 ipaddr_string(ndo
, &addr
),
609 EXTRACT_BE_U_3(pptr
+ 1)>>4,
610 ((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/%d, 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 ((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
)
877 const u_char
*vpn_ip
;
881 /* if the NLRI is not predefined length, quit.*/
882 if (EXTRACT_U_1(pptr
) != MDT_VPN_NLRI_LEN
* 8)
892 ND_TCHECK_LEN(pptr
, sizeof(struct in_addr
));
894 pptr
+=sizeof(struct in_addr
);
896 /* MDT Group Address */
897 ND_TCHECK_LEN(pptr
, sizeof(struct in_addr
));
899 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
900 bgp_vpn_rd_print(ndo
, rd
), ipaddr_string(ndo
, vpn_ip
), ipaddr_string(ndo
, pptr
));
902 return MDT_VPN_NLRI_LEN
+ 1;
909 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
910 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
911 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
912 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
913 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
914 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
915 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
917 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
918 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
919 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
920 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
921 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
922 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
923 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
924 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
929 decode_multicast_vpn(netdissect_options
*ndo
,
930 const u_char
*pptr
, char *buf
, u_int buflen
)
932 uint8_t route_type
, route_length
, addr_length
, sg_length
;
936 route_type
= EXTRACT_U_1(pptr
);
938 route_length
= EXTRACT_U_1(pptr
);
941 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
942 tok2str(bgp_multicast_vpn_route_type_values
,
943 "Unknown", route_type
),
944 route_type
, route_length
);
947 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
948 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
949 offset
= strlen(buf
);
950 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
951 bgp_vpn_rd_print(ndo
, pptr
),
952 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
953 (route_length
- BGP_VPN_RD_LEN
) << 3));
955 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
956 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
957 offset
= strlen(buf
);
958 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
959 bgp_vpn_rd_print(ndo
, pptr
),
960 as_printf(ndo
, astostr
, sizeof(astostr
),
961 EXTRACT_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
964 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
965 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
966 offset
= strlen(buf
);
967 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
968 bgp_vpn_rd_print(ndo
, pptr
));
969 pptr
+= BGP_VPN_RD_LEN
;
971 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
972 addr_length
= route_length
- sg_length
;
974 ND_TCHECK_LEN(pptr
, addr_length
);
975 offset
= strlen(buf
);
976 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
977 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
980 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
981 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
982 offset
= strlen(buf
);
983 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
984 bgp_vpn_rd_print(ndo
, pptr
));
985 pptr
+= BGP_VPN_RD_LEN
;
987 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
990 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
991 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
992 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
993 offset
= strlen(buf
);
994 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
995 bgp_vpn_rd_print(ndo
, pptr
),
996 as_printf(ndo
, astostr
, sizeof(astostr
),
997 EXTRACT_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
998 pptr
+= BGP_VPN_RD_LEN
+ 4;
1000 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1004 * no per route-type printing yet.
1006 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1011 return route_length
+ 2;
1018 * As I remember, some versions of systems have an snprintf() that
1019 * returns -1 if the buffer would have overflowed. If the return
1020 * value is negative, set buflen to 0, to indicate that we've filled
1023 * If the return value is greater than buflen, that means that
1024 * the buffer would have overflowed; again, set buflen to 0 in
1027 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1030 else if ((u_int)stringlen>buflen) \
1033 buflen-=stringlen; \
1038 decode_labeled_vpn_l2(netdissect_options
*ndo
,
1039 const u_char
*pptr
, char *buf
, u_int buflen
)
1041 int plen
,tlen
,stringlen
,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)
1059 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1063 } else if (plen
>17) {
1064 /* assume old format */
1065 /* RD, ID, LBLKOFF, LBLBASE */
1067 ND_TCHECK_LEN(pptr
, 15);
1069 stringlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1070 bgp_vpn_rd_print(ndo
, pptr
),
1071 EXTRACT_BE_U_2(pptr
+ 8),
1072 EXTRACT_BE_U_2(pptr
+ 10),
1073 EXTRACT_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1074 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1078 /* ok now the variable part - lets read out TLVs*/
1083 tlv_type
=EXTRACT_U_1(pptr
);
1085 tlv_len
=EXTRACT_BE_U_2(pptr
);
1092 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1095 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1097 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
1098 while (ttlv_len
>0) {
1101 stringlen
=snprintf(buf
,buflen
, "%02x",
1104 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1111 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1114 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1118 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
1123 /* complain bitterly ? */
1133 decode_prefix6(netdissect_options
*ndo
,
1134 const u_char
*pd
, u_int itemlen
, char *buf
, u_int buflen
)
1136 struct in6_addr addr
;
1137 u_int plen
, plenbytes
;
1141 plen
= EXTRACT_U_1(pd
);
1146 memset(&addr
, 0, sizeof(addr
));
1147 plenbytes
= (plen
+ 7) / 8;
1148 ND_TCHECK_LEN(pd
+ 1, plenbytes
);
1149 ITEMCHECK(plenbytes
);
1150 memcpy(&addr
, pd
+ 1, plenbytes
);
1152 addr
.s6_addr
[plenbytes
- 1] &=
1153 ((0xff00 >> (plen
% 8)) & 0xff);
1155 snprintf(buf
, buflen
, "%s/%d", ip6addr_string(ndo
, &addr
), plen
);
1156 return 1 + plenbytes
;
1166 decode_labeled_prefix6(netdissect_options
*ndo
,
1167 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
1169 struct in6_addr addr
;
1170 u_int plen
, plenbytes
;
1172 /* prefix length and label = 4 bytes */
1175 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
1180 plen
-=24; /* adjust prefixlen - labellength */
1186 memset(&addr
, 0, sizeof(addr
));
1187 plenbytes
= (plen
+ 7) / 8;
1188 ND_TCHECK_LEN(pptr
+ 4, plenbytes
);
1189 memcpy(&addr
, pptr
+ 4, plenbytes
);
1191 addr
.s6_addr
[plenbytes
- 1] &=
1192 ((0xff00 >> (plen
% 8)) & 0xff);
1194 /* the label may get offsetted by 4 bits so lets shift it right */
1195 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
1196 ip6addr_string(ndo
, &addr
),
1198 EXTRACT_BE_U_3(pptr
+ 1)>>4,
1199 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1201 return 4 + plenbytes
;
1211 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1212 const u_char
*pptr
, char *buf
, u_int buflen
)
1214 struct in6_addr addr
;
1218 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
1223 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1228 memset(&addr
, 0, sizeof(addr
));
1229 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
1230 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1232 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1233 ((0xff00 >> (plen
% 8)) & 0xff);
1235 /* the label may get offsetted by 4 bits so lets shift it right */
1236 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1237 bgp_vpn_rd_print(ndo
, pptr
+4),
1238 ip6addr_string(ndo
, &addr
),
1240 EXTRACT_BE_U_3(pptr
+ 1)>>4,
1241 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1243 return 12 + (plen
+ 7) / 8;
1250 decode_clnp_prefix(netdissect_options
*ndo
,
1251 const u_char
*pptr
, char *buf
, u_int buflen
)
1257 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
1262 memset(&addr
, 0, sizeof(addr
));
1263 ND_TCHECK_LEN(pptr
+ 4, (plen
+ 7) / 8);
1264 memcpy(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1266 addr
[(plen
+ 7) / 8 - 1] &=
1267 ((0xff00 >> (plen
% 8)) & 0xff);
1269 snprintf(buf
, buflen
, "%s/%d",
1270 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1273 return 1 + (plen
+ 7) / 8;
1280 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1281 const u_char
*pptr
, char *buf
, u_int buflen
)
1287 plen
= EXTRACT_U_1(pptr
); /* get prefix length */
1292 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1297 memset(&addr
, 0, sizeof(addr
));
1298 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
1299 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1301 addr
[(plen
+ 7) / 8 - 1] &=
1302 ((0xff00 >> (plen
% 8)) & 0xff);
1304 /* the label may get offsetted by 4 bits so lets shift it right */
1305 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1306 bgp_vpn_rd_print(ndo
, pptr
+4),
1307 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1309 EXTRACT_BE_U_3(pptr
+ 1)>>4,
1310 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1312 return 12 + (plen
+ 7) / 8;
1319 * bgp_attr_get_as_size
1321 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1322 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1323 * support, exchange AS-Path with the same path-attribute type value 0x02.
1326 bgp_attr_get_as_size(netdissect_options
*ndo
,
1327 uint8_t bgpa_type
, const u_char
*pptr
, int len
)
1329 const u_char
*tptr
= pptr
;
1332 * If the path attribute is the optional AS4 path type, then we already
1333 * know, that ASs must be encoded in 4 byte format.
1335 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1340 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1341 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1344 while (tptr
< pptr
+ len
) {
1348 * If we do not find a valid segment type, our guess might be wrong.
1350 if (EXTRACT_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| EXTRACT_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1353 ND_TCHECK_1(tptr
+ 1);
1354 tptr
+= 2 + EXTRACT_U_1(tptr
+ 1) * 2;
1358 * If we correctly reached end of the AS path attribute data content,
1359 * then most likely ASs were indeed encoded as 2 bytes.
1361 if (tptr
== pptr
+ len
) {
1368 * We can come here, either we did not have enough data, or if we
1369 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1370 * so that calller can try to decode each AS as of 4 bytes. If indeed
1371 * there was not enough data, it will crib and end the parse anyways.
1377 * The only way to know that a BGP UPDATE message is using add path is
1378 * by checking if the capability is in the OPEN message which we may have missed.
1379 * So this function checks if it is possible that the update could contain add path
1380 * and if so it checks that standard BGP doesn't make sense.
1384 check_add_path(const u_char
*pptr
, u_int length
, u_int max_prefix_length
) {
1386 u_int offset
, prefix_length
;
1391 /* check if it could be add path */
1392 for(offset
= 0; offset
< length
;) {
1394 prefix_length
= pptr
[offset
];
1396 * Add 4 to cover the path id
1397 * and check the prefix length isn't greater than 32/128.
1399 if (prefix_length
> max_prefix_length
) {
1402 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1403 offset
+= 1 + ((prefix_length
+ 7) / 8);
1405 /* check we haven't gone past the end of the section */
1406 if (offset
> length
) {
1410 /* check it's not standard BGP */
1411 for(offset
= 0; offset
< length
; ) {
1412 prefix_length
= pptr
[offset
];
1414 * If the prefix_length is zero (0.0.0.0/0)
1415 * and since it's not the only address (length >= 5)
1416 * then it is add-path
1418 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1421 offset
+= 1 + ((prefix_length
+ 7) / 8);
1423 if (offset
> length
) {
1427 /* assume not add-path by default */
1433 bgp_attr_print(netdissect_options
*ndo
,
1434 u_int atype
, const u_char
*pptr
, u_int len
)
1438 uint8_t safi
, snpa
, nhlen
;
1439 union { /* copy buffer for bandwidth values */
1446 char buf
[MAXHOSTNAMELEN
+ 100];
1448 int add_path4
, add_path6
, path_id
;
1454 case BGPTYPE_ORIGIN
:
1456 ND_PRINT((ndo
, "invalid len"));
1459 ND_PRINT((ndo
, "%s", tok2str(bgp_origin_values
,
1460 "Unknown Origin Typecode",
1461 EXTRACT_U_1(tptr
))));
1466 * Process AS4 byte path and AS2 byte path attributes here.
1468 case BGPTYPE_AS4_PATH
:
1469 case BGPTYPE_AS_PATH
:
1471 ND_PRINT((ndo
, "invalid len"));
1475 ND_PRINT((ndo
, "empty"));
1480 * BGP updates exchanged between New speakers that support 4
1481 * byte AS, ASs are always encoded in 4 bytes. There is no
1482 * definitive way to find this, just by the packet's
1483 * contents. So, check for packet's TLV's sanity assuming
1484 * 2 bytes first, and it does not pass, assume that ASs are
1485 * encoded in 4 bytes format and move on.
1487 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1489 while (tptr
< pptr
+ len
) {
1491 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_open_values
,
1492 "?", EXTRACT_U_1(tptr
))));
1493 ND_TCHECK_1(tptr
+ 1);
1494 for (i
= 0; i
< tptr
[1] * as_size
; i
+= as_size
) {
1495 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
1496 ND_PRINT((ndo
, "%s ",
1497 as_printf(ndo
, astostr
, sizeof(astostr
),
1499 EXTRACT_BE_U_2(tptr
+ i
+ 2) :
1500 EXTRACT_BE_U_4(tptr
+ i
+ 2))));
1503 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_close_values
,
1504 "?", EXTRACT_U_1(tptr
))));
1505 ND_TCHECK_1(tptr
+ 1);
1506 tptr
+= 2 + EXTRACT_U_1(tptr
+ 1) * as_size
;
1509 case BGPTYPE_NEXT_HOP
:
1511 ND_PRINT((ndo
, "invalid len"));
1514 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1517 case BGPTYPE_MULTI_EXIT_DISC
:
1518 case BGPTYPE_LOCAL_PREF
:
1520 ND_PRINT((ndo
, "invalid len"));
1523 ND_PRINT((ndo
, "%u", EXTRACT_BE_U_4(tptr
)));
1526 case BGPTYPE_ATOMIC_AGGREGATE
:
1528 ND_PRINT((ndo
, "invalid len"));
1530 case BGPTYPE_AGGREGATOR
:
1533 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1534 * the length of this PA can be either 6 bytes or 8 bytes.
1536 if (len
!= 6 && len
!= 8) {
1537 ND_PRINT((ndo
, "invalid len"));
1540 ND_TCHECK_LEN(tptr
, len
);
1542 ND_PRINT((ndo
, " AS #%s, origin %s",
1543 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_2(tptr
)),
1544 ipaddr_string(ndo
, tptr
+ 2)));
1546 ND_PRINT((ndo
, " AS #%s, origin %s",
1547 as_printf(ndo
, astostr
, sizeof(astostr
),
1548 EXTRACT_BE_U_4(tptr
)), ipaddr_string(ndo
, tptr
+ 4)));
1551 case BGPTYPE_AGGREGATOR4
:
1553 ND_PRINT((ndo
, "invalid len"));
1557 ND_PRINT((ndo
, " AS #%s, origin %s",
1558 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(tptr
)),
1559 ipaddr_string(ndo
, tptr
+ 4)));
1561 case BGPTYPE_COMMUNITIES
:
1563 ND_PRINT((ndo
, "invalid len"));
1569 comm
= EXTRACT_BE_U_4(tptr
);
1571 case BGP_COMMUNITY_NO_EXPORT
:
1572 ND_PRINT((ndo
, " NO_EXPORT"));
1574 case BGP_COMMUNITY_NO_ADVERT
:
1575 ND_PRINT((ndo
, " NO_ADVERTISE"));
1577 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1578 ND_PRINT((ndo
, " NO_EXPORT_SUBCONFED"));
1581 ND_PRINT((ndo
, "%u:%u%s",
1582 (comm
>> 16) & 0xffff,
1584 (tlen
>4) ? ", " : ""));
1591 case BGPTYPE_ORIGINATOR_ID
:
1593 ND_PRINT((ndo
, "invalid len"));
1597 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1599 case BGPTYPE_CLUSTER_LIST
:
1601 ND_PRINT((ndo
, "invalid len"));
1606 ND_PRINT((ndo
, "%s%s",
1607 ipaddr_string(ndo
, tptr
),
1608 (tlen
>4) ? ", " : ""));
1613 case BGPTYPE_MP_REACH_NLRI
:
1615 af
= EXTRACT_BE_U_2(tptr
);
1616 safi
= EXTRACT_U_1(tptr
+ 2);
1618 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1619 tok2str(af_values
, "Unknown AFI", af
),
1621 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1622 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1625 switch(af
<<8 | safi
) {
1626 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1627 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1628 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1629 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1630 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1631 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1632 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1633 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1634 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1635 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1636 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1637 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1638 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1639 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1640 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1641 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1642 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1643 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1644 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1645 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1646 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1647 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1648 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1649 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1650 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1651 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1652 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1655 ND_TCHECK_LEN(tptr
, tlen
);
1656 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1657 if (ndo
->ndo_vflag
<= 1)
1658 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1666 nhlen
= EXTRACT_U_1(tptr
);
1672 ND_PRINT((ndo
, "\n\t nexthop: "));
1675 ND_PRINT((ndo
, ", " ));
1677 switch(af
<<8 | safi
) {
1678 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1679 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1680 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1681 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1682 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1683 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1684 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1685 if (tlen
< sizeof(struct in_addr
)) {
1686 ND_PRINT((ndo
, "invalid len"));
1689 ND_TCHECK_LEN(tptr
, sizeof(struct in_addr
));
1690 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1691 tlen
-= sizeof(struct in_addr
);
1692 tptr
+= sizeof(struct in_addr
);
1695 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1696 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1697 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1698 if (tlen
< sizeof(struct in_addr
)+BGP_VPN_RD_LEN
) {
1699 ND_PRINT((ndo
, "invalid len"));
1703 sizeof(struct in_addr
) + BGP_VPN_RD_LEN
);
1704 ND_PRINT((ndo
, "RD: %s, %s",
1705 bgp_vpn_rd_print(ndo
, tptr
),
1706 ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1707 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1708 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1711 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1712 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1713 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1714 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1715 if (tlen
< sizeof(struct in6_addr
)) {
1716 ND_PRINT((ndo
, "invalid len"));
1719 ND_TCHECK_LEN(tptr
, sizeof(struct in6_addr
));
1720 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, tptr
)));
1721 tlen
-= sizeof(struct in6_addr
);
1722 tptr
+= sizeof(struct in6_addr
);
1725 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1726 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1727 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1728 if (tlen
< sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
) {
1729 ND_PRINT((ndo
, "invalid len"));
1733 sizeof(struct in6_addr
) + BGP_VPN_RD_LEN
);
1734 ND_PRINT((ndo
, "RD: %s, %s",
1735 bgp_vpn_rd_print(ndo
, tptr
),
1736 ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1737 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1738 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1741 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1742 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1743 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1744 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1745 if (tlen
< sizeof(struct in_addr
)) {
1746 ND_PRINT((ndo
, "invalid len"));
1749 ND_TCHECK_LEN(tptr
, sizeof(struct in_addr
));
1750 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1751 tlen
-= (sizeof(struct in_addr
));
1752 tptr
+= (sizeof(struct in_addr
));
1755 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1756 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1757 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1758 ND_TCHECK_LEN(tptr
, tlen
);
1759 ND_PRINT((ndo
, "%s", isonsap_string(ndo
, tptr
, tlen
)));
1764 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1765 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1766 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1767 if (tlen
< BGP_VPN_RD_LEN
+1) {
1768 ND_PRINT((ndo
, "invalid len"));
1771 ND_TCHECK_LEN(tptr
, tlen
);
1772 ND_PRINT((ndo
, "RD: %s, %s",
1773 bgp_vpn_rd_print(ndo
, tptr
),
1774 isonsap_string(ndo
, tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
)));
1775 /* rfc986 mapped IPv4 address ? */
1776 if (EXTRACT_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
1777 ND_PRINT((ndo
, " = %s", ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+4)));
1778 /* rfc1888 mapped IPv6 address ? */
1779 else if (EXTRACT_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
1780 ND_PRINT((ndo
, " = %s", ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+3)));
1786 ND_TCHECK_LEN(tptr
, tlen
);
1787 ND_PRINT((ndo
, "no AFI %u/SAFI %u decoder", af
, safi
));
1788 if (ndo
->ndo_vflag
<= 1)
1789 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1797 ND_PRINT((ndo
, ", nh-length: %u", nhlen
));
1801 snpa
= EXTRACT_U_1(tptr
);
1805 ND_PRINT((ndo
, "\n\t %u SNPA", snpa
));
1806 for (/*nothing*/; snpa
> 0; snpa
--) {
1808 ND_PRINT((ndo
, "\n\t %d bytes", EXTRACT_U_1(tptr
)));
1809 tptr
+= EXTRACT_U_1(tptr
) + 1;
1812 ND_PRINT((ndo
, ", no SNPA"));
1815 add_path4
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 32);
1816 add_path6
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 128);
1818 while (tptr
< pptr
+ len
) {
1819 switch (af
<<8 | safi
) {
1820 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1821 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1822 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1824 path_id
= EXTRACT_32BITS(tptr
);
1827 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1829 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1830 else if (advance
== -2)
1832 else if (advance
== -3)
1833 break; /* bytes left, but not enough */
1835 ND_PRINT((ndo
, "\n\t %s", buf
));
1837 ND_PRINT((ndo
, " Path Id: %d", path_id
));
1840 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1841 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1843 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1844 else if (advance
== -2)
1846 else if (advance
== -3)
1847 break; /* bytes left, but not enough */
1849 ND_PRINT((ndo
, "\n\t %s", buf
));
1851 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1852 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1853 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1854 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1856 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1857 else if (advance
== -2)
1860 ND_PRINT((ndo
, "\n\t %s", buf
));
1862 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1863 advance
= decode_rt_routing_info(ndo
, tptr
, buf
, sizeof(buf
));
1865 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1866 else if (advance
== -2)
1869 ND_PRINT((ndo
, "\n\t %s", buf
));
1871 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1872 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1873 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1875 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1876 else if (advance
== -2)
1879 ND_PRINT((ndo
, "\n\t %s", buf
));
1882 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1883 advance
= decode_mdt_vpn_nlri(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_INET6
<<8 | SAFNUM_UNICAST
):
1892 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1893 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1895 path_id
= EXTRACT_32BITS(tptr
);
1898 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1900 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1901 else if (advance
== -2)
1903 else if (advance
== -3)
1904 break; /* bytes left, but not enough */
1906 ND_PRINT((ndo
, "\n\t %s", buf
));
1908 ND_PRINT((ndo
, " Path Id: %d", path_id
));
1911 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1912 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1914 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1915 else if (advance
== -2)
1917 else if (advance
== -3)
1918 break; /* bytes left, but not enough */
1920 ND_PRINT((ndo
, "\n\t %s", buf
));
1922 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1923 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1924 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1925 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1927 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1928 else if (advance
== -2)
1931 ND_PRINT((ndo
, "\n\t %s", buf
));
1933 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1934 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1935 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1936 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1937 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1939 ND_PRINT((ndo
, "\n\t (illegal length)"));
1940 else if (advance
== -2)
1943 ND_PRINT((ndo
, "\n\t %s", buf
));
1945 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1946 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1947 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1948 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1950 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1951 else if (advance
== -2)
1954 ND_PRINT((ndo
, "\n\t %s", buf
));
1956 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1957 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1958 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1959 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1961 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1962 else if (advance
== -2)
1965 ND_PRINT((ndo
, "\n\t %s", buf
));
1968 ND_TCHECK_LEN(tptr
, tlen
);
1969 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1970 if (ndo
->ndo_vflag
<= 1)
1971 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1983 case BGPTYPE_MP_UNREACH_NLRI
:
1984 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
1985 af
= EXTRACT_BE_U_2(tptr
);
1986 safi
= EXTRACT_U_1(tptr
+ 2);
1988 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1989 tok2str(af_values
, "Unknown AFI", af
),
1991 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1992 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1995 if (len
== BGP_MP_NLRI_MINSIZE
)
1996 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
2000 add_path4
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 32);
2001 add_path6
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 128);
2003 while (tptr
< pptr
+ len
) {
2004 switch (af
<<8 | safi
) {
2005 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
2006 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
2007 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
2009 path_id
= EXTRACT_32BITS(tptr
);
2012 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
2014 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2015 else if (advance
== -2)
2017 else if (advance
== -3)
2018 break; /* bytes left, but not enough */
2020 ND_PRINT((ndo
, "\n\t %s", buf
));
2022 ND_PRINT((ndo
, " Path Id: %d", path_id
));
2025 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
2026 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
2028 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2029 else if (advance
== -2)
2031 else if (advance
== -3)
2032 break; /* bytes left, but not enough */
2034 ND_PRINT((ndo
, "\n\t %s", buf
));
2036 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
2037 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
2038 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
2039 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
2041 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2042 else if (advance
== -2)
2045 ND_PRINT((ndo
, "\n\t %s", buf
));
2047 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
2048 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
2049 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
2051 path_id
= EXTRACT_32BITS(tptr
);
2054 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
2056 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2057 else if (advance
== -2)
2059 else if (advance
== -3)
2060 break; /* bytes left, but not enough */
2062 ND_PRINT((ndo
, "\n\t %s", buf
));
2064 ND_PRINT((ndo
, " Path Id: %d", path_id
));
2067 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
2068 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
2070 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2071 else if (advance
== -2)
2073 else if (advance
== -3)
2074 break; /* bytes left, but not enough */
2076 ND_PRINT((ndo
, "\n\t %s", buf
));
2078 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
2079 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
2080 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2081 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
2083 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2084 else if (advance
== -2)
2087 ND_PRINT((ndo
, "\n\t %s", buf
));
2089 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2090 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2091 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2092 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2093 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
2095 ND_PRINT((ndo
, "\n\t (illegal length)"));
2096 else if (advance
== -2)
2099 ND_PRINT((ndo
, "\n\t %s", buf
));
2101 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2102 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2103 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2104 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2106 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2107 else if (advance
== -2)
2110 ND_PRINT((ndo
, "\n\t %s", buf
));
2112 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2113 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2114 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2115 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2117 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2118 else if (advance
== -2)
2121 ND_PRINT((ndo
, "\n\t %s", buf
));
2123 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
2124 advance
= decode_mdt_vpn_nlri(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_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
2133 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
2134 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
2136 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2137 else if (advance
== -2)
2140 ND_PRINT((ndo
, "\n\t %s", buf
));
2143 ND_TCHECK_LEN(tptr
- 3, tlen
);
2144 ND_PRINT((ndo
, "no AFI %u / SAFI %u decoder", af
, safi
));
2145 if (ndo
->ndo_vflag
<= 1)
2146 print_unknown_data(ndo
, tptr
-3, "\n\t ", tlen
);
2156 case BGPTYPE_EXTD_COMMUNITIES
:
2158 ND_PRINT((ndo
, "invalid len"));
2165 extd_comm
=EXTRACT_BE_U_2(tptr
);
2167 ND_PRINT((ndo
, "\n\t %s (0x%04x), Flags [%s]",
2168 tok2str(bgp_extd_comm_subtype_values
,
2169 "unknown extd community typecode",
2172 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
)));
2174 ND_TCHECK_6(tptr
+ 2);
2176 case BGP_EXT_COM_RT_0
:
2177 case BGP_EXT_COM_RO_0
:
2178 case BGP_EXT_COM_L2VPN_RT_0
:
2179 ND_PRINT((ndo
, ": %u:%u (= %s)",
2180 EXTRACT_BE_U_2(tptr
+ 2),
2181 EXTRACT_BE_U_4(tptr
+ 4),
2182 ipaddr_string(ndo
, tptr
+4)));
2184 case BGP_EXT_COM_RT_1
:
2185 case BGP_EXT_COM_RO_1
:
2186 case BGP_EXT_COM_L2VPN_RT_1
:
2187 case BGP_EXT_COM_VRF_RT_IMP
:
2188 ND_PRINT((ndo
, ": %s:%u",
2189 ipaddr_string(ndo
, tptr
+2),
2190 EXTRACT_BE_U_2(tptr
+ 6)));
2192 case BGP_EXT_COM_RT_2
:
2193 case BGP_EXT_COM_RO_2
:
2194 ND_PRINT((ndo
, ": %s:%u",
2195 as_printf(ndo
, astostr
, sizeof(astostr
),
2196 EXTRACT_BE_U_4(tptr
+ 2)), EXTRACT_BE_U_2(tptr
+ 6)));
2198 case BGP_EXT_COM_LINKBAND
:
2199 bw
.i
= EXTRACT_BE_U_4(tptr
+ 2);
2200 ND_PRINT((ndo
, ": bandwidth: %.3f Mbps",
2203 case BGP_EXT_COM_VPN_ORIGIN
:
2204 case BGP_EXT_COM_VPN_ORIGIN2
:
2205 case BGP_EXT_COM_VPN_ORIGIN3
:
2206 case BGP_EXT_COM_VPN_ORIGIN4
:
2207 case BGP_EXT_COM_OSPF_RID
:
2208 case BGP_EXT_COM_OSPF_RID2
:
2209 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
+2)));
2211 case BGP_EXT_COM_OSPF_RTYPE
:
2212 case BGP_EXT_COM_OSPF_RTYPE2
:
2213 ND_PRINT((ndo
, ": area:%s, router-type:%s, metric-type:%s%s",
2214 ipaddr_string(ndo
, tptr
+2),
2215 tok2str(bgp_extd_comm_ospf_rtype_values
,
2217 EXTRACT_U_1((tptr
+ 6))),
2218 (EXTRACT_U_1(tptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
2219 ((EXTRACT_U_1(tptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (EXTRACT_U_1(tptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : ""));
2221 case BGP_EXT_COM_L2INFO
:
2222 ND_PRINT((ndo
, ": %s Control Flags [0x%02x]:MTU %u",
2223 tok2str(l2vpn_encaps_values
,
2225 EXTRACT_U_1((tptr
+ 2))),
2226 EXTRACT_U_1((tptr
+ 3)),
2227 EXTRACT_BE_U_2(tptr
+ 4)));
2229 case BGP_EXT_COM_SOURCE_AS
:
2230 ND_PRINT((ndo
, ": AS %u", EXTRACT_BE_U_2(tptr
+ 2)));
2234 print_unknown_data(ndo
, tptr
, "\n\t ", 8);
2242 case BGPTYPE_PMSI_TUNNEL
:
2244 uint8_t tunnel_type
, flags
;
2247 flags
= EXTRACT_U_1(tptr
);
2248 tunnel_type
= EXTRACT_U_1(tptr
+ 1);
2251 ND_PRINT((ndo
, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2252 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2254 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2255 EXTRACT_BE_U_3(tptr
+ 2)>>4));
2260 switch (tunnel_type
) {
2261 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2262 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2264 ND_PRINT((ndo
, "\n\t Sender %s, P-Group %s",
2265 ipaddr_string(ndo
, tptr
),
2266 ipaddr_string(ndo
, tptr
+4)));
2269 case BGP_PMSI_TUNNEL_PIM_SSM
:
2271 ND_PRINT((ndo
, "\n\t Root-Node %s, P-Group %s",
2272 ipaddr_string(ndo
, tptr
),
2273 ipaddr_string(ndo
, tptr
+4)));
2275 case BGP_PMSI_TUNNEL_INGRESS
:
2277 ND_PRINT((ndo
, "\n\t Tunnel-Endpoint %s",
2278 ipaddr_string(ndo
, tptr
)));
2280 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2281 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2283 ND_PRINT((ndo
, "\n\t Root-Node %s, LSP-ID 0x%08x",
2284 ipaddr_string(ndo
, tptr
),
2285 EXTRACT_BE_U_4(tptr
+ 4)));
2287 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2289 ND_PRINT((ndo
, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2290 ipaddr_string(ndo
, tptr
),
2291 EXTRACT_BE_U_4(tptr
+ 4)));
2294 if (ndo
->ndo_vflag
<= 1) {
2295 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2311 type
= EXTRACT_U_1(tptr
);
2312 length
= EXTRACT_BE_U_2(tptr
+ 1);
2316 ND_PRINT((ndo
, "\n\t %s TLV (%u), length %u",
2317 tok2str(bgp_aigp_values
, "Unknown", type
),
2325 * Check if we can read the TLV data.
2327 ND_TCHECK_LEN(tptr
+ 3, length
);
2334 ND_PRINT((ndo
, ", metric %" PRIu64
,
2335 EXTRACT_BE_U_8(tptr
)));
2339 if (ndo
->ndo_vflag
<= 1) {
2340 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2349 case BGPTYPE_ATTR_SET
:
2353 ND_PRINT((ndo
, "\n\t Origin AS: %s",
2354 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(tptr
))));
2359 u_int aflags
, alenlen
, alen
;
2364 aflags
= EXTRACT_U_1(tptr
);
2365 atype
= EXTRACT_U_1(tptr
+ 1);
2368 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2369 ND_TCHECK_LEN(tptr
, alenlen
);
2372 alen
= bgp_attr_len(aflags
, tptr
);
2376 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2377 tok2str(bgp_attr_values
,
2378 "Unknown Attribute", atype
),
2383 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2384 aflags
& 0x80 ? "O" : "",
2385 aflags
& 0x40 ? "T" : "",
2386 aflags
& 0x20 ? "P" : "",
2387 aflags
& 0x10 ? "E" : ""));
2389 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2390 ND_PRINT((ndo
, "]: "));
2392 /* FIXME check for recursion */
2393 if (!bgp_attr_print(ndo
, atype
, tptr
, alen
))
2400 case BGPTYPE_LARGE_COMMUNITY
:
2401 if (len
== 0 || len
% 12) {
2402 ND_PRINT((ndo
, "invalid len"));
2405 ND_PRINT((ndo
, "\n\t "));
2407 ND_TCHECK_LEN(tptr
, 12);
2408 ND_PRINT((ndo
, "%u:%u:%u%s",
2409 EXTRACT_BE_U_4(tptr
),
2410 EXTRACT_BE_U_4(tptr
+ 4),
2411 EXTRACT_BE_U_4(tptr
+ 8),
2412 (len
> 12) ? ", " : ""));
2418 ND_TCHECK_LEN(pptr
, len
);
2419 ND_PRINT((ndo
, "\n\t no Attribute %u decoder", atype
)); /* we have no decoder for the attribute */
2420 if (ndo
->ndo_vflag
<= 1)
2421 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2424 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2425 ND_TCHECK_LEN(pptr
, len
);
2426 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2435 bgp_capabilities_print(netdissect_options
*ndo
,
2436 const u_char
*opt
, u_int caps_len
)
2438 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2441 while (i
< caps_len
) {
2442 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2443 cap_type
=EXTRACT_U_1(opt
+ i
);
2444 cap_len
=EXTRACT_U_1(opt
+ i
+ 1);
2446 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2447 tok2str(bgp_capcode_values
, "Unknown",
2451 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2453 case BGP_CAPCODE_MP
:
2454 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u)",
2455 tok2str(af_values
, "Unknown",
2456 EXTRACT_BE_U_2(opt
+ i
+ 2)),
2457 EXTRACT_BE_U_2(opt
+ i
+ 2),
2458 tok2str(bgp_safi_values
, "Unknown",
2459 EXTRACT_U_1(opt
+ i
+ 5)),
2460 EXTRACT_U_1(opt
+ i
+ 5)));
2462 case BGP_CAPCODE_RESTART
:
2463 ND_PRINT((ndo
, "\n\t\tRestart Flags: [%s], Restart Time %us",
2464 ((EXTRACT_U_1(opt
+ i
+ 2))&0x80) ? "R" : "none",
2465 EXTRACT_BE_U_2(opt
+ i
+ 2)&0xfff));
2468 while(tcap_len
>=4) {
2469 ND_PRINT((ndo
, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2470 tok2str(af_values
,"Unknown",
2471 EXTRACT_BE_U_2(opt
+ i
+ cap_offset
)),
2472 EXTRACT_BE_U_2(opt
+ i
+ cap_offset
),
2473 tok2str(bgp_safi_values
,"Unknown",
2474 EXTRACT_U_1(opt
+ i
+ cap_offset
+ 2)),
2475 EXTRACT_U_1(opt
+ (i
+ cap_offset
+ 2)),
2476 ((EXTRACT_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" ));
2481 case BGP_CAPCODE_RR
:
2482 case BGP_CAPCODE_RR_CISCO
:
2484 case BGP_CAPCODE_AS_NEW
:
2487 * Extract the 4 byte AS number encoded.
2490 ND_PRINT((ndo
, "\n\t\t 4 Byte AS %s",
2491 as_printf(ndo
, astostr
, sizeof(astostr
),
2492 EXTRACT_BE_U_4(opt
+ i
+ 2))));
2495 case BGP_CAPCODE_ADD_PATH
:
2497 if (tcap_len
== 0) {
2498 ND_PRINT((ndo
, " (bogus)")); /* length */
2501 while (tcap_len
> 0) {
2503 ND_PRINT((ndo
, "\n\t\t(invalid)"));
2506 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2507 tok2str(af_values
,"Unknown",EXTRACT_BE_U_2(opt
+ i
+ cap_offset
)),
2508 EXTRACT_BE_U_2(opt
+ i
+ cap_offset
),
2509 tok2str(bgp_safi_values
,"Unknown",EXTRACT_U_1(opt
+ i
+ cap_offset
+ 2)),
2510 EXTRACT_U_1(opt
+ (i
+ cap_offset
+ 2)),
2511 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",EXTRACT_U_1(opt
+ i
+ cap_offset
+ 3))
2518 ND_PRINT((ndo
, "\n\t\tno decoder for Capability %u",
2520 if (ndo
->ndo_vflag
<= 1)
2521 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2525 if (ndo
->ndo_vflag
> 1 && cap_len
> 0) {
2526 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2528 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2533 ND_PRINT((ndo
, "[|BGP]"));
2537 bgp_open_print(netdissect_options
*ndo
,
2538 const u_char
*dat
, u_int length
)
2540 const struct bgp_open
*bgp_open_header
;
2542 const struct bgp_opt
*bgpopt
;
2546 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2547 if (length
< BGP_OPEN_SIZE
)
2550 bgp_open_header
= (const struct bgp_open
*)dat
;
2552 ND_PRINT((ndo
, "\n\t Version %u, ",
2553 EXTRACT_U_1(bgp_open_header
->bgpo_version
)));
2554 ND_PRINT((ndo
, "my AS %s, ",
2555 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_2(bgp_open_header
->bgpo_myas
))));
2556 ND_PRINT((ndo
, "Holdtime %us, ",
2557 EXTRACT_BE_U_2(bgp_open_header
->bgpo_holdtime
)));
2558 ND_PRINT((ndo
, "ID %s", ipaddr_string(ndo
, &bgp_open_header
->bgpo_id
)));
2559 optslen
= EXTRACT_U_1(bgp_open_header
->bgpo_optlen
);
2560 ND_PRINT((ndo
, "\n\t Optional parameters, length: %u", optslen
));
2562 opt
= dat
+ BGP_OPEN_SIZE
;
2563 length
-= BGP_OPEN_SIZE
;
2566 while (i
< optslen
) {
2567 uint8_t opt_type
, opt_len
;
2569 ND_TCHECK_LEN(opt
+ i
, BGP_OPT_SIZE
);
2570 if (length
< BGP_OPT_SIZE
+ i
)
2572 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2573 opt_type
= EXTRACT_U_1(bgpopt
->bgpopt_type
);
2574 opt_len
= EXTRACT_U_1(bgpopt
->bgpopt_len
);
2575 if (BGP_OPT_SIZE
+ i
+ opt_len
> optslen
) {
2576 ND_PRINT((ndo
, "\n\t Option %u, length: %u, goes past the end of the options",
2577 opt_type
, opt_len
));
2581 ND_PRINT((ndo
, "\n\t Option %s (%u), length: %u",
2582 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2586 /* now let's decode the options we know*/
2590 bgp_capabilities_print(ndo
, opt
+ BGP_OPT_SIZE
+ i
,
2596 ND_PRINT((ndo
, "\n\t no decoder for option %u",
2600 i
+= BGP_OPT_SIZE
+ opt_len
;
2604 ND_PRINT((ndo
, "[|BGP]"));
2608 bgp_update_print(netdissect_options
*ndo
,
2609 const u_char
*dat
, int length
)
2611 const struct bgp
*bgp_header
;
2613 int withdrawn_routes_len
;
2614 char buf
[MAXHOSTNAMELEN
+ 100];
2621 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2622 if (length
< BGP_SIZE
)
2624 bgp_header
= (const struct bgp
*)dat
;
2628 /* Unfeasible routes */
2632 withdrawn_routes_len
= EXTRACT_BE_U_2(p
);
2635 if (withdrawn_routes_len
> 1) {
2637 * Without keeping state from the original NLRI message,
2638 * it's not possible to tell if this a v4 or v6 route,
2639 * so only try to decode it if we're not v6 enabled.
2641 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2642 if (length
< withdrawn_routes_len
)
2645 ND_PRINT((ndo
, "\n\t Withdrawn routes:"));
2646 add_path
= check_add_path(p
, withdrawn_routes_len
, 32);
2647 while(withdrawn_routes_len
> 0) {
2649 path_id
= EXTRACT_32BITS(p
);
2652 withdrawn_routes_len
-= 4;
2654 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2656 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2658 } else if (wpfx
== -2)
2660 else if (wpfx
== -3)
2661 goto trunc
; /* bytes left, but not enough */
2663 ND_PRINT((ndo
, "\n\t %s", buf
));
2665 ND_PRINT((ndo
, " Path Id: %d", path_id
));
2669 withdrawn_routes_len
-= wpfx
;
2673 p
+= withdrawn_routes_len
;
2674 length
-= withdrawn_routes_len
;
2680 len
= EXTRACT_BE_U_2(p
);
2684 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2685 /* No withdrawn routes, no path attributes, no NLRI */
2686 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
2691 /* do something more useful!*/
2693 int aflags
, atype
, alenlen
, alen
;
2700 aflags
= EXTRACT_U_1(p
);
2701 atype
= EXTRACT_U_1(p
+ 1);
2705 alenlen
= bgp_attr_lenlen(aflags
, p
);
2706 ND_TCHECK_LEN(p
, alenlen
);
2709 if (length
< alenlen
)
2711 alen
= bgp_attr_len(aflags
, p
);
2716 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2717 tok2str(bgp_attr_values
, "Unknown Attribute",
2723 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2724 aflags
& 0x80 ? "O" : "",
2725 aflags
& 0x40 ? "T" : "",
2726 aflags
& 0x20 ? "P" : "",
2727 aflags
& 0x10 ? "E" : ""));
2729 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2730 ND_PRINT((ndo
, "]: "));
2736 if (!bgp_attr_print(ndo
, atype
, p
, alen
))
2745 add_path
= check_add_path(p
, length
, 32);
2746 ND_PRINT((ndo
, "\n\t Updated routes:"));
2747 while (length
> 0) {
2749 path_id
= EXTRACT_32BITS(p
);
2753 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2755 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2760 goto trunc
; /* bytes left, but not enough */
2762 ND_PRINT((ndo
, "\n\t %s", buf
));
2764 ND_PRINT((ndo
, " Path Id: %d", path_id
));
2773 ND_PRINT((ndo
, "[|BGP]"));
2777 bgp_notification_print(netdissect_options
*ndo
,
2778 const u_char
*dat
, int length
)
2780 const struct bgp_notification
*bgp_notification_header
;
2782 uint8_t bgpn_major
, bgpn_minor
;
2783 uint8_t shutdown_comm_length
;
2784 uint8_t remainder_offset
;
2786 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
2787 if (length
<BGP_NOTIFICATION_SIZE
)
2790 bgp_notification_header
= (const struct bgp_notification
*)dat
;
2791 bgpn_major
= EXTRACT_U_1(bgp_notification_header
->bgpn_major
);
2792 bgpn_minor
= EXTRACT_U_1(bgp_notification_header
->bgpn_minor
);
2794 ND_PRINT((ndo
, ", %s (%u)",
2795 tok2str(bgp_notify_major_values
, "Unknown Error",
2799 switch (bgpn_major
) {
2801 case BGP_NOTIFY_MAJOR_MSG
:
2802 ND_PRINT((ndo
, ", subcode %s (%u)",
2803 tok2str(bgp_notify_minor_msg_values
, "Unknown",
2807 case BGP_NOTIFY_MAJOR_OPEN
:
2808 ND_PRINT((ndo
, ", subcode %s (%u)",
2809 tok2str(bgp_notify_minor_open_values
, "Unknown",
2813 case BGP_NOTIFY_MAJOR_UPDATE
:
2814 ND_PRINT((ndo
, ", subcode %s (%u)",
2815 tok2str(bgp_notify_minor_update_values
, "Unknown",
2819 case BGP_NOTIFY_MAJOR_FSM
:
2820 ND_PRINT((ndo
, " subcode %s (%u)",
2821 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
2825 case BGP_NOTIFY_MAJOR_CAP
:
2826 ND_PRINT((ndo
, " subcode %s (%u)",
2827 tok2str(bgp_notify_minor_cap_values
, "Unknown",
2831 case BGP_NOTIFY_MAJOR_CEASE
:
2832 ND_PRINT((ndo
, ", subcode %s (%u)",
2833 tok2str(bgp_notify_minor_cease_values
, "Unknown",
2837 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2838 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2840 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2841 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2843 ND_PRINT((ndo
, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2844 tok2str(af_values
, "Unknown",
2845 EXTRACT_BE_U_2(tptr
)),
2846 EXTRACT_BE_U_2(tptr
),
2847 tok2str(bgp_safi_values
, "Unknown", EXTRACT_U_1((tptr
+ 2))),
2848 EXTRACT_U_1((tptr
+ 2)),
2849 EXTRACT_BE_U_4(tptr
+ 3)));
2852 * draft-ietf-idr-shutdown describes a method to send a communication
2853 * intended for human consumption regarding the Administrative Shutdown
2855 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
2856 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
2857 length
>= BGP_NOTIFICATION_SIZE
+ 1) {
2858 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2860 shutdown_comm_length
= EXTRACT_U_1(tptr
);
2861 remainder_offset
= 0;
2862 /* garbage, hexdump it all */
2863 if (shutdown_comm_length
> BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN
||
2864 shutdown_comm_length
> length
- (BGP_NOTIFICATION_SIZE
+ 1)) {
2865 ND_PRINT((ndo
, ", invalid Shutdown Communication length"));
2867 else if (shutdown_comm_length
== 0) {
2868 ND_PRINT((ndo
, ", empty Shutdown Communication"));
2869 remainder_offset
+= 1;
2871 /* a proper shutdown communication */
2873 ND_TCHECK_LEN(tptr
+ 1, shutdown_comm_length
);
2874 ND_PRINT((ndo
, ", Shutdown Communication (length: %u): \"", shutdown_comm_length
));
2875 (void)fn_printn(ndo
, tptr
+1, shutdown_comm_length
, NULL
);
2876 ND_PRINT((ndo
, "\""));
2877 remainder_offset
+= shutdown_comm_length
+ 1;
2879 /* if there is trailing data, hexdump it */
2880 if(length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
) > 0) {
2881 ND_PRINT((ndo
, ", Data: (length: %u)", length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
)));
2882 hex_print(ndo
, "\n\t\t", tptr
+ remainder_offset
, length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
2892 ND_PRINT((ndo
, "[|BGP]"));
2896 bgp_route_refresh_print(netdissect_options
*ndo
,
2897 const u_char
*pptr
, int len
)
2899 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2901 ND_TCHECK_LEN(pptr
, BGP_ROUTE_REFRESH_SIZE
);
2903 /* some little sanity checking */
2904 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2907 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2909 ND_PRINT((ndo
, "\n\t AFI %s (%u), SAFI %s (%u)",
2910 tok2str(af_values
,"Unknown",
2911 EXTRACT_BE_U_2(bgp_route_refresh_header
->afi
)),
2912 EXTRACT_BE_U_2(bgp_route_refresh_header
->afi
),
2913 tok2str(bgp_safi_values
,"Unknown",
2914 EXTRACT_U_1(bgp_route_refresh_header
->safi
)),
2915 EXTRACT_U_1(bgp_route_refresh_header
->safi
)));
2917 if (ndo
->ndo_vflag
> 1) {
2918 ND_TCHECK_LEN(pptr
, len
);
2919 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2924 ND_PRINT((ndo
, "[|BGP]"));
2928 bgp_pdu_print(netdissect_options
*ndo
,
2929 const u_char
*dat
, u_int length
)
2931 const struct bgp
*bgp_header
;
2934 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2935 bgp_header
= (const struct bgp
*)dat
;
2936 bgp_type
= EXTRACT_U_1(bgp_header
->bgp_type
);
2938 ND_PRINT((ndo
, "\n\t%s Message (%u), length: %u",
2939 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
2945 bgp_open_print(ndo
, dat
, length
);
2948 bgp_update_print(ndo
, dat
, length
);
2950 case BGP_NOTIFICATION
:
2951 bgp_notification_print(ndo
, dat
, length
);
2955 case BGP_ROUTE_REFRESH
:
2956 bgp_route_refresh_print(ndo
, dat
, length
);
2959 /* we have no decoder for the BGP message */
2960 ND_TCHECK_LEN(dat
, length
);
2961 ND_PRINT((ndo
, "\n\t no Message %u decoder", bgp_type
));
2962 print_unknown_data(ndo
, dat
, "\n\t ", length
);
2967 ND_PRINT((ndo
, "[|BGP]"));
2972 bgp_print(netdissect_options
*ndo
,
2973 const u_char
*dat
, int length
)
2977 const u_char
*start
;
2978 const u_char marker
[] = {
2979 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2980 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2982 const struct bgp
*bgp_header
;
2986 if (ndo
->ndo_snapend
< dat
+ length
)
2987 ep
= ndo
->ndo_snapend
;
2989 ND_PRINT((ndo
, ": BGP"));
2991 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
2999 if (EXTRACT_U_1(p
) != 0xff) {
3004 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
3006 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
3011 /* found BGP header */
3012 ND_TCHECK_LEN(p
, BGP_SIZE
);
3013 bgp_header
= (const struct bgp
*)p
;
3016 ND_PRINT((ndo
, " [|BGP]"));
3018 hlen
= EXTRACT_BE_U_2(bgp_header
->bgp_len
);
3019 if (hlen
< BGP_SIZE
) {
3020 ND_PRINT((ndo
, "\n[|BGP Bogus header length %u < %u]", hlen
,
3025 if (ND_TTEST_LEN(p
, hlen
)) {
3026 if (!bgp_pdu_print(ndo
, p
, hlen
))
3031 ND_PRINT((ndo
, "\n[|BGP %s]",
3032 tok2str(bgp_msg_values
,
3033 "Unknown Message Type",
3034 EXTRACT_U_1(bgp_header
->bgp_type
))));
3042 ND_PRINT((ndo
, " [|BGP]"));
3047 * c-style: whitesmith