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 uint8_t 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 uint8_t bgpo_marker
[16];
78 uint16_t bgpo_holdtime
;
81 /* options should follow */
83 #define BGP_OPEN_SIZE 29 /* unaligned */
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 uint8_t bgpn_marker
[16];
100 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
102 struct bgp_route_refresh
{
103 uint8_t bgp_marker
[16];
106 uint8_t afi
[2]; /* the compiler messes this structure up */
107 uint8_t res
; /* when doing misaligned sequences of int8 and int16 */
108 uint8_t safi
; /* afi should be int16 - so we have to access it using */
109 }; /* EXTRACT_BE_U_2(&bgp_route_refresh->afi) (sigh) */
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) : *(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_TCHECK2(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_TCHECK2(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_TCHECK2(pptr
[0], sizeof(struct in_addr
));
638 snprintf(pos
, sizeof(addr
), "%s", ipaddr_string(ndo
, pptr
));
640 case (sizeof(struct in6_addr
) << 3): /* 128 */
641 ND_TCHECK2(pptr
[0], 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_TCHECK2(pptr
[0], (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_TCHECK2(pptr
[0], (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_TCHECK2(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_TCHECK2(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_TCHECK2(pptr
[0], sizeof(struct in_addr
));
894 pptr
+=sizeof(struct in_addr
);
896 /* MDT Group Address */
897 ND_TCHECK2(pptr
[0], 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_TCHECK2(pptr
[0], 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_TCHECK2(pptr
[0], 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_TCHECK2(pptr
[0], 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_TCHECK2(pptr
[0], 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_TCHECK2(pptr
[0], 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_TCHECK2(pptr
[0], 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_TCHECK2(pptr
[0],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_TCHECK2(pptr
[0],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_TCHECK2(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_TCHECK2(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_TCHECK2(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_TCHECK2(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_TCHECK2(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 + 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 bgp_attr_print(netdissect_options
*ndo
,
1378 u_int atype
, const u_char
*pptr
, u_int len
)
1382 uint8_t safi
, snpa
, nhlen
;
1383 union { /* copy buffer for bandwidth values */
1390 char buf
[MAXHOSTNAMELEN
+ 100];
1397 case BGPTYPE_ORIGIN
:
1399 ND_PRINT((ndo
, "invalid len"));
1402 ND_PRINT((ndo
, "%s", tok2str(bgp_origin_values
,
1403 "Unknown Origin Typecode",
1404 EXTRACT_U_1(tptr
))));
1409 * Process AS4 byte path and AS2 byte path attributes here.
1411 case BGPTYPE_AS4_PATH
:
1412 case BGPTYPE_AS_PATH
:
1414 ND_PRINT((ndo
, "invalid len"));
1418 ND_PRINT((ndo
, "empty"));
1423 * BGP updates exchanged between New speakers that support 4
1424 * byte AS, ASs are always encoded in 4 bytes. There is no
1425 * definitive way to find this, just by the packet's
1426 * contents. So, check for packet's TLV's sanity assuming
1427 * 2 bytes first, and it does not pass, assume that ASs are
1428 * encoded in 4 bytes format and move on.
1430 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1432 while (tptr
< pptr
+ len
) {
1434 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_open_values
,
1435 "?", EXTRACT_U_1(tptr
))));
1436 ND_TCHECK_1(tptr
+ 1);
1437 for (i
= 0; i
< tptr
[1] * as_size
; i
+= as_size
) {
1438 ND_TCHECK2(tptr
[2 + i
], as_size
);
1439 ND_PRINT((ndo
, "%s ",
1440 as_printf(ndo
, astostr
, sizeof(astostr
),
1442 EXTRACT_BE_U_2(tptr
+ i
+ 2) :
1443 EXTRACT_BE_U_4(tptr
+ i
+ 2))));
1446 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_close_values
,
1447 "?", EXTRACT_U_1(tptr
))));
1448 ND_TCHECK_1(tptr
+ 1);
1449 tptr
+= 2 + tptr
[1] * as_size
;
1452 case BGPTYPE_NEXT_HOP
:
1454 ND_PRINT((ndo
, "invalid len"));
1457 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1460 case BGPTYPE_MULTI_EXIT_DISC
:
1461 case BGPTYPE_LOCAL_PREF
:
1463 ND_PRINT((ndo
, "invalid len"));
1466 ND_PRINT((ndo
, "%u", EXTRACT_BE_U_4(tptr
)));
1469 case BGPTYPE_ATOMIC_AGGREGATE
:
1471 ND_PRINT((ndo
, "invalid len"));
1473 case BGPTYPE_AGGREGATOR
:
1476 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1477 * the length of this PA can be either 6 bytes or 8 bytes.
1479 if (len
!= 6 && len
!= 8) {
1480 ND_PRINT((ndo
, "invalid len"));
1483 ND_TCHECK2(tptr
[0], len
);
1485 ND_PRINT((ndo
, " AS #%s, origin %s",
1486 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_2(tptr
)),
1487 ipaddr_string(ndo
, tptr
+ 2)));
1489 ND_PRINT((ndo
, " AS #%s, origin %s",
1490 as_printf(ndo
, astostr
, sizeof(astostr
),
1491 EXTRACT_BE_U_4(tptr
)), ipaddr_string(ndo
, tptr
+ 4)));
1494 case BGPTYPE_AGGREGATOR4
:
1496 ND_PRINT((ndo
, "invalid len"));
1500 ND_PRINT((ndo
, " AS #%s, origin %s",
1501 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(tptr
)),
1502 ipaddr_string(ndo
, tptr
+ 4)));
1504 case BGPTYPE_COMMUNITIES
:
1506 ND_PRINT((ndo
, "invalid len"));
1512 comm
= EXTRACT_BE_U_4(tptr
);
1514 case BGP_COMMUNITY_NO_EXPORT
:
1515 ND_PRINT((ndo
, " NO_EXPORT"));
1517 case BGP_COMMUNITY_NO_ADVERT
:
1518 ND_PRINT((ndo
, " NO_ADVERTISE"));
1520 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1521 ND_PRINT((ndo
, " NO_EXPORT_SUBCONFED"));
1524 ND_PRINT((ndo
, "%u:%u%s",
1525 (comm
>> 16) & 0xffff,
1527 (tlen
>4) ? ", " : ""));
1534 case BGPTYPE_ORIGINATOR_ID
:
1536 ND_PRINT((ndo
, "invalid len"));
1540 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1542 case BGPTYPE_CLUSTER_LIST
:
1544 ND_PRINT((ndo
, "invalid len"));
1549 ND_PRINT((ndo
, "%s%s",
1550 ipaddr_string(ndo
, tptr
),
1551 (tlen
>4) ? ", " : ""));
1556 case BGPTYPE_MP_REACH_NLRI
:
1558 af
= EXTRACT_BE_U_2(tptr
);
1559 safi
= EXTRACT_U_1(tptr
+ 2);
1561 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1562 tok2str(af_values
, "Unknown AFI", af
),
1564 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1565 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1568 switch(af
<<8 | safi
) {
1569 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1570 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1571 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1572 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1573 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1574 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1575 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1576 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1577 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1578 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1579 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1580 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1581 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1582 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1583 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1584 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1585 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1586 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1587 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1588 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1589 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1590 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1591 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1592 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1593 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1594 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1595 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1598 ND_TCHECK2(tptr
[0], tlen
);
1599 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1600 if (ndo
->ndo_vflag
<= 1)
1601 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1609 nhlen
= EXTRACT_U_1(tptr
);
1615 ND_PRINT((ndo
, "\n\t nexthop: "));
1618 ND_PRINT((ndo
, ", " ));
1620 switch(af
<<8 | safi
) {
1621 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1622 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1623 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1624 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1625 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1626 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1627 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1628 if (tlen
< sizeof(struct in_addr
)) {
1629 ND_PRINT((ndo
, "invalid len"));
1632 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1633 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1634 tlen
-= sizeof(struct in_addr
);
1635 tptr
+= sizeof(struct in_addr
);
1638 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1639 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1640 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1641 if (tlen
< sizeof(struct in_addr
)+BGP_VPN_RD_LEN
) {
1642 ND_PRINT((ndo
, "invalid len"));
1645 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1646 ND_PRINT((ndo
, "RD: %s, %s",
1647 bgp_vpn_rd_print(ndo
, tptr
),
1648 ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1649 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1650 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1653 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1654 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1655 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1656 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1657 if (tlen
< sizeof(struct in6_addr
)) {
1658 ND_PRINT((ndo
, "invalid len"));
1661 ND_TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1662 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, tptr
)));
1663 tlen
-= sizeof(struct in6_addr
);
1664 tptr
+= sizeof(struct in6_addr
);
1667 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1668 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1669 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1670 if (tlen
< sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
) {
1671 ND_PRINT((ndo
, "invalid len"));
1674 ND_TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1675 ND_PRINT((ndo
, "RD: %s, %s",
1676 bgp_vpn_rd_print(ndo
, tptr
),
1677 ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1678 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1679 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1682 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1683 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1684 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1685 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1686 if (tlen
< sizeof(struct in_addr
)) {
1687 ND_PRINT((ndo
, "invalid len"));
1690 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1691 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1692 tlen
-= (sizeof(struct in_addr
));
1693 tptr
+= (sizeof(struct in_addr
));
1696 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1697 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1698 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1699 ND_TCHECK2(tptr
[0], tlen
);
1700 ND_PRINT((ndo
, "%s", isonsap_string(ndo
, tptr
, tlen
)));
1705 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1706 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1707 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1708 if (tlen
< BGP_VPN_RD_LEN
+1) {
1709 ND_PRINT((ndo
, "invalid len"));
1712 ND_TCHECK2(tptr
[0], tlen
);
1713 ND_PRINT((ndo
, "RD: %s, %s",
1714 bgp_vpn_rd_print(ndo
, tptr
),
1715 isonsap_string(ndo
, tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
)));
1716 /* rfc986 mapped IPv4 address ? */
1717 if (EXTRACT_BE_U_4(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
1718 ND_PRINT((ndo
, " = %s", ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+4)));
1719 /* rfc1888 mapped IPv6 address ? */
1720 else if (EXTRACT_BE_U_3(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
1721 ND_PRINT((ndo
, " = %s", ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+3)));
1727 ND_TCHECK2(tptr
[0], tlen
);
1728 ND_PRINT((ndo
, "no AFI %u/SAFI %u decoder", af
, safi
));
1729 if (ndo
->ndo_vflag
<= 1)
1730 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1738 ND_PRINT((ndo
, ", nh-length: %u", nhlen
));
1742 snpa
= EXTRACT_U_1(tptr
);
1746 ND_PRINT((ndo
, "\n\t %u SNPA", snpa
));
1747 for (/*nothing*/; snpa
> 0; snpa
--) {
1749 ND_PRINT((ndo
, "\n\t %d bytes", EXTRACT_U_1(tptr
)));
1750 tptr
+= tptr
[0] + 1;
1753 ND_PRINT((ndo
, ", no SNPA"));
1756 while (tptr
< pptr
+ len
) {
1757 switch (af
<<8 | safi
) {
1758 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1759 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1760 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1761 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1763 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1764 else if (advance
== -2)
1766 else if (advance
== -3)
1767 break; /* bytes left, but not enough */
1769 ND_PRINT((ndo
, "\n\t %s", buf
));
1771 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1772 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1774 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1775 else if (advance
== -2)
1777 else if (advance
== -3)
1778 break; /* bytes left, but not enough */
1780 ND_PRINT((ndo
, "\n\t %s", buf
));
1782 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1783 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1784 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1785 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1787 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1788 else if (advance
== -2)
1791 ND_PRINT((ndo
, "\n\t %s", buf
));
1793 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1794 advance
= decode_rt_routing_info(ndo
, tptr
, buf
, sizeof(buf
));
1796 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1797 else if (advance
== -2)
1800 ND_PRINT((ndo
, "\n\t %s", buf
));
1802 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1803 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1804 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1806 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1807 else if (advance
== -2)
1810 ND_PRINT((ndo
, "\n\t %s", buf
));
1813 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1814 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
1816 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1817 else if (advance
== -2)
1820 ND_PRINT((ndo
, "\n\t %s", buf
));
1822 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1823 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1824 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1825 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1827 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1828 else if (advance
== -2)
1830 else if (advance
== -3)
1831 break; /* bytes left, but not enough */
1833 ND_PRINT((ndo
, "\n\t %s", buf
));
1835 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1836 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1838 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1839 else if (advance
== -2)
1841 else if (advance
== -3)
1842 break; /* bytes left, but not enough */
1844 ND_PRINT((ndo
, "\n\t %s", buf
));
1846 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1847 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1848 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1849 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1851 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1852 else if (advance
== -2)
1855 ND_PRINT((ndo
, "\n\t %s", buf
));
1857 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1858 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1859 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1860 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1861 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1863 ND_PRINT((ndo
, "\n\t (illegal length)"));
1864 else if (advance
== -2)
1867 ND_PRINT((ndo
, "\n\t %s", buf
));
1869 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1870 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1871 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1872 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1874 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1875 else if (advance
== -2)
1878 ND_PRINT((ndo
, "\n\t %s", buf
));
1880 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1881 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1882 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1883 advance
= decode_labeled_vpn_clnp_prefix(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
));
1892 ND_TCHECK2(*tptr
,tlen
);
1893 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1894 if (ndo
->ndo_vflag
<= 1)
1895 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1907 case BGPTYPE_MP_UNREACH_NLRI
:
1908 ND_TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1909 af
= EXTRACT_BE_U_2(tptr
);
1910 safi
= EXTRACT_U_1(tptr
+ 2);
1912 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1913 tok2str(af_values
, "Unknown AFI", af
),
1915 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1916 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1919 if (len
== BGP_MP_NLRI_MINSIZE
)
1920 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
1924 while (tptr
< pptr
+ len
) {
1925 switch (af
<<8 | safi
) {
1926 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1927 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1928 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1929 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1931 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1932 else if (advance
== -2)
1934 else if (advance
== -3)
1935 break; /* bytes left, but not enough */
1937 ND_PRINT((ndo
, "\n\t %s", buf
));
1939 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1940 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1942 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1943 else if (advance
== -2)
1945 else if (advance
== -3)
1946 break; /* bytes left, but not enough */
1948 ND_PRINT((ndo
, "\n\t %s", buf
));
1950 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1951 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1952 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1953 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1955 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1956 else if (advance
== -2)
1959 ND_PRINT((ndo
, "\n\t %s", buf
));
1961 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1962 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1963 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1964 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1966 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1967 else if (advance
== -2)
1969 else if (advance
== -3)
1970 break; /* bytes left, but not enough */
1972 ND_PRINT((ndo
, "\n\t %s", buf
));
1974 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1975 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1977 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1978 else if (advance
== -2)
1980 else if (advance
== -3)
1981 break; /* bytes left, but not enough */
1983 ND_PRINT((ndo
, "\n\t %s", buf
));
1985 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1986 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1987 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1988 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1990 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1991 else if (advance
== -2)
1994 ND_PRINT((ndo
, "\n\t %s", buf
));
1996 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1997 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1998 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1999 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2000 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
2002 ND_PRINT((ndo
, "\n\t (illegal length)"));
2003 else if (advance
== -2)
2006 ND_PRINT((ndo
, "\n\t %s", buf
));
2008 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2009 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2010 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2011 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2013 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2014 else if (advance
== -2)
2017 ND_PRINT((ndo
, "\n\t %s", buf
));
2019 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2020 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2021 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2022 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2024 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2025 else if (advance
== -2)
2028 ND_PRINT((ndo
, "\n\t %s", buf
));
2030 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
2031 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
2033 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2034 else if (advance
== -2)
2037 ND_PRINT((ndo
, "\n\t %s", buf
));
2039 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
2040 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
2041 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
2043 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2044 else if (advance
== -2)
2047 ND_PRINT((ndo
, "\n\t %s", buf
));
2050 ND_TCHECK2(*(tptr
-3),tlen
);
2051 ND_PRINT((ndo
, "no AFI %u / SAFI %u decoder", af
, safi
));
2052 if (ndo
->ndo_vflag
<= 1)
2053 print_unknown_data(ndo
, tptr
-3, "\n\t ", tlen
);
2063 case BGPTYPE_EXTD_COMMUNITIES
:
2065 ND_PRINT((ndo
, "invalid len"));
2072 extd_comm
=EXTRACT_BE_U_2(tptr
);
2074 ND_PRINT((ndo
, "\n\t %s (0x%04x), Flags [%s]",
2075 tok2str(bgp_extd_comm_subtype_values
,
2076 "unknown extd community typecode",
2079 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
)));
2081 ND_TCHECK_6(tptr
+ 2);
2083 case BGP_EXT_COM_RT_0
:
2084 case BGP_EXT_COM_RO_0
:
2085 case BGP_EXT_COM_L2VPN_RT_0
:
2086 ND_PRINT((ndo
, ": %u:%u (= %s)",
2087 EXTRACT_BE_U_2(tptr
+ 2),
2088 EXTRACT_BE_U_4(tptr
+ 4),
2089 ipaddr_string(ndo
, tptr
+4)));
2091 case BGP_EXT_COM_RT_1
:
2092 case BGP_EXT_COM_RO_1
:
2093 case BGP_EXT_COM_L2VPN_RT_1
:
2094 case BGP_EXT_COM_VRF_RT_IMP
:
2095 ND_PRINT((ndo
, ": %s:%u",
2096 ipaddr_string(ndo
, tptr
+2),
2097 EXTRACT_BE_U_2(tptr
+ 6)));
2099 case BGP_EXT_COM_RT_2
:
2100 case BGP_EXT_COM_RO_2
:
2101 ND_PRINT((ndo
, ": %s:%u",
2102 as_printf(ndo
, astostr
, sizeof(astostr
),
2103 EXTRACT_BE_U_4(tptr
+ 2)), EXTRACT_BE_U_2(tptr
+ 6)));
2105 case BGP_EXT_COM_LINKBAND
:
2106 bw
.i
= EXTRACT_BE_U_4(tptr
+ 2);
2107 ND_PRINT((ndo
, ": bandwidth: %.3f Mbps",
2110 case BGP_EXT_COM_VPN_ORIGIN
:
2111 case BGP_EXT_COM_VPN_ORIGIN2
:
2112 case BGP_EXT_COM_VPN_ORIGIN3
:
2113 case BGP_EXT_COM_VPN_ORIGIN4
:
2114 case BGP_EXT_COM_OSPF_RID
:
2115 case BGP_EXT_COM_OSPF_RID2
:
2116 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
+2)));
2118 case BGP_EXT_COM_OSPF_RTYPE
:
2119 case BGP_EXT_COM_OSPF_RTYPE2
:
2120 ND_PRINT((ndo
, ": area:%s, router-type:%s, metric-type:%s%s",
2121 ipaddr_string(ndo
, tptr
+2),
2122 tok2str(bgp_extd_comm_ospf_rtype_values
,
2124 EXTRACT_U_1((tptr
+ 6))),
2125 (EXTRACT_U_1(tptr
+ 7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
2126 ((EXTRACT_U_1(tptr
+ 6) == BGP_OSPF_RTYPE_EXT
) || (EXTRACT_U_1(tptr
+ 6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : ""));
2128 case BGP_EXT_COM_L2INFO
:
2129 ND_PRINT((ndo
, ": %s Control Flags [0x%02x]:MTU %u",
2130 tok2str(l2vpn_encaps_values
,
2132 EXTRACT_U_1((tptr
+ 2))),
2133 EXTRACT_U_1((tptr
+ 3)),
2134 EXTRACT_BE_U_2(tptr
+ 4)));
2136 case BGP_EXT_COM_SOURCE_AS
:
2137 ND_PRINT((ndo
, ": AS %u", EXTRACT_BE_U_2(tptr
+ 2)));
2141 print_unknown_data(ndo
, tptr
, "\n\t ", 8);
2149 case BGPTYPE_PMSI_TUNNEL
:
2151 uint8_t tunnel_type
, flags
;
2154 flags
= EXTRACT_U_1(tptr
);
2155 tunnel_type
= EXTRACT_U_1(tptr
+ 1);
2158 ND_PRINT((ndo
, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2159 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2161 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2162 EXTRACT_BE_U_3(tptr
+ 2)>>4));
2167 switch (tunnel_type
) {
2168 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2169 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2171 ND_PRINT((ndo
, "\n\t Sender %s, P-Group %s",
2172 ipaddr_string(ndo
, tptr
),
2173 ipaddr_string(ndo
, tptr
+4)));
2176 case BGP_PMSI_TUNNEL_PIM_SSM
:
2178 ND_PRINT((ndo
, "\n\t Root-Node %s, P-Group %s",
2179 ipaddr_string(ndo
, tptr
),
2180 ipaddr_string(ndo
, tptr
+4)));
2182 case BGP_PMSI_TUNNEL_INGRESS
:
2184 ND_PRINT((ndo
, "\n\t Tunnel-Endpoint %s",
2185 ipaddr_string(ndo
, tptr
)));
2187 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2188 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2190 ND_PRINT((ndo
, "\n\t Root-Node %s, LSP-ID 0x%08x",
2191 ipaddr_string(ndo
, tptr
),
2192 EXTRACT_BE_U_4(tptr
+ 4)));
2194 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2196 ND_PRINT((ndo
, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2197 ipaddr_string(ndo
, tptr
),
2198 EXTRACT_BE_U_4(tptr
+ 4)));
2201 if (ndo
->ndo_vflag
<= 1) {
2202 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2218 type
= EXTRACT_U_1(tptr
);
2219 length
= EXTRACT_BE_U_2(tptr
+ 1);
2223 ND_PRINT((ndo
, "\n\t %s TLV (%u), length %u",
2224 tok2str(bgp_aigp_values
, "Unknown", type
),
2232 * Check if we can read the TLV data.
2234 ND_TCHECK2(tptr
[3], length
);
2241 ND_PRINT((ndo
, ", metric %" PRIu64
,
2242 EXTRACT_BE_U_8(tptr
)));
2246 if (ndo
->ndo_vflag
<= 1) {
2247 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2256 case BGPTYPE_ATTR_SET
:
2260 ND_PRINT((ndo
, "\n\t Origin AS: %s",
2261 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_U_4(tptr
))));
2266 u_int aflags
, alenlen
, alen
;
2271 aflags
= EXTRACT_U_1(tptr
);
2272 atype
= EXTRACT_U_1(tptr
+ 1);
2275 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2276 ND_TCHECK2(tptr
[0], alenlen
);
2279 alen
= bgp_attr_len(aflags
, tptr
);
2283 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2284 tok2str(bgp_attr_values
,
2285 "Unknown Attribute", atype
),
2290 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2291 aflags
& 0x80 ? "O" : "",
2292 aflags
& 0x40 ? "T" : "",
2293 aflags
& 0x20 ? "P" : "",
2294 aflags
& 0x10 ? "E" : ""));
2296 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2297 ND_PRINT((ndo
, "]: "));
2299 /* FIXME check for recursion */
2300 if (!bgp_attr_print(ndo
, atype
, tptr
, alen
))
2307 case BGPTYPE_LARGE_COMMUNITY
:
2308 if (len
== 0 || len
% 12) {
2309 ND_PRINT((ndo
, "invalid len"));
2312 ND_PRINT((ndo
, "\n\t "));
2314 ND_TCHECK2(*tptr
, 12);
2315 ND_PRINT((ndo
, "%u:%u:%u%s",
2316 EXTRACT_BE_U_4(tptr
),
2317 EXTRACT_BE_U_4(tptr
+ 4),
2318 EXTRACT_BE_U_4(tptr
+ 8),
2319 (len
> 12) ? ", " : ""));
2325 ND_TCHECK2(*pptr
,len
);
2326 ND_PRINT((ndo
, "\n\t no Attribute %u decoder", atype
)); /* we have no decoder for the attribute */
2327 if (ndo
->ndo_vflag
<= 1)
2328 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2331 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2332 ND_TCHECK2(*pptr
,len
);
2333 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2342 bgp_capabilities_print(netdissect_options
*ndo
,
2343 const u_char
*opt
, int caps_len
)
2345 int cap_type
, cap_len
, tcap_len
, cap_offset
;
2348 while (i
< caps_len
) {
2349 ND_TCHECK2(opt
[i
], BGP_CAP_HEADER_SIZE
);
2350 cap_type
=EXTRACT_U_1(opt
+ i
);
2351 cap_len
=EXTRACT_U_1(opt
+ i
+ 1);
2353 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2354 tok2str(bgp_capcode_values
, "Unknown",
2358 ND_TCHECK2(opt
[i
+2], cap_len
);
2360 case BGP_CAPCODE_MP
:
2361 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u)",
2362 tok2str(af_values
, "Unknown",
2363 EXTRACT_BE_U_2(opt
+ i
+ 2)),
2364 EXTRACT_BE_U_2(opt
+ i
+ 2),
2365 tok2str(bgp_safi_values
, "Unknown",
2366 EXTRACT_U_1(opt
+ i
+ 5)),
2367 EXTRACT_U_1(opt
+ i
+ 5)));
2369 case BGP_CAPCODE_RESTART
:
2370 ND_PRINT((ndo
, "\n\t\tRestart Flags: [%s], Restart Time %us",
2371 ((EXTRACT_U_1(opt
+ i
+ 2))&0x80) ? "R" : "none",
2372 EXTRACT_BE_U_2(opt
+ i
+ 2)&0xfff));
2375 while(tcap_len
>=4) {
2376 ND_PRINT((ndo
, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2377 tok2str(af_values
,"Unknown",
2378 EXTRACT_BE_U_2(opt
+ i
+ cap_offset
)),
2379 EXTRACT_BE_U_2(opt
+ i
+ cap_offset
),
2380 tok2str(bgp_safi_values
,"Unknown",
2381 EXTRACT_U_1(opt
+ i
+ cap_offset
+ 2)),
2382 EXTRACT_U_1(opt
+ (i
+ cap_offset
+ 2)),
2383 ((EXTRACT_U_1(opt
+ (i
+ cap_offset
+ 3)))&0x80) ? "yes" : "no" ));
2388 case BGP_CAPCODE_RR
:
2389 case BGP_CAPCODE_RR_CISCO
:
2391 case BGP_CAPCODE_AS_NEW
:
2394 * Extract the 4 byte AS number encoded.
2397 ND_PRINT((ndo
, "\n\t\t 4 Byte AS %s",
2398 as_printf(ndo
, astostr
, sizeof(astostr
),
2399 EXTRACT_BE_U_4(opt
+ i
+ 2))));
2402 case BGP_CAPCODE_ADD_PATH
:
2404 if (tcap_len
== 0) {
2405 ND_PRINT((ndo
, " (bogus)")); /* length */
2408 while (tcap_len
> 0) {
2410 ND_PRINT((ndo
, "\n\t\t(invalid)"));
2413 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2414 tok2str(af_values
,"Unknown",EXTRACT_BE_U_2(opt
+ i
+ cap_offset
)),
2415 EXTRACT_BE_U_2(opt
+ i
+ cap_offset
),
2416 tok2str(bgp_safi_values
,"Unknown",EXTRACT_U_1(opt
+ i
+ cap_offset
+ 2)),
2417 EXTRACT_U_1(opt
+ (i
+ cap_offset
+ 2)),
2418 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",EXTRACT_U_1(opt
+ i
+ cap_offset
+ 3))
2425 ND_PRINT((ndo
, "\n\t\tno decoder for Capability %u",
2427 if (ndo
->ndo_vflag
<= 1)
2428 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t",
2432 if (ndo
->ndo_vflag
> 1 && cap_len
> 0) {
2433 print_unknown_data(ndo
, opt
+ i
+ 2, "\n\t\t", cap_len
);
2435 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2440 ND_PRINT((ndo
, "[|BGP]"));
2444 bgp_open_print(netdissect_options
*ndo
,
2445 const u_char
*dat
, int length
)
2447 struct bgp_open bgpo
;
2448 struct bgp_opt bgpopt
;
2452 ND_TCHECK2(dat
[0], BGP_OPEN_SIZE
);
2453 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
2455 ND_PRINT((ndo
, "\n\t Version %d, ", bgpo
.bgpo_version
));
2456 ND_PRINT((ndo
, "my AS %s, ",
2457 as_printf(ndo
, astostr
, sizeof(astostr
), ntohs(bgpo
.bgpo_myas
))));
2458 ND_PRINT((ndo
, "Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
)));
2459 ND_PRINT((ndo
, "ID %s", ipaddr_string(ndo
, &bgpo
.bgpo_id
)));
2460 ND_PRINT((ndo
, "\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
));
2462 /* some little sanity checking */
2463 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
2467 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
2471 while (i
< bgpo
.bgpo_optlen
) {
2472 ND_TCHECK2(opt
[i
], BGP_OPT_SIZE
);
2473 memcpy(&bgpopt
, opt
+ i
, BGP_OPT_SIZE
);
2474 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
2475 ND_PRINT((ndo
, "\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
));
2479 ND_PRINT((ndo
, "\n\t Option %s (%u), length: %u",
2480 tok2str(bgp_opt_values
,"Unknown",
2481 bgpopt
.bgpopt_type
),
2483 bgpopt
.bgpopt_len
));
2485 /* now let's decode the options we know*/
2486 switch(bgpopt
.bgpopt_type
) {
2489 bgp_capabilities_print(ndo
, opt
+ i
+ BGP_OPT_SIZE
,
2495 ND_PRINT((ndo
, "\n\t no decoder for option %u",
2496 bgpopt
.bgpopt_type
));
2499 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
2503 ND_PRINT((ndo
, "[|BGP]"));
2507 bgp_update_print(netdissect_options
*ndo
,
2508 const u_char
*dat
, int length
)
2512 int withdrawn_routes_len
;
2516 ND_TCHECK2(dat
[0], BGP_SIZE
);
2517 if (length
< BGP_SIZE
)
2519 memcpy(&bgp
, dat
, BGP_SIZE
);
2520 p
= dat
+ BGP_SIZE
; /*XXX*/
2523 /* Unfeasible routes */
2527 withdrawn_routes_len
= EXTRACT_BE_U_2(p
);
2530 if (withdrawn_routes_len
) {
2532 * Without keeping state from the original NLRI message,
2533 * it's not possible to tell if this a v4 or v6 route,
2534 * so only try to decode it if we're not v6 enabled.
2536 ND_TCHECK2(p
[0], withdrawn_routes_len
);
2537 if (length
< withdrawn_routes_len
)
2539 ND_PRINT((ndo
, "\n\t Withdrawn routes: %d bytes", withdrawn_routes_len
));
2540 p
+= withdrawn_routes_len
;
2541 length
-= withdrawn_routes_len
;
2547 len
= EXTRACT_BE_U_2(p
);
2551 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2552 /* No withdrawn routes, no path attributes, no NLRI */
2553 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
2558 /* do something more useful!*/
2560 int aflags
, atype
, alenlen
, alen
;
2567 aflags
= EXTRACT_U_1(p
);
2568 atype
= EXTRACT_U_1(p
+ 1);
2572 alenlen
= bgp_attr_lenlen(aflags
, p
);
2573 ND_TCHECK2(p
[0], alenlen
);
2576 if (length
< alenlen
)
2578 alen
= bgp_attr_len(aflags
, p
);
2583 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2584 tok2str(bgp_attr_values
, "Unknown Attribute",
2590 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2591 aflags
& 0x80 ? "O" : "",
2592 aflags
& 0x40 ? "T" : "",
2593 aflags
& 0x20 ? "P" : "",
2594 aflags
& 0x10 ? "E" : ""));
2596 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2597 ND_PRINT((ndo
, "]: "));
2603 if (!bgp_attr_print(ndo
, atype
, p
, alen
))
2613 * XXX - what if they're using the "Advertisement of
2614 * Multiple Paths in BGP" feature:
2616 * https://datatracker.ietf.org/doc/draft-ietf-idr-add-paths/
2618 * http://tools.ietf.org/html/draft-ietf-idr-add-paths-06
2620 ND_PRINT((ndo
, "\n\t Updated routes:"));
2622 char buf
[MAXHOSTNAMELEN
+ 100];
2623 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2625 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2630 goto trunc
; /* bytes left, but not enough */
2632 ND_PRINT((ndo
, "\n\t %s", buf
));
2640 ND_PRINT((ndo
, "[|BGP]"));
2644 bgp_notification_print(netdissect_options
*ndo
,
2645 const u_char
*dat
, int length
)
2647 struct bgp_notification bgpn
;
2649 uint8_t shutdown_comm_length
;
2650 uint8_t remainder_offset
;
2652 ND_TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
2653 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
2655 /* some little sanity checking */
2656 if (length
<BGP_NOTIFICATION_SIZE
)
2659 ND_PRINT((ndo
, ", %s (%u)",
2660 tok2str(bgp_notify_major_values
, "Unknown Error",
2664 switch (bgpn
.bgpn_major
) {
2666 case BGP_NOTIFY_MAJOR_MSG
:
2667 ND_PRINT((ndo
, ", subcode %s (%u)",
2668 tok2str(bgp_notify_minor_msg_values
, "Unknown",
2672 case BGP_NOTIFY_MAJOR_OPEN
:
2673 ND_PRINT((ndo
, ", subcode %s (%u)",
2674 tok2str(bgp_notify_minor_open_values
, "Unknown",
2678 case BGP_NOTIFY_MAJOR_UPDATE
:
2679 ND_PRINT((ndo
, ", subcode %s (%u)",
2680 tok2str(bgp_notify_minor_update_values
, "Unknown",
2684 case BGP_NOTIFY_MAJOR_FSM
:
2685 ND_PRINT((ndo
, " subcode %s (%u)",
2686 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
2690 case BGP_NOTIFY_MAJOR_CAP
:
2691 ND_PRINT((ndo
, " subcode %s (%u)",
2692 tok2str(bgp_notify_minor_cap_values
, "Unknown",
2696 case BGP_NOTIFY_MAJOR_CEASE
:
2697 ND_PRINT((ndo
, ", subcode %s (%u)",
2698 tok2str(bgp_notify_minor_cease_values
, "Unknown",
2702 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2703 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2705 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2706 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2708 ND_PRINT((ndo
, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2709 tok2str(af_values
, "Unknown",
2710 EXTRACT_BE_U_2(tptr
)),
2711 EXTRACT_BE_U_2(tptr
),
2712 tok2str(bgp_safi_values
, "Unknown", EXTRACT_U_1((tptr
+ 2))),
2713 EXTRACT_U_1((tptr
+ 2)),
2714 EXTRACT_BE_U_4(tptr
+ 3)));
2717 * draft-ietf-idr-shutdown describes a method to send a communication
2718 * intended for human consumption regarding the Administrative Shutdown
2720 if ((bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
2721 bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
2722 length
>= BGP_NOTIFICATION_SIZE
+ 1) {
2723 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2725 shutdown_comm_length
= EXTRACT_U_1(tptr
);
2726 remainder_offset
= 0;
2727 /* garbage, hexdump it all */
2728 if (shutdown_comm_length
> BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN
||
2729 shutdown_comm_length
> length
- (BGP_NOTIFICATION_SIZE
+ 1)) {
2730 ND_PRINT((ndo
, ", invalid Shutdown Communication length"));
2732 else if (shutdown_comm_length
== 0) {
2733 ND_PRINT((ndo
, ", empty Shutdown Communication"));
2734 remainder_offset
+= 1;
2736 /* a proper shutdown communication */
2738 ND_TCHECK2(*(tptr
+1), shutdown_comm_length
);
2739 ND_PRINT((ndo
, ", Shutdown Communication (length: %u): \"", shutdown_comm_length
));
2740 (void)fn_printn(ndo
, tptr
+1, shutdown_comm_length
, NULL
);
2741 ND_PRINT((ndo
, "\""));
2742 remainder_offset
+= shutdown_comm_length
+ 1;
2744 /* if there is trailing data, hexdump it */
2745 if(length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
) > 0) {
2746 ND_PRINT((ndo
, ", Data: (length: %u)", length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
)));
2747 hex_print(ndo
, "\n\t\t", tptr
+ remainder_offset
, length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
2757 ND_PRINT((ndo
, "[|BGP]"));
2761 bgp_route_refresh_print(netdissect_options
*ndo
,
2762 const u_char
*pptr
, int len
)
2764 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2766 ND_TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
2768 /* some little sanity checking */
2769 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2772 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2774 ND_PRINT((ndo
, "\n\t AFI %s (%u), SAFI %s (%u)",
2775 tok2str(af_values
,"Unknown",
2776 /* this stinks but the compiler pads the structure
2778 EXTRACT_BE_U_2(&bgp_route_refresh_header
->afi
)),
2779 EXTRACT_BE_U_2(&bgp_route_refresh_header
->afi
),
2780 tok2str(bgp_safi_values
,"Unknown",
2781 bgp_route_refresh_header
->safi
),
2782 bgp_route_refresh_header
->safi
));
2784 if (ndo
->ndo_vflag
> 1) {
2785 ND_TCHECK2(*pptr
, len
);
2786 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2791 ND_PRINT((ndo
, "[|BGP]"));
2795 bgp_header_print(netdissect_options
*ndo
,
2796 const u_char
*dat
, int length
)
2800 ND_TCHECK2(dat
[0], BGP_SIZE
);
2801 memcpy(&bgp
, dat
, BGP_SIZE
);
2802 ND_PRINT((ndo
, "\n\t%s Message (%u), length: %u",
2803 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
2807 switch (bgp
.bgp_type
) {
2809 bgp_open_print(ndo
, dat
, length
);
2812 bgp_update_print(ndo
, dat
, length
);
2814 case BGP_NOTIFICATION
:
2815 bgp_notification_print(ndo
, dat
, length
);
2819 case BGP_ROUTE_REFRESH
:
2820 bgp_route_refresh_print(ndo
, dat
, length
);
2823 /* we have no decoder for the BGP message */
2824 ND_TCHECK2(*dat
, length
);
2825 ND_PRINT((ndo
, "\n\t no Message %u decoder", bgp
.bgp_type
));
2826 print_unknown_data(ndo
, dat
, "\n\t ", length
);
2831 ND_PRINT((ndo
, "[|BGP]"));
2836 bgp_print(netdissect_options
*ndo
,
2837 const u_char
*dat
, int length
)
2841 const u_char
*start
;
2842 const u_char marker
[] = {
2843 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2844 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2850 if (ndo
->ndo_snapend
< dat
+ length
)
2851 ep
= ndo
->ndo_snapend
;
2853 ND_PRINT((ndo
, ": BGP"));
2855 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
2863 if (EXTRACT_U_1(p
) != 0xff) {
2868 if (!ND_TTEST2(p
[0], sizeof(marker
)))
2870 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2875 /* found BGP header */
2876 ND_TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2877 memcpy(&bgp
, p
, BGP_SIZE
);
2880 ND_PRINT((ndo
, " [|BGP]"));
2882 hlen
= ntohs(bgp
.bgp_len
);
2883 if (hlen
< BGP_SIZE
) {
2884 ND_PRINT((ndo
, "\n[|BGP Bogus header length %u < %u]", hlen
,
2889 if (ND_TTEST2(p
[0], hlen
)) {
2890 if (!bgp_header_print(ndo
, p
, hlen
))
2895 ND_PRINT((ndo
, "\n[|BGP %s]",
2896 tok2str(bgp_msg_values
,
2897 "Unknown Message Type",
2906 ND_PRINT((ndo
, " [|BGP]"));
2911 * c-style: whitesmith