2 * Copyright (C) 1999 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Extensively modified by Hannes Gredler (hannes@gredler.at) for more
30 * complete BGP support.
33 /* \summary: Border Gateway Protocol (BGP) printer */
35 /* specification: RFC 4271 */
41 #include "netdissect-stdinc.h"
46 #include "netdissect.h"
47 #include "addrtoname.h"
53 nd_byte bgp_marker
[16];
57 #define BGP_SIZE 19 /* unaligned */
61 #define BGP_NOTIFICATION 3
62 #define BGP_KEEPALIVE 4
63 #define BGP_ROUTE_REFRESH 5
65 static const struct tok bgp_msg_values
[] = {
67 { BGP_UPDATE
, "Update"},
68 { BGP_NOTIFICATION
, "Notification"},
69 { BGP_KEEPALIVE
, "Keepalive"},
70 { BGP_ROUTE_REFRESH
, "Route Refresh"},
75 nd_byte bgpo_marker
[16];
78 nd_uint8_t bgpo_version
;
79 nd_uint16_t bgpo_myas
;
80 nd_uint16_t bgpo_holdtime
;
82 nd_uint8_t bgpo_optlen
;
83 /* options should follow */
85 #define BGP_OPEN_SIZE 29 /* unaligned */
88 nd_uint8_t bgpopt_type
;
89 nd_uint8_t bgpopt_len
;
92 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
93 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
95 struct bgp_notification
{
96 nd_byte bgpn_marker
[16];
99 nd_uint8_t bgpn_major
;
100 nd_uint8_t bgpn_minor
;
102 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
104 struct bgp_route_refresh
{
105 nd_byte bgp_marker
[16];
107 nd_uint8_t type
; /* No padding after this; afi is, in fact, not aligned */
112 #define BGP_ROUTE_REFRESH_SIZE 23
114 #define bgp_attr_lenlen(flags, p) \
115 (((flags) & 0x10) ? 2U : 1U)
116 #define bgp_attr_len(flags, p) \
117 (((flags) & 0x10) ? GET_BE_U_2(p) : GET_U_1(p))
119 #define BGPTYPE_ORIGIN 1
120 #define BGPTYPE_AS_PATH 2
121 #define BGPTYPE_NEXT_HOP 3
122 #define BGPTYPE_MULTI_EXIT_DISC 4
123 #define BGPTYPE_LOCAL_PREF 5
124 #define BGPTYPE_ATOMIC_AGGREGATE 6
125 #define BGPTYPE_AGGREGATOR 7
126 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
127 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC4456 */
128 #define BGPTYPE_CLUSTER_LIST 10 /* RFC4456 */
129 #define BGPTYPE_DPA 11 /* deprecated, draft-ietf-idr-bgp-dpa */
130 #define BGPTYPE_ADVERTISERS 12 /* deprecated RFC1863 */
131 #define BGPTYPE_RCID_PATH 13 /* deprecated RFC1863 */
132 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */
133 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */
134 #define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */
135 #define BGPTYPE_AS4_PATH 17 /* RFC6793 */
136 #define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */
137 #define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */
138 #define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */
139 #define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */
140 #define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */
141 #define BGPTYPE_AIGP 26 /* RFC7311 */
142 #define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */
143 #define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */
144 #define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */
145 #define BGPTYPE_ATTR_SET 128 /* RFC6368 */
147 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
149 static const struct tok bgp_attr_values
[] = {
150 { BGPTYPE_ORIGIN
, "Origin"},
151 { BGPTYPE_AS_PATH
, "AS Path"},
152 { BGPTYPE_AS4_PATH
, "AS4 Path"},
153 { BGPTYPE_NEXT_HOP
, "Next Hop"},
154 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
155 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
156 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
157 { BGPTYPE_AGGREGATOR
, "Aggregator"},
158 { BGPTYPE_AGGREGATOR4
, "Aggregator4"},
159 { BGPTYPE_COMMUNITIES
, "Community"},
160 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
161 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
162 { BGPTYPE_DPA
, "DPA"},
163 { BGPTYPE_ADVERTISERS
, "Advertisers"},
164 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
165 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
166 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
167 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
168 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
169 { BGPTYPE_TUNNEL_ENCAP
, "Tunnel Encapsulation"},
170 { BGPTYPE_TRAFFIC_ENG
, "Traffic Engineering"},
171 { BGPTYPE_IPV6_EXTD_COMMUNITIES
, "IPv6 Extended Community"},
172 { BGPTYPE_AIGP
, "Accumulated IGP Metric"},
173 { BGPTYPE_PE_DISTINGUISHER_LABEL
, "PE Distinguisher Label"},
174 { BGPTYPE_ENTROPY_LABEL
, "Entropy Label"},
175 { BGPTYPE_LARGE_COMMUNITY
, "Large Community"},
176 { BGPTYPE_ATTR_SET
, "Attribute Set"},
177 { 255, "Reserved for development"},
182 #define BGP_AS_SEQUENCE 2
183 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
184 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
186 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
187 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
189 static const struct tok bgp_as_path_segment_open_values
[] = {
190 { BGP_AS_SEQUENCE
, ""},
192 { BGP_CONFED_AS_SEQUENCE
, "( "},
193 { BGP_CONFED_AS_SET
, "({ "},
197 static const struct tok bgp_as_path_segment_close_values
[] = {
198 { BGP_AS_SEQUENCE
, ""},
200 { BGP_CONFED_AS_SEQUENCE
, ")"},
201 { BGP_CONFED_AS_SET
, "})"},
205 #define BGP_OPT_AUTH 1
206 #define BGP_OPT_CAP 2
208 static const struct tok bgp_opt_values
[] = {
209 { BGP_OPT_AUTH
, "Authentication Information"},
210 { BGP_OPT_CAP
, "Capabilities Advertisement"},
214 #define BGP_CAPCODE_MP 1 /* RFC2858 */
215 #define BGP_CAPCODE_RR 2 /* RFC2918 */
216 #define BGP_CAPCODE_ORF 3 /* RFC5291 */
217 #define BGP_CAPCODE_MR 4 /* RFC3107 */
218 #define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */
219 #define BGP_CAPCODE_ML 8 /* RFC8277 */
220 #define BGP_CAPCODE_RESTART 64 /* RFC4724 */
221 #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */
222 #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */
223 #define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */
224 #define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */
225 #define BGP_CAPCODE_ENH_RR 70 /* draft-keyur-bgp-enhanced-route-refresh */
226 #define BGP_CAPCODE_RR_CISCO 128
228 static const struct tok bgp_capcode_values
[] = {
229 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
230 { BGP_CAPCODE_RR
, "Route Refresh"},
231 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
232 { BGP_CAPCODE_MR
, "Multiple Routes to a Destination"},
233 { BGP_CAPCODE_EXT_NH
, "Extended Next Hop Encoding"},
234 { BGP_CAPCODE_ML
, "Multiple Labels"},
235 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
236 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
237 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
238 { BGP_CAPCODE_MULTISESS
, "Multisession BGP"},
239 { BGP_CAPCODE_ADD_PATH
, "Multiple Paths"},
240 { BGP_CAPCODE_ENH_RR
, "Enhanced Route Refresh"},
241 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
245 #define BGP_NOTIFY_MAJOR_MSG 1
246 #define BGP_NOTIFY_MAJOR_OPEN 2
247 #define BGP_NOTIFY_MAJOR_UPDATE 3
248 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
249 #define BGP_NOTIFY_MAJOR_FSM 5
250 #define BGP_NOTIFY_MAJOR_CEASE 6
251 #define BGP_NOTIFY_MAJOR_CAP 7
253 static const struct tok bgp_notify_major_values
[] = {
254 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
255 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
256 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
257 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
258 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
259 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
260 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
264 /* draft-ietf-idr-cease-subcode-02 */
265 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
266 /* draft-ietf-idr-shutdown-07 */
267 #define BGP_NOTIFY_MINOR_CEASE_SHUT 2
268 #define BGP_NOTIFY_MINOR_CEASE_RESET 4
269 #define BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN 128
270 static const struct tok bgp_notify_minor_cease_values
[] = {
271 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
272 { BGP_NOTIFY_MINOR_CEASE_SHUT
, "Administrative Shutdown"},
273 { 3, "Peer Unconfigured"},
274 { BGP_NOTIFY_MINOR_CEASE_RESET
, "Administrative Reset"},
275 { 5, "Connection Rejected"},
276 { 6, "Other Configuration Change"},
277 { 7, "Connection Collision Resolution"},
281 static const struct tok bgp_notify_minor_msg_values
[] = {
282 { 1, "Connection Not Synchronized"},
283 { 2, "Bad Message Length"},
284 { 3, "Bad Message Type"},
288 static const struct tok bgp_notify_minor_open_values
[] = {
289 { 1, "Unsupported Version Number"},
291 { 3, "Bad BGP Identifier"},
292 { 4, "Unsupported Optional Parameter"},
293 { 5, "Authentication Failure"},
294 { 6, "Unacceptable Hold Time"},
295 { 7, "Capability Message Error"},
299 static const struct tok bgp_notify_minor_update_values
[] = {
300 { 1, "Malformed Attribute List"},
301 { 2, "Unrecognized Well-known Attribute"},
302 { 3, "Missing Well-known Attribute"},
303 { 4, "Attribute Flags Error"},
304 { 5, "Attribute Length Error"},
305 { 6, "Invalid ORIGIN Attribute"},
306 { 7, "AS Routing Loop"},
307 { 8, "Invalid NEXT_HOP Attribute"},
308 { 9, "Optional Attribute Error"},
309 { 10, "Invalid Network Field"},
310 { 11, "Malformed AS_PATH"},
314 static const struct tok bgp_notify_minor_fsm_values
[] = {
315 { 0, "Unspecified Error"},
316 { 1, "In OpenSent State"},
317 { 2, "In OpenConfirm State"},
318 { 3, "In Established State"},
322 static const struct tok bgp_notify_minor_cap_values
[] = {
323 { 1, "Invalid Action Value" },
324 { 2, "Invalid Capability Length" },
325 { 3, "Malformed Capability Value" },
326 { 4, "Unsupported Capability Code" },
330 static const struct tok bgp_origin_values
[] = {
337 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
338 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
339 #define BGP_PMSI_TUNNEL_PIM_SSM 3
340 #define BGP_PMSI_TUNNEL_PIM_SM 4
341 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
342 #define BGP_PMSI_TUNNEL_INGRESS 6
343 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
345 static const struct tok bgp_pmsi_tunnel_values
[] = {
346 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
347 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
348 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
349 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
350 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
351 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
352 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
356 static const struct tok bgp_pmsi_flag_values
[] = {
357 { 0x01, "Leaf Information required"},
361 #define BGP_AIGP_TLV 1
363 static const struct tok bgp_aigp_values
[] = {
364 { BGP_AIGP_TLV
, "AIGP"},
368 /* Subsequent address family identifier, RFC2283 section 7 */
370 #define SAFNUM_UNICAST 1
371 #define SAFNUM_MULTICAST 2
372 #define SAFNUM_UNIMULTICAST 3 /* deprecated now */
373 /* labeled BGP RFC3107 */
374 #define SAFNUM_LABUNICAST 4
376 #define SAFNUM_MULTICAST_VPN 5
377 /* draft-nalawade-kapoor-tunnel-safi */
378 #define SAFNUM_TUNNEL 64
380 #define SAFNUM_VPLS 65
382 #define SAFNUM_MDT 66
384 #define SAFNUM_VPNUNICAST 128
386 #define SAFNUM_VPNMULTICAST 129
387 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
389 #define SAFNUM_RT_ROUTING_INFO 132
391 #define BGP_VPN_RD_LEN 8
393 static const struct tok bgp_safi_values
[] = {
394 { SAFNUM_RES
, "Reserved"},
395 { SAFNUM_UNICAST
, "Unicast"},
396 { SAFNUM_MULTICAST
, "Multicast"},
397 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
398 { SAFNUM_LABUNICAST
, "labeled Unicast"},
399 { SAFNUM_TUNNEL
, "Tunnel"},
400 { SAFNUM_VPLS
, "VPLS"},
401 { SAFNUM_MDT
, "MDT"},
402 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
403 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
404 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
405 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
406 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
410 /* well-known community */
411 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
412 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
413 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
415 /* Extended community type - RFC 4360 */
416 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
417 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
418 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
419 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
420 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
421 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
422 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
423 /* rfc2547 bgp-mpls-vpns */
424 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
425 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatibility */
426 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatibility */
427 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatibility */
429 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
430 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatibility */
432 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
433 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatibility */
435 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
437 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
438 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
439 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
440 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
442 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
443 #define BGP_EXT_COM_EIGRP_GEN 0x8800
444 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
445 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
446 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
447 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
448 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
450 static const struct tok bgp_extd_comm_flag_values
[] = {
451 { 0x8000, "vendor-specific"},
452 { 0x4000, "non-transitive"},
456 static const struct tok bgp_extd_comm_subtype_values
[] = {
457 { BGP_EXT_COM_RT_0
, "target"},
458 { BGP_EXT_COM_RT_1
, "target"},
459 { BGP_EXT_COM_RT_2
, "target"},
460 { BGP_EXT_COM_RO_0
, "origin"},
461 { BGP_EXT_COM_RO_1
, "origin"},
462 { BGP_EXT_COM_RO_2
, "origin"},
463 { BGP_EXT_COM_LINKBAND
, "link-BW"},
464 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
465 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
466 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
467 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
468 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
469 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
470 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
471 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
472 { BGP_EXT_COM_L2INFO
, "layer2-info"},
473 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
474 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
475 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
476 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
477 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
478 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
479 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
480 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
481 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
482 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
486 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
487 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
488 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
489 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
490 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
491 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
492 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
493 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
495 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
496 { BGP_OSPF_RTYPE_RTR
, "Router" },
497 { BGP_OSPF_RTYPE_NET
, "Network" },
498 { BGP_OSPF_RTYPE_SUM
, "Summary" },
499 { BGP_OSPF_RTYPE_EXT
, "External" },
500 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
501 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
505 /* ADD-PATH Send/Receive field values */
506 static const struct tok bgp_add_path_recvsend
[] = {
513 static char astostr
[20];
518 * Convert an AS number into a string and return string pointer.
520 * Depending on bflag is set or not, AS number is converted into ASDOT notation
521 * or plain number notation.
525 as_printf(netdissect_options
*ndo
,
526 char *str
, size_t size
, u_int asnum
)
528 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
529 snprintf(str
, size
, "%u", asnum
);
531 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
536 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
539 decode_prefix4(netdissect_options
*ndo
,
540 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
543 u_int plen
, plenbytes
;
547 plen
= GET_U_1(pptr
);
552 memset(&addr
, 0, sizeof(addr
));
553 plenbytes
= (plen
+ 7) / 8;
554 ND_TCHECK_LEN(pptr
+ 1, plenbytes
);
555 ITEMCHECK(plenbytes
);
556 memcpy(&addr
, pptr
+ 1, plenbytes
);
558 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
560 snprintf(buf
, buflen
, "%s/%u", ipaddr_string(ndo
, (const u_char
*)&addr
), plen
);
561 return 1 + plenbytes
;
571 decode_labeled_prefix4(netdissect_options
*ndo
,
572 const u_char
*pptr
, u_int itemlen
, char *buf
,
576 u_int plen
, plenbytes
;
578 /* prefix length and label = 4 bytes */
581 plen
= GET_U_1(pptr
); /* get prefix length */
583 /* this is one of the weirdnesses of rfc3107
584 the label length (actually the label + COS bits)
585 is added to the prefix length;
586 we also do only read out just one label -
587 there is no real application for advertisement of
588 stacked labels in a single BGP message
594 plen
-=24; /* adjust prefixlen - labellength */
600 memset(&addr
, 0, sizeof(addr
));
601 plenbytes
= (plen
+ 7) / 8;
602 ND_TCHECK_LEN(pptr
+ 4, plenbytes
);
603 ITEMCHECK(plenbytes
);
604 memcpy(&addr
, pptr
+ 4, plenbytes
);
606 ((u_char
*)&addr
)[plenbytes
- 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
608 /* the label may get offsetted by 4 bits so lets shift it right */
609 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
610 ipaddr_string(ndo
, (const u_char
*)&addr
),
612 GET_BE_U_3(pptr
+ 1)>>4,
613 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
615 return 4 + plenbytes
;
627 * print an ipv4 or ipv6 address into a buffer dependend on address length.
630 bgp_vpn_ip_print(netdissect_options
*ndo
,
631 const u_char
*pptr
, u_int addr_length
)
634 /* worst case string is s fully formatted v6 address */
635 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
638 switch(addr_length
) {
639 case (sizeof(nd_ipv4
) << 3): /* 32 */
640 ND_TCHECK_LEN(pptr
, sizeof(nd_ipv4
));
641 snprintf(pos
, sizeof(addr
), "%s", ipaddr_string(ndo
, pptr
));
643 case (sizeof(nd_ipv6
) << 3): /* 128 */
644 ND_TCHECK_LEN(pptr
, sizeof(nd_ipv6
));
645 snprintf(pos
, sizeof(addr
), "%s", ip6addr_string(ndo
, pptr
));
648 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
661 * print an multicast s,g entry into a buffer.
662 * the s,g entry is encoded like this.
664 * +-----------------------------------+
665 * | Multicast Source Length (1 octet) |
666 * +-----------------------------------+
667 * | Multicast Source (Variable) |
668 * +-----------------------------------+
669 * | Multicast Group Length (1 octet) |
670 * +-----------------------------------+
671 * | Multicast Group (Variable) |
672 * +-----------------------------------+
674 * return the number of bytes read from the wire.
677 bgp_vpn_sg_print(netdissect_options
*ndo
,
678 const u_char
*pptr
, char *buf
, size_t buflen
)
681 u_int total_length
, offset
;
685 /* Source address length, encoded in bits */
687 addr_length
= GET_U_1(pptr
);
691 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
692 total_length
+= (addr_length
>> 3) + 1;
693 offset
= (u_int
)strlen(buf
);
695 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
696 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
697 pptr
+= (addr_length
>> 3);
700 /* Group address length, encoded in bits */
702 addr_length
= GET_U_1(pptr
);
706 ND_TCHECK_LEN(pptr
, (addr_length
>> 3));
707 total_length
+= (addr_length
>> 3) + 1;
708 offset
= (u_int
)strlen(buf
);
710 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
711 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
712 pptr
+= (addr_length
>> 3);
716 return (total_length
);
719 /* Print an RFC 4364 Route Distinguisher */
721 bgp_vpn_rd_print(netdissect_options
*ndo
,
724 /* allocate space for the largest possible string */
725 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
728 /* ok lets load the RD format */
729 switch (GET_BE_U_2(pptr
)) {
732 /* 2-byte-AS:number fmt */
733 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
734 GET_BE_U_2(pptr
+ 2),
735 GET_BE_U_4(pptr
+ 4),
736 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
737 GET_U_1(pptr
+ 6), GET_U_1(pptr
+ 7));
741 /* IP-address:AS fmt */
742 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
743 GET_U_1(pptr
+ 2), GET_U_1(pptr
+ 3),
744 GET_U_1(pptr
+ 4), GET_U_1(pptr
+ 5),
745 GET_BE_U_2(pptr
+ 6));
749 /* 4-byte-AS:number fmt */
750 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
751 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(pptr
+ 2)),
752 GET_BE_U_2(pptr
+ 6), GET_U_1(pptr
+ 2),
753 GET_U_1(pptr
+ 3), GET_U_1(pptr
+ 4),
754 GET_U_1(pptr
+ 5), GET_BE_U_2(pptr
+ 6));
757 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
766 * Print an RFC 4360 Extended Community.
769 bgp_extended_community_print(netdissect_options
*ndo
,
772 union { /* copy buffer for bandwidth values */
777 switch (GET_BE_U_2(pptr
)) {
779 case BGP_EXT_COM_RT_0
:
780 case BGP_EXT_COM_RO_0
:
781 case BGP_EXT_COM_L2VPN_RT_0
:
782 ND_PRINT("%u:%u (= %s)",
783 GET_BE_U_2(pptr
+ 2),
784 GET_BE_U_4(pptr
+ 4),
785 ipaddr_string(ndo
, pptr
+4));
788 case BGP_EXT_COM_RT_1
:
789 case BGP_EXT_COM_RO_1
:
790 case BGP_EXT_COM_L2VPN_RT_1
:
791 case BGP_EXT_COM_VRF_RT_IMP
:
793 ipaddr_string(ndo
, pptr
+2),
794 GET_BE_U_2(pptr
+ 6));
797 case BGP_EXT_COM_RT_2
:
798 case BGP_EXT_COM_RO_2
:
800 as_printf(ndo
, astostr
, sizeof(astostr
),
801 GET_BE_U_4(pptr
+ 2)), GET_BE_U_2(pptr
+ 6));
804 case BGP_EXT_COM_LINKBAND
:
805 bw
.i
= GET_BE_U_4(pptr
+ 2);
806 ND_PRINT("bandwidth: %.3f Mbps",
810 case BGP_EXT_COM_VPN_ORIGIN
:
811 case BGP_EXT_COM_VPN_ORIGIN2
:
812 case BGP_EXT_COM_VPN_ORIGIN3
:
813 case BGP_EXT_COM_VPN_ORIGIN4
:
814 case BGP_EXT_COM_OSPF_RID
:
815 case BGP_EXT_COM_OSPF_RID2
:
816 ND_PRINT("%s", ipaddr_string(ndo
, pptr
+2));
819 case BGP_EXT_COM_OSPF_RTYPE
:
820 case BGP_EXT_COM_OSPF_RTYPE2
:
821 ND_PRINT("area:%s, router-type:%s, metric-type:%s%s",
822 ipaddr_string(ndo
, pptr
+2),
823 tok2str(bgp_extd_comm_ospf_rtype_values
,
825 GET_U_1((pptr
+ 6))),
826 (GET_U_1(pptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
827 ((GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (GET_U_1(pptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : "");
830 case BGP_EXT_COM_L2INFO
:
831 ND_PRINT("%s Control Flags [0x%02x]:MTU %u",
832 tok2str(l2vpn_encaps_values
,
834 GET_U_1((pptr
+ 2))),
836 GET_BE_U_2(pptr
+ 4));
839 case BGP_EXT_COM_SOURCE_AS
:
840 ND_PRINT("AS %u", GET_BE_U_2(pptr
+ 2));
844 ND_PRINT("%02x%02x%02x%02x%02x%02x",
857 decode_rt_routing_info(netdissect_options
*ndo
,
861 char asbuf
[sizeof(astostr
)]; /* bgp_vpn_rd_print() overwrites astostr */
863 /* NLRI "prefix length" from RFC 2858 Section 4. */
865 plen
= GET_U_1(pptr
); /* get prefix length */
867 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
868 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
869 * target" fields inside the "prefix" depending on its length.
872 /* Without "origin AS", without "route target". */
873 ND_PRINT("\n\t default route target");
878 ND_PRINT("\n\t (illegal prefix length)");
882 /* With at least "origin AS", possibly with "route target". */
883 ND_TCHECK_4(pptr
+ 1);
884 as_printf(ndo
, asbuf
, sizeof(asbuf
), GET_BE_U_4(pptr
+ 1));
886 plen
-= 32; /* adjust prefix length */
888 /* An extended community is 8 octets, so the remaining prefix
892 ND_PRINT("\n\t (illegal prefix length)");
895 ND_TCHECK_LEN(pptr
+ 5, 8);
896 ND_PRINT("\n\t origin AS: %s, route target ", asbuf
);
897 bgp_extended_community_print(ndo
, pptr
+ 5);
906 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
907 const u_char
*pptr
, char *buf
, size_t buflen
)
913 plen
= GET_U_1(pptr
); /* get prefix length */
918 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
923 memset(&addr
, 0, sizeof(addr
));
924 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
925 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
927 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
928 ((0xff00 >> (plen
% 8)) & 0xff);
930 /* the label may get offsetted by 4 bits so lets shift it right */
931 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
932 bgp_vpn_rd_print(ndo
, pptr
+4),
933 ipaddr_string(ndo
, (const u_char
*)&addr
),
935 GET_BE_U_3(pptr
+ 1)>>4,
936 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
938 return 12 + (plen
+ 7) / 8;
945 * +-------------------------------+
947 * | RD:IPv4-address (12 octets) |
949 * +-------------------------------+
950 * | MDT Group-address (4 octets) |
951 * +-------------------------------+
954 #define MDT_VPN_NLRI_LEN 16
957 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
958 const u_char
*pptr
, char *buf
, size_t buflen
)
961 const u_char
*vpn_ip
;
965 /* if the NLRI is not predefined length, quit.*/
966 if (GET_U_1(pptr
) != MDT_VPN_NLRI_LEN
* 8)
976 ND_TCHECK_LEN(pptr
, sizeof(nd_ipv4
));
978 pptr
+= sizeof(nd_ipv4
);
980 /* MDT Group Address */
981 ND_TCHECK_LEN(pptr
, sizeof(nd_ipv4
));
983 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
984 bgp_vpn_rd_print(ndo
, rd
), ipaddr_string(ndo
, vpn_ip
), ipaddr_string(ndo
, pptr
));
986 return MDT_VPN_NLRI_LEN
+ 1;
992 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
993 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
994 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
995 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
996 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
997 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
998 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
1000 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
1001 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
1002 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
1003 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
1004 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
1005 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
1006 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
1007 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
1012 decode_multicast_vpn(netdissect_options
*ndo
,
1013 const u_char
*pptr
, char *buf
, size_t buflen
)
1015 uint8_t route_type
, route_length
;
1016 u_int addr_length
, sg_length
;
1020 route_type
= GET_U_1(pptr
);
1022 route_length
= GET_U_1(pptr
);
1025 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
1026 tok2str(bgp_multicast_vpn_route_type_values
,
1027 "Unknown", route_type
),
1028 route_type
, route_length
);
1030 switch(route_type
) {
1031 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
1032 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1033 offset
= (u_int
)strlen(buf
);
1034 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
1035 bgp_vpn_rd_print(ndo
, pptr
),
1036 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
1037 (route_length
- BGP_VPN_RD_LEN
) << 3));
1039 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
1040 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1041 offset
= (u_int
)strlen(buf
);
1042 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1043 bgp_vpn_rd_print(ndo
, pptr
),
1044 as_printf(ndo
, astostr
, sizeof(astostr
),
1045 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1048 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
1049 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1050 offset
= (u_int
)strlen(buf
);
1051 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1052 bgp_vpn_rd_print(ndo
, pptr
));
1053 pptr
+= BGP_VPN_RD_LEN
;
1055 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1056 addr_length
= route_length
- sg_length
;
1058 ND_TCHECK_LEN(pptr
, addr_length
);
1059 offset
= (u_int
)strlen(buf
);
1060 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
1061 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
1064 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
1065 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
);
1066 offset
= (u_int
)strlen(buf
);
1067 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
1068 bgp_vpn_rd_print(ndo
, pptr
));
1069 pptr
+= BGP_VPN_RD_LEN
;
1071 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1074 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
1075 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
1076 ND_TCHECK_LEN(pptr
, BGP_VPN_RD_LEN
+ 4);
1077 offset
= (u_int
)strlen(buf
);
1078 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
1079 bgp_vpn_rd_print(ndo
, pptr
),
1080 as_printf(ndo
, astostr
, sizeof(astostr
),
1081 GET_BE_U_4(pptr
+ BGP_VPN_RD_LEN
)));
1082 pptr
+= BGP_VPN_RD_LEN
+ 4;
1084 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
1088 * no per route-type printing yet.
1090 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1095 return route_length
+ 2;
1102 * As I remember, some versions of systems have an snprintf() that
1103 * returns -1 if the buffer would have overflowed. If the return
1104 * value is negative, set buflen to 0, to indicate that we've filled
1107 * If the return value is greater than buflen, that means that
1108 * the buffer would have overflowed; again, set buflen to 0 in
1111 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1114 else if ((u_int)stringlen>buflen) \
1117 buflen-=stringlen; \
1122 decode_labeled_vpn_l2(netdissect_options
*ndo
,
1123 const u_char
*pptr
, char *buf
, size_t buflen
)
1125 u_int plen
, tlen
, tlv_type
, tlv_len
, ttlv_len
;
1129 plen
= GET_BE_U_2(pptr
);
1132 /* Old and new L2VPN NLRI share AFI/SAFI
1133 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1134 * and > 17 as old format. Complain for the middle case
1137 /* assume AD-only with RD, BGPNH */
1138 ND_TCHECK_LEN(pptr
, 12);
1140 stringlen
= snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
1141 bgp_vpn_rd_print(ndo
, pptr
),
1142 ipaddr_string(ndo
, pptr
+8));
1143 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1147 } else if (plen
> 17) {
1148 /* assume old format */
1149 /* RD, ID, LBLKOFF, LBLBASE */
1151 ND_TCHECK_LEN(pptr
, 15);
1153 stringlen
= snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1154 bgp_vpn_rd_print(ndo
, pptr
),
1155 GET_BE_U_2(pptr
+ 8),
1156 GET_BE_U_2(pptr
+ 10),
1157 GET_BE_U_3(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1158 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1162 /* ok now the variable part - lets read out TLVs*/
1166 stringlen
=snprintf(buf
,buflen
, "\n\t\tran past the end");
1167 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1172 tlv_type
= GET_U_1(pptr
);
1174 tlv_len
= GET_BE_U_2(pptr
); /* length, in *bits* */
1175 ttlv_len
= (tlv_len
+ 7)/8; /* length, in *bytes* */
1181 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1184 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1186 while (ttlv_len
!= 0) {
1189 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1190 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1196 stringlen
=snprintf(buf
,buflen
, "%02x",
1199 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1207 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1210 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1212 if (tlen
< ttlv_len
) {
1214 stringlen
=snprintf(buf
,buflen
, " (ran past the end)");
1215 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1225 /* complain bitterly ? */
1235 decode_prefix6(netdissect_options
*ndo
,
1236 const u_char
*pd
, u_int itemlen
, char *buf
, size_t buflen
)
1239 u_int plen
, plenbytes
;
1248 memset(&addr
, 0, sizeof(addr
));
1249 plenbytes
= (plen
+ 7) / 8;
1250 ND_TCHECK_LEN(pd
+ 1, plenbytes
);
1251 ITEMCHECK(plenbytes
);
1252 memcpy(&addr
, pd
+ 1, plenbytes
);
1254 addr
[plenbytes
- 1] &=
1255 ((0xff00 >> (plen
% 8)) & 0xff);
1257 snprintf(buf
, buflen
, "%s/%u", ip6addr_string(ndo
, (const u_char
*)&addr
), plen
);
1258 return 1 + plenbytes
;
1268 decode_labeled_prefix6(netdissect_options
*ndo
,
1269 const u_char
*pptr
, u_int itemlen
, char *buf
, size_t buflen
)
1272 u_int plen
, plenbytes
;
1274 /* prefix length and label = 4 bytes */
1277 plen
= GET_U_1(pptr
); /* get prefix length */
1282 plen
-= 24; /* adjust prefixlen - labellength */
1288 memset(&addr
, 0, sizeof(addr
));
1289 plenbytes
= (plen
+ 7) / 8;
1290 ND_TCHECK_LEN(pptr
+ 4, plenbytes
);
1291 memcpy(&addr
, pptr
+ 4, plenbytes
);
1293 addr
[plenbytes
- 1] &=
1294 ((0xff00 >> (plen
% 8)) & 0xff);
1296 /* the label may get offsetted by 4 bits so lets shift it right */
1297 snprintf(buf
, buflen
, "%s/%u, label:%u %s",
1298 ip6addr_string(ndo
, (const u_char
*)&addr
),
1300 GET_BE_U_3(pptr
+ 1)>>4,
1301 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1303 return 4 + plenbytes
;
1313 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1314 const u_char
*pptr
, char *buf
, size_t buflen
)
1320 plen
= GET_U_1(pptr
); /* get prefix length */
1325 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1330 memset(&addr
, 0, sizeof(addr
));
1331 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
1332 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1334 addr
[(plen
+ 7) / 8 - 1] &=
1335 ((0xff00 >> (plen
% 8)) & 0xff);
1337 /* the label may get offsetted by 4 bits so lets shift it right */
1338 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1339 bgp_vpn_rd_print(ndo
, pptr
+4),
1340 ip6addr_string(ndo
, (const u_char
*)&addr
),
1342 GET_BE_U_3(pptr
+ 1)>>4,
1343 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1345 return 12 + (plen
+ 7) / 8;
1352 decode_clnp_prefix(netdissect_options
*ndo
,
1353 const u_char
*pptr
, char *buf
, size_t buflen
)
1359 plen
= GET_U_1(pptr
); /* get prefix length */
1364 memset(&addr
, 0, sizeof(addr
));
1365 ND_TCHECK_LEN(pptr
+ 4, (plen
+ 7) / 8);
1366 memcpy(&addr
, pptr
+ 4, (plen
+ 7) / 8);
1368 addr
[(plen
+ 7) / 8 - 1] &=
1369 ((0xff00 >> (plen
% 8)) & 0xff);
1371 snprintf(buf
, buflen
, "%s/%u",
1372 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1375 return 1 + (plen
+ 7) / 8;
1382 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1383 const u_char
*pptr
, char *buf
, size_t buflen
)
1389 plen
= GET_U_1(pptr
); /* get prefix length */
1394 plen
-= (24+64); /* adjust prefixlen - labellength - RD len*/
1399 memset(&addr
, 0, sizeof(addr
));
1400 ND_TCHECK_LEN(pptr
+ 12, (plen
+ 7) / 8);
1401 memcpy(&addr
, pptr
+ 12, (plen
+ 7) / 8);
1403 addr
[(plen
+ 7) / 8 - 1] &= ((0xff00 >> (plen
% 8)) & 0xff);
1405 /* the label may get offsetted by 4 bits so lets shift it right */
1406 snprintf(buf
, buflen
, "RD: %s, %s/%u, label:%u %s",
1407 bgp_vpn_rd_print(ndo
, pptr
+4),
1408 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1410 GET_BE_U_3(pptr
+ 1)>>4,
1411 ((GET_U_1(pptr
+ 3) & 1) == 0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1413 return 12 + (plen
+ 7) / 8;
1420 * bgp_attr_get_as_size
1422 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1423 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1424 * support, exchange AS-Path with the same path-attribute type value 0x02.
1427 bgp_attr_get_as_size(netdissect_options
*ndo
,
1428 uint8_t bgpa_type
, const u_char
*pptr
, u_int len
)
1430 const u_char
*tptr
= pptr
;
1433 * If the path attribute is the optional AS4 path type, then we already
1434 * know, that ASs must be encoded in 4 byte format.
1436 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1441 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1442 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1445 while (tptr
< pptr
+ len
) {
1449 * If we do not find a valid segment type, our guess might be wrong.
1451 if (GET_U_1(tptr
) < BGP_AS_SEG_TYPE_MIN
|| GET_U_1(tptr
) > BGP_AS_SEG_TYPE_MAX
) {
1454 ND_TCHECK_1(tptr
+ 1);
1455 tptr
+= 2 + GET_U_1(tptr
+ 1) * 2;
1459 * If we correctly reached end of the AS path attribute data content,
1460 * then most likely ASs were indeed encoded as 2 bytes.
1462 if (tptr
== pptr
+ len
) {
1469 * We can come here, either we did not have enough data, or if we
1470 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1471 * so that calller can try to decode each AS as of 4 bytes. If indeed
1472 * there was not enough data, it will crib and end the parse anyways.
1478 * The only way to know that a BGP UPDATE message is using add path is
1479 * by checking if the capability is in the OPEN message which we may have missed.
1480 * So this function checks if it is possible that the update could contain add path
1481 * and if so it checks that standard BGP doesn't make sense.
1484 check_add_path(netdissect_options
*ndo
, const u_char
*pptr
, u_int length
,
1485 u_int max_prefix_length
)
1487 u_int offset
, prefix_length
;
1494 * Scan through the NLRI information under the assumpetion that
1495 * it doesn't have path IDs.
1497 for (offset
= 0; offset
< length
;) {
1499 if (!ND_TTEST_1(pptr
+ offset
)) {
1500 /* We ran out of captured data; quit scanning. */
1503 prefix_length
= GET_U_1(pptr
+ offset
);
1505 * Add 4 to cover the path id
1506 * and check the prefix length isn't greater than 32/128.
1508 if (prefix_length
> max_prefix_length
) {
1511 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1512 offset
+= 1 + ((prefix_length
+ 7) / 8);
1514 /* check we haven't gone past the end of the section */
1515 if (offset
> length
) {
1519 /* check it's not standard BGP */
1520 for (offset
= 0; offset
< length
; ) {
1521 if (!ND_TTEST_1(pptr
+ offset
)) {
1522 /* We ran out of captured data; quit scanning. */
1525 prefix_length
= GET_U_1(pptr
+ offset
);
1527 * If the prefix_length is zero (0.0.0.0/0)
1528 * and since it's not the only address (length >= 5)
1529 * then it is add-path
1531 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1534 offset
+= 1 + ((prefix_length
+ 7) / 8);
1536 if (offset
> length
) {
1540 /* assume not add-path by default */
1545 bgp_mp_af_print(netdissect_options
*ndo
,
1546 const u_char
*tptr
, u_int tlen
,
1547 uint16_t *afp
, uint8_t *safip
)
1552 af
= GET_BE_U_2(tptr
);
1554 safi
= GET_U_1(tptr
+ 2);
1557 ND_PRINT("\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1558 tok2str(af_values
, "Unknown AFI", af
),
1560 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1561 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1564 switch(af
<<8 | safi
) {
1565 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1566 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1567 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1568 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1569 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1570 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1571 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1572 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1573 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1574 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1575 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1576 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1577 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1578 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1579 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1580 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1581 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1582 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1583 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1584 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1585 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1586 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1587 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1588 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1589 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1590 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1591 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1594 ND_TCHECK_LEN(tptr
, tlen
);
1595 ND_PRINT("\n\t no AFI %u / SAFI %u decoder", af
, safi
);
1596 if (ndo
->ndo_vflag
<= 1)
1597 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1606 bgp_nlri_print(netdissect_options
*ndo
, uint16_t af
, uint8_t safi
,
1607 const u_char
*tptr
, u_int len
,
1608 char *buf
, size_t buflen
,
1609 int add_path4
, int add_path6
)
1614 switch (af
<<8 | safi
) {
1615 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1616 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1617 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1619 path_id
= GET_BE_U_4(tptr
);
1622 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1624 ND_PRINT("\n\t (illegal prefix length)");
1625 else if (advance
== -2)
1627 else if (advance
== -3)
1628 break; /* bytes left, but not enough */
1630 ND_PRINT("\n\t %s", buf
);
1632 ND_PRINT(" Path Id: %u", path_id
);
1636 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1637 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, buflen
);
1639 ND_PRINT("\n\t (illegal prefix length)");
1640 else if (advance
== -2)
1642 else if (advance
== -3)
1643 break; /* bytes left, but not enough */
1645 ND_PRINT("\n\t %s", buf
);
1647 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1648 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1649 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1650 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, buflen
);
1652 ND_PRINT("\n\t (illegal prefix length)");
1653 else if (advance
== -2)
1656 ND_PRINT("\n\t %s", buf
);
1658 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1659 advance
= decode_rt_routing_info(ndo
, tptr
);
1663 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1664 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1665 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, buflen
);
1667 ND_PRINT("\n\t (illegal prefix length)");
1668 else if (advance
== -2)
1671 ND_PRINT("\n\t %s", buf
);
1674 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1675 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, buflen
);
1677 ND_PRINT("\n\t (illegal prefix length)");
1678 else if (advance
== -2)
1681 ND_PRINT("\n\t %s", buf
);
1683 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1684 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1685 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1687 path_id
= GET_BE_U_4(tptr
);
1690 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1692 ND_PRINT("\n\t (illegal prefix length)");
1693 else if (advance
== -2)
1695 else if (advance
== -3)
1696 break; /* bytes left, but not enough */
1698 ND_PRINT("\n\t %s", buf
);
1700 ND_PRINT(" Path Id: %u", path_id
);
1704 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1705 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, buflen
);
1707 ND_PRINT("\n\t (illegal prefix length)");
1708 else if (advance
== -2)
1710 else if (advance
== -3)
1711 break; /* bytes left, but not enough */
1713 ND_PRINT("\n\t %s", buf
);
1715 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1716 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1717 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1718 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, buflen
);
1720 ND_PRINT("\n\t (illegal prefix length)");
1721 else if (advance
== -2)
1724 ND_PRINT("\n\t %s", buf
);
1726 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1727 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1728 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1729 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1730 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, buflen
);
1732 ND_PRINT("\n\t (illegal length)");
1733 else if (advance
== -2)
1736 ND_PRINT("\n\t %s", buf
);
1738 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1739 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1740 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1741 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1743 ND_PRINT("\n\t (illegal prefix length)");
1744 else if (advance
== -2)
1747 ND_PRINT("\n\t %s", buf
);
1749 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1750 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1751 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1752 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, buflen
);
1754 ND_PRINT("\n\t (illegal prefix length)");
1755 else if (advance
== -2)
1758 ND_PRINT("\n\t %s", buf
);
1762 * This should not happen, we should have been protected
1763 * by bgp_mp_af_print()'s return value.
1765 ND_PRINT("\n\t ERROR: no AFI %u / SAFI %u decoder", af
, safi
);
1770 trunc
: /* we rely on the caller to recognize -2 return value */
1775 bgp_attr_print(netdissect_options
*ndo
,
1776 uint8_t atype
, const u_char
*pptr
, u_int len
)
1780 uint8_t safi
, snpa
, nhlen
;
1784 char buf
[MAXHOSTNAMELEN
+ 100];
1786 int add_path4
, add_path6
;
1793 case BGPTYPE_ORIGIN
:
1795 ND_PRINT("invalid len");
1798 ND_PRINT("%s", tok2str(bgp_origin_values
,
1799 "Unknown Origin Typecode",
1805 * Process AS4 byte path and AS2 byte path attributes here.
1807 case BGPTYPE_AS4_PATH
:
1808 case BGPTYPE_AS_PATH
:
1810 ND_PRINT("invalid len");
1819 * BGP updates exchanged between New speakers that support 4
1820 * byte AS, ASs are always encoded in 4 bytes. There is no
1821 * definitive way to find this, just by the packet's
1822 * contents. So, check for packet's TLV's sanity assuming
1823 * 2 bytes first, and it does not pass, assume that ASs are
1824 * encoded in 4 bytes format and move on.
1826 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1828 while (tptr
< pptr
+ len
) {
1830 ND_PRINT("%s", tok2str(bgp_as_path_segment_open_values
,
1831 "?", GET_U_1(tptr
)));
1832 ND_TCHECK_1(tptr
+ 1);
1833 for (i
= 0; i
< GET_U_1(tptr
+ 1) * as_size
; i
+= as_size
) {
1834 ND_TCHECK_LEN(tptr
+ 2 + i
, as_size
);
1836 as_printf(ndo
, astostr
, sizeof(astostr
),
1838 GET_BE_U_2(tptr
+ i
+ 2) :
1839 GET_BE_U_4(tptr
+ i
+ 2)));
1842 ND_PRINT("%s", tok2str(bgp_as_path_segment_close_values
,
1843 "?", GET_U_1(tptr
)));
1844 ND_TCHECK_1(tptr
+ 1);
1845 tptr
+= 2 + GET_U_1(tptr
+ 1) * as_size
;
1848 case BGPTYPE_NEXT_HOP
:
1850 ND_PRINT("invalid len");
1853 ND_PRINT("%s", ipaddr_string(ndo
, tptr
));
1856 case BGPTYPE_MULTI_EXIT_DISC
:
1857 case BGPTYPE_LOCAL_PREF
:
1859 ND_PRINT("invalid len");
1862 ND_PRINT("%u", GET_BE_U_4(tptr
));
1865 case BGPTYPE_ATOMIC_AGGREGATE
:
1867 ND_PRINT("invalid len");
1869 case BGPTYPE_AGGREGATOR
:
1872 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1873 * the length of this PA can be either 6 bytes or 8 bytes.
1875 if (len
!= 6 && len
!= 8) {
1876 ND_PRINT("invalid len");
1879 ND_TCHECK_LEN(tptr
, len
);
1881 ND_PRINT(" AS #%s, origin %s",
1882 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(tptr
)),
1883 ipaddr_string(ndo
, tptr
+ 2));
1885 ND_PRINT(" AS #%s, origin %s",
1886 as_printf(ndo
, astostr
, sizeof(astostr
),
1887 GET_BE_U_4(tptr
)), ipaddr_string(ndo
, tptr
+ 4));
1890 case BGPTYPE_AGGREGATOR4
:
1892 ND_PRINT("invalid len");
1896 ND_PRINT(" AS #%s, origin %s",
1897 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)),
1898 ipaddr_string(ndo
, tptr
+ 4));
1900 case BGPTYPE_COMMUNITIES
:
1902 ND_PRINT("invalid len");
1910 comm
= GET_BE_U_4(tptr
);
1912 case BGP_COMMUNITY_NO_EXPORT
:
1913 ND_PRINT(" NO_EXPORT");
1915 case BGP_COMMUNITY_NO_ADVERT
:
1916 ND_PRINT(" NO_ADVERTISE");
1918 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1919 ND_PRINT(" NO_EXPORT_SUBCONFED");
1923 (comm
>> 16) & 0xffff,
1925 (tlen
>4) ? ", " : "");
1932 case BGPTYPE_ORIGINATOR_ID
:
1934 ND_PRINT("invalid len");
1938 ND_PRINT("%s",ipaddr_string(ndo
, tptr
));
1940 case BGPTYPE_CLUSTER_LIST
:
1942 ND_PRINT("invalid len");
1950 ipaddr_string(ndo
, tptr
),
1951 (tlen
>4) ? ", " : "");
1956 case BGPTYPE_MP_REACH_NLRI
:
1960 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
1969 nhlen
= GET_U_1(tptr
);
1975 ND_PRINT("\n\t nexthop: ");
1980 switch(af
<<8 | safi
) {
1981 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1982 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1983 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1984 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1985 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1986 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1987 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1988 if (tlen
< sizeof(nd_ipv4
)) {
1989 ND_PRINT("invalid len");
1992 ND_TCHECK_LEN(tptr
, sizeof(nd_ipv4
));
1993 ND_PRINT("%s",ipaddr_string(ndo
, tptr
));
1994 tlen
-= sizeof(nd_ipv4
);
1995 tptr
+= sizeof(nd_ipv4
);
1998 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1999 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
2000 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
2001 if (tlen
< sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
) {
2002 ND_PRINT("invalid len");
2006 sizeof(nd_ipv4
) + BGP_VPN_RD_LEN
);
2007 ND_PRINT("RD: %s, %s",
2008 bgp_vpn_rd_print(ndo
, tptr
),
2009 ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
));
2010 tlen
-= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2011 tptr
+= (sizeof(nd_ipv4
)+BGP_VPN_RD_LEN
);
2014 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
2015 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
2016 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
2017 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
2018 if (tlen
< sizeof(nd_ipv6
)) {
2019 ND_PRINT("invalid len");
2022 ND_TCHECK_LEN(tptr
, sizeof(nd_ipv6
));
2023 ND_PRINT("%s", ip6addr_string(ndo
, tptr
));
2024 tlen
-= sizeof(nd_ipv6
);
2025 tptr
+= sizeof(nd_ipv6
);
2028 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
2029 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
2030 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2031 if (tlen
< sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
) {
2032 ND_PRINT("invalid len");
2036 sizeof(nd_ipv6
) + BGP_VPN_RD_LEN
);
2037 ND_PRINT("RD: %s, %s",
2038 bgp_vpn_rd_print(ndo
, tptr
),
2039 ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
));
2040 tlen
-= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2041 tptr
+= (sizeof(nd_ipv6
)+BGP_VPN_RD_LEN
);
2044 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2045 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2046 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2047 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2048 if (tlen
< sizeof(nd_ipv4
)) {
2049 ND_PRINT("invalid len");
2052 ND_TCHECK_LEN(tptr
, sizeof(nd_ipv4
));
2053 ND_PRINT("%s", ipaddr_string(ndo
, tptr
));
2054 tlen
-= (sizeof(nd_ipv4
));
2055 tptr
+= (sizeof(nd_ipv4
));
2058 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2059 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2060 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2061 ND_TCHECK_LEN(tptr
, tlen
);
2062 ND_PRINT("%s", isonsap_string(ndo
, tptr
, tlen
));
2067 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2068 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2069 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2070 if (tlen
< BGP_VPN_RD_LEN
+1) {
2071 ND_PRINT("invalid len");
2074 ND_TCHECK_LEN(tptr
, tlen
);
2075 ND_PRINT("RD: %s, %s",
2076 bgp_vpn_rd_print(ndo
, tptr
),
2077 isonsap_string(ndo
, tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
));
2078 /* rfc986 mapped IPv4 address ? */
2079 if (GET_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
2080 ND_PRINT(" = %s", ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+4));
2081 /* rfc1888 mapped IPv6 address ? */
2082 else if (GET_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
2083 ND_PRINT(" = %s", ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+3));
2090 * bgp_mp_af_print() should have saved us from
2091 * an unsupported AFI/SAFI.
2093 ND_PRINT("ERROR: no AFI %u/SAFI %u nexthop decoder", af
, safi
);
2101 ND_PRINT(", nh-length: %u", nhlen
);
2105 snpa
= GET_U_1(tptr
);
2109 ND_PRINT("\n\t %u SNPA", snpa
);
2110 for (/*nothing*/; snpa
!= 0; snpa
--) {
2112 ND_PRINT("\n\t %u bytes", GET_U_1(tptr
));
2113 tptr
+= GET_U_1(tptr
) + 1;
2116 ND_PRINT(", no SNPA");
2119 add_path4
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 32);
2120 add_path6
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 128);
2122 while (tptr
< pptr
+ len
) {
2123 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2124 add_path4
, add_path6
);
2133 case BGPTYPE_MP_UNREACH_NLRI
:
2134 ND_TCHECK_LEN(tptr
, BGP_MP_NLRI_MINSIZE
);
2135 ret
= bgp_mp_af_print(ndo
, tptr
, tlen
, &af
, &safi
);
2141 if (len
== BGP_MP_NLRI_MINSIZE
)
2142 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2146 add_path4
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 32);
2147 add_path6
= check_add_path(ndo
, tptr
, (len
-ND_BYTES_BETWEEN(tptr
, pptr
)), 128);
2149 while (tptr
< pptr
+ len
) {
2150 advance
= bgp_nlri_print(ndo
, af
, safi
, tptr
, len
, buf
, sizeof(buf
),
2151 add_path4
, add_path6
);
2159 case BGPTYPE_EXTD_COMMUNITIES
:
2161 ND_PRINT("invalid len");
2170 extd_comm
=GET_BE_U_2(tptr
);
2172 ND_PRINT("\n\t %s (0x%04x), Flags [%s]",
2173 tok2str(bgp_extd_comm_subtype_values
,
2174 "unknown extd community typecode",
2177 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
));
2183 bgp_extended_community_print(ndo
, tptr
);
2189 case BGPTYPE_PMSI_TUNNEL
:
2191 uint8_t tunnel_type
, flags
;
2196 flags
= GET_U_1(tptr
);
2197 tunnel_type
= GET_U_1(tptr
+ 1);
2200 ND_PRINT("\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2201 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2203 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2204 GET_BE_U_3(tptr
+ 2)>>4);
2209 switch (tunnel_type
) {
2210 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2211 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2213 ND_PRINT("\n\t Sender %s, P-Group %s",
2214 ipaddr_string(ndo
, tptr
),
2215 ipaddr_string(ndo
, tptr
+4));
2218 case BGP_PMSI_TUNNEL_PIM_SSM
:
2220 ND_PRINT("\n\t Root-Node %s, P-Group %s",
2221 ipaddr_string(ndo
, tptr
),
2222 ipaddr_string(ndo
, tptr
+4));
2224 case BGP_PMSI_TUNNEL_INGRESS
:
2226 ND_PRINT("\n\t Tunnel-Endpoint %s",
2227 ipaddr_string(ndo
, tptr
));
2229 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2230 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2232 ND_PRINT("\n\t Root-Node %s, LSP-ID 0x%08x",
2233 ipaddr_string(ndo
, tptr
),
2234 GET_BE_U_4(tptr
+ 4));
2236 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2238 ND_PRINT("\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2239 ipaddr_string(ndo
, tptr
),
2240 GET_BE_U_4(tptr
+ 4));
2243 if (ndo
->ndo_vflag
<= 1) {
2244 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2260 type
= GET_U_1(tptr
);
2261 length
= GET_BE_U_2(tptr
+ 1);
2265 ND_PRINT("\n\t %s TLV (%u), length %u",
2266 tok2str(bgp_aigp_values
, "Unknown", type
),
2274 * Check if we can read the TLV data.
2276 ND_TCHECK_LEN(tptr
+ 3, length
);
2285 ND_PRINT(", metric %" PRIu64
,
2290 if (ndo
->ndo_vflag
<= 1) {
2291 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2300 case BGPTYPE_ATTR_SET
:
2304 ND_PRINT("\n\t Origin AS: %s",
2305 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_4(tptr
)));
2310 u_int aflags
, alenlen
, alen
;
2314 ND_PRINT(" [path attr too short]");
2318 aflags
= GET_U_1(tptr
);
2319 atype
= GET_U_1(tptr
+ 1);
2322 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2323 ND_TCHECK_LEN(tptr
, alenlen
);
2324 if (len
< alenlen
) {
2325 ND_PRINT(" [path attr too short]");
2329 alen
= bgp_attr_len(aflags
, tptr
);
2333 ND_PRINT("\n\t %s (%u), length: %u",
2334 tok2str(bgp_attr_values
,
2335 "Unknown Attribute", atype
),
2340 ND_PRINT(", Flags [%s%s%s%s",
2341 aflags
& 0x80 ? "O" : "",
2342 aflags
& 0x40 ? "T" : "",
2343 aflags
& 0x20 ? "P" : "",
2344 aflags
& 0x10 ? "E" : "");
2346 ND_PRINT("+%x", aflags
& 0xf);
2351 ND_PRINT(" [path attr too short]");
2355 /* FIXME check for recursion */
2356 if (!bgp_attr_print(ndo
, atype
, tptr
, alen
))
2363 case BGPTYPE_LARGE_COMMUNITY
:
2364 if (len
== 0 || len
% 12) {
2365 ND_PRINT("invalid len");
2370 ND_TCHECK_LEN(tptr
, 12);
2371 ND_PRINT("%u:%u:%u%s",
2373 GET_BE_U_4(tptr
+ 4),
2374 GET_BE_U_4(tptr
+ 8),
2375 (len
> 12) ? ", " : "");
2378 * len will always be a multiple of 12, as per the above,
2379 * so this will never underflow.
2385 ND_TCHECK_LEN(pptr
, len
);
2386 ND_PRINT("\n\t no Attribute %u decoder", atype
); /* we have no decoder for the attribute */
2387 if (ndo
->ndo_vflag
<= 1)
2388 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2392 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2393 ND_TCHECK_LEN(pptr
, len
);
2394 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2403 bgp_capabilities_print(netdissect_options
*ndo
,
2404 const u_char
*opt
, u_int caps_len
)
2406 u_int cap_type
, cap_len
, tcap_len
, cap_offset
;
2409 while (i
< caps_len
) {
2410 ND_TCHECK_LEN(opt
+ i
, BGP_CAP_HEADER_SIZE
);
2411 cap_type
=GET_U_1(opt
+ i
);
2412 cap_len
=GET_U_1(opt
+ i
+ 1);
2413 ND_PRINT("\n\t %s (%u), length: %u",
2414 tok2str(bgp_capcode_values
, "Unknown", cap_type
),
2417 ND_TCHECK_LEN(opt
+ 2 + i
, cap_len
);
2419 case BGP_CAPCODE_MP
:
2420 /* AFI (16 bits), Reserved (8 bits), SAFI (8 bits) */
2422 ND_PRINT(" (too short, < 4)");
2425 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u)",
2426 tok2str(af_values
, "Unknown", GET_BE_U_2(opt
+ i
+ 2)),
2427 GET_BE_U_2(opt
+ i
+ 2),
2428 tok2str(bgp_safi_values
, "Unknown", GET_U_1(opt
+ i
+ 5)),
2429 GET_U_1(opt
+ i
+ 5));
2431 case BGP_CAPCODE_ML
:
2434 while (tcap_len
>= 4) {
2435 ND_PRINT( "\n\t\tAFI %s (%u), SAFI %s (%u), Count: %u",
2436 tok2str(af_values
, "Unknown",
2437 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2438 GET_BE_U_2(opt
+ i
+ cap_offset
),
2439 tok2str(bgp_safi_values
, "Unknown",
2440 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2441 GET_U_1(opt
+ i
+ cap_offset
+ 2),
2442 GET_U_1(opt
+ i
+ cap_offset
+ 3));
2447 case BGP_CAPCODE_RESTART
:
2448 /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */
2450 ND_PRINT(" (too short, < 2)");
2454 ND_PRINT("\n\t\tRestart Flags: [%s], Restart Time %us",
2455 ((GET_U_1(opt
+ i
+ 2))&0x80) ? "R" : "none",
2456 GET_BE_U_2(opt
+ i
+ 2)&0xfff);
2459 while(tcap_len
>=4) {
2460 ND_PRINT("\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2461 tok2str(af_values
,"Unknown",
2462 GET_BE_U_2(opt
+ i
+ cap_offset
)),
2463 GET_BE_U_2(opt
+ i
+ cap_offset
),
2464 tok2str(bgp_safi_values
,"Unknown",
2465 GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2466 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2467 ((GET_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
:
2477 * Extract the 4 byte AS number encoded.
2480 ND_PRINT(" (too short, < 4)");
2483 ND_PRINT("\n\t\t 4 Byte AS %s",
2484 as_printf(ndo
, astostr
, sizeof(astostr
),
2485 GET_BE_U_4(opt
+ i
+ 2)));
2487 case BGP_CAPCODE_ADD_PATH
:
2489 ND_PRINT(" (bogus)"); /* length */
2494 while (tcap_len
!= 0) {
2496 nd_print_invalid(ndo
);
2499 ND_PRINT("\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2500 tok2str(af_values
,"Unknown",GET_BE_U_2(opt
+ i
+ cap_offset
)),
2501 GET_BE_U_2(opt
+ i
+ cap_offset
),
2502 tok2str(bgp_safi_values
,"Unknown",GET_U_1(opt
+ i
+ cap_offset
+ 2)),
2503 GET_U_1(opt
+ (i
+ cap_offset
+ 2)),
2504 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",GET_U_1(opt
+ i
+ cap_offset
+ 3))
2511 ND_PRINT("\n\t\tno decoder for Capability %u",
2513 if (ndo
->ndo_vflag
<= 1)
2514 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2518 if (ndo
->ndo_vflag
> 1 && cap_len
!= 0) {
2519 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2521 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2526 nd_print_trunc(ndo
);
2530 bgp_open_print(netdissect_options
*ndo
,
2531 const u_char
*dat
, u_int length
)
2533 const struct bgp_open
*bgp_open_header
;
2535 const struct bgp_opt
*bgpopt
;
2539 ND_TCHECK_LEN(dat
, BGP_OPEN_SIZE
);
2540 if (length
< BGP_OPEN_SIZE
)
2543 bgp_open_header
= (const struct bgp_open
*)dat
;
2545 ND_PRINT("\n\t Version %u, ",
2546 GET_U_1(bgp_open_header
->bgpo_version
));
2547 ND_PRINT("my AS %s, ",
2548 as_printf(ndo
, astostr
, sizeof(astostr
), GET_BE_U_2(bgp_open_header
->bgpo_myas
)));
2549 ND_PRINT("Holdtime %us, ",
2550 GET_BE_U_2(bgp_open_header
->bgpo_holdtime
));
2551 ND_PRINT("ID %s", ipaddr_string(ndo
, bgp_open_header
->bgpo_id
));
2552 optslen
= GET_U_1(bgp_open_header
->bgpo_optlen
);
2553 ND_PRINT("\n\t Optional parameters, length: %u", optslen
);
2555 opt
= dat
+ BGP_OPEN_SIZE
;
2556 length
-= BGP_OPEN_SIZE
;
2559 while (i
< optslen
) {
2560 uint8_t opt_type
, opt_len
;
2562 ND_TCHECK_LEN(opt
+ i
, BGP_OPT_SIZE
);
2563 if (length
< BGP_OPT_SIZE
+ i
)
2565 bgpopt
= (const struct bgp_opt
*)(opt
+ i
);
2566 opt_type
= GET_U_1(bgpopt
->bgpopt_type
);
2567 opt_len
= GET_U_1(bgpopt
->bgpopt_len
);
2568 if (BGP_OPT_SIZE
+ i
+ opt_len
> optslen
) {
2569 ND_PRINT("\n\t Option %u, length: %u, goes past the end of the options",
2574 ND_PRINT("\n\t Option %s (%u), length: %u",
2575 tok2str(bgp_opt_values
,"Unknown",opt_type
),
2579 /* now let's decode the options we know*/
2583 bgp_capabilities_print(ndo
, opt
+ BGP_OPT_SIZE
+ i
,
2589 ND_PRINT("\n\t no decoder for option %u",
2593 i
+= BGP_OPT_SIZE
+ opt_len
;
2597 nd_print_trunc(ndo
);
2601 bgp_update_print(netdissect_options
*ndo
,
2602 const u_char
*dat
, u_int length
)
2605 u_int withdrawn_routes_len
;
2606 char buf
[MAXHOSTNAMELEN
+ 100];
2613 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2614 if (length
< BGP_SIZE
)
2619 /* Unfeasible routes */
2623 withdrawn_routes_len
= GET_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("\n\t Withdrawn routes:");
2636 add_path
= check_add_path(ndo
, p
, withdrawn_routes_len
, 32);
2637 while (withdrawn_routes_len
!= 0) {
2639 if (withdrawn_routes_len
< 4) {
2640 p
+= withdrawn_routes_len
;
2641 length
-= withdrawn_routes_len
;
2644 path_id
= GET_BE_U_4(p
);
2647 withdrawn_routes_len
-= 4;
2649 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2651 ND_PRINT("\n\t (illegal prefix length)");
2653 } else if (wpfx
== -2)
2655 else if (wpfx
== -3)
2656 goto trunc
; /* bytes left, but not enough */
2658 ND_PRINT("\n\t %s", buf
);
2660 ND_PRINT(" Path Id: %u", path_id
);
2664 withdrawn_routes_len
-= wpfx
;
2668 ND_TCHECK_LEN(p
, withdrawn_routes_len
);
2669 if (length
< withdrawn_routes_len
)
2671 p
+= withdrawn_routes_len
;
2672 length
-= withdrawn_routes_len
;
2678 len
= GET_BE_U_2(p
);
2682 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2683 /* No withdrawn routes, no path attributes, no NLRI */
2684 ND_PRINT("\n\t End-of-Rib Marker (empty NLRI)");
2689 /* do something more useful!*/
2691 uint8_t aflags
, atype
, alenlen
;
2698 ND_PRINT("\n\t [path attrs too short]");
2703 aflags
= GET_U_1(p
);
2704 atype
= GET_U_1(p
+ 1);
2708 alenlen
= bgp_attr_lenlen(aflags
, p
);
2709 ND_TCHECK_LEN(p
, alenlen
);
2710 if (length
< alenlen
)
2712 if (len
< alenlen
) {
2713 ND_PRINT("\n\t [path attrs too short]");
2718 alen
= bgp_attr_len(aflags
, p
);
2723 ND_PRINT("\n\t %s (%u), length: %u",
2724 tok2str(bgp_attr_values
, "Unknown Attribute", atype
),
2729 ND_PRINT(", Flags [%s%s%s%s",
2730 aflags
& 0x80 ? "O" : "",
2731 aflags
& 0x40 ? "T" : "",
2732 aflags
& 0x20 ? "P" : "",
2733 aflags
& 0x10 ? "E" : "");
2735 ND_PRINT("+%x", aflags
& 0xf);
2739 ND_PRINT(" [path attrs too short]");
2746 if (!bgp_attr_print(ndo
, atype
, p
, alen
))
2755 add_path
= check_add_path(ndo
, p
, length
, 32);
2756 ND_PRINT("\n\t Updated routes:");
2757 while (length
!= 0) {
2762 path_id
= GET_BE_U_4(p
);
2766 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2768 ND_PRINT("\n\t (illegal prefix length)");
2773 goto trunc
; /* bytes left, but not enough */
2775 ND_PRINT("\n\t %s", buf
);
2777 ND_PRINT(" Path Id: %u", path_id
);
2786 nd_print_trunc(ndo
);
2790 bgp_notification_print(netdissect_options
*ndo
,
2791 const u_char
*dat
, u_int length
)
2793 const struct bgp_notification
*bgp_notification_header
;
2795 uint8_t bgpn_major
, bgpn_minor
;
2796 uint8_t shutdown_comm_length
;
2797 uint8_t remainder_offset
;
2799 ND_TCHECK_LEN(dat
, BGP_NOTIFICATION_SIZE
);
2800 if (length
<BGP_NOTIFICATION_SIZE
)
2803 bgp_notification_header
= (const struct bgp_notification
*)dat
;
2804 bgpn_major
= GET_U_1(bgp_notification_header
->bgpn_major
);
2805 bgpn_minor
= GET_U_1(bgp_notification_header
->bgpn_minor
);
2807 ND_PRINT(", %s (%u)",
2808 tok2str(bgp_notify_major_values
, "Unknown Error",
2812 switch (bgpn_major
) {
2814 case BGP_NOTIFY_MAJOR_MSG
:
2815 ND_PRINT(", subcode %s (%u)",
2816 tok2str(bgp_notify_minor_msg_values
, "Unknown",
2820 case BGP_NOTIFY_MAJOR_OPEN
:
2821 ND_PRINT(", subcode %s (%u)",
2822 tok2str(bgp_notify_minor_open_values
, "Unknown",
2826 case BGP_NOTIFY_MAJOR_UPDATE
:
2827 ND_PRINT(", subcode %s (%u)",
2828 tok2str(bgp_notify_minor_update_values
, "Unknown",
2832 case BGP_NOTIFY_MAJOR_FSM
:
2833 ND_PRINT(" subcode %s (%u)",
2834 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
2838 case BGP_NOTIFY_MAJOR_CAP
:
2839 ND_PRINT(" subcode %s (%u)",
2840 tok2str(bgp_notify_minor_cap_values
, "Unknown",
2844 case BGP_NOTIFY_MAJOR_CEASE
:
2845 ND_PRINT(", subcode %s (%u)",
2846 tok2str(bgp_notify_minor_cease_values
, "Unknown",
2850 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2851 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2853 if(bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2854 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2856 ND_PRINT(", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2857 tok2str(af_values
, "Unknown", GET_BE_U_2(tptr
)),
2859 tok2str(bgp_safi_values
, "Unknown", GET_U_1((tptr
+ 2))),
2860 GET_U_1((tptr
+ 2)),
2861 GET_BE_U_4(tptr
+ 3));
2864 * draft-ietf-idr-shutdown describes a method to send a communication
2865 * intended for human consumption regarding the Administrative Shutdown
2867 if ((bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
2868 bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
2869 length
>= BGP_NOTIFICATION_SIZE
+ 1) {
2870 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2872 shutdown_comm_length
= GET_U_1(tptr
);
2873 remainder_offset
= 0;
2874 /* garbage, hexdump it all */
2875 if (shutdown_comm_length
> BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN
||
2876 shutdown_comm_length
> length
- (BGP_NOTIFICATION_SIZE
+ 1)) {
2877 ND_PRINT(", invalid Shutdown Communication length");
2879 else if (shutdown_comm_length
== 0) {
2880 ND_PRINT(", empty Shutdown Communication");
2881 remainder_offset
+= 1;
2883 /* a proper shutdown communication */
2885 ND_TCHECK_LEN(tptr
+ 1, shutdown_comm_length
);
2886 ND_PRINT(", Shutdown Communication (length: %u): \"", shutdown_comm_length
);
2887 (void)nd_printn(ndo
, tptr
+1, shutdown_comm_length
, NULL
);
2889 remainder_offset
+= shutdown_comm_length
+ 1;
2891 /* if there is trailing data, hexdump it */
2892 if(length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
) > 0) {
2893 ND_PRINT(", Data: (length: %u)", length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
2894 hex_print(ndo
, "\n\t\t", tptr
+ remainder_offset
, length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
2904 nd_print_trunc(ndo
);
2908 bgp_route_refresh_print(netdissect_options
*ndo
,
2909 const u_char
*pptr
, u_int len
)
2911 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2913 ND_TCHECK_LEN(pptr
, BGP_ROUTE_REFRESH_SIZE
);
2915 /* some little sanity checking */
2916 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2919 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2921 ND_PRINT("\n\t AFI %s (%u), SAFI %s (%u)",
2922 tok2str(af_values
,"Unknown",
2923 GET_BE_U_2(bgp_route_refresh_header
->afi
)),
2924 GET_BE_U_2(bgp_route_refresh_header
->afi
),
2925 tok2str(bgp_safi_values
,"Unknown",
2926 GET_U_1(bgp_route_refresh_header
->safi
)),
2927 GET_U_1(bgp_route_refresh_header
->safi
));
2929 if (ndo
->ndo_vflag
> 1) {
2930 ND_TCHECK_LEN(pptr
, len
);
2931 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2936 nd_print_trunc(ndo
);
2940 bgp_pdu_print(netdissect_options
*ndo
,
2941 const u_char
*dat
, u_int length
)
2943 const struct bgp
*bgp_header
;
2946 ND_TCHECK_LEN(dat
, BGP_SIZE
);
2947 bgp_header
= (const struct bgp
*)dat
;
2948 bgp_type
= GET_U_1(bgp_header
->bgp_type
);
2950 ND_PRINT("\n\t%s Message (%u), length: %u",
2951 tok2str(bgp_msg_values
, "Unknown", bgp_type
),
2957 bgp_open_print(ndo
, dat
, length
);
2960 bgp_update_print(ndo
, dat
, length
);
2962 case BGP_NOTIFICATION
:
2963 bgp_notification_print(ndo
, dat
, length
);
2967 case BGP_ROUTE_REFRESH
:
2968 bgp_route_refresh_print(ndo
, dat
, length
);
2971 /* we have no decoder for the BGP message */
2972 ND_TCHECK_LEN(dat
, length
);
2973 ND_PRINT("\n\t no Message %u decoder", bgp_type
);
2974 print_unknown_data(ndo
, dat
, "\n\t ", length
);
2979 nd_print_trunc(ndo
);
2984 bgp_print(netdissect_options
*ndo
,
2985 const u_char
*dat
, u_int length _U_
)
2988 const u_char
*ep
= ndo
->ndo_snapend
;
2989 const u_char
*start
;
2990 const u_char marker
[] = {
2991 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2992 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2994 const struct bgp
*bgp_header
;
2997 ndo
->ndo_protocol
= "bgp";
3000 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
3008 if (GET_U_1(p
) != 0xff) {
3013 if (!ND_TTEST_LEN(p
, sizeof(marker
)))
3015 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
3020 /* found BGP header */
3021 ND_TCHECK_LEN(p
, BGP_SIZE
);
3022 bgp_header
= (const struct bgp
*)p
;
3025 nd_print_trunc(ndo
);
3027 hlen
= GET_BE_U_2(bgp_header
->bgp_len
);
3028 if (hlen
< BGP_SIZE
) {
3029 ND_PRINT("\nmessage length %u < %u", hlen
, BGP_SIZE
);
3030 nd_print_invalid(ndo
);
3034 if (ND_TTEST_LEN(p
, hlen
)) {
3035 if (!bgp_pdu_print(ndo
, p
, hlen
))
3040 ND_PRINT("\n[|BGP %s]",
3041 tok2str(bgp_msg_values
,
3042 "Unknown Message Type",
3043 GET_U_1(bgp_header
->bgp_type
)));
3051 nd_print_trunc(ndo
);