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_BE_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_BE_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_BE_16BITS(pptr
)) {
728 /* 2-byte-AS:number fmt*/
730 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
731 EXTRACT_BE_16BITS(pptr
+ 2),
732 EXTRACT_BE_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),
740 EXTRACT_BE_16BITS(pptr
+ 6));
743 /* 4-byte-AS:number fmt*/
745 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
746 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_32BITS(pptr
+ 2)),
747 EXTRACT_BE_16BITS(pptr
+ 6), *(pptr
+2), *(pptr
+3), *(pptr
+4),
748 *(pptr
+5), EXTRACT_BE_16BITS(pptr
+ 6));
751 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
760 decode_rt_routing_info(netdissect_options
*ndo
,
761 const u_char
*pptr
, char *buf
, u_int buflen
)
763 uint8_t route_target
[8];
765 char asbuf
[sizeof(astostr
)]; /* bgp_vpn_rd_print() overwrites astostr */
767 /* NLRI "prefix length" from RFC 2858 Section 4. */
769 plen
= pptr
[0]; /* get prefix length */
771 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
772 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
773 * target" fields inside the "prefix" depending on its length.
776 /* Without "origin AS", without "route target". */
777 snprintf(buf
, buflen
, "default route target");
784 /* With at least "origin AS", possibly with "route target". */
785 ND_TCHECK_32BITS(pptr
+ 1);
786 as_printf(ndo
, asbuf
, sizeof(asbuf
), EXTRACT_BE_32BITS(pptr
+ 1));
788 plen
-=32; /* adjust prefix length */
793 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
794 * and gives the number of octets in the variable-length "route
795 * target" field inside this NLRI "prefix". Look for it.
797 memset(&route_target
, 0, sizeof(route_target
));
798 ND_TCHECK2(pptr
[5], (plen
+ 7) / 8);
799 memcpy(&route_target
, &pptr
[5], (plen
+ 7) / 8);
800 /* Which specification says to do this? */
802 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
803 ((0xff00 >> (plen
% 8)) & 0xff);
805 snprintf(buf
, buflen
, "origin AS: %s, route target %s",
807 bgp_vpn_rd_print(ndo
, (u_char
*)&route_target
));
809 return 5 + (plen
+ 7) / 8;
816 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
817 const u_char
*pptr
, char *buf
, u_int buflen
)
823 plen
= pptr
[0]; /* get prefix length */
828 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
833 memset(&addr
, 0, sizeof(addr
));
834 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
835 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
837 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
838 ((0xff00 >> (plen
% 8)) & 0xff);
840 /* the label may get offsetted by 4 bits so lets shift it right */
841 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
842 bgp_vpn_rd_print(ndo
, pptr
+4),
843 ipaddr_string(ndo
, &addr
),
845 EXTRACT_BE_24BITS(pptr
+ 1)>>4,
846 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
848 return 12 + (plen
+ 7) / 8;
855 * +-------------------------------+
857 * | RD:IPv4-address (12 octets) |
859 * +-------------------------------+
860 * | MDT Group-address (4 octets) |
861 * +-------------------------------+
864 #define MDT_VPN_NLRI_LEN 16
867 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
868 const u_char
*pptr
, char *buf
, u_int buflen
)
872 const u_char
*vpn_ip
;
876 /* if the NLRI is not predefined length, quit.*/
877 if (*pptr
!= MDT_VPN_NLRI_LEN
* 8)
882 ND_TCHECK2(pptr
[0], 8);
887 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
889 pptr
+=sizeof(struct in_addr
);
891 /* MDT Group Address */
892 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
894 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
895 bgp_vpn_rd_print(ndo
, rd
), ipaddr_string(ndo
, vpn_ip
), ipaddr_string(ndo
, pptr
));
897 return MDT_VPN_NLRI_LEN
+ 1;
904 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
905 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
906 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
907 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
908 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
909 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
910 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
912 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
913 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
914 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
915 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
916 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
917 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
918 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
919 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
924 decode_multicast_vpn(netdissect_options
*ndo
,
925 const u_char
*pptr
, char *buf
, u_int buflen
)
927 uint8_t route_type
, route_length
, addr_length
, sg_length
;
930 ND_TCHECK2(pptr
[0], 2);
931 route_type
= *pptr
++;
932 route_length
= *pptr
++;
934 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
935 tok2str(bgp_multicast_vpn_route_type_values
,
936 "Unknown", route_type
),
937 route_type
, route_length
);
940 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
941 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
942 offset
= strlen(buf
);
943 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
944 bgp_vpn_rd_print(ndo
, pptr
),
945 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
946 (route_length
- BGP_VPN_RD_LEN
) << 3));
948 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
949 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
+ 4);
950 offset
= strlen(buf
);
951 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
952 bgp_vpn_rd_print(ndo
, pptr
),
953 as_printf(ndo
, astostr
, sizeof(astostr
),
954 EXTRACT_BE_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
957 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
958 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
959 offset
= strlen(buf
);
960 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
961 bgp_vpn_rd_print(ndo
, pptr
));
962 pptr
+= BGP_VPN_RD_LEN
;
964 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
965 addr_length
= route_length
- sg_length
;
967 ND_TCHECK2(pptr
[0], addr_length
);
968 offset
= strlen(buf
);
969 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
970 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
973 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
974 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
975 offset
= strlen(buf
);
976 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
977 bgp_vpn_rd_print(ndo
, pptr
));
978 pptr
+= BGP_VPN_RD_LEN
;
980 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
983 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
984 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
985 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
+ 4);
986 offset
= strlen(buf
);
987 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
988 bgp_vpn_rd_print(ndo
, pptr
),
989 as_printf(ndo
, astostr
, sizeof(astostr
),
990 EXTRACT_BE_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
991 pptr
+= BGP_VPN_RD_LEN
+ 4;
993 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
997 * no per route-type printing yet.
999 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
1004 return route_length
+ 2;
1011 * As I remember, some versions of systems have an snprintf() that
1012 * returns -1 if the buffer would have overflowed. If the return
1013 * value is negative, set buflen to 0, to indicate that we've filled
1016 * If the return value is greater than buflen, that means that
1017 * the buffer would have overflowed; again, set buflen to 0 in
1020 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1023 else if ((u_int)stringlen>buflen) \
1026 buflen-=stringlen; \
1031 decode_labeled_vpn_l2(netdissect_options
*ndo
,
1032 const u_char
*pptr
, char *buf
, u_int buflen
)
1034 int plen
,tlen
,stringlen
,tlv_type
,tlv_len
,ttlv_len
;
1036 ND_TCHECK2(pptr
[0], 2);
1037 plen
=EXTRACT_BE_16BITS(pptr
);
1040 /* Old and new L2VPN NLRI share AFI/SAFI
1041 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1042 * and > 17 as old format. Complain for the middle case
1045 /* assume AD-only with RD, BGPNH */
1046 ND_TCHECK2(pptr
[0],12);
1048 stringlen
=snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
1049 bgp_vpn_rd_print(ndo
, pptr
),
1050 ipaddr_string(ndo
, pptr
+8)
1052 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1056 } else if (plen
>17) {
1057 /* assume old format */
1058 /* RD, ID, LBLKOFF, LBLBASE */
1060 ND_TCHECK2(pptr
[0],15);
1062 stringlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1063 bgp_vpn_rd_print(ndo
, pptr
),
1064 EXTRACT_BE_16BITS(pptr
+ 8),
1065 EXTRACT_BE_16BITS(pptr
+ 10),
1066 EXTRACT_BE_24BITS(pptr
+ 12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1067 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1071 /* ok now the variable part - lets read out TLVs*/
1075 ND_TCHECK2(pptr
[0], 3);
1077 tlv_len
=EXTRACT_BE_16BITS(pptr
);
1084 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1087 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1089 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
1090 while (ttlv_len
>0) {
1093 stringlen
=snprintf(buf
,buflen
, "%02x",*pptr
++);
1094 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1101 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1104 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1108 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
1113 /* complain bitterly ? */
1123 decode_prefix6(netdissect_options
*ndo
,
1124 const u_char
*pd
, u_int itemlen
, char *buf
, u_int buflen
)
1126 struct in6_addr addr
;
1127 u_int plen
, plenbytes
;
1136 memset(&addr
, 0, sizeof(addr
));
1137 plenbytes
= (plen
+ 7) / 8;
1138 ND_TCHECK2(pd
[1], plenbytes
);
1139 ITEMCHECK(plenbytes
);
1140 memcpy(&addr
, &pd
[1], plenbytes
);
1142 addr
.s6_addr
[plenbytes
- 1] &=
1143 ((0xff00 >> (plen
% 8)) & 0xff);
1145 snprintf(buf
, buflen
, "%s/%d", ip6addr_string(ndo
, &addr
), plen
);
1146 return 1 + plenbytes
;
1156 decode_labeled_prefix6(netdissect_options
*ndo
,
1157 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
1159 struct in6_addr addr
;
1160 u_int plen
, plenbytes
;
1162 /* prefix length and label = 4 bytes */
1163 ND_TCHECK2(pptr
[0], 4);
1165 plen
= pptr
[0]; /* get prefix length */
1170 plen
-=24; /* adjust prefixlen - labellength */
1176 memset(&addr
, 0, sizeof(addr
));
1177 plenbytes
= (plen
+ 7) / 8;
1178 ND_TCHECK2(pptr
[4], plenbytes
);
1179 memcpy(&addr
, &pptr
[4], plenbytes
);
1181 addr
.s6_addr
[plenbytes
- 1] &=
1182 ((0xff00 >> (plen
% 8)) & 0xff);
1184 /* the label may get offsetted by 4 bits so lets shift it right */
1185 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
1186 ip6addr_string(ndo
, &addr
),
1188 EXTRACT_BE_24BITS(pptr
+ 1)>>4,
1189 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1191 return 4 + plenbytes
;
1201 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1202 const u_char
*pptr
, char *buf
, u_int buflen
)
1204 struct in6_addr addr
;
1208 plen
= pptr
[0]; /* get prefix length */
1213 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1218 memset(&addr
, 0, sizeof(addr
));
1219 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
1220 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1222 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1223 ((0xff00 >> (plen
% 8)) & 0xff);
1225 /* the label may get offsetted by 4 bits so lets shift it right */
1226 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1227 bgp_vpn_rd_print(ndo
, pptr
+4),
1228 ip6addr_string(ndo
, &addr
),
1230 EXTRACT_BE_24BITS(pptr
+ 1)>>4,
1231 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1233 return 12 + (plen
+ 7) / 8;
1240 decode_clnp_prefix(netdissect_options
*ndo
,
1241 const u_char
*pptr
, char *buf
, u_int buflen
)
1247 plen
= pptr
[0]; /* get prefix length */
1252 memset(&addr
, 0, sizeof(addr
));
1253 ND_TCHECK2(pptr
[4], (plen
+ 7) / 8);
1254 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
1256 addr
[(plen
+ 7) / 8 - 1] &=
1257 ((0xff00 >> (plen
% 8)) & 0xff);
1259 snprintf(buf
, buflen
, "%s/%d",
1260 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1263 return 1 + (plen
+ 7) / 8;
1270 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1271 const u_char
*pptr
, char *buf
, u_int buflen
)
1277 plen
= pptr
[0]; /* get prefix length */
1282 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1287 memset(&addr
, 0, sizeof(addr
));
1288 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
1289 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1291 addr
[(plen
+ 7) / 8 - 1] &=
1292 ((0xff00 >> (plen
% 8)) & 0xff);
1294 /* the label may get offsetted by 4 bits so lets shift it right */
1295 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1296 bgp_vpn_rd_print(ndo
, pptr
+4),
1297 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1299 EXTRACT_BE_24BITS(pptr
+ 1)>>4,
1300 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1302 return 12 + (plen
+ 7) / 8;
1309 * bgp_attr_get_as_size
1311 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1312 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1313 * support, exchange AS-Path with the same path-attribute type value 0x02.
1316 bgp_attr_get_as_size(netdissect_options
*ndo
,
1317 uint8_t bgpa_type
, const u_char
*pptr
, int len
)
1319 const u_char
*tptr
= pptr
;
1322 * If the path attribute is the optional AS4 path type, then we already
1323 * know, that ASs must be encoded in 4 byte format.
1325 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1330 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1331 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1334 while (tptr
< pptr
+ len
) {
1338 * If we do not find a valid segment type, our guess might be wrong.
1340 if (tptr
[0] < BGP_AS_SEG_TYPE_MIN
|| tptr
[0] > BGP_AS_SEG_TYPE_MAX
) {
1344 tptr
+= 2 + tptr
[1] * 2;
1348 * If we correctly reached end of the AS path attribute data content,
1349 * then most likely ASs were indeed encoded as 2 bytes.
1351 if (tptr
== pptr
+ len
) {
1358 * We can come here, either we did not have enough data, or if we
1359 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1360 * so that calller can try to decode each AS as of 4 bytes. If indeed
1361 * there was not enough data, it will crib and end the parse anyways.
1367 bgp_attr_print(netdissect_options
*ndo
,
1368 u_int atype
, const u_char
*pptr
, u_int len
)
1372 uint8_t safi
, snpa
, nhlen
;
1373 union { /* copy buffer for bandwidth values */
1380 char buf
[MAXHOSTNAMELEN
+ 100];
1387 case BGPTYPE_ORIGIN
:
1389 ND_PRINT((ndo
, "invalid len"));
1392 ND_PRINT((ndo
, "%s", tok2str(bgp_origin_values
,
1393 "Unknown Origin Typecode",
1399 * Process AS4 byte path and AS2 byte path attributes here.
1401 case BGPTYPE_AS4_PATH
:
1402 case BGPTYPE_AS_PATH
:
1404 ND_PRINT((ndo
, "invalid len"));
1408 ND_PRINT((ndo
, "empty"));
1413 * BGP updates exchanged between New speakers that support 4
1414 * byte AS, ASs are always encoded in 4 bytes. There is no
1415 * definitive way to find this, just by the packet's
1416 * contents. So, check for packet's TLV's sanity assuming
1417 * 2 bytes first, and it does not pass, assume that ASs are
1418 * encoded in 4 bytes format and move on.
1420 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1422 while (tptr
< pptr
+ len
) {
1424 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_open_values
,
1427 for (i
= 0; i
< tptr
[1] * as_size
; i
+= as_size
) {
1428 ND_TCHECK2(tptr
[2 + i
], as_size
);
1429 ND_PRINT((ndo
, "%s ",
1430 as_printf(ndo
, astostr
, sizeof(astostr
),
1432 EXTRACT_BE_16BITS(&tptr
[2 + i
]) :
1433 EXTRACT_BE_32BITS(&tptr
[2 + i
]))));
1436 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_close_values
,
1439 tptr
+= 2 + tptr
[1] * as_size
;
1442 case BGPTYPE_NEXT_HOP
:
1444 ND_PRINT((ndo
, "invalid len"));
1446 ND_TCHECK2(tptr
[0], 4);
1447 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1450 case BGPTYPE_MULTI_EXIT_DISC
:
1451 case BGPTYPE_LOCAL_PREF
:
1453 ND_PRINT((ndo
, "invalid len"));
1455 ND_TCHECK2(tptr
[0], 4);
1456 ND_PRINT((ndo
, "%u", EXTRACT_BE_32BITS(tptr
)));
1459 case BGPTYPE_ATOMIC_AGGREGATE
:
1461 ND_PRINT((ndo
, "invalid len"));
1463 case BGPTYPE_AGGREGATOR
:
1466 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1467 * the length of this PA can be either 6 bytes or 8 bytes.
1469 if (len
!= 6 && len
!= 8) {
1470 ND_PRINT((ndo
, "invalid len"));
1473 ND_TCHECK2(tptr
[0], len
);
1475 ND_PRINT((ndo
, " AS #%s, origin %s",
1476 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_16BITS(tptr
)),
1477 ipaddr_string(ndo
, tptr
+ 2)));
1479 ND_PRINT((ndo
, " AS #%s, origin %s",
1480 as_printf(ndo
, astostr
, sizeof(astostr
),
1481 EXTRACT_BE_32BITS(tptr
)), ipaddr_string(ndo
, tptr
+ 4)));
1484 case BGPTYPE_AGGREGATOR4
:
1486 ND_PRINT((ndo
, "invalid len"));
1489 ND_TCHECK2(tptr
[0], 8);
1490 ND_PRINT((ndo
, " AS #%s, origin %s",
1491 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_32BITS(tptr
)),
1492 ipaddr_string(ndo
, tptr
+ 4)));
1494 case BGPTYPE_COMMUNITIES
:
1496 ND_PRINT((ndo
, "invalid len"));
1501 ND_TCHECK2(tptr
[0], 4);
1502 comm
= EXTRACT_BE_32BITS(tptr
);
1504 case BGP_COMMUNITY_NO_EXPORT
:
1505 ND_PRINT((ndo
, " NO_EXPORT"));
1507 case BGP_COMMUNITY_NO_ADVERT
:
1508 ND_PRINT((ndo
, " NO_ADVERTISE"));
1510 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1511 ND_PRINT((ndo
, " NO_EXPORT_SUBCONFED"));
1514 ND_PRINT((ndo
, "%u:%u%s",
1515 (comm
>> 16) & 0xffff,
1517 (tlen
>4) ? ", " : ""));
1524 case BGPTYPE_ORIGINATOR_ID
:
1526 ND_PRINT((ndo
, "invalid len"));
1529 ND_TCHECK2(tptr
[0], 4);
1530 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1532 case BGPTYPE_CLUSTER_LIST
:
1534 ND_PRINT((ndo
, "invalid len"));
1538 ND_TCHECK2(tptr
[0], 4);
1539 ND_PRINT((ndo
, "%s%s",
1540 ipaddr_string(ndo
, tptr
),
1541 (tlen
>4) ? ", " : ""));
1546 case BGPTYPE_MP_REACH_NLRI
:
1547 ND_TCHECK2(tptr
[0], 3);
1548 af
= EXTRACT_BE_16BITS(tptr
);
1551 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1552 tok2str(af_values
, "Unknown AFI", af
),
1554 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1555 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1558 switch(af
<<8 | safi
) {
1559 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1560 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1561 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1562 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1563 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1564 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1565 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1566 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1567 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1568 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1569 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1570 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1571 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1572 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1573 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1574 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1575 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1576 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1577 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1578 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1579 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1580 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1581 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1582 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1583 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1584 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1585 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1588 ND_TCHECK2(tptr
[0], tlen
);
1589 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1590 if (ndo
->ndo_vflag
<= 1)
1591 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1605 ND_PRINT((ndo
, "\n\t nexthop: "));
1608 ND_PRINT((ndo
, ", " ));
1610 switch(af
<<8 | safi
) {
1611 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1612 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1613 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1614 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1615 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1616 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1617 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1618 if (tlen
< (int)sizeof(struct in_addr
)) {
1619 ND_PRINT((ndo
, "invalid len"));
1622 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1623 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1624 tlen
-= sizeof(struct in_addr
);
1625 tptr
+= sizeof(struct in_addr
);
1628 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1629 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1630 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1631 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1632 ND_PRINT((ndo
, "invalid len"));
1635 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1636 ND_PRINT((ndo
, "RD: %s, %s",
1637 bgp_vpn_rd_print(ndo
, tptr
),
1638 ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1639 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1640 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1643 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1644 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1645 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1646 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1647 if (tlen
< (int)sizeof(struct in6_addr
)) {
1648 ND_PRINT((ndo
, "invalid len"));
1651 ND_TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1652 ND_PRINT((ndo
, "%s", ip6addr_string(ndo
, tptr
)));
1653 tlen
-= sizeof(struct in6_addr
);
1654 tptr
+= sizeof(struct in6_addr
);
1657 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1658 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1659 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1660 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1661 ND_PRINT((ndo
, "invalid len"));
1664 ND_TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1665 ND_PRINT((ndo
, "RD: %s, %s",
1666 bgp_vpn_rd_print(ndo
, tptr
),
1667 ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1668 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1669 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1672 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1673 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1674 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1675 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1676 if (tlen
< (int)sizeof(struct in_addr
)) {
1677 ND_PRINT((ndo
, "invalid len"));
1680 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1681 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1682 tlen
-= (sizeof(struct in_addr
));
1683 tptr
+= (sizeof(struct in_addr
));
1686 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1687 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1688 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1689 ND_TCHECK2(tptr
[0], tlen
);
1690 ND_PRINT((ndo
, "%s", isonsap_string(ndo
, tptr
, tlen
)));
1695 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1696 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1697 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1698 if (tlen
< BGP_VPN_RD_LEN
+1) {
1699 ND_PRINT((ndo
, "invalid len"));
1702 ND_TCHECK2(tptr
[0], tlen
);
1703 ND_PRINT((ndo
, "RD: %s, %s",
1704 bgp_vpn_rd_print(ndo
, tptr
),
1705 isonsap_string(ndo
, tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
)));
1706 /* rfc986 mapped IPv4 address ? */
1707 if (EXTRACT_BE_32BITS(tptr
+ BGP_VPN_RD_LEN
) == 0x47000601)
1708 ND_PRINT((ndo
, " = %s", ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+4)));
1709 /* rfc1888 mapped IPv6 address ? */
1710 else if (EXTRACT_BE_24BITS(tptr
+ BGP_VPN_RD_LEN
) == 0x350000)
1711 ND_PRINT((ndo
, " = %s", ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+3)));
1717 ND_TCHECK2(tptr
[0], tlen
);
1718 ND_PRINT((ndo
, "no AFI %u/SAFI %u decoder", af
, safi
));
1719 if (ndo
->ndo_vflag
<= 1)
1720 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1728 ND_PRINT((ndo
, ", nh-length: %u", nhlen
));
1736 ND_PRINT((ndo
, "\n\t %u SNPA", snpa
));
1737 for (/*nothing*/; snpa
> 0; snpa
--) {
1739 ND_PRINT((ndo
, "\n\t %d bytes", tptr
[0]));
1740 tptr
+= tptr
[0] + 1;
1743 ND_PRINT((ndo
, ", no SNPA"));
1746 while (tptr
< pptr
+ len
) {
1747 switch (af
<<8 | safi
) {
1748 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1749 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1750 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1751 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1753 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1754 else if (advance
== -2)
1756 else if (advance
== -3)
1757 break; /* bytes left, but not enough */
1759 ND_PRINT((ndo
, "\n\t %s", buf
));
1761 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1762 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1764 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1765 else if (advance
== -2)
1767 else if (advance
== -3)
1768 break; /* bytes left, but not enough */
1770 ND_PRINT((ndo
, "\n\t %s", buf
));
1772 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1773 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1774 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1775 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1777 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1778 else if (advance
== -2)
1781 ND_PRINT((ndo
, "\n\t %s", buf
));
1783 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1784 advance
= decode_rt_routing_info(ndo
, tptr
, buf
, sizeof(buf
));
1786 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1787 else if (advance
== -2)
1790 ND_PRINT((ndo
, "\n\t %s", buf
));
1792 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1793 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1794 advance
= decode_multicast_vpn(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
));
1803 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1804 advance
= decode_mdt_vpn_nlri(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
));
1812 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1813 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1814 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1815 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1817 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1818 else if (advance
== -2)
1820 else if (advance
== -3)
1821 break; /* bytes left, but not enough */
1823 ND_PRINT((ndo
, "\n\t %s", buf
));
1825 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1826 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1828 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1829 else if (advance
== -2)
1831 else if (advance
== -3)
1832 break; /* bytes left, but not enough */
1834 ND_PRINT((ndo
, "\n\t %s", buf
));
1836 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1837 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1838 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1839 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1841 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1842 else if (advance
== -2)
1845 ND_PRINT((ndo
, "\n\t %s", buf
));
1847 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1848 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1849 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1850 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1851 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1853 ND_PRINT((ndo
, "\n\t (illegal length)"));
1854 else if (advance
== -2)
1857 ND_PRINT((ndo
, "\n\t %s", buf
));
1859 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1860 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1861 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1862 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1864 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1865 else if (advance
== -2)
1868 ND_PRINT((ndo
, "\n\t %s", buf
));
1870 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1871 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1872 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1873 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1875 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1876 else if (advance
== -2)
1879 ND_PRINT((ndo
, "\n\t %s", buf
));
1882 ND_TCHECK2(*tptr
,tlen
);
1883 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1884 if (ndo
->ndo_vflag
<= 1)
1885 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1897 case BGPTYPE_MP_UNREACH_NLRI
:
1898 ND_TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1899 af
= EXTRACT_BE_16BITS(tptr
);
1902 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1903 tok2str(af_values
, "Unknown AFI", af
),
1905 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1906 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1909 if (len
== BGP_MP_NLRI_MINSIZE
)
1910 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
1914 while (tptr
< pptr
+ len
) {
1915 switch (af
<<8 | safi
) {
1916 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1917 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1918 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1919 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1921 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1922 else if (advance
== -2)
1924 else if (advance
== -3)
1925 break; /* bytes left, but not enough */
1927 ND_PRINT((ndo
, "\n\t %s", buf
));
1929 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1930 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1932 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1933 else if (advance
== -2)
1935 else if (advance
== -3)
1936 break; /* bytes left, but not enough */
1938 ND_PRINT((ndo
, "\n\t %s", buf
));
1940 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1941 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1942 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1943 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1945 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1946 else if (advance
== -2)
1949 ND_PRINT((ndo
, "\n\t %s", buf
));
1951 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1952 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1953 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1954 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1956 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1957 else if (advance
== -2)
1959 else if (advance
== -3)
1960 break; /* bytes left, but not enough */
1962 ND_PRINT((ndo
, "\n\t %s", buf
));
1964 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1965 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1967 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1968 else if (advance
== -2)
1970 else if (advance
== -3)
1971 break; /* bytes left, but not enough */
1973 ND_PRINT((ndo
, "\n\t %s", buf
));
1975 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1976 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1977 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1978 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1980 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1981 else if (advance
== -2)
1984 ND_PRINT((ndo
, "\n\t %s", buf
));
1986 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1987 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1988 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1989 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1990 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1992 ND_PRINT((ndo
, "\n\t (illegal length)"));
1993 else if (advance
== -2)
1996 ND_PRINT((ndo
, "\n\t %s", buf
));
1998 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1999 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
2000 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
2001 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2003 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2004 else if (advance
== -2)
2007 ND_PRINT((ndo
, "\n\t %s", buf
));
2009 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
2010 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
2011 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
2012 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
2014 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2015 else if (advance
== -2)
2018 ND_PRINT((ndo
, "\n\t %s", buf
));
2020 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
2021 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
2023 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2024 else if (advance
== -2)
2027 ND_PRINT((ndo
, "\n\t %s", buf
));
2029 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
2030 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
2031 advance
= decode_multicast_vpn(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
));
2040 ND_TCHECK2(*(tptr
-3),tlen
);
2041 ND_PRINT((ndo
, "no AFI %u / SAFI %u decoder", af
, safi
));
2042 if (ndo
->ndo_vflag
<= 1)
2043 print_unknown_data(ndo
, tptr
-3, "\n\t ", tlen
);
2053 case BGPTYPE_EXTD_COMMUNITIES
:
2055 ND_PRINT((ndo
, "invalid len"));
2061 ND_TCHECK2(tptr
[0], 2);
2062 extd_comm
=EXTRACT_BE_16BITS(tptr
);
2064 ND_PRINT((ndo
, "\n\t %s (0x%04x), Flags [%s]",
2065 tok2str(bgp_extd_comm_subtype_values
,
2066 "unknown extd community typecode",
2069 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
)));
2071 ND_TCHECK2(*(tptr
+2), 6);
2073 case BGP_EXT_COM_RT_0
:
2074 case BGP_EXT_COM_RO_0
:
2075 case BGP_EXT_COM_L2VPN_RT_0
:
2076 ND_PRINT((ndo
, ": %u:%u (= %s)",
2077 EXTRACT_BE_16BITS(tptr
+ 2),
2078 EXTRACT_BE_32BITS(tptr
+ 4),
2079 ipaddr_string(ndo
, tptr
+4)));
2081 case BGP_EXT_COM_RT_1
:
2082 case BGP_EXT_COM_RO_1
:
2083 case BGP_EXT_COM_L2VPN_RT_1
:
2084 case BGP_EXT_COM_VRF_RT_IMP
:
2085 ND_PRINT((ndo
, ": %s:%u",
2086 ipaddr_string(ndo
, tptr
+2),
2087 EXTRACT_BE_16BITS(tptr
+ 6)));
2089 case BGP_EXT_COM_RT_2
:
2090 case BGP_EXT_COM_RO_2
:
2091 ND_PRINT((ndo
, ": %s:%u",
2092 as_printf(ndo
, astostr
, sizeof(astostr
),
2093 EXTRACT_BE_32BITS(tptr
+ 2)), EXTRACT_BE_16BITS(tptr
+ 6)));
2095 case BGP_EXT_COM_LINKBAND
:
2096 bw
.i
= EXTRACT_BE_32BITS(tptr
+ 2);
2097 ND_PRINT((ndo
, ": bandwidth: %.3f Mbps",
2100 case BGP_EXT_COM_VPN_ORIGIN
:
2101 case BGP_EXT_COM_VPN_ORIGIN2
:
2102 case BGP_EXT_COM_VPN_ORIGIN3
:
2103 case BGP_EXT_COM_VPN_ORIGIN4
:
2104 case BGP_EXT_COM_OSPF_RID
:
2105 case BGP_EXT_COM_OSPF_RID2
:
2106 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
+2)));
2108 case BGP_EXT_COM_OSPF_RTYPE
:
2109 case BGP_EXT_COM_OSPF_RTYPE2
:
2110 ND_PRINT((ndo
, ": area:%s, router-type:%s, metric-type:%s%s",
2111 ipaddr_string(ndo
, tptr
+2),
2112 tok2str(bgp_extd_comm_ospf_rtype_values
,
2114 EXTRACT_8BITS((tptr
+ 6))),
2115 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
2116 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : ""));
2118 case BGP_EXT_COM_L2INFO
:
2119 ND_PRINT((ndo
, ": %s Control Flags [0x%02x]:MTU %u",
2120 tok2str(l2vpn_encaps_values
,
2122 EXTRACT_8BITS((tptr
+ 2))),
2124 EXTRACT_BE_16BITS(tptr
+ 4)));
2126 case BGP_EXT_COM_SOURCE_AS
:
2127 ND_PRINT((ndo
, ": AS %u", EXTRACT_BE_16BITS(tptr
+ 2)));
2130 ND_TCHECK2(*tptr
,8);
2131 print_unknown_data(ndo
, tptr
, "\n\t ", 8);
2139 case BGPTYPE_PMSI_TUNNEL
:
2141 uint8_t tunnel_type
, flags
;
2143 ND_TCHECK2(tptr
[0], 5);
2144 tunnel_type
= *(tptr
+1);
2148 ND_PRINT((ndo
, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2149 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2151 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2152 EXTRACT_BE_24BITS(tptr
+ 2)>>4));
2157 switch (tunnel_type
) {
2158 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2159 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2160 ND_TCHECK2(tptr
[0], 8);
2161 ND_PRINT((ndo
, "\n\t Sender %s, P-Group %s",
2162 ipaddr_string(ndo
, tptr
),
2163 ipaddr_string(ndo
, tptr
+4)));
2166 case BGP_PMSI_TUNNEL_PIM_SSM
:
2167 ND_TCHECK2(tptr
[0], 8);
2168 ND_PRINT((ndo
, "\n\t Root-Node %s, P-Group %s",
2169 ipaddr_string(ndo
, tptr
),
2170 ipaddr_string(ndo
, tptr
+4)));
2172 case BGP_PMSI_TUNNEL_INGRESS
:
2173 ND_TCHECK2(tptr
[0], 4);
2174 ND_PRINT((ndo
, "\n\t Tunnel-Endpoint %s",
2175 ipaddr_string(ndo
, tptr
)));
2177 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2178 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2179 ND_TCHECK2(tptr
[0], 8);
2180 ND_PRINT((ndo
, "\n\t Root-Node %s, LSP-ID 0x%08x",
2181 ipaddr_string(ndo
, tptr
),
2182 EXTRACT_BE_32BITS(tptr
+ 4)));
2184 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2185 ND_TCHECK2(tptr
[0], 8);
2186 ND_PRINT((ndo
, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2187 ipaddr_string(ndo
, tptr
),
2188 EXTRACT_BE_32BITS(tptr
+ 4)));
2191 if (ndo
->ndo_vflag
<= 1) {
2192 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2206 ND_TCHECK2(tptr
[0], 3);
2209 length
= EXTRACT_BE_16BITS(tptr
+ 1);
2213 ND_PRINT((ndo
, "\n\t %s TLV (%u), length %u",
2214 tok2str(bgp_aigp_values
, "Unknown", type
),
2222 * Check if we can read the TLV data.
2224 ND_TCHECK2(tptr
[3], length
);
2231 ND_PRINT((ndo
, ", metric %" PRIu64
,
2232 EXTRACT_BE_64BITS(tptr
)));
2236 if (ndo
->ndo_vflag
<= 1) {
2237 print_unknown_data(ndo
, tptr
,"\n\t ", length
);
2246 case BGPTYPE_ATTR_SET
:
2247 ND_TCHECK2(tptr
[0], 4);
2250 ND_PRINT((ndo
, "\n\t Origin AS: %s",
2251 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_BE_32BITS(tptr
))));
2256 u_int aflags
, alenlen
, alen
;
2258 ND_TCHECK2(tptr
[0], 2);
2262 atype
= *(tptr
+ 1);
2265 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2266 ND_TCHECK2(tptr
[0], alenlen
);
2269 alen
= bgp_attr_len(aflags
, tptr
);
2273 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2274 tok2str(bgp_attr_values
,
2275 "Unknown Attribute", atype
),
2280 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2281 aflags
& 0x80 ? "O" : "",
2282 aflags
& 0x40 ? "T" : "",
2283 aflags
& 0x20 ? "P" : "",
2284 aflags
& 0x10 ? "E" : ""));
2286 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2287 ND_PRINT((ndo
, "]: "));
2289 /* FIXME check for recursion */
2290 if (!bgp_attr_print(ndo
, atype
, tptr
, alen
))
2297 case BGPTYPE_LARGE_COMMUNITY
:
2298 if (len
== 0 || len
% 12) {
2299 ND_PRINT((ndo
, "invalid len"));
2302 ND_PRINT((ndo
, "\n\t "));
2304 ND_TCHECK2(*tptr
, 12);
2305 ND_PRINT((ndo
, "%u:%u:%u%s",
2306 EXTRACT_BE_32BITS(tptr
),
2307 EXTRACT_BE_32BITS(tptr
+ 4),
2308 EXTRACT_BE_32BITS(tptr
+ 8),
2309 (len
> 12) ? ", " : ""));
2315 ND_TCHECK2(*pptr
,len
);
2316 ND_PRINT((ndo
, "\n\t no Attribute %u decoder", atype
)); /* we have no decoder for the attribute */
2317 if (ndo
->ndo_vflag
<= 1)
2318 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2321 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2322 ND_TCHECK2(*pptr
,len
);
2323 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2332 bgp_capabilities_print(netdissect_options
*ndo
,
2333 const u_char
*opt
, int caps_len
)
2335 int cap_type
, cap_len
, tcap_len
, cap_offset
;
2338 while (i
< caps_len
) {
2339 ND_TCHECK2(opt
[i
], BGP_CAP_HEADER_SIZE
);
2343 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2344 tok2str(bgp_capcode_values
, "Unknown",
2348 ND_TCHECK2(opt
[i
+2], cap_len
);
2350 case BGP_CAPCODE_MP
:
2351 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u)",
2352 tok2str(af_values
, "Unknown",
2353 EXTRACT_BE_16BITS(opt
+ i
+ 2)),
2354 EXTRACT_BE_16BITS(opt
+ i
+ 2),
2355 tok2str(bgp_safi_values
, "Unknown",
2359 case BGP_CAPCODE_RESTART
:
2360 ND_PRINT((ndo
, "\n\t\tRestart Flags: [%s], Restart Time %us",
2361 ((opt
[i
+2])&0x80) ? "R" : "none",
2362 EXTRACT_BE_16BITS(opt
+ i
+ 2)&0xfff));
2365 while(tcap_len
>=4) {
2366 ND_PRINT((ndo
, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2367 tok2str(af_values
,"Unknown",
2368 EXTRACT_BE_16BITS(opt
+ i
+ cap_offset
)),
2369 EXTRACT_BE_16BITS(opt
+ i
+ cap_offset
),
2370 tok2str(bgp_safi_values
,"Unknown",
2371 opt
[i
+cap_offset
+2]),
2372 opt
[i
+cap_offset
+2],
2373 ((opt
[i
+cap_offset
+3])&0x80) ? "yes" : "no" ));
2378 case BGP_CAPCODE_RR
:
2379 case BGP_CAPCODE_RR_CISCO
:
2381 case BGP_CAPCODE_AS_NEW
:
2384 * Extract the 4 byte AS number encoded.
2387 ND_PRINT((ndo
, "\n\t\t 4 Byte AS %s",
2388 as_printf(ndo
, astostr
, sizeof(astostr
),
2389 EXTRACT_BE_32BITS(opt
+ i
+ 2))));
2392 case BGP_CAPCODE_ADD_PATH
:
2394 if (tcap_len
== 0) {
2395 ND_PRINT((ndo
, " (bogus)")); /* length */
2398 while (tcap_len
> 0) {
2400 ND_PRINT((ndo
, "\n\t\t(invalid)"));
2403 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2404 tok2str(af_values
,"Unknown",EXTRACT_BE_16BITS(opt
+ i
+ cap_offset
)),
2405 EXTRACT_BE_16BITS(opt
+ i
+ cap_offset
),
2406 tok2str(bgp_safi_values
,"Unknown",opt
[i
+cap_offset
+2]),
2407 opt
[i
+cap_offset
+2],
2408 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",opt
[i
+cap_offset
+3])
2415 ND_PRINT((ndo
, "\n\t\tno decoder for Capability %u",
2417 if (ndo
->ndo_vflag
<= 1)
2418 print_unknown_data(ndo
, &opt
[i
+2], "\n\t\t", cap_len
);
2421 if (ndo
->ndo_vflag
> 1 && cap_len
> 0) {
2422 print_unknown_data(ndo
, &opt
[i
+2], "\n\t\t", cap_len
);
2424 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2429 ND_PRINT((ndo
, "[|BGP]"));
2433 bgp_open_print(netdissect_options
*ndo
,
2434 const u_char
*dat
, int length
)
2436 struct bgp_open bgpo
;
2437 struct bgp_opt bgpopt
;
2441 ND_TCHECK2(dat
[0], BGP_OPEN_SIZE
);
2442 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
2444 ND_PRINT((ndo
, "\n\t Version %d, ", bgpo
.bgpo_version
));
2445 ND_PRINT((ndo
, "my AS %s, ",
2446 as_printf(ndo
, astostr
, sizeof(astostr
), ntohs(bgpo
.bgpo_myas
))));
2447 ND_PRINT((ndo
, "Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
)));
2448 ND_PRINT((ndo
, "ID %s", ipaddr_string(ndo
, &bgpo
.bgpo_id
)));
2449 ND_PRINT((ndo
, "\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
));
2451 /* some little sanity checking */
2452 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
2456 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
2460 while (i
< bgpo
.bgpo_optlen
) {
2461 ND_TCHECK2(opt
[i
], BGP_OPT_SIZE
);
2462 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
2463 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
2464 ND_PRINT((ndo
, "\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
));
2468 ND_PRINT((ndo
, "\n\t Option %s (%u), length: %u",
2469 tok2str(bgp_opt_values
,"Unknown",
2470 bgpopt
.bgpopt_type
),
2472 bgpopt
.bgpopt_len
));
2474 /* now let's decode the options we know*/
2475 switch(bgpopt
.bgpopt_type
) {
2478 bgp_capabilities_print(ndo
, &opt
[i
+BGP_OPT_SIZE
],
2484 ND_PRINT((ndo
, "\n\t no decoder for option %u",
2485 bgpopt
.bgpopt_type
));
2488 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
2492 ND_PRINT((ndo
, "[|BGP]"));
2496 bgp_update_print(netdissect_options
*ndo
,
2497 const u_char
*dat
, int length
)
2501 int withdrawn_routes_len
;
2505 ND_TCHECK2(dat
[0], BGP_SIZE
);
2506 if (length
< BGP_SIZE
)
2508 memcpy(&bgp
, dat
, BGP_SIZE
);
2509 p
= dat
+ BGP_SIZE
; /*XXX*/
2512 /* Unfeasible routes */
2513 ND_TCHECK2(p
[0], 2);
2516 withdrawn_routes_len
= EXTRACT_BE_16BITS(p
);
2519 if (withdrawn_routes_len
) {
2521 * Without keeping state from the original NLRI message,
2522 * it's not possible to tell if this a v4 or v6 route,
2523 * so only try to decode it if we're not v6 enabled.
2525 ND_TCHECK2(p
[0], withdrawn_routes_len
);
2526 if (length
< withdrawn_routes_len
)
2528 ND_PRINT((ndo
, "\n\t Withdrawn routes: %d bytes", withdrawn_routes_len
));
2529 p
+= withdrawn_routes_len
;
2530 length
-= withdrawn_routes_len
;
2533 ND_TCHECK2(p
[0], 2);
2536 len
= EXTRACT_BE_16BITS(p
);
2540 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2541 /* No withdrawn routes, no path attributes, no NLRI */
2542 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
2547 /* do something more useful!*/
2549 int aflags
, atype
, alenlen
, alen
;
2551 ND_TCHECK2(p
[0], 2);
2561 alenlen
= bgp_attr_lenlen(aflags
, p
);
2562 ND_TCHECK2(p
[0], alenlen
);
2565 if (length
< alenlen
)
2567 alen
= bgp_attr_len(aflags
, p
);
2572 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2573 tok2str(bgp_attr_values
, "Unknown Attribute",
2579 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2580 aflags
& 0x80 ? "O" : "",
2581 aflags
& 0x40 ? "T" : "",
2582 aflags
& 0x20 ? "P" : "",
2583 aflags
& 0x10 ? "E" : ""));
2585 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2586 ND_PRINT((ndo
, "]: "));
2592 if (!bgp_attr_print(ndo
, atype
, p
, alen
))
2602 * XXX - what if they're using the "Advertisement of
2603 * Multiple Paths in BGP" feature:
2605 * https://datatracker.ietf.org/doc/draft-ietf-idr-add-paths/
2607 * http://tools.ietf.org/html/draft-ietf-idr-add-paths-06
2609 ND_PRINT((ndo
, "\n\t Updated routes:"));
2611 char buf
[MAXHOSTNAMELEN
+ 100];
2612 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2614 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2619 goto trunc
; /* bytes left, but not enough */
2621 ND_PRINT((ndo
, "\n\t %s", buf
));
2629 ND_PRINT((ndo
, "[|BGP]"));
2633 bgp_notification_print(netdissect_options
*ndo
,
2634 const u_char
*dat
, int length
)
2636 struct bgp_notification bgpn
;
2638 uint8_t shutdown_comm_length
;
2639 uint8_t remainder_offset
;
2641 ND_TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
2642 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
2644 /* some little sanity checking */
2645 if (length
<BGP_NOTIFICATION_SIZE
)
2648 ND_PRINT((ndo
, ", %s (%u)",
2649 tok2str(bgp_notify_major_values
, "Unknown Error",
2653 switch (bgpn
.bgpn_major
) {
2655 case BGP_NOTIFY_MAJOR_MSG
:
2656 ND_PRINT((ndo
, ", subcode %s (%u)",
2657 tok2str(bgp_notify_minor_msg_values
, "Unknown",
2661 case BGP_NOTIFY_MAJOR_OPEN
:
2662 ND_PRINT((ndo
, ", subcode %s (%u)",
2663 tok2str(bgp_notify_minor_open_values
, "Unknown",
2667 case BGP_NOTIFY_MAJOR_UPDATE
:
2668 ND_PRINT((ndo
, ", subcode %s (%u)",
2669 tok2str(bgp_notify_minor_update_values
, "Unknown",
2673 case BGP_NOTIFY_MAJOR_FSM
:
2674 ND_PRINT((ndo
, " subcode %s (%u)",
2675 tok2str(bgp_notify_minor_fsm_values
, "Unknown",
2679 case BGP_NOTIFY_MAJOR_CAP
:
2680 ND_PRINT((ndo
, " subcode %s (%u)",
2681 tok2str(bgp_notify_minor_cap_values
, "Unknown",
2685 case BGP_NOTIFY_MAJOR_CEASE
:
2686 ND_PRINT((ndo
, ", subcode %s (%u)",
2687 tok2str(bgp_notify_minor_cease_values
, "Unknown",
2691 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2692 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2694 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2695 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2696 ND_TCHECK2(*tptr
, 7);
2697 ND_PRINT((ndo
, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2698 tok2str(af_values
, "Unknown",
2699 EXTRACT_BE_16BITS(tptr
)),
2700 EXTRACT_BE_16BITS(tptr
),
2701 tok2str(bgp_safi_values
, "Unknown", EXTRACT_8BITS((tptr
+ 2))),
2703 EXTRACT_BE_32BITS(tptr
+ 3)));
2706 * draft-ietf-idr-shutdown describes a method to send a communication
2707 * intended for human consumption regarding the Administrative Shutdown
2709 if ((bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_SHUT
||
2710 bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_RESET
) &&
2711 length
>= BGP_NOTIFICATION_SIZE
+ 1) {
2712 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2713 ND_TCHECK2(*tptr
, 1);
2714 shutdown_comm_length
= *(tptr
);
2715 remainder_offset
= 0;
2716 /* garbage, hexdump it all */
2717 if (shutdown_comm_length
> BGP_NOTIFY_MINOR_CEASE_ADMIN_SHUTDOWN_LEN
||
2718 shutdown_comm_length
> length
- (BGP_NOTIFICATION_SIZE
+ 1)) {
2719 ND_PRINT((ndo
, ", invalid Shutdown Communication length"));
2721 else if (shutdown_comm_length
== 0) {
2722 ND_PRINT((ndo
, ", empty Shutdown Communication"));
2723 remainder_offset
+= 1;
2725 /* a proper shutdown communication */
2727 ND_TCHECK2(*(tptr
+1), shutdown_comm_length
);
2728 ND_PRINT((ndo
, ", Shutdown Communication (length: %u): \"", shutdown_comm_length
));
2729 (void)fn_printn(ndo
, tptr
+1, shutdown_comm_length
, NULL
);
2730 ND_PRINT((ndo
, "\""));
2731 remainder_offset
+= shutdown_comm_length
+ 1;
2733 /* if there is trailing data, hexdump it */
2734 if(length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
) > 0) {
2735 ND_PRINT((ndo
, ", Data: (length: %u)", length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
)));
2736 hex_print(ndo
, "\n\t\t", tptr
+ remainder_offset
, length
- (remainder_offset
+ BGP_NOTIFICATION_SIZE
));
2746 ND_PRINT((ndo
, "[|BGP]"));
2750 bgp_route_refresh_print(netdissect_options
*ndo
,
2751 const u_char
*pptr
, int len
)
2753 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2755 ND_TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
2757 /* some little sanity checking */
2758 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2761 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2763 ND_PRINT((ndo
, "\n\t AFI %s (%u), SAFI %s (%u)",
2764 tok2str(af_values
,"Unknown",
2765 /* this stinks but the compiler pads the structure
2767 EXTRACT_BE_16BITS(&bgp_route_refresh_header
->afi
)),
2768 EXTRACT_BE_16BITS(&bgp_route_refresh_header
->afi
),
2769 tok2str(bgp_safi_values
,"Unknown",
2770 bgp_route_refresh_header
->safi
),
2771 bgp_route_refresh_header
->safi
));
2773 if (ndo
->ndo_vflag
> 1) {
2774 ND_TCHECK2(*pptr
, len
);
2775 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2780 ND_PRINT((ndo
, "[|BGP]"));
2784 bgp_header_print(netdissect_options
*ndo
,
2785 const u_char
*dat
, int length
)
2789 ND_TCHECK2(dat
[0], BGP_SIZE
);
2790 memcpy(&bgp
, dat
, BGP_SIZE
);
2791 ND_PRINT((ndo
, "\n\t%s Message (%u), length: %u",
2792 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
2796 switch (bgp
.bgp_type
) {
2798 bgp_open_print(ndo
, dat
, length
);
2801 bgp_update_print(ndo
, dat
, length
);
2803 case BGP_NOTIFICATION
:
2804 bgp_notification_print(ndo
, dat
, length
);
2808 case BGP_ROUTE_REFRESH
:
2809 bgp_route_refresh_print(ndo
, dat
, length
);
2812 /* we have no decoder for the BGP message */
2813 ND_TCHECK2(*dat
, length
);
2814 ND_PRINT((ndo
, "\n\t no Message %u decoder", bgp
.bgp_type
));
2815 print_unknown_data(ndo
, dat
, "\n\t ", length
);
2820 ND_PRINT((ndo
, "[|BGP]"));
2825 bgp_print(netdissect_options
*ndo
,
2826 const u_char
*dat
, int length
)
2830 const u_char
*start
;
2831 const u_char marker
[] = {
2832 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2833 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2839 if (ndo
->ndo_snapend
< dat
+ length
)
2840 ep
= ndo
->ndo_snapend
;
2842 ND_PRINT((ndo
, ": BGP"));
2844 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
2850 if (!ND_TTEST2(p
[0], 1))
2857 if (!ND_TTEST2(p
[0], sizeof(marker
)))
2859 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2864 /* found BGP header */
2865 ND_TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2866 memcpy(&bgp
, p
, BGP_SIZE
);
2869 ND_PRINT((ndo
, " [|BGP]"));
2871 hlen
= ntohs(bgp
.bgp_len
);
2872 if (hlen
< BGP_SIZE
) {
2873 ND_PRINT((ndo
, "\n[|BGP Bogus header length %u < %u]", hlen
,
2878 if (ND_TTEST2(p
[0], hlen
)) {
2879 if (!bgp_header_print(ndo
, p
, hlen
))
2884 ND_PRINT((ndo
, "\n[|BGP %s]",
2885 tok2str(bgp_msg_values
,
2886 "Unknown Message Type",
2895 ND_PRINT((ndo
, " [|BGP]"));
2900 * c-style: whitesmith