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_16BITS(&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_16BITS(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
;
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 */
575 ND_TCHECK2(pptr
[0], 4);
577 plen
= pptr
[0]; /* 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_24BITS(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 */
683 ND_TCHECK2(pptr
[0], 1);
684 addr_length
= *pptr
++;
687 ND_TCHECK2(pptr
[0], (addr_length
>> 3));
688 total_length
+= (addr_length
>> 3) + 1;
689 offset
= strlen(buf
);
691 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
692 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
693 pptr
+= (addr_length
>> 3);
696 /* Group address length, encoded in bits */
697 ND_TCHECK2(pptr
[0], 1);
698 addr_length
= *pptr
++;
701 ND_TCHECK2(pptr
[0], (addr_length
>> 3));
702 total_length
+= (addr_length
>> 3) + 1;
703 offset
= strlen(buf
);
705 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
706 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
707 pptr
+= (addr_length
>> 3);
711 return (total_length
);
714 /* RDs and RTs share the same semantics
715 * we use bgp_vpn_rd_print for
716 * printing route targets inside a NLRI */
718 bgp_vpn_rd_print(netdissect_options
*ndo
,
721 /* allocate space for the largest possible string */
722 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
725 /* ok lets load the RD format */
726 switch (EXTRACT_16BITS(pptr
)) {
728 /* 2-byte-AS:number fmt*/
730 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
731 EXTRACT_16BITS(pptr
+2),
732 EXTRACT_32BITS(pptr
+4),
733 *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
735 /* IP-address:AS fmt*/
738 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
739 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
742 /* 4-byte-AS:number fmt*/
744 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
745 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(pptr
+2)),
746 EXTRACT_16BITS(pptr
+6), *(pptr
+2), *(pptr
+3), *(pptr
+4),
747 *(pptr
+5), EXTRACT_16BITS(pptr
+6));
750 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
759 decode_rt_routing_info(netdissect_options
*ndo
,
760 const u_char
*pptr
, char *buf
, u_int buflen
)
762 uint8_t route_target
[8];
764 char asbuf
[sizeof(astostr
)]; /* bgp_vpn_rd_print() overwrites astostr */
766 /* NLRI "prefix length" from RFC 2858 Section 4. */
768 plen
= pptr
[0]; /* get prefix length */
770 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
771 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
772 * target" fields inside the "prefix" depending on its length.
775 /* Without "origin AS", without "route target". */
776 snprintf(buf
, buflen
, "default route target");
783 /* With at least "origin AS", possibly with "route target". */
784 ND_TCHECK_32BITS(pptr
+ 1);
785 as_printf(ndo
, asbuf
, sizeof(asbuf
), EXTRACT_32BITS(pptr
+ 1));
787 plen
-=32; /* adjust prefix length */
792 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
793 * and gives the number of octets in the variable-length "route
794 * target" field inside this NLRI "prefix". Look for it.
796 memset(&route_target
, 0, sizeof(route_target
));
797 ND_TCHECK2(pptr
[5], (plen
+ 7) / 8);
798 memcpy(&route_target
, &pptr
[5], (plen
+ 7) / 8);
799 /* Which specification says to do this? */
801 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
802 ((0xff00 >> (plen
% 8)) & 0xff);
804 snprintf(buf
, buflen
, "origin AS: %s, route target %s",
806 bgp_vpn_rd_print(ndo
, (u_char
*)&route_target
));
808 return 5 + (plen
+ 7) / 8;
815 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
816 const u_char
*pptr
, char *buf
, u_int buflen
)
822 plen
= pptr
[0]; /* get prefix length */
827 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
832 memset(&addr
, 0, sizeof(addr
));
833 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
834 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
836 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
837 ((0xff00 >> (plen
% 8)) & 0xff);
839 /* the label may get offsetted by 4 bits so lets shift it right */
840 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
841 bgp_vpn_rd_print(ndo
, pptr
+4),
842 ipaddr_string(ndo
, &addr
),
844 EXTRACT_24BITS(pptr
+1)>>4,
845 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
847 return 12 + (plen
+ 7) / 8;
854 * +-------------------------------+
856 * | RD:IPv4-address (12 octets) |
858 * +-------------------------------+
859 * | MDT Group-address (4 octets) |
860 * +-------------------------------+
863 #define MDT_VPN_NLRI_LEN 16
866 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
867 const u_char
*pptr
, char *buf
, u_int buflen
)
871 const u_char
*vpn_ip
;
875 /* if the NLRI is not predefined length, quit.*/
876 if (*pptr
!= MDT_VPN_NLRI_LEN
* 8)
881 ND_TCHECK2(pptr
[0], 8);
886 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
888 pptr
+=sizeof(struct in_addr
);
890 /* MDT Group Address */
891 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
893 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
894 bgp_vpn_rd_print(ndo
, rd
), ipaddr_string(ndo
, vpn_ip
), ipaddr_string(ndo
, pptr
));
896 return MDT_VPN_NLRI_LEN
+ 1;
903 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
904 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
905 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
906 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
907 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
908 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
909 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
911 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
912 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
913 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
914 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
915 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
916 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
917 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
918 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
923 decode_multicast_vpn(netdissect_options
*ndo
,
924 const u_char
*pptr
, char *buf
, u_int buflen
)
926 uint8_t route_type
, route_length
, addr_length
, sg_length
;
929 ND_TCHECK2(pptr
[0], 2);
930 route_type
= *pptr
++;
931 route_length
= *pptr
++;
933 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
934 tok2str(bgp_multicast_vpn_route_type_values
,
935 "Unknown", route_type
),
936 route_type
, route_length
);
939 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
940 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
941 offset
= strlen(buf
);
942 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
943 bgp_vpn_rd_print(ndo
, pptr
),
944 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
945 (route_length
- BGP_VPN_RD_LEN
) << 3));
947 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
948 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
+ 4);
949 offset
= strlen(buf
);
950 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
951 bgp_vpn_rd_print(ndo
, pptr
),
952 as_printf(ndo
, astostr
, sizeof(astostr
),
953 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
956 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
957 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
958 offset
= strlen(buf
);
959 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
960 bgp_vpn_rd_print(ndo
, pptr
));
961 pptr
+= BGP_VPN_RD_LEN
;
963 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
964 addr_length
= route_length
- sg_length
;
966 ND_TCHECK2(pptr
[0], addr_length
);
967 offset
= strlen(buf
);
968 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
969 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
972 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
973 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
974 offset
= strlen(buf
);
975 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
976 bgp_vpn_rd_print(ndo
, pptr
));
977 pptr
+= BGP_VPN_RD_LEN
;
979 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
982 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
983 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
984 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
+ 4);
985 offset
= strlen(buf
);
986 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
987 bgp_vpn_rd_print(ndo
, pptr
),
988 as_printf(ndo
, astostr
, sizeof(astostr
),
989 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
990 pptr
+= BGP_VPN_RD_LEN
+ 4;
992 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
996 * no per route-type printing yet.
998 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1003 return route_length
+ 2;
1010 * As I remember, some versions of systems have an snprintf() that
1011 * returns -1 if the buffer would have overflowed. If the return
1012 * value is negative, set buflen to 0, to indicate that we've filled
1015 * If the return value is greater than buflen, that means that
1016 * the buffer would have overflowed; again, set buflen to 0 in
1019 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1022 else if ((u_int)stringlen>buflen) \
1025 buflen-=stringlen; \
1030 decode_labeled_vpn_l2(netdissect_options
*ndo
,
1031 const u_char
*pptr
, char *buf
, u_int buflen
)
1033 int plen
,tlen
,stringlen
,tlv_type
,tlv_len
,ttlv_len
;
1035 ND_TCHECK2(pptr
[0], 2);
1036 plen
=EXTRACT_16BITS(pptr
);
1039 /* Old and new L2VPN NLRI share AFI/SAFI
1040 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1041 * and > 17 as old format. Complain for the middle case
1044 /* assume AD-only with RD, BGPNH */
1045 ND_TCHECK2(pptr
[0],12);
1047 stringlen
=snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
1048 bgp_vpn_rd_print(ndo
, pptr
),
1049 ipaddr_string(ndo
, pptr
+8)
1051 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1055 } else if (plen
>17) {
1056 /* assume old format */
1057 /* RD, ID, LBLKOFF, LBLBASE */
1059 ND_TCHECK2(pptr
[0],15);
1061 stringlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1062 bgp_vpn_rd_print(ndo
, pptr
),
1063 EXTRACT_16BITS(pptr
+8),
1064 EXTRACT_16BITS(pptr
+10),
1065 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1066 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1070 /* ok now the variable part - lets read out TLVs*/
1074 ND_TCHECK2(pptr
[0], 3);
1076 tlv_len
=EXTRACT_16BITS(pptr
);
1083 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1086 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1088 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
1089 while (ttlv_len
>0) {
1092 stringlen
=snprintf(buf
,buflen
, "%02x",*pptr
++);
1093 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1100 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1103 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1107 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
1112 /* complain bitterly ? */
1122 decode_prefix6(netdissect_options
*ndo
,
1123 const u_char
*pd
, u_int itemlen
, char *buf
, u_int buflen
)
1125 struct in6_addr addr
;
1126 u_int plen
, plenbytes
;
1135 memset(&addr
, 0, sizeof(addr
));
1136 plenbytes
= (plen
+ 7) / 8;
1137 ND_TCHECK2(pd
[1], plenbytes
);
1138 ITEMCHECK(plenbytes
);
1139 memcpy(&addr
, &pd
[1], plenbytes
);
1141 addr
.s6_addr
[plenbytes
- 1] &=
1142 ((0xff00 >> (plen
% 8)) & 0xff);
1144 snprintf(buf
, buflen
, "%s/%d", ip6addr_string(ndo
, &addr
), plen
);
1145 return 1 + plenbytes
;
1155 decode_labeled_prefix6(netdissect_options
*ndo
,
1156 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
1158 struct in6_addr addr
;
1159 u_int plen
, plenbytes
;
1161 /* prefix length and label = 4 bytes */
1162 ND_TCHECK2(pptr
[0], 4);
1164 plen
= pptr
[0]; /* get prefix length */
1169 plen
-=24; /* adjust prefixlen - labellength */
1175 memset(&addr
, 0, sizeof(addr
));
1176 plenbytes
= (plen
+ 7) / 8;
1177 ND_TCHECK2(pptr
[4], plenbytes
);
1178 memcpy(&addr
, &pptr
[4], plenbytes
);
1180 addr
.s6_addr
[plenbytes
- 1] &=
1181 ((0xff00 >> (plen
% 8)) & 0xff);
1183 /* the label may get offsetted by 4 bits so lets shift it right */
1184 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
1185 ip6addr_string(ndo
, &addr
),
1187 EXTRACT_24BITS(pptr
+1)>>4,
1188 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1190 return 4 + plenbytes
;
1200 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1201 const u_char
*pptr
, char *buf
, u_int buflen
)
1203 struct in6_addr addr
;
1207 plen
= pptr
[0]; /* get prefix length */
1212 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1217 memset(&addr
, 0, sizeof(addr
));
1218 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
1219 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1221 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1222 ((0xff00 >> (plen
% 8)) & 0xff);
1224 /* the label may get offsetted by 4 bits so lets shift it right */
1225 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1226 bgp_vpn_rd_print(ndo
, pptr
+4),
1227 ip6addr_string(ndo
, &addr
),
1229 EXTRACT_24BITS(pptr
+1)>>4,
1230 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1232 return 12 + (plen
+ 7) / 8;
1239 decode_clnp_prefix(netdissect_options
*ndo
,
1240 const u_char
*pptr
, char *buf
, u_int buflen
)
1246 plen
= pptr
[0]; /* get prefix length */
1251 memset(&addr
, 0, sizeof(addr
));
1252 ND_TCHECK2(pptr
[4], (plen
+ 7) / 8);
1253 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
1255 addr
[(plen
+ 7) / 8 - 1] &=
1256 ((0xff00 >> (plen
% 8)) & 0xff);
1258 snprintf(buf
, buflen
, "%s/%d",
1259 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1262 return 1 + (plen
+ 7) / 8;
1269 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1270 const u_char
*pptr
, char *buf
, u_int buflen
)
1276 plen
= pptr
[0]; /* get prefix length */
1281 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1286 memset(&addr
, 0, sizeof(addr
));
1287 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
1288 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1290 addr
[(plen
+ 7) / 8 - 1] &=
1291 ((0xff00 >> (plen
% 8)) & 0xff);
1293 /* the label may get offsetted by 4 bits so lets shift it right */
1294 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1295 bgp_vpn_rd_print(ndo
, pptr
+4),
1296 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1298 EXTRACT_24BITS(pptr
+1)>>4,
1299 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1301 return 12 + (plen
+ 7) / 8;
1308 * bgp_attr_get_as_size
1310 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1311 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1312 * support, exchange AS-Path with the same path-attribute type value 0x02.
1315 bgp_attr_get_as_size(netdissect_options
*ndo
,
1316 uint8_t bgpa_type
, const u_char
*pptr
, int len
)
1318 const u_char
*tptr
= pptr
;
1321 * If the path attribute is the optional AS4 path type, then we already
1322 * know, that ASs must be encoded in 4 byte format.
1324 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1329 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1330 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1333 while (tptr
< pptr
+ len
) {
1337 * If we do not find a valid segment type, our guess might be wrong.
1339 if (tptr
[0] < BGP_AS_SEG_TYPE_MIN
|| tptr
[0] > BGP_AS_SEG_TYPE_MAX
) {
1343 tptr
+= 2 + tptr
[1] * 2;
1347 * If we correctly reached end of the AS path attribute data content,
1348 * then most likely ASs were indeed encoded as 2 bytes.
1350 if (tptr
== pptr
+ len
) {
1357 * We can come here, either we did not have enough data, or if we
1358 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1359 * so that calller can try to decode each AS as of 4 bytes. If indeed
1360 * there was not enough data, it will crib and end the parse anyways.
1366 * The only way to know that a BGP UPDATE message is using add path is
1367 * by checking if the capability is in the OPEN message which we may have missed.
1368 * So this function checks if it is possible that the update could contain add path
1369 * and if so it checks that standard BGP doesn't make sense.
1373 check_add_path(const u_char
*pptr
, u_int length
, u_int max_prefix_length
) {
1375 u_int offset
, prefix_length
;
1380 /* check if it could be add path */
1381 for(offset
= 0; offset
< length
;) {
1383 prefix_length
= pptr
[offset
];
1385 * Add 4 to cover the path id
1386 * and check the prefix length isn't greater than 32/128.
1388 if (prefix_length
> max_prefix_length
) {
1391 /* Add 1 for the prefix_length byte and prefix_length to cover the address */
1392 offset
+= 1 + ((prefix_length
+ 7) / 8);
1394 /* check we haven't gone past the end of the section */
1395 if (offset
> length
) {
1399 /* check it's not standard BGP */
1400 for(offset
= 0; offset
< length
; ) {
1401 prefix_length
= pptr
[offset
];
1403 * If the prefix_length is zero (0.0.0.0/0)
1404 * and since it's not the only address (length >= 5)
1405 * then it is add-path
1407 if (prefix_length
< 1 || prefix_length
> max_prefix_length
) {
1410 offset
+= 1 + ((prefix_length
+ 7) / 8);
1412 if (offset
> length
) {
1416 /* assume not add-path by default */
1422 bgp_attr_print(netdissect_options
*ndo
,
1423 u_int atype
, const u_char
*pptr
, u_int len
)
1427 uint8_t safi
, snpa
, nhlen
;
1428 union { /* copy buffer for bandwidth values */
1435 char buf
[MAXHOSTNAMELEN
+ 100];
1437 int add_path4
, add_path6
, path_id
;
1443 case BGPTYPE_ORIGIN
:
1445 ND_PRINT((ndo
, "invalid len"));
1448 ND_PRINT((ndo
, "%s", tok2str(bgp_origin_values
,
1449 "Unknown Origin Typecode",
1455 * Process AS4 byte path and AS2 byte path attributes here.
1457 case BGPTYPE_AS4_PATH
:
1458 case BGPTYPE_AS_PATH
:
1460 ND_PRINT((ndo
, "invalid len"));
1464 ND_PRINT((ndo
, "empty"));
1469 * BGP updates exchanged between New speakers that support 4
1470 * byte AS, ASs are always encoded in 4 bytes. There is no
1471 * definitive way to find this, just by the packet's
1472 * contents. So, check for packet's TLV's sanity assuming
1473 * 2 bytes first, and it does not pass, assume that ASs are
1474 * encoded in 4 bytes format and move on.
1476 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1478 while (tptr
< pptr
+ len
) {
1480 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_open_values
,
1483 for (i
= 0; i
< tptr
[1] * as_size
; i
+= as_size
) {
1484 ND_TCHECK2(tptr
[2 + i
], as_size
);
1485 ND_PRINT((ndo
, "%s ",
1486 as_printf(ndo
, astostr
, sizeof(astostr
),
1488 EXTRACT_16BITS(&tptr
[2 + i
]) :
1489 EXTRACT_32BITS(&tptr
[2 + i
]))));
1492 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_close_values
,
1495 tptr
+= 2 + tptr
[1] * as_size
;
1498 case BGPTYPE_NEXT_HOP
:
1500 ND_PRINT((ndo
, "invalid len"));
1502 ND_TCHECK2(tptr
[0], 4);
1503 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1506 case BGPTYPE_MULTI_EXIT_DISC
:
1507 case BGPTYPE_LOCAL_PREF
:
1509 ND_PRINT((ndo
, "invalid len"));
1511 ND_TCHECK2(tptr
[0], 4);
1512 ND_PRINT((ndo
, "%u", EXTRACT_32BITS(tptr
)));
1515 case BGPTYPE_ATOMIC_AGGREGATE
:
1517 ND_PRINT((ndo
, "invalid len"));
1519 case BGPTYPE_AGGREGATOR
:
1522 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1523 * the length of this PA can be either 6 bytes or 8 bytes.
1525 if (len
!= 6 && len
!= 8) {
1526 ND_PRINT((ndo
, "invalid len"));
1529 ND_TCHECK2(tptr
[0], len
);
1531 ND_PRINT((ndo
, " AS #%s, origin %s",
1532 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_16BITS(tptr
)),
1533 ipaddr_string(ndo
, tptr
+ 2)));
1535 ND_PRINT((ndo
, " AS #%s, origin %s",
1536 as_printf(ndo
, astostr
, sizeof(astostr
),
1537 EXTRACT_32BITS(tptr
)), ipaddr_string(ndo
, tptr
+ 4)));
1540 case BGPTYPE_AGGREGATOR4
:
1542 ND_PRINT((ndo
, "invalid len"));
1545 ND_TCHECK2(tptr
[0], 8);
1546 ND_PRINT((ndo
, " AS #%s, origin %s",
1547 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(tptr
)),
1548 ipaddr_string(ndo
, tptr
+ 4)));
1550 case BGPTYPE_COMMUNITIES
:
1552 ND_PRINT((ndo
, "invalid len"));
1557 ND_TCHECK2(tptr
[0], 4);
1558 comm
= EXTRACT_32BITS(tptr
);
1560 case BGP_COMMUNITY_NO_EXPORT
:
1561 ND_PRINT((ndo
, " NO_EXPORT"));
1563 case BGP_COMMUNITY_NO_ADVERT
:
1564 ND_PRINT((ndo
, " NO_ADVERTISE"));
1566 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1567 ND_PRINT((ndo
, " NO_EXPORT_SUBCONFED"));
1570 ND_PRINT((ndo
, "%u:%u%s",
1571 (comm
>> 16) & 0xffff,
1573 (tlen
>4) ? ", " : ""));
1580 case BGPTYPE_ORIGINATOR_ID
:
1582 ND_PRINT((ndo
, "invalid len"));
1585 ND_TCHECK2(tptr
[0], 4);
1586 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1588 case BGPTYPE_CLUSTER_LIST
:
1590 ND_PRINT((ndo
, "invalid len"));
1594 ND_TCHECK2(tptr
[0], 4);
1595 ND_PRINT((ndo
, "%s%s",
1596 ipaddr_string(ndo
, tptr
),
1597 (tlen
>4) ? ", " : ""));
1602 case BGPTYPE_MP_REACH_NLRI
:
1603 ND_TCHECK2(tptr
[0], 3);
1604 af
= EXTRACT_16BITS(tptr
);
1607 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1608 tok2str(af_values
, "Unknown AFI", af
),
1610 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1611 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
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
):
1618 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1619 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1620 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1621 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1622 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1623 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1624 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1625 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1626 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1627 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1628 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1629 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1630 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1631 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1632 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1633 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1634 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1635 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1636 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1637 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1638 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1639 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1640 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1641 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1644 ND_TCHECK2(tptr
[0], tlen
);
1645 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1646 if (ndo
->ndo_vflag
<= 1)
1647 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1661 ND_PRINT((ndo
, "\n\t nexthop: "));
1664 ND_PRINT((ndo
, ", " ));
1666 switch(af
<<8 | safi
) {
1667 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1668 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1669 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1670 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1671 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1672 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1673 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1674 if (tlen
< (int)sizeof(struct in_addr
)) {
1675 ND_PRINT((ndo
, "invalid len"));
1678 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1679 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1680 tlen
-= sizeof(struct in_addr
);
1681 tptr
+= sizeof(struct in_addr
);
1684 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1685 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1686 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1687 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1688 ND_PRINT((ndo
, "invalid len"));
1691 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1692 ND_PRINT((ndo
, "RD: %s, %s",
1693 bgp_vpn_rd_print(ndo
, tptr
),
1694 ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1695 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1696 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1699 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1700 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1701 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1702 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1703 if (tlen
< (int)sizeof(struct in6_addr
)) {
1704 ND_PRINT((ndo
, "invalid len"));
1707 ND_TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1708 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, tptr
)));
1709 tlen
-= sizeof(struct in6_addr
);
1710 tptr
+= sizeof(struct in6_addr
);
1713 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1714 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1715 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1716 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1717 ND_PRINT((ndo
, "invalid len"));
1720 ND_TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1721 ND_PRINT((ndo
, "RD: %s, %s",
1722 bgp_vpn_rd_print(ndo
, tptr
),
1723 ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1724 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1725 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1728 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1729 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1730 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1731 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1732 if (tlen
< (int)sizeof(struct in_addr
)) {
1733 ND_PRINT((ndo
, "invalid len"));
1736 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1737 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1738 tlen
-= (sizeof(struct in_addr
));
1739 tptr
+= (sizeof(struct in_addr
));
1742 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1743 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1744 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1745 ND_TCHECK2(tptr
[0], tlen
);
1746 ND_PRINT((ndo
, "%s", isonsap_string(ndo
, tptr
, tlen
)));
1751 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1752 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1753 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1754 if (tlen
< BGP_VPN_RD_LEN
+1) {
1755 ND_PRINT((ndo
, "invalid len"));
1758 ND_TCHECK2(tptr
[0], tlen
);
1759 ND_PRINT((ndo
, "RD: %s, %s",
1760 bgp_vpn_rd_print(ndo
, tptr
),
1761 isonsap_string(ndo
, tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
)));
1762 /* rfc986 mapped IPv4 address ? */
1763 if (EXTRACT_32BITS(tptr
+BGP_VPN_RD_LEN
) == 0x47000601)
1764 ND_PRINT((ndo
, " = %s", ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+4)));
1765 /* rfc1888 mapped IPv6 address ? */
1766 else if (EXTRACT_24BITS(tptr
+BGP_VPN_RD_LEN
) == 0x350000)
1767 ND_PRINT((ndo
, " = %s", ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+3)));
1773 ND_TCHECK2(tptr
[0], tlen
);
1774 ND_PRINT((ndo
, "no AFI %u/SAFI %u decoder", af
, safi
));
1775 if (ndo
->ndo_vflag
<= 1)
1776 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1784 ND_PRINT((ndo
, ", nh-length: %u", nhlen
));
1792 ND_PRINT((ndo
, "\n\t %u SNPA", snpa
));
1793 for (/*nothing*/; snpa
> 0; snpa
--) {
1795 ND_PRINT((ndo
, "\n\t %d bytes", tptr
[0]));
1796 tptr
+= tptr
[0] + 1;
1799 ND_PRINT((ndo
, ", no SNPA"));
1802 add_path4
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 32);
1803 add_path6
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 128);
1805 while (tptr
< pptr
+ len
) {
1806 switch (af
<<8 | safi
) {
1807 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1808 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1809 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1811 path_id
= EXTRACT_32BITS(tptr
);
1814 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1816 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1817 else if (advance
== -2)
1819 else if (advance
== -3)
1820 break; /* bytes left, but not enough */
1822 ND_PRINT((ndo
, "\n\t %s", buf
));
1824 ND_PRINT((ndo
, " Path Id: %d", path_id
));
1827 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1828 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1830 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1831 else if (advance
== -2)
1833 else if (advance
== -3)
1834 break; /* bytes left, but not enough */
1836 ND_PRINT((ndo
, "\n\t %s", buf
));
1838 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1839 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1840 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1841 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1843 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1844 else if (advance
== -2)
1847 ND_PRINT((ndo
, "\n\t %s", buf
));
1849 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1850 advance
= decode_rt_routing_info(ndo
, tptr
, buf
, sizeof(buf
));
1852 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1853 else if (advance
== -2)
1856 ND_PRINT((ndo
, "\n\t %s", buf
));
1858 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1859 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1860 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1862 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1863 else if (advance
== -2)
1866 ND_PRINT((ndo
, "\n\t %s", buf
));
1869 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1870 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
1872 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1873 else if (advance
== -2)
1876 ND_PRINT((ndo
, "\n\t %s", buf
));
1878 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1879 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1880 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1882 path_id
= EXTRACT_32BITS(tptr
);
1885 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1887 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1888 else if (advance
== -2)
1890 else if (advance
== -3)
1891 break; /* bytes left, but not enough */
1893 ND_PRINT((ndo
, "\n\t %s", buf
));
1895 ND_PRINT((ndo
, " Path Id: %d", path_id
));
1898 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1899 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1901 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1902 else if (advance
== -2)
1904 else if (advance
== -3)
1905 break; /* bytes left, but not enough */
1907 ND_PRINT((ndo
, "\n\t %s", buf
));
1909 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1910 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1911 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1912 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1914 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1915 else if (advance
== -2)
1918 ND_PRINT((ndo
, "\n\t %s", buf
));
1920 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1921 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1922 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1923 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1924 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1926 ND_PRINT((ndo
, "\n\t (illegal length)"));
1927 else if (advance
== -2)
1930 ND_PRINT((ndo
, "\n\t %s", buf
));
1932 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1933 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1934 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1935 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1937 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1938 else if (advance
== -2)
1941 ND_PRINT((ndo
, "\n\t %s", buf
));
1943 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1944 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1945 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1946 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1948 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1949 else if (advance
== -2)
1952 ND_PRINT((ndo
, "\n\t %s", buf
));
1955 ND_TCHECK2(*tptr
,tlen
);
1956 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1957 if (ndo
->ndo_vflag
<= 1)
1958 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1970 case BGPTYPE_MP_UNREACH_NLRI
:
1971 ND_TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1972 af
= EXTRACT_16BITS(tptr
);
1975 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1976 tok2str(af_values
, "Unknown AFI", af
),
1978 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1979 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1982 if (len
== BGP_MP_NLRI_MINSIZE
)
1983 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
1987 add_path4
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 32);
1988 add_path6
= check_add_path(tptr
, (len
-(tptr
- pptr
)), 128);
1990 while (tptr
< pptr
+ len
) {
1991 switch (af
<<8 | safi
) {
1992 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1993 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1994 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1996 path_id
= EXTRACT_32BITS(tptr
);
1999 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
2001 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2002 else if (advance
== -2)
2004 else if (advance
== -3)
2005 break; /* bytes left, but not enough */
2007 ND_PRINT((ndo
, "\n\t %s", buf
));
2009 ND_PRINT((ndo
, " Path Id: %d", path_id
));
2012 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
2013 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
2015 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2016 else if (advance
== -2)
2018 else if (advance
== -3)
2019 break; /* bytes left, but not enough */
2021 ND_PRINT((ndo
, "\n\t %s", buf
));
2023 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
2024 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
2025 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
2026 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
2028 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2029 else if (advance
== -2)
2032 ND_PRINT((ndo
, "\n\t %s", buf
));
2034 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
2035 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
2036 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
2038 path_id
= EXTRACT_32BITS(tptr
);
2041 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
2043 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2044 else if (advance
== -2)
2046 else if (advance
== -3)
2047 break; /* bytes left, but not enough */
2049 ND_PRINT((ndo
, "\n\t %s", buf
));
2051 ND_PRINT((ndo
, " Path Id: %d", path_id
));
2054 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
2055 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
2057 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2058 else if (advance
== -2)
2060 else if (advance
== -3)
2061 break; /* bytes left, but not enough */
2063 ND_PRINT((ndo
, "\n\t %s", buf
));
2065 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
2066 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
2067 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
2068 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
2070 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2071 else if (advance
== -2)
2074 ND_PRINT((ndo
, "\n\t %s", buf
));
2076 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
2077 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
2078 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
2079 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
2080 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
2082 ND_PRINT((ndo
, "\n\t (illegal length)"));
2083 else if (advance
== -2)
2086 ND_PRINT((ndo
, "\n\t %s", buf
));
2088 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
2089 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2090 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2091 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2093 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2094 else if (advance
== -2)
2097 ND_PRINT((ndo
, "\n\t %s", buf
));
2099 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2100 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2101 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2102 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2104 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2105 else if (advance
== -2)
2108 ND_PRINT((ndo
, "\n\t %s", buf
));
2110 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
2111 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
2113 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2114 else if (advance
== -2)
2117 ND_PRINT((ndo
, "\n\t %s", buf
));
2119 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
2120 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
2121 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
2123 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2124 else if (advance
== -2)
2127 ND_PRINT((ndo
, "\n\t %s", buf
));
2130 ND_TCHECK2(*(tptr
-3),tlen
);
2131 ND_PRINT((ndo
, "no AFI %u / SAFI %u decoder", af
, safi
));
2132 if (ndo
->ndo_vflag
<= 1)
2133 print_unknown_data(ndo
, tptr
-3, "\n\t ", tlen
);
2143 case BGPTYPE_EXTD_COMMUNITIES
:
2145 ND_PRINT((ndo
, "invalid len"));
2151 ND_TCHECK2(tptr
[0], 2);
2152 extd_comm
=EXTRACT_16BITS(tptr
);
2154 ND_PRINT((ndo
, "\n\t %s (0x%04x), Flags [%s]",
2155 tok2str(bgp_extd_comm_subtype_values
,
2156 "unknown extd community typecode",
2159 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
)));
2161 ND_TCHECK2(*(tptr
+2), 6);
2163 case BGP_EXT_COM_RT_0
:
2164 case BGP_EXT_COM_RO_0
:
2165 case BGP_EXT_COM_L2VPN_RT_0
:
2166 ND_PRINT((ndo
, ": %u:%u (= %s)",
2167 EXTRACT_16BITS(tptr
+2),
2168 EXTRACT_32BITS(tptr
+4),
2169 ipaddr_string(ndo
, tptr
+4)));
2171 case BGP_EXT_COM_RT_1
:
2172 case BGP_EXT_COM_RO_1
:
2173 case BGP_EXT_COM_L2VPN_RT_1
:
2174 case BGP_EXT_COM_VRF_RT_IMP
:
2175 ND_PRINT((ndo
, ": %s:%u",
2176 ipaddr_string(ndo
, tptr
+2),
2177 EXTRACT_16BITS(tptr
+6)));
2179 case BGP_EXT_COM_RT_2
:
2180 case BGP_EXT_COM_RO_2
:
2181 ND_PRINT((ndo
, ": %s:%u",
2182 as_printf(ndo
, astostr
, sizeof(astostr
),
2183 EXTRACT_32BITS(tptr
+2)), EXTRACT_16BITS(tptr
+6)));
2185 case BGP_EXT_COM_LINKBAND
:
2186 bw
.i
= EXTRACT_32BITS(tptr
+2);
2187 ND_PRINT((ndo
, ": bandwidth: %.3f Mbps",
2190 case BGP_EXT_COM_VPN_ORIGIN
:
2191 case BGP_EXT_COM_VPN_ORIGIN2
:
2192 case BGP_EXT_COM_VPN_ORIGIN3
:
2193 case BGP_EXT_COM_VPN_ORIGIN4
:
2194 case BGP_EXT_COM_OSPF_RID
:
2195 case BGP_EXT_COM_OSPF_RID2
:
2196 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
+2)));
2198 case BGP_EXT_COM_OSPF_RTYPE
:
2199 case BGP_EXT_COM_OSPF_RTYPE2
:
2200 ND_PRINT((ndo
, ": area:%s, router-type:%s, metric-type:%s%s",
2201 ipaddr_string(ndo
, tptr
+2),
2202 tok2str(bgp_extd_comm_ospf_rtype_values
,
2205 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
2206 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : ""));
2208 case BGP_EXT_COM_L2INFO
:
2209 ND_PRINT((ndo
, ": %s Control Flags [0x%02x]:MTU %u",
2210 tok2str(l2vpn_encaps_values
,
2214 EXTRACT_16BITS(tptr
+4)));
2216 case BGP_EXT_COM_SOURCE_AS
:
2217 ND_PRINT((ndo
, ": AS %u", EXTRACT_16BITS(tptr
+2)));
2220 ND_TCHECK2(*tptr
,8);
2221 print_unknown_data(ndo
, tptr
, "\n\t ", 8);
2229 case BGPTYPE_PMSI_TUNNEL
:
2231 uint8_t tunnel_type
, flags
;
2233 ND_TCHECK2(tptr
[0], 5);
2234 tunnel_type
= *(tptr
+1);
2238 ND_PRINT((ndo
, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2239 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2241 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2242 EXTRACT_24BITS(tptr
+2)>>4));
2247 switch (tunnel_type
) {
2248 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2249 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2250 ND_TCHECK2(tptr
[0], 8);
2251 ND_PRINT((ndo
, "\n\t Sender %s, P-Group %s",
2252 ipaddr_string(ndo
, tptr
),
2253 ipaddr_string(ndo
, tptr
+4)));
2256 case BGP_PMSI_TUNNEL_PIM_SSM
:
2257 ND_TCHECK2(tptr
[0], 8);
2258 ND_PRINT((ndo
, "\n\t Root-Node %s, P-Group %s",
2259 ipaddr_string(ndo
, tptr
),
2260 ipaddr_string(ndo
, tptr
+4)));
2262 case BGP_PMSI_TUNNEL_INGRESS
:
2263 ND_TCHECK2(tptr
[0], 4);
2264 ND_PRINT((ndo
, "\n\t Tunnel-Endpoint %s",
2265 ipaddr_string(ndo
, tptr
)));
2267 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2268 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2269 ND_TCHECK2(tptr
[0], 8);
2270 ND_PRINT((ndo
, "\n\t Root-Node %s, LSP-ID 0x%08x",
2271 ipaddr_string(ndo
, tptr
),
2272 EXTRACT_32BITS(tptr
+4)));
2274 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2275 ND_TCHECK2(tptr
[0], 8);
2276 ND_PRINT((ndo
, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2277 ipaddr_string(ndo
, tptr
),
2278 EXTRACT_32BITS(tptr
+4)));
2281 if (ndo
->ndo_vflag
<= 1) {
2282 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2296 ND_TCHECK2(tptr
[0], 3);
2299 length
= EXTRACT_16BITS(tptr
+1);
2303 ND_PRINT((ndo
, "\n\t %s TLV (%u), length %u",
2304 tok2str(bgp_aigp_values
, "Unknown", type
),
2312 * Check if we can read the TLV data.
2314 ND_TCHECK2(tptr
[3], length
);
2321 ND_PRINT((ndo
, ", metric %" PRIu64
,
2322 EXTRACT_64BITS(tptr
)));
2326 if (ndo
->ndo_vflag
<= 1) {
2327 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2336 case BGPTYPE_ATTR_SET
:
2337 ND_TCHECK2(tptr
[0], 4);
2340 ND_PRINT((ndo
, "\n\t Origin AS: %s",
2341 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(tptr
))));
2346 u_int aflags
, alenlen
, alen
;
2348 ND_TCHECK2(tptr
[0], 2);
2352 atype
= *(tptr
+ 1);
2355 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2356 ND_TCHECK2(tptr
[0], alenlen
);
2359 alen
= bgp_attr_len(aflags
, tptr
);
2363 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2364 tok2str(bgp_attr_values
,
2365 "Unknown Attribute", atype
),
2370 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2371 aflags
& 0x80 ? "O" : "",
2372 aflags
& 0x40 ? "T" : "",
2373 aflags
& 0x20 ? "P" : "",
2374 aflags
& 0x10 ? "E" : ""));
2376 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2377 ND_PRINT((ndo
, "]: "));
2379 /* FIXME check for recursion */
2380 if (!bgp_attr_print(ndo
, atype
, tptr
, alen
))
2387 case BGPTYPE_LARGE_COMMUNITY
:
2388 if (len
== 0 || len
% 12) {
2389 ND_PRINT((ndo
, "invalid len"));
2392 ND_PRINT((ndo
, "\n\t "));
2394 ND_TCHECK2(*tptr
, 12);
2395 ND_PRINT((ndo
, "%u:%u:%u%s",
2396 EXTRACT_32BITS(tptr
),
2397 EXTRACT_32BITS(tptr
+ 4),
2398 EXTRACT_32BITS(tptr
+ 8),
2399 (len
> 12) ? ", " : ""));
2405 ND_TCHECK2(*pptr
,len
);
2406 ND_PRINT((ndo
, "\n\t no Attribute %u decoder", atype
)); /* we have no decoder for the attribute */
2407 if (ndo
->ndo_vflag
<= 1)
2408 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2411 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2412 ND_TCHECK2(*pptr
,len
);
2413 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2422 bgp_capabilities_print(netdissect_options
*ndo
,
2423 const u_char
*opt
, int caps_len
)
2425 int cap_type
, cap_len
, tcap_len
, cap_offset
;
2428 while (i
< caps_len
) {
2429 ND_TCHECK2(opt
[i
], BGP_CAP_HEADER_SIZE
);
2433 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2434 tok2str(bgp_capcode_values
, "Unknown",
2438 ND_TCHECK2(opt
[i
+2], cap_len
);
2440 case BGP_CAPCODE_MP
:
2441 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u)",
2442 tok2str(af_values
, "Unknown",
2443 EXTRACT_16BITS(opt
+i
+2)),
2444 EXTRACT_16BITS(opt
+i
+2),
2445 tok2str(bgp_safi_values
, "Unknown",
2449 case BGP_CAPCODE_RESTART
:
2450 ND_PRINT((ndo
, "\n\t\tRestart Flags: [%s], Restart Time %us",
2451 ((opt
[i
+2])&0x80) ? "R" : "none",
2452 EXTRACT_16BITS(opt
+i
+2)&0xfff));
2455 while(tcap_len
>=4) {
2456 ND_PRINT((ndo
, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2457 tok2str(af_values
,"Unknown",
2458 EXTRACT_16BITS(opt
+i
+cap_offset
)),
2459 EXTRACT_16BITS(opt
+i
+cap_offset
),
2460 tok2str(bgp_safi_values
,"Unknown",
2461 opt
[i
+cap_offset
+2]),
2462 opt
[i
+cap_offset
+2],
2463 ((opt
[i
+cap_offset
+3])&0x80) ? "yes" : "no" ));
2468 case BGP_CAPCODE_RR
:
2469 case BGP_CAPCODE_RR_CISCO
:
2471 case BGP_CAPCODE_AS_NEW
:
2474 * Extract the 4 byte AS number encoded.
2477 ND_PRINT((ndo
, "\n\t\t 4 Byte AS %s",
2478 as_printf(ndo
, astostr
, sizeof(astostr
),
2479 EXTRACT_32BITS(opt
+ i
+ 2))));
2482 case BGP_CAPCODE_ADD_PATH
:
2484 if (tcap_len
== 0) {
2485 ND_PRINT((ndo
, " (bogus)")); /* length */
2488 while (tcap_len
> 0) {
2490 ND_PRINT((ndo
, "\n\t\t(invalid)"));
2493 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2494 tok2str(af_values
,"Unknown",EXTRACT_16BITS(opt
+i
+cap_offset
)),
2495 EXTRACT_16BITS(opt
+i
+cap_offset
),
2496 tok2str(bgp_safi_values
,"Unknown",opt
[i
+cap_offset
+2]),
2497 opt
[i
+cap_offset
+2],
2498 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",opt
[i
+cap_offset
+3])
2505 ND_PRINT((ndo
, "\n\t\tno decoder for Capability %u",
2507 if (ndo
->ndo_vflag
<= 1)
2508 print_unknown_data(ndo
, &opt
[i
+2], "\n\t\t", cap_len
);
2511 if (ndo
->ndo_vflag
> 1 && cap_len
> 0) {
2512 print_unknown_data(ndo
, &opt
[i
+2], "\n\t\t", cap_len
);
2514 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2519 ND_PRINT((ndo
, "[|BGP]"));
2523 bgp_open_print(netdissect_options
*ndo
,
2524 const u_char
*dat
, int length
)
2526 struct bgp_open bgpo
;
2527 struct bgp_opt bgpopt
;
2531 ND_TCHECK2(dat
[0], BGP_OPEN_SIZE
);
2532 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
2534 ND_PRINT((ndo
, "\n\t Version %d, ", bgpo
.bgpo_version
));
2535 ND_PRINT((ndo
, "my AS %s, ",
2536 as_printf(ndo
, astostr
, sizeof(astostr
), ntohs(bgpo
.bgpo_myas
))));
2537 ND_PRINT((ndo
, "Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
)));
2538 ND_PRINT((ndo
, "ID %s", ipaddr_string(ndo
, &bgpo
.bgpo_id
)));
2539 ND_PRINT((ndo
, "\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
));
2541 /* some little sanity checking */
2542 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
2546 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
2550 while (i
< bgpo
.bgpo_optlen
) {
2551 ND_TCHECK2(opt
[i
], BGP_OPT_SIZE
);
2552 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
2553 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
2554 ND_PRINT((ndo
, "\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
));
2558 ND_PRINT((ndo
, "\n\t Option %s (%u), length: %u",
2559 tok2str(bgp_opt_values
,"Unknown",
2560 bgpopt
.bgpopt_type
),
2562 bgpopt
.bgpopt_len
));
2564 /* now let's decode the options we know*/
2565 switch(bgpopt
.bgpopt_type
) {
2568 bgp_capabilities_print(ndo
, &opt
[i
+BGP_OPT_SIZE
],
2574 ND_PRINT((ndo
, "\n\t no decoder for option %u",
2575 bgpopt
.bgpopt_type
));
2578 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
2582 ND_PRINT((ndo
, "[|BGP]"));
2586 bgp_update_print(netdissect_options
*ndo
,
2587 const u_char
*dat
, int length
)
2591 int withdrawn_routes_len
;
2592 char buf
[MAXHOSTNAMELEN
+ 100];
2597 ND_TCHECK2(dat
[0], BGP_SIZE
);
2598 if (length
< BGP_SIZE
)
2600 memcpy(&bgp
, dat
, BGP_SIZE
);
2601 p
= dat
+ BGP_SIZE
; /*XXX*/
2604 /* Unfeasible routes */
2605 ND_TCHECK2(p
[0], 2);
2608 withdrawn_routes_len
= EXTRACT_16BITS(p
);
2611 if (withdrawn_routes_len
) {
2612 ND_TCHECK2(p
[0], withdrawn_routes_len
);
2613 if (length
< withdrawn_routes_len
)
2615 if (withdrawn_routes_len
< 2)
2618 ND_PRINT((ndo
, "\n\t Withdrawn routes:"));
2619 int add_path
, path_id
;
2620 add_path
= check_add_path(p
, withdrawn_routes_len
, 32);
2621 while(withdrawn_routes_len
> 0) {
2623 path_id
= EXTRACT_32BITS(p
);
2626 withdrawn_routes_len
-= 4;
2628 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2630 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2632 } else if (wpfx
== -2)
2634 else if (wpfx
== -3)
2635 goto trunc
; /* bytes left, but not enough */
2637 ND_PRINT((ndo
, "\n\t %s", buf
));
2639 ND_PRINT((ndo
, " Path Id: %d", path_id
));
2643 withdrawn_routes_len
-= wpfx
;
2648 ND_TCHECK2(p
[0], 2);
2651 len
= EXTRACT_16BITS(p
);
2655 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2656 /* No withdrawn routes, no path attributes, no NLRI */
2657 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
2662 /* do something more useful!*/
2664 int aflags
, atype
, alenlen
, alen
;
2666 ND_TCHECK2(p
[0], 2);
2676 alenlen
= bgp_attr_lenlen(aflags
, p
);
2677 ND_TCHECK2(p
[0], alenlen
);
2680 if (length
< alenlen
)
2682 alen
= bgp_attr_len(aflags
, p
);
2687 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2688 tok2str(bgp_attr_values
, "Unknown Attribute",
2694 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2695 aflags
& 0x80 ? "O" : "",
2696 aflags
& 0x40 ? "T" : "",
2697 aflags
& 0x20 ? "P" : "",
2698 aflags
& 0x10 ? "E" : ""));
2700 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2701 ND_PRINT((ndo
, "]: "));
2707 if (!bgp_attr_print(ndo
, atype
, p
, alen
))
2716 int add_path
= check_add_path(p
, length
, 32);
2718 ND_PRINT((ndo
, "\n\t Updated routes:"));
2719 while (length
> 0) {
2721 path_id
= EXTRACT_32BITS(p
);
2725 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2727 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2732 goto trunc
; /* bytes left, but not enough */
2734 ND_PRINT((ndo
, "\n\t %s", buf
));
2736 ND_PRINT((ndo
, " Path Id: %d", path_id
));
2745 ND_PRINT((ndo
, "[|BGP]"));
2749 bgp_notification_print(netdissect_options
*ndo
,
2750 const u_char
*dat
, int length
)
2752 struct bgp_notification bgpn
;
2754 uint8_t shutdown_comm_length
;
2755 uint8_t remainder_offset
;
2757 ND_TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
2758 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
2760 /* some little sanity checking */
2761 if (length
<BGP_NOTIFICATION_SIZE
)
2764 ND_PRINT((ndo
, ", %s (%u)",
2765 tok2str(bgp_notify_major_values
, "Unknown Error",
2769 switch (bgpn
.bgpn_major
) {
2771 case BGP_NOTIFY_MAJOR_MSG
:
2772 ND_PRINT((ndo
, ", subcode %s (%u)",
2773 tok2str(bgp_notify_minor_msg_values
, "Unknown",
2777 case BGP_NOTIFY_MAJOR_OPEN
:
2778 ND_PRINT((ndo
, ", subcode %s (%u)",
2779 tok2str(bgp_notify_minor_open_values
, "Unknown",
2783 case BGP_NOTIFY_MAJOR_UPDATE
:
2784 ND_PRINT((ndo
, ", subcode %s (%u)",
2785 tok2str(bgp_notify_minor_update_values
, "Unknown",
2789 case BGP_NOTIFY_MAJOR_FSM
:
2790 ND_PRINT((ndo
, " subcode %s (%u)",
2791 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
2795 case BGP_NOTIFY_MAJOR_CAP
:
2796 ND_PRINT((ndo
, " subcode %s (%u)",
2797 tok2str(bgp_notify_minor_cap_values
, "Unknown",
2801 case BGP_NOTIFY_MAJOR_CEASE
:
2802 ND_PRINT((ndo
, ", subcode %s (%u)",
2803 tok2str(bgp_notify_minor_cease_values
, "Unknown",
2807 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2808 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2810 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2811 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2812 ND_TCHECK2(*tptr
, 7);
2813 ND_PRINT((ndo
, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2814 tok2str(af_values
, "Unknown",
2815 EXTRACT_16BITS(tptr
)),
2816 EXTRACT_16BITS(tptr
),
2817 tok2str(bgp_safi_values
, "Unknown", *(tptr
+2)),
2819 EXTRACT_32BITS(tptr
+3)));
2822 * draft-ietf-idr-shutdown describes a method to send a communication
2823 * intended for human consumption regarding the Administrative Shutdown
2825 if ((bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
2826 bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
2827 length
>= BGP_NOTIFICATION_SIZE
+ 1) {
2828 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2829 ND_TCHECK2(*tptr
, 1);
2830 shutdown_comm_length
= *(tptr
);
2831 remainder_offset
= 0;
2832 /* garbage, hexdump it all */
2833 if (shutdown_comm_length
> BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN
||
2834 shutdown_comm_length
> length
- (BGP_NOTIFICATION_SIZE
+ 1)) {
2835 ND_PRINT((ndo
, ", invalid Shutdown Communication length"));
2837 else if (shutdown_comm_length
== 0) {
2838 ND_PRINT((ndo
, ", empty Shutdown Communication"));
2839 remainder_offset
+= 1;
2841 /* a proper shutdown communication */
2843 ND_TCHECK2(*(tptr
+1), shutdown_comm_length
);
2844 ND_PRINT((ndo
, ", Shutdown Communication (length: %u): \"", shutdown_comm_length
));
2845 (void)fn_printn(ndo
, tptr
+1, shutdown_comm_length
, NULL
);
2846 ND_PRINT((ndo
, "\""));
2847 remainder_offset
+= shutdown_comm_length
+ 1;
2849 /* if there is trailing data, hexdump it */
2850 if(length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
) > 0) {
2851 ND_PRINT((ndo
, ", Data: (length: %u)", length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
)));
2852 hex_print(ndo
, "\n\t\t", tptr
+ remainder_offset
, length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
2862 ND_PRINT((ndo
, "[|BGP]"));
2866 bgp_route_refresh_print(netdissect_options
*ndo
,
2867 const u_char
*pptr
, int len
)
2869 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2871 ND_TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
2873 /* some little sanity checking */
2874 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2877 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2879 ND_PRINT((ndo
, "\n\t AFI %s (%u), SAFI %s (%u)",
2880 tok2str(af_values
,"Unknown",
2881 /* this stinks but the compiler pads the structure
2883 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
)),
2884 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2885 tok2str(bgp_safi_values
,"Unknown",
2886 bgp_route_refresh_header
->safi
),
2887 bgp_route_refresh_header
->safi
));
2889 if (ndo
->ndo_vflag
> 1) {
2890 ND_TCHECK2(*pptr
, len
);
2891 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2896 ND_PRINT((ndo
, "[|BGP]"));
2900 bgp_header_print(netdissect_options
*ndo
,
2901 const u_char
*dat
, int length
)
2905 ND_TCHECK2(dat
[0], BGP_SIZE
);
2906 memcpy(&bgp
, dat
, BGP_SIZE
);
2907 ND_PRINT((ndo
, "\n\t%s Message (%u), length: %u",
2908 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
2912 switch (bgp
.bgp_type
) {
2914 bgp_open_print(ndo
, dat
, length
);
2917 bgp_update_print(ndo
, dat
, length
);
2919 case BGP_NOTIFICATION
:
2920 bgp_notification_print(ndo
, dat
, length
);
2924 case BGP_ROUTE_REFRESH
:
2925 bgp_route_refresh_print(ndo
, dat
, length
);
2928 /* we have no decoder for the BGP message */
2929 ND_TCHECK2(*dat
, length
);
2930 ND_PRINT((ndo
, "\n\t no Message %u decoder", bgp
.bgp_type
));
2931 print_unknown_data(ndo
, dat
, "\n\t ", length
);
2936 ND_PRINT((ndo
, "[|BGP]"));
2941 bgp_print(netdissect_options
*ndo
,
2942 const u_char
*dat
, int length
)
2946 const u_char
*start
;
2947 const u_char marker
[] = {
2948 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2949 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2955 if (ndo
->ndo_snapend
< dat
+ length
)
2956 ep
= ndo
->ndo_snapend
;
2958 ND_PRINT((ndo
, ": BGP"));
2960 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
2966 if (!ND_TTEST2(p
[0], 1))
2973 if (!ND_TTEST2(p
[0], sizeof(marker
)))
2975 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2980 /* found BGP header */
2981 ND_TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2982 memcpy(&bgp
, p
, BGP_SIZE
);
2985 ND_PRINT((ndo
, " [|BGP]"));
2987 hlen
= ntohs(bgp
.bgp_len
);
2988 if (hlen
< BGP_SIZE
) {
2989 ND_PRINT((ndo
, "\n[|BGP Bogus header length %u < %u]", hlen
,
2994 if (ND_TTEST2(p
[0], hlen
)) {
2995 if (!bgp_header_print(ndo
, p
, hlen
))
3000 ND_PRINT((ndo
, "\n[|BGP %s]",
3001 tok2str(bgp_msg_values
,
3002 "Unknown Message Type",
3011 ND_PRINT((ndo
, " [|BGP]"));
3016 * c-style: whitesmith