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@juniper.net) for more
30 * complete BGP support.
33 #include <sys/cdefs.h>
35 __RCSID("$NetBSD: print-bgp.c,v 1.6 2015/03/31 21:59:35 christos Exp $");
38 #define NETDISSECT_REWORKED
43 #include <tcpdump-stdinc.h>
48 #include "interface.h"
49 #include "addrtoname.h"
55 uint8_t bgp_marker
[16];
59 #define BGP_SIZE 19 /* unaligned */
63 #define BGP_NOTIFICATION 3
64 #define BGP_KEEPALIVE 4
65 #define BGP_ROUTE_REFRESH 5
67 static const struct tok bgp_msg_values
[] = {
69 { BGP_UPDATE
, "Update"},
70 { BGP_NOTIFICATION
, "Notification"},
71 { BGP_KEEPALIVE
, "Keepalive"},
72 { BGP_ROUTE_REFRESH
, "Route Refresh"},
77 uint8_t bgpo_marker
[16];
82 uint16_t bgpo_holdtime
;
85 /* options should follow */
87 #define BGP_OPEN_SIZE 29 /* unaligned */
94 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
95 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
97 struct bgp_notification
{
98 uint8_t bgpn_marker
[16];
104 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
106 struct bgp_route_refresh
{
107 uint8_t bgp_marker
[16];
110 uint8_t afi
[2]; /* the compiler messes this structure up */
111 uint8_t res
; /* when doing misaligned sequences of int8 and int16 */
112 uint8_t safi
; /* afi should be int16 - so we have to access it using */
113 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
114 #define BGP_ROUTE_REFRESH_SIZE 23
116 #define bgp_attr_lenlen(flags, p) \
117 (((flags) & 0x10) ? 2 : 1)
118 #define bgp_attr_len(flags, p) \
119 (((flags) & 0x10) ? EXTRACT_16BITS(p) : *(p))
121 #define BGPTYPE_ORIGIN 1
122 #define BGPTYPE_AS_PATH 2
123 #define BGPTYPE_NEXT_HOP 3
124 #define BGPTYPE_MULTI_EXIT_DISC 4
125 #define BGPTYPE_LOCAL_PREF 5
126 #define BGPTYPE_ATOMIC_AGGREGATE 6
127 #define BGPTYPE_AGGREGATOR 7
128 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
129 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
130 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
131 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
132 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
133 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
134 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
135 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
136 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
137 #define BGPTYPE_AS4_PATH 17 /* RFC4893 */
138 #define BGPTYPE_AGGREGATOR4 18 /* RFC4893 */
139 #define BGPTYPE_PMSI_TUNNEL 22 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
140 #define BGPTYPE_ATTR_SET 128 /* draft-marques-ppvpn-ibgp */
142 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
144 static const struct tok bgp_attr_values
[] = {
145 { BGPTYPE_ORIGIN
, "Origin"},
146 { BGPTYPE_AS_PATH
, "AS Path"},
147 { BGPTYPE_AS4_PATH
, "AS4 Path"},
148 { BGPTYPE_NEXT_HOP
, "Next Hop"},
149 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
150 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
151 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
152 { BGPTYPE_AGGREGATOR
, "Aggregator"},
153 { BGPTYPE_AGGREGATOR4
, "Aggregator4"},
154 { BGPTYPE_COMMUNITIES
, "Community"},
155 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
156 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
157 { BGPTYPE_DPA
, "DPA"},
158 { BGPTYPE_ADVERTISERS
, "Advertisers"},
159 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
160 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
161 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
162 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
163 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
164 { BGPTYPE_ATTR_SET
, "Attribute Set"},
165 { 255, "Reserved for development"},
170 #define BGP_AS_SEQUENCE 2
171 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
172 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
174 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
175 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
177 static const struct tok bgp_as_path_segment_open_values
[] = {
178 { BGP_AS_SEQUENCE
, ""},
180 { BGP_CONFED_AS_SEQUENCE
, "( "},
181 { BGP_CONFED_AS_SET
, "({ "},
185 static const struct tok bgp_as_path_segment_close_values
[] = {
186 { BGP_AS_SEQUENCE
, ""},
188 { BGP_CONFED_AS_SEQUENCE
, ")"},
189 { BGP_CONFED_AS_SET
, "})"},
193 #define BGP_OPT_AUTH 1
194 #define BGP_OPT_CAP 2
197 static const struct tok bgp_opt_values
[] = {
198 { BGP_OPT_AUTH
, "Authentication Information"},
199 { BGP_OPT_CAP
, "Capabilities Advertisement"},
203 #define BGP_CAPCODE_MP 1
204 #define BGP_CAPCODE_RR 2
205 #define BGP_CAPCODE_ORF 3 /* XXX */
206 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
207 #define BGP_CAPCODE_AS_NEW 65 /* XXX */
208 #define BGP_CAPCODE_DYN_CAP 67 /* XXX */
209 #define BGP_CAPCODE_RR_CISCO 128
211 static const struct tok bgp_capcode_values
[] = {
212 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
213 { BGP_CAPCODE_RR
, "Route Refresh"},
214 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
215 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
216 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
217 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
218 { BGP_CAPCODE_RR_CISCO
, "Route Refresh (Cisco)"},
222 #define BGP_NOTIFY_MAJOR_MSG 1
223 #define BGP_NOTIFY_MAJOR_OPEN 2
224 #define BGP_NOTIFY_MAJOR_UPDATE 3
225 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
226 #define BGP_NOTIFY_MAJOR_FSM 5
227 #define BGP_NOTIFY_MAJOR_CEASE 6
228 #define BGP_NOTIFY_MAJOR_CAP 7
230 static const struct tok bgp_notify_major_values
[] = {
231 { BGP_NOTIFY_MAJOR_MSG
, "Message Header Error"},
232 { BGP_NOTIFY_MAJOR_OPEN
, "OPEN Message Error"},
233 { BGP_NOTIFY_MAJOR_UPDATE
, "UPDATE Message Error"},
234 { BGP_NOTIFY_MAJOR_HOLDTIME
,"Hold Timer Expired"},
235 { BGP_NOTIFY_MAJOR_FSM
, "Finite State Machine Error"},
236 { BGP_NOTIFY_MAJOR_CEASE
, "Cease"},
237 { BGP_NOTIFY_MAJOR_CAP
, "Capability Message Error"},
241 /* draft-ietf-idr-cease-subcode-02 */
242 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
243 static const struct tok bgp_notify_minor_cease_values
[] = {
244 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX
, "Maximum Number of Prefixes Reached"},
245 { 2, "Administratively Shutdown"},
246 { 3, "Peer Unconfigured"},
247 { 4, "Administratively Reset"},
248 { 5, "Connection Rejected"},
249 { 6, "Other Configuration Change"},
250 { 7, "Connection Collision Resolution"},
254 static const struct tok bgp_notify_minor_msg_values
[] = {
255 { 1, "Connection Not Synchronized"},
256 { 2, "Bad Message Length"},
257 { 3, "Bad Message Type"},
261 static const struct tok bgp_notify_minor_open_values
[] = {
262 { 1, "Unsupported Version Number"},
264 { 3, "Bad BGP Identifier"},
265 { 4, "Unsupported Optional Parameter"},
266 { 5, "Authentication Failure"},
267 { 6, "Unacceptable Hold Time"},
268 { 7, "Capability Message Error"},
272 static const struct tok bgp_notify_minor_update_values
[] = {
273 { 1, "Malformed Attribute List"},
274 { 2, "Unrecognized Well-known Attribute"},
275 { 3, "Missing Well-known Attribute"},
276 { 4, "Attribute Flags Error"},
277 { 5, "Attribute Length Error"},
278 { 6, "Invalid ORIGIN Attribute"},
279 { 7, "AS Routing Loop"},
280 { 8, "Invalid NEXT_HOP Attribute"},
281 { 9, "Optional Attribute Error"},
282 { 10, "Invalid Network Field"},
283 { 11, "Malformed AS_PATH"},
287 static const struct tok bgp_notify_minor_cap_values
[] = {
288 { 1, "Invalid Action Value" },
289 { 2, "Invalid Capability Length" },
290 { 3, "Malformed Capability Value" },
291 { 4, "Unsupported Capability Code" },
295 static const struct tok bgp_origin_values
[] = {
302 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
303 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
304 #define BGP_PMSI_TUNNEL_PIM_SSM 3
305 #define BGP_PMSI_TUNNEL_PIM_SM 4
306 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
307 #define BGP_PMSI_TUNNEL_INGRESS 6
308 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
310 static const struct tok bgp_pmsi_tunnel_values
[] = {
311 { BGP_PMSI_TUNNEL_RSVP_P2MP
, "RSVP-TE P2MP LSP"},
312 { BGP_PMSI_TUNNEL_LDP_P2MP
, "LDP P2MP LSP"},
313 { BGP_PMSI_TUNNEL_PIM_SSM
, "PIM-SSM Tree"},
314 { BGP_PMSI_TUNNEL_PIM_SM
, "PIM-SM Tree"},
315 { BGP_PMSI_TUNNEL_PIM_BIDIR
, "PIM-Bidir Tree"},
316 { BGP_PMSI_TUNNEL_INGRESS
, "Ingress Replication"},
317 { BGP_PMSI_TUNNEL_LDP_MP2MP
, "LDP MP2MP LSP"},
321 static const struct tok bgp_pmsi_flag_values
[] = {
322 { 0x01, "Leaf Information required"},
327 /* Subsequent address family identifier, RFC2283 section 7 */
329 #define SAFNUM_UNICAST 1
330 #define SAFNUM_MULTICAST 2
331 #define SAFNUM_UNIMULTICAST 3
332 /* labeled BGP RFC3107 */
333 #define SAFNUM_LABUNICAST 4
334 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
335 #define SAFNUM_MULTICAST_VPN 5
336 #define SAFNUM_TUNNEL 64 /* XXX */
337 #define SAFNUM_VPLS 65 /* XXX */
338 /* draft-nalawade-idr-mdt-safi-03 */
339 #define SAFNUM_MDT 66
340 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
341 #define SAFNUM_VPNUNICAST 128
342 #define SAFNUM_VPNMULTICAST 129
343 #define SAFNUM_VPNUNIMULTICAST 130
344 /* draft-marques-ppvpn-rt-constrain-01.txt */
345 #define SAFNUM_RT_ROUTING_INFO 132
347 #define BGP_VPN_RD_LEN 8
349 static const struct tok bgp_safi_values
[] = {
350 { SAFNUM_RES
, "Reserved"},
351 { SAFNUM_UNICAST
, "Unicast"},
352 { SAFNUM_MULTICAST
, "Multicast"},
353 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
354 { SAFNUM_LABUNICAST
, "labeled Unicast"},
355 { SAFNUM_TUNNEL
, "Tunnel"},
356 { SAFNUM_VPLS
, "VPLS"},
357 { SAFNUM_MDT
, "MDT"},
358 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
359 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
360 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
361 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
362 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
366 /* well-known community */
367 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
368 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
369 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
371 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
372 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
373 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
374 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
375 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
376 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
377 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
378 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
379 /* rfc2547 bgp-mpls-vpns */
380 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
381 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
382 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
383 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
385 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
386 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
388 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
389 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
391 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
393 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
394 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
395 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
396 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
399 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
400 #define BGP_EXT_COM_EIGRP_GEN 0x8800
401 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
402 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
403 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
404 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
405 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
407 static const struct tok bgp_extd_comm_flag_values
[] = {
408 { 0x8000, "vendor-specific"},
409 { 0x4000, "non-transitive"},
413 static const struct tok bgp_extd_comm_subtype_values
[] = {
414 { BGP_EXT_COM_RT_0
, "target"},
415 { BGP_EXT_COM_RT_1
, "target"},
416 { BGP_EXT_COM_RT_2
, "target"},
417 { BGP_EXT_COM_RO_0
, "origin"},
418 { BGP_EXT_COM_RO_1
, "origin"},
419 { BGP_EXT_COM_RO_2
, "origin"},
420 { BGP_EXT_COM_LINKBAND
, "link-BW"},
421 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
422 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
423 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
424 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
425 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
426 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
427 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
428 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
429 { BGP_EXT_COM_L2INFO
, "layer2-info"},
430 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
431 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
432 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
433 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
434 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
435 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
436 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
437 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
438 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
439 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
443 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
444 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
445 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
446 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
447 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
448 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
449 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
450 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
452 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
453 { BGP_OSPF_RTYPE_RTR
, "Router" },
454 { BGP_OSPF_RTYPE_NET
, "Network" },
455 { BGP_OSPF_RTYPE_SUM
, "Summary" },
456 { BGP_OSPF_RTYPE_EXT
, "External" },
457 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
458 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
462 #define TOKBUFSIZE 128
463 static char astostr
[20];
468 * Convert an AS number into a string and return string pointer.
470 * Depending on bflag is set or not, AS number is converted into ASDOT notation
471 * or plain number notation.
475 as_printf(netdissect_options
*ndo
,
476 char *str
, int size
, u_int asnum
)
478 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
479 snprintf(str
, size
, "%u", asnum
);
481 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
486 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
489 decode_prefix4(netdissect_options
*ndo
,
490 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
493 u_int plen
, plenbytes
;
502 memset(&addr
, 0, sizeof(addr
));
503 plenbytes
= (plen
+ 7) / 8;
504 ND_TCHECK2(pptr
[1], plenbytes
);
505 ITEMCHECK(plenbytes
);
506 memcpy(&addr
, &pptr
[1], plenbytes
);
508 ((u_char
*)&addr
)[plenbytes
- 1] &=
509 ((0xff00 >> (plen
% 8)) & 0xff);
511 snprintf(buf
, buflen
, "%s/%d", getname(ndo
, (u_char
*)&addr
), plen
);
512 return 1 + plenbytes
;
522 decode_labeled_prefix4(netdissect_options
*ndo
,
523 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
526 u_int plen
, plenbytes
;
528 /* prefix length and label = 4 bytes */
529 ND_TCHECK2(pptr
[0], 4);
531 plen
= pptr
[0]; /* get prefix length */
533 /* this is one of the weirdnesses of rfc3107
534 the label length (actually the label + COS bits)
535 is added to the prefix length;
536 we also do only read out just one label -
537 there is no real application for advertisement of
538 stacked labels in a single BGP message
544 plen
-=24; /* adjust prefixlen - labellength */
550 memset(&addr
, 0, sizeof(addr
));
551 plenbytes
= (plen
+ 7) / 8;
552 ND_TCHECK2(pptr
[4], plenbytes
);
553 ITEMCHECK(plenbytes
);
554 memcpy(&addr
, &pptr
[4], plenbytes
);
556 ((u_char
*)&addr
)[plenbytes
- 1] &=
557 ((0xff00 >> (plen
% 8)) & 0xff);
559 /* the label may get offsetted by 4 bits so lets shift it right */
560 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
561 getname(ndo
, (u_char
*)&addr
),
563 EXTRACT_24BITS(pptr
+1)>>4,
564 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
566 return 4 + plenbytes
;
578 * print an ipv4 or ipv6 address into a buffer dependend on address length.
581 bgp_vpn_ip_print(netdissect_options
*ndo
,
582 const u_char
*pptr
, u_int addr_length
)
585 /* worst case string is s fully formatted v6 address */
586 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
589 switch(addr_length
) {
590 case (sizeof(struct in_addr
) << 3): /* 32 */
591 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
592 snprintf(pos
, sizeof(addr
), "%s", ipaddr_string(ndo
, pptr
));
595 case (sizeof(struct in6_addr
) << 3): /* 128 */
596 ND_TCHECK2(pptr
[0], sizeof(struct in6_addr
));
597 snprintf(pos
, sizeof(addr
), "%s", ip6addr_string(ndo
, pptr
));
601 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
614 * print an multicast s,g entry into a buffer.
615 * the s,g entry is encoded like this.
617 * +-----------------------------------+
618 * | Multicast Source Length (1 octet) |
619 * +-----------------------------------+
620 * | Multicast Source (Variable) |
621 * +-----------------------------------+
622 * | Multicast Group Length (1 octet) |
623 * +-----------------------------------+
624 * | Multicast Group (Variable) |
625 * +-----------------------------------+
627 * return the number of bytes read from the wire.
630 bgp_vpn_sg_print(netdissect_options
*ndo
,
631 const u_char
*pptr
, char *buf
, u_int buflen
)
634 u_int total_length
, offset
;
638 /* Source address length, encoded in bits */
639 ND_TCHECK2(pptr
[0], 1);
640 addr_length
= *pptr
++;
643 ND_TCHECK2(pptr
[0], (addr_length
>> 3));
644 total_length
+= (addr_length
>> 3) + 1;
645 offset
= strlen(buf
);
647 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
648 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
649 pptr
+= (addr_length
>> 3);
652 /* Group address length, encoded in bits */
653 ND_TCHECK2(pptr
[0], 1);
654 addr_length
= *pptr
++;
657 ND_TCHECK2(pptr
[0], (addr_length
>> 3));
658 total_length
+= (addr_length
>> 3) + 1;
659 offset
= strlen(buf
);
661 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
662 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
663 pptr
+= (addr_length
>> 3);
667 return (total_length
);
671 /* RDs and RTs share the same semantics
672 * we use bgp_vpn_rd_print for
673 * printing route targets inside a NLRI */
675 bgp_vpn_rd_print(netdissect_options
*ndo
,
678 /* allocate space for the largest possible string */
679 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
682 /* ok lets load the RD format */
683 switch (EXTRACT_16BITS(pptr
)) {
685 /* 2-byte-AS:number fmt*/
687 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
688 EXTRACT_16BITS(pptr
+2),
689 EXTRACT_32BITS(pptr
+4),
690 *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
692 /* IP-address:AS fmt*/
695 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
696 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
699 /* 4-byte-AS:number fmt*/
701 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
702 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(pptr
+2)),
703 EXTRACT_16BITS(pptr
+6), *(pptr
+2), *(pptr
+3), *(pptr
+4),
704 *(pptr
+5), EXTRACT_16BITS(pptr
+6));
707 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
716 decode_rt_routing_info(netdissect_options
*ndo
,
717 const u_char
*pptr
, char *buf
, u_int buflen
)
719 uint8_t route_target
[8];
723 plen
= pptr
[0]; /* get prefix length */
726 snprintf(buf
, buflen
, "default route target");
733 plen
-=32; /* adjust prefix length */
738 memset(&route_target
, 0, sizeof(route_target
));
739 ND_TCHECK2(pptr
[1], (plen
+ 7) / 8);
740 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
742 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
743 ((0xff00 >> (plen
% 8)) & 0xff);
745 snprintf(buf
, buflen
, "origin AS: %s, route target %s",
746 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(pptr
+1)),
747 bgp_vpn_rd_print(ndo
, (u_char
*)&route_target
));
749 return 5 + (plen
+ 7) / 8;
756 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
757 const u_char
*pptr
, char *buf
, u_int buflen
)
763 plen
= pptr
[0]; /* get prefix length */
768 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
773 memset(&addr
, 0, sizeof(addr
));
774 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
775 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
777 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
778 ((0xff00 >> (plen
% 8)) & 0xff);
780 /* the label may get offsetted by 4 bits so lets shift it right */
781 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
782 bgp_vpn_rd_print(ndo
, pptr
+4),
783 getname(ndo
, (u_char
*)&addr
),
785 EXTRACT_24BITS(pptr
+1)>>4,
786 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
788 return 12 + (plen
+ 7) / 8;
795 * +-------------------------------+
797 * | RD:IPv4-address (12 octets) |
799 * +-------------------------------+
800 * | MDT Group-address (4 octets) |
801 * +-------------------------------+
804 #define MDT_VPN_NLRI_LEN 16
807 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
808 const u_char
*pptr
, char *buf
, u_int buflen
)
812 const u_char
*vpn_ip
;
816 /* if the NLRI is not predefined length, quit.*/
817 if (*pptr
!= MDT_VPN_NLRI_LEN
* 8)
822 ND_TCHECK2(pptr
[0], 8);
827 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
829 pptr
+=sizeof(struct in_addr
);
831 /* MDT Group Address */
832 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
834 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
835 bgp_vpn_rd_print(ndo
, rd
), ipaddr_string(ndo
, vpn_ip
), ipaddr_string(ndo
, pptr
));
837 return MDT_VPN_NLRI_LEN
+ 1;
844 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
845 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
846 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
847 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
848 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
849 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
850 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
852 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
853 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
854 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
855 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
856 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
857 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
858 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
859 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
863 decode_multicast_vpn(netdissect_options
*ndo
,
864 const u_char
*pptr
, char *buf
, u_int buflen
)
866 uint8_t route_type
, route_length
, addr_length
, sg_length
;
869 ND_TCHECK2(pptr
[0], 2);
870 route_type
= *pptr
++;
871 route_length
= *pptr
++;
873 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
874 tok2str(bgp_multicast_vpn_route_type_values
,
875 "Unknown", route_type
),
876 route_type
, route_length
);
879 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
880 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
881 offset
= strlen(buf
);
882 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
883 bgp_vpn_rd_print(ndo
, pptr
),
884 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
885 (route_length
- BGP_VPN_RD_LEN
) << 3));
887 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
888 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
+ 4);
889 offset
= strlen(buf
);
890 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
891 bgp_vpn_rd_print(ndo
, pptr
),
892 as_printf(ndo
, astostr
, sizeof(astostr
),
893 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
896 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
897 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
898 offset
= strlen(buf
);
899 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
900 bgp_vpn_rd_print(ndo
, pptr
));
901 pptr
+= BGP_VPN_RD_LEN
;
903 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
904 addr_length
= route_length
- sg_length
;
906 ND_TCHECK2(pptr
[0], addr_length
);
907 offset
= strlen(buf
);
908 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
909 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
912 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
913 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
914 offset
= strlen(buf
);
915 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
916 bgp_vpn_rd_print(ndo
, pptr
));
917 pptr
+= BGP_VPN_RD_LEN
;
919 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
922 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
923 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
924 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
925 offset
= strlen(buf
);
926 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
927 bgp_vpn_rd_print(ndo
, pptr
),
928 as_printf(ndo
, astostr
, sizeof(astostr
),
929 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
930 pptr
+= BGP_VPN_RD_LEN
;
932 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
936 * no per route-type printing yet.
938 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
943 return route_length
+ 2;
950 * As I remember, some versions of systems have an snprintf() that
951 * returns -1 if the buffer would have overflowed. If the return
952 * value is negative, set buflen to 0, to indicate that we've filled
955 * If the return value is greater than buflen, that means that
956 * the buffer would have overflowed; again, set buflen to 0 in
959 #define UPDATE_BUF_BUFLEN(buf, buflen, strlen) \
962 else if ((u_int)strlen>buflen) \
970 decode_labeled_vpn_l2(netdissect_options
*ndo
,
971 const u_char
*pptr
, char *buf
, u_int buflen
)
973 int plen
,tlen
,strlen
,tlv_type
,tlv_len
,ttlv_len
;
975 ND_TCHECK2(pptr
[0], 2);
976 plen
=EXTRACT_16BITS(pptr
);
979 /* Old and new L2VPN NLRI share AFI/SAFI
980 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
981 * and > 17 as old format. Complain for the middle case
984 /* assume AD-only with RD, BGPNH */
985 ND_TCHECK2(pptr
[0],12);
987 strlen
=snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
988 bgp_vpn_rd_print(ndo
, pptr
),
989 /* need something like getname(ndo, ) here */
992 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
996 } else if (plen
>17) {
997 /* assume old format */
998 /* RD, ID, LBLKOFF, LBLBASE */
1000 ND_TCHECK2(pptr
[0],15);
1002 strlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1003 bgp_vpn_rd_print(ndo
, pptr
),
1004 EXTRACT_16BITS(pptr
+8),
1005 EXTRACT_16BITS(pptr
+10),
1006 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1007 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
1011 /* ok now the variable part - lets read out TLVs*/
1015 ND_TCHECK2(pptr
[0], 3);
1017 tlv_len
=EXTRACT_16BITS(pptr
);
1024 strlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1027 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
1029 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
1030 while (ttlv_len
>0) {
1033 strlen
=snprintf(buf
,buflen
, "%02x",*pptr
++);
1034 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
1041 strlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1044 UPDATE_BUF_BUFLEN(buf
, buflen
, strlen
);
1048 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
1053 /* complain bitterly ? */
1064 decode_prefix6(netdissect_options
*ndo
,
1065 const u_char
*pd
, u_int itemlen
, char *buf
, u_int buflen
)
1067 struct in6_addr addr
;
1068 u_int plen
, plenbytes
;
1077 memset(&addr
, 0, sizeof(addr
));
1078 plenbytes
= (plen
+ 7) / 8;
1079 ND_TCHECK2(pd
[1], plenbytes
);
1080 ITEMCHECK(plenbytes
);
1081 memcpy(&addr
, &pd
[1], plenbytes
);
1083 addr
.s6_addr
[plenbytes
- 1] &=
1084 ((0xff00 >> (plen
% 8)) & 0xff);
1086 snprintf(buf
, buflen
, "%s/%d", getname6(ndo
, (u_char
*)&addr
), plen
);
1087 return 1 + plenbytes
;
1097 decode_labeled_prefix6(netdissect_options
*ndo
,
1098 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
1100 struct in6_addr addr
;
1101 u_int plen
, plenbytes
;
1103 /* prefix length and label = 4 bytes */
1104 ND_TCHECK2(pptr
[0], 4);
1106 plen
= pptr
[0]; /* get prefix length */
1111 plen
-=24; /* adjust prefixlen - labellength */
1117 memset(&addr
, 0, sizeof(addr
));
1118 plenbytes
= (plen
+ 7) / 8;
1119 ND_TCHECK2(pptr
[4], plenbytes
);
1120 memcpy(&addr
, &pptr
[4], plenbytes
);
1122 addr
.s6_addr
[plenbytes
- 1] &=
1123 ((0xff00 >> (plen
% 8)) & 0xff);
1125 /* the label may get offsetted by 4 bits so lets shift it right */
1126 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
1127 getname6(ndo
, (u_char
*)&addr
),
1129 EXTRACT_24BITS(pptr
+1)>>4,
1130 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1132 return 4 + plenbytes
;
1142 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1143 const u_char
*pptr
, char *buf
, u_int buflen
)
1145 struct in6_addr addr
;
1149 plen
= pptr
[0]; /* get prefix length */
1154 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1159 memset(&addr
, 0, sizeof(addr
));
1160 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
1161 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1163 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1164 ((0xff00 >> (plen
% 8)) & 0xff);
1166 /* the label may get offsetted by 4 bits so lets shift it right */
1167 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1168 bgp_vpn_rd_print(ndo
, pptr
+4),
1169 getname6(ndo
, (u_char
*)&addr
),
1171 EXTRACT_24BITS(pptr
+1)>>4,
1172 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1174 return 12 + (plen
+ 7) / 8;
1182 decode_clnp_prefix(netdissect_options
*ndo
,
1183 const u_char
*pptr
, char *buf
, u_int buflen
)
1189 plen
= pptr
[0]; /* get prefix length */
1194 memset(&addr
, 0, sizeof(addr
));
1195 ND_TCHECK2(pptr
[4], (plen
+ 7) / 8);
1196 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
1198 addr
[(plen
+ 7) / 8 - 1] &=
1199 ((0xff00 >> (plen
% 8)) & 0xff);
1201 snprintf(buf
, buflen
, "%s/%d",
1202 isonsap_string(addr
,(plen
+ 7) / 8),
1205 return 1 + (plen
+ 7) / 8;
1212 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1213 const u_char
*pptr
, char *buf
, u_int buflen
)
1219 plen
= pptr
[0]; /* get prefix length */
1224 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1229 memset(&addr
, 0, sizeof(addr
));
1230 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
1231 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1233 addr
[(plen
+ 7) / 8 - 1] &=
1234 ((0xff00 >> (plen
% 8)) & 0xff);
1236 /* the label may get offsetted by 4 bits so lets shift it right */
1237 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1238 bgp_vpn_rd_print(ndo
, pptr
+4),
1239 isonsap_string(addr
,(plen
+ 7) / 8),
1241 EXTRACT_24BITS(pptr
+1)>>4,
1242 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1244 return 12 + (plen
+ 7) / 8;
1251 * bgp_attr_get_as_size
1253 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1254 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1255 * support, exchange AS-Path with the same path-attribute type value 0x02.
1258 bgp_attr_get_as_size(netdissect_options
*ndo
,
1259 uint8_t bgpa_type
, const u_char
*pptr
, int len
)
1261 const u_char
*tptr
= pptr
;
1264 * If the path attribute is the optional AS4 path type, then we already
1265 * know, that ASs must be encoded in 4 byte format.
1267 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1272 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1273 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1276 while (tptr
< pptr
+ len
) {
1280 * If we do not find a valid segment type, our guess might be wrong.
1282 if (tptr
[0] < BGP_AS_SEG_TYPE_MIN
|| tptr
[0] > BGP_AS_SEG_TYPE_MAX
) {
1286 tptr
+= 2 + tptr
[1] * 2;
1290 * If we correctly reached end of the AS path attribute data content,
1291 * then most likely ASs were indeed encoded as 2 bytes.
1293 if (tptr
== pptr
+ len
) {
1300 * We can come here, either we did not have enough data, or if we
1301 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1302 * so that calller can try to decode each AS as of 4 bytes. If indeed
1303 * there was not enough data, it will crib and end the parse anyways.
1309 bgp_attr_print(netdissect_options
*ndo
,
1310 u_int atype
, const u_char
*pptr
, u_int len
)
1314 uint8_t safi
, snpa
, nhlen
;
1315 union { /* copy buffer for bandwidth values */
1322 char buf
[MAXHOSTNAMELEN
+ 100];
1323 char tokbuf
[TOKBUFSIZE
];
1330 case BGPTYPE_ORIGIN
:
1332 ND_PRINT((ndo
, "invalid len"));
1335 ND_PRINT((ndo
, "%s", tok2strbuf(bgp_origin_values
,
1336 "Unknown Origin Typecode",
1338 tokbuf
, sizeof(tokbuf
))));
1344 * Process AS4 byte path and AS2 byte path attributes here.
1346 case BGPTYPE_AS4_PATH
:
1347 case BGPTYPE_AS_PATH
:
1349 ND_PRINT((ndo
, "invalid len"));
1353 ND_PRINT((ndo
, "empty"));
1358 * BGP updates exchanged between New speakers that support 4
1359 * byte AS, ASs are always encoded in 4 bytes. There is no
1360 * definitive way to find this, just by the packet's
1361 * contents. So, check for packet's TLV's sanity assuming
1362 * 2 bytes first, and it does not pass, assume that ASs are
1363 * encoded in 4 bytes format and move on.
1365 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1367 while (tptr
< pptr
+ len
) {
1369 ND_PRINT((ndo
, "%s", tok2strbuf(bgp_as_path_segment_open_values
,
1371 tokbuf
, sizeof(tokbuf
))));
1372 for (i
= 0; i
< tptr
[1] * as_size
; i
+= as_size
) {
1373 ND_TCHECK2(tptr
[2 + i
], as_size
);
1374 ND_PRINT((ndo
, "%s ",
1375 as_printf(ndo
, astostr
, sizeof(astostr
),
1377 EXTRACT_16BITS(&tptr
[2 + i
]) :
1378 EXTRACT_32BITS(&tptr
[2 + i
]))));
1381 ND_PRINT((ndo
, "%s", tok2strbuf(bgp_as_path_segment_close_values
,
1383 tokbuf
, sizeof(tokbuf
))));
1385 tptr
+= 2 + tptr
[1] * as_size
;
1388 case BGPTYPE_NEXT_HOP
:
1390 ND_PRINT((ndo
, "invalid len"));
1392 ND_TCHECK2(tptr
[0], 4);
1393 ND_PRINT((ndo
, "%s", getname(ndo
, tptr
)));
1396 case BGPTYPE_MULTI_EXIT_DISC
:
1397 case BGPTYPE_LOCAL_PREF
:
1399 ND_PRINT((ndo
, "invalid len"));
1401 ND_TCHECK2(tptr
[0], 4);
1402 ND_PRINT((ndo
, "%u", EXTRACT_32BITS(tptr
)));
1405 case BGPTYPE_ATOMIC_AGGREGATE
:
1407 ND_PRINT((ndo
, "invalid len"));
1409 case BGPTYPE_AGGREGATOR
:
1412 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1413 * the length of this PA can be either 6 bytes or 8 bytes.
1415 if (len
!= 6 && len
!= 8) {
1416 ND_PRINT((ndo
, "invalid len"));
1419 ND_TCHECK2(tptr
[0], len
);
1421 ND_PRINT((ndo
, " AS #%s, origin %s",
1422 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_16BITS(tptr
)),
1423 getname(ndo
, tptr
+ 2)));
1425 ND_PRINT((ndo
, " AS #%s, origin %s",
1426 as_printf(ndo
, astostr
, sizeof(astostr
),
1427 EXTRACT_32BITS(tptr
)), getname(ndo
, tptr
+ 4)));
1430 case BGPTYPE_AGGREGATOR4
:
1432 ND_PRINT((ndo
, "invalid len"));
1435 ND_TCHECK2(tptr
[0], 8);
1436 ND_PRINT((ndo
, " AS #%s, origin %s",
1437 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(tptr
)),
1438 getname(ndo
, tptr
+ 4)));
1440 case BGPTYPE_COMMUNITIES
:
1442 ND_PRINT((ndo
, "invalid len"));
1447 ND_TCHECK2(tptr
[0], 4);
1448 comm
= EXTRACT_32BITS(tptr
);
1450 case BGP_COMMUNITY_NO_EXPORT
:
1451 ND_PRINT((ndo
, " NO_EXPORT"));
1453 case BGP_COMMUNITY_NO_ADVERT
:
1454 ND_PRINT((ndo
, " NO_ADVERTISE"));
1456 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1457 ND_PRINT((ndo
, " NO_EXPORT_SUBCONFED"));
1460 ND_PRINT((ndo
, "%u:%u%s",
1461 (comm
>> 16) & 0xffff,
1463 (tlen
>4) ? ", " : ""));
1470 case BGPTYPE_ORIGINATOR_ID
:
1472 ND_PRINT((ndo
, "invalid len"));
1475 ND_TCHECK2(tptr
[0], 4);
1476 ND_PRINT((ndo
, "%s",getname(ndo
, tptr
)));
1478 case BGPTYPE_CLUSTER_LIST
:
1480 ND_PRINT((ndo
, "invalid len"));
1484 ND_TCHECK2(tptr
[0], 4);
1485 ND_PRINT((ndo
, "%s%s",
1487 (tlen
>4) ? ", " : ""));
1492 case BGPTYPE_MP_REACH_NLRI
:
1493 ND_TCHECK2(tptr
[0], 3);
1494 af
= EXTRACT_16BITS(tptr
);
1497 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1498 tok2strbuf(af_values
, "Unknown AFI", af
,
1499 tokbuf
, sizeof(tokbuf
)),
1501 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1502 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1503 tokbuf
, sizeof(tokbuf
)),
1506 switch(af
<<8 | safi
) {
1507 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1508 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1509 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1510 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1511 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1512 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1513 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1514 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1515 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1516 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1518 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1519 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1520 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1521 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1522 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1523 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1524 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1526 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1527 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1528 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1529 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1530 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1531 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1532 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1533 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1534 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1535 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1538 ND_TCHECK2(tptr
[0], tlen
);
1539 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1540 if (ndo
->ndo_vflag
<= 1)
1541 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1555 ND_PRINT((ndo
, "\n\t nexthop: "));
1558 ND_PRINT((ndo
, ", " ));
1560 switch(af
<<8 | safi
) {
1561 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1562 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1563 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1564 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1565 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1566 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1567 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1568 if (tlen
< (int)sizeof(struct in_addr
)) {
1569 ND_PRINT((ndo
, "invalid len"));
1572 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1573 ND_PRINT((ndo
, "%s",getname(ndo
, tptr
)));
1574 tlen
-= sizeof(struct in_addr
);
1575 tptr
+= sizeof(struct in_addr
);
1578 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1579 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1580 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1581 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1582 ND_PRINT((ndo
, "invalid len"));
1585 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1586 ND_PRINT((ndo
, "RD: %s, %s",
1587 bgp_vpn_rd_print(ndo
, tptr
),
1588 getname(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1589 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1590 tptr
+= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1594 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1595 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1596 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1597 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1598 if (tlen
< (int)sizeof(struct in6_addr
)) {
1599 ND_PRINT((ndo
, "invalid len"));
1602 ND_TCHECK2(tptr
[0], sizeof(struct in6_addr
));
1603 ND_PRINT((ndo
, "%s", getname6(ndo
, tptr
)));
1604 tlen
-= sizeof(struct in6_addr
);
1605 tptr
+= sizeof(struct in6_addr
);
1608 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1609 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1610 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1611 if (tlen
< (int)(sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
)) {
1612 ND_PRINT((ndo
, "invalid len"));
1615 ND_TCHECK2(tptr
[0], sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1616 ND_PRINT((ndo
, "RD: %s, %s",
1617 bgp_vpn_rd_print(ndo
, tptr
),
1618 getname6(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1619 tlen
-= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1620 tptr
+= (sizeof(struct in6_addr
)+BGP_VPN_RD_LEN
);
1624 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1625 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1626 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1627 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1628 if (tlen
< (int)sizeof(struct in_addr
)) {
1629 ND_PRINT((ndo
, "invalid len"));
1632 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1633 ND_PRINT((ndo
, "%s", getname(ndo
, tptr
)));
1634 tlen
-= (sizeof(struct in_addr
));
1635 tptr
+= (sizeof(struct in_addr
));
1638 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1639 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1640 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1641 ND_TCHECK2(tptr
[0], tlen
);
1642 ND_PRINT((ndo
, "%s", isonsap_string(tptr
, tlen
)));
1647 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1648 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1649 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1650 if (tlen
< BGP_VPN_RD_LEN
+1) {
1651 ND_PRINT((ndo
, "invalid len"));
1654 ND_TCHECK2(tptr
[0], tlen
);
1655 ND_PRINT((ndo
, "RD: %s, %s",
1656 bgp_vpn_rd_print(ndo
, tptr
),
1657 isonsap_string(tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
)));
1658 /* rfc986 mapped IPv4 address ? */
1659 if (EXTRACT_32BITS(tptr
+BGP_VPN_RD_LEN
) == 0x47000601)
1660 ND_PRINT((ndo
, " = %s", getname(ndo
, tptr
+BGP_VPN_RD_LEN
+4)));
1662 /* rfc1888 mapped IPv6 address ? */
1663 else if (EXTRACT_24BITS(tptr
+BGP_VPN_RD_LEN
) == 0x350000)
1664 ND_PRINT((ndo
, " = %s", getname6(ndo
, tptr
+BGP_VPN_RD_LEN
+3)));
1671 ND_TCHECK2(tptr
[0], tlen
);
1672 ND_PRINT((ndo
, "no AFI %u/SAFI %u decoder", af
, safi
));
1673 if (ndo
->ndo_vflag
<= 1)
1674 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1682 ND_PRINT((ndo
, ", nh-length: %u", nhlen
));
1690 ND_PRINT((ndo
, "\n\t %u SNPA", snpa
));
1691 for (/*nothing*/; snpa
> 0; snpa
--) {
1693 ND_PRINT((ndo
, "\n\t %d bytes", tptr
[0]));
1694 tptr
+= tptr
[0] + 1;
1697 ND_PRINT((ndo
, ", no SNPA"));
1700 while (len
- (tptr
- pptr
) > 0) {
1701 switch (af
<<8 | safi
) {
1702 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1703 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1704 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1705 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1707 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1708 else if (advance
== -2)
1710 else if (advance
== -3)
1711 break; /* bytes left, but not enough */
1713 ND_PRINT((ndo
, "\n\t %s", buf
));
1715 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1716 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1718 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1719 else if (advance
== -2)
1721 else if (advance
== -3)
1722 break; /* bytes left, but not enough */
1724 ND_PRINT((ndo
, "\n\t %s", buf
));
1726 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1727 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1728 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1729 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1731 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1732 else if (advance
== -2)
1735 ND_PRINT((ndo
, "\n\t %s", buf
));
1737 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1738 advance
= decode_rt_routing_info(ndo
, tptr
, buf
, sizeof(buf
));
1740 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1741 else if (advance
== -2)
1744 ND_PRINT((ndo
, "\n\t %s", buf
));
1746 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1747 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1748 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1750 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1751 else if (advance
== -2)
1754 ND_PRINT((ndo
, "\n\t %s", buf
));
1757 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1758 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
1760 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1761 else if (advance
== -2)
1764 ND_PRINT((ndo
, "\n\t %s", buf
));
1767 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1768 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1769 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1770 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1772 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1773 else if (advance
== -2)
1775 else if (advance
== -3)
1776 break; /* bytes left, but not enough */
1778 ND_PRINT((ndo
, "\n\t %s", buf
));
1780 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1781 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1783 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1784 else if (advance
== -2)
1786 else if (advance
== -3)
1787 break; /* bytes left, but not enough */
1789 ND_PRINT((ndo
, "\n\t %s", buf
));
1791 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1792 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1793 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1794 advance
= decode_labeled_vpn_prefix6(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_VPLS
<<8 | SAFNUM_VPLS
):
1804 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1805 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1806 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1807 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1809 ND_PRINT((ndo
, "\n\t (illegal length)"));
1810 else if (advance
== -2)
1813 ND_PRINT((ndo
, "\n\t %s", buf
));
1815 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1816 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1817 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1818 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1820 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1821 else if (advance
== -2)
1824 ND_PRINT((ndo
, "\n\t %s", buf
));
1826 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1827 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1828 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1829 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1831 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1832 else if (advance
== -2)
1835 ND_PRINT((ndo
, "\n\t %s", buf
));
1838 ND_TCHECK2(*tptr
,tlen
);
1839 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1840 if (ndo
->ndo_vflag
<= 1)
1841 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1853 case BGPTYPE_MP_UNREACH_NLRI
:
1854 ND_TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1855 af
= EXTRACT_16BITS(tptr
);
1858 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1859 tok2strbuf(af_values
, "Unknown AFI", af
,
1860 tokbuf
, sizeof(tokbuf
)),
1862 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1863 tok2strbuf(bgp_safi_values
, "Unknown SAFI", safi
,
1864 tokbuf
, sizeof(tokbuf
)),
1867 if (len
== BGP_MP_NLRI_MINSIZE
)
1868 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
1872 while (len
- (tptr
- pptr
) > 0) {
1873 switch (af
<<8 | safi
) {
1874 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1875 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1876 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1877 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1879 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1880 else if (advance
== -2)
1882 else if (advance
== -3)
1883 break; /* bytes left, but not enough */
1885 ND_PRINT((ndo
, "\n\t %s", buf
));
1887 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1888 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1890 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1891 else if (advance
== -2)
1893 else if (advance
== -3)
1894 break; /* bytes left, but not enough */
1896 ND_PRINT((ndo
, "\n\t %s", buf
));
1898 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1899 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1900 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1901 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1903 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1904 else if (advance
== -2)
1907 ND_PRINT((ndo
, "\n\t %s", buf
));
1910 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1911 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1912 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1913 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1915 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1916 else if (advance
== -2)
1918 else if (advance
== -3)
1919 break; /* bytes left, but not enough */
1921 ND_PRINT((ndo
, "\n\t %s", buf
));
1923 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1924 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1926 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1927 else if (advance
== -2)
1929 else if (advance
== -3)
1930 break; /* bytes left, but not enough */
1932 ND_PRINT((ndo
, "\n\t %s", buf
));
1934 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1935 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1936 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1937 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1939 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1940 else if (advance
== -2)
1943 ND_PRINT((ndo
, "\n\t %s", buf
));
1946 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1947 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1948 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1949 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1950 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1952 ND_PRINT((ndo
, "\n\t (illegal length)"));
1953 else if (advance
== -2)
1956 ND_PRINT((ndo
, "\n\t %s", buf
));
1958 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1959 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1960 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1961 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1963 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1964 else if (advance
== -2)
1967 ND_PRINT((ndo
, "\n\t %s", buf
));
1969 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1970 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1971 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1972 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1974 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1975 else if (advance
== -2)
1978 ND_PRINT((ndo
, "\n\t %s", buf
));
1980 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1981 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
1983 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1984 else if (advance
== -2)
1987 ND_PRINT((ndo
, "\n\t %s", buf
));
1989 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1990 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1991 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1993 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1994 else if (advance
== -2)
1997 ND_PRINT((ndo
, "\n\t %s", buf
));
2000 ND_TCHECK2(*(tptr
-3),tlen
);
2001 ND_PRINT((ndo
, "no AFI %u / SAFI %u decoder", af
, safi
));
2002 if (ndo
->ndo_vflag
<= 1)
2003 print_unknown_data(ndo
, tptr
-3, "\n\t ", tlen
);
2013 case BGPTYPE_EXTD_COMMUNITIES
:
2015 ND_PRINT((ndo
, "invalid len"));
2021 ND_TCHECK2(tptr
[0], 2);
2022 extd_comm
=EXTRACT_16BITS(tptr
);
2024 ND_PRINT((ndo
, "\n\t %s (0x%04x), Flags [%s]",
2025 tok2strbuf(bgp_extd_comm_subtype_values
,
2026 "unknown extd community typecode",
2027 extd_comm
, tokbuf
, sizeof(tokbuf
)),
2029 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
)));
2031 ND_TCHECK2(*(tptr
+2), 6);
2033 case BGP_EXT_COM_RT_0
:
2034 case BGP_EXT_COM_RO_0
:
2035 case BGP_EXT_COM_L2VPN_RT_0
:
2036 ND_PRINT((ndo
, ": %u:%u (= %s)",
2037 EXTRACT_16BITS(tptr
+2),
2038 EXTRACT_32BITS(tptr
+4),
2039 getname(ndo
, tptr
+4)));
2041 case BGP_EXT_COM_RT_1
:
2042 case BGP_EXT_COM_RO_1
:
2043 case BGP_EXT_COM_L2VPN_RT_1
:
2044 case BGP_EXT_COM_VRF_RT_IMP
:
2045 ND_PRINT((ndo
, ": %s:%u",
2046 getname(ndo
, tptr
+2),
2047 EXTRACT_16BITS(tptr
+6)));
2049 case BGP_EXT_COM_RT_2
:
2050 case BGP_EXT_COM_RO_2
:
2051 ND_PRINT((ndo
, ": %s:%u",
2052 as_printf(ndo
, astostr
, sizeof(astostr
),
2053 EXTRACT_32BITS(tptr
+2)), EXTRACT_16BITS(tptr
+6)));
2055 case BGP_EXT_COM_LINKBAND
:
2056 bw
.i
= EXTRACT_32BITS(tptr
+2);
2057 ND_PRINT((ndo
, ": bandwidth: %.3f Mbps",
2060 case BGP_EXT_COM_VPN_ORIGIN
:
2061 case BGP_EXT_COM_VPN_ORIGIN2
:
2062 case BGP_EXT_COM_VPN_ORIGIN3
:
2063 case BGP_EXT_COM_VPN_ORIGIN4
:
2064 case BGP_EXT_COM_OSPF_RID
:
2065 case BGP_EXT_COM_OSPF_RID2
:
2066 ND_PRINT((ndo
, "%s", getname(ndo
, tptr
+2)));
2068 case BGP_EXT_COM_OSPF_RTYPE
:
2069 case BGP_EXT_COM_OSPF_RTYPE2
:
2070 ND_PRINT((ndo
, ": area:%s, router-type:%s, metric-type:%s%s",
2071 getname(ndo
, tptr
+2),
2072 tok2strbuf(bgp_extd_comm_ospf_rtype_values
,
2075 tokbuf
, sizeof(tokbuf
)),
2076 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
2077 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : ""));
2079 case BGP_EXT_COM_L2INFO
:
2080 ND_PRINT((ndo
, ": %s Control Flags [0x%02x]:MTU %u",
2081 tok2strbuf(l2vpn_encaps_values
,
2084 tokbuf
, sizeof(tokbuf
)),
2086 EXTRACT_16BITS(tptr
+4)));
2088 case BGP_EXT_COM_SOURCE_AS
:
2089 ND_PRINT((ndo
, ": AS %u", EXTRACT_16BITS(tptr
+2)));
2092 ND_TCHECK2(*tptr
,8);
2093 print_unknown_data(ndo
, tptr
, "\n\t ", 8);
2101 case BGPTYPE_PMSI_TUNNEL
:
2103 uint8_t tunnel_type
, flags
;
2105 tunnel_type
= *(tptr
+1);
2109 ND_TCHECK2(tptr
[0], 5);
2110 ND_PRINT((ndo
, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2111 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2113 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2114 EXTRACT_24BITS(tptr
+2)>>4));
2119 switch (tunnel_type
) {
2120 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2121 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2122 ND_TCHECK2(tptr
[0], 8);
2123 ND_PRINT((ndo
, "\n\t Sender %s, P-Group %s",
2124 ipaddr_string(ndo
, tptr
),
2125 ipaddr_string(ndo
, tptr
+4)));
2128 case BGP_PMSI_TUNNEL_PIM_SSM
:
2129 ND_TCHECK2(tptr
[0], 8);
2130 ND_PRINT((ndo
, "\n\t Root-Node %s, P-Group %s",
2131 ipaddr_string(ndo
, tptr
),
2132 ipaddr_string(ndo
, tptr
+4)));
2134 case BGP_PMSI_TUNNEL_INGRESS
:
2135 ND_TCHECK2(tptr
[0], 4);
2136 ND_PRINT((ndo
, "\n\t Tunnel-Endpoint %s",
2137 ipaddr_string(ndo
, tptr
)));
2139 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2140 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2141 ND_TCHECK2(tptr
[0], 8);
2142 ND_PRINT((ndo
, "\n\t Root-Node %s, LSP-ID 0x%08x",
2143 ipaddr_string(ndo
, tptr
),
2144 EXTRACT_32BITS(tptr
+4)));
2146 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2147 ND_TCHECK2(tptr
[0], 8);
2148 ND_PRINT((ndo
, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2149 ipaddr_string(ndo
, tptr
),
2150 EXTRACT_32BITS(tptr
+4)));
2153 if (ndo
->ndo_vflag
<= 1) {
2154 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2159 case BGPTYPE_ATTR_SET
:
2160 ND_TCHECK2(tptr
[0], 4);
2163 ND_PRINT((ndo
, "\n\t Origin AS: %s",
2164 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(tptr
))));
2169 u_int aflags
, atype
, alenlen
, alen
;
2171 ND_TCHECK2(tptr
[0], 2);
2175 atype
= *(tptr
+ 1);
2178 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2179 ND_TCHECK2(tptr
[0], alenlen
);
2182 alen
= bgp_attr_len(aflags
, tptr
);
2186 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2187 tok2strbuf(bgp_attr_values
,
2188 "Unknown Attribute", atype
,
2189 tokbuf
, sizeof(tokbuf
)),
2194 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2195 aflags
& 0x80 ? "O" : "",
2196 aflags
& 0x40 ? "T" : "",
2197 aflags
& 0x20 ? "P" : "",
2198 aflags
& 0x10 ? "E" : ""));
2200 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2201 ND_PRINT((ndo
, "]: "));
2203 /* FIXME check for recursion */
2204 if (!bgp_attr_print(ndo
, atype
, tptr
, alen
))
2213 ND_TCHECK2(*pptr
,len
);
2214 ND_PRINT((ndo
, "\n\t no Attribute %u decoder", atype
)); /* we have no decoder for the attribute */
2215 if (ndo
->ndo_vflag
<= 1)
2216 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2219 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2220 ND_TCHECK2(*pptr
,len
);
2221 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2230 bgp_capabilities_print(netdissect_options
*ndo
,
2231 const u_char
*opt
, int caps_len
)
2233 char tokbuf
[TOKBUFSIZE
];
2234 char tokbuf2
[TOKBUFSIZE
];
2235 int cap_type
, cap_len
, tcap_len
, cap_offset
;
2238 while (i
< caps_len
) {
2239 ND_TCHECK2(opt
[i
], BGP_CAP_HEADER_SIZE
);
2243 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2244 tok2strbuf(bgp_capcode_values
, "Unknown",
2245 cap_type
, tokbuf
, sizeof(tokbuf
)),
2248 ND_TCHECK2(opt
[i
+2], cap_len
);
2250 case BGP_CAPCODE_MP
:
2251 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u)",
2252 tok2strbuf(af_values
, "Unknown",
2253 EXTRACT_16BITS(opt
+i
+2),
2254 tokbuf
, sizeof(tokbuf
)),
2255 EXTRACT_16BITS(opt
+i
+2),
2256 tok2strbuf(bgp_safi_values
, "Unknown",
2258 tokbuf
, sizeof(tokbuf
)),
2261 case BGP_CAPCODE_RESTART
:
2262 ND_PRINT((ndo
, "\n\t\tRestart Flags: [%s], Restart Time %us",
2263 ((opt
[i
+2])&0x80) ? "R" : "none",
2264 EXTRACT_16BITS(opt
+i
+2)&0xfff));
2267 while(tcap_len
>=4) {
2268 ND_PRINT((ndo
, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2269 tok2strbuf(af_values
,"Unknown",
2270 EXTRACT_16BITS(opt
+i
+cap_offset
),
2271 tokbuf
, sizeof(tokbuf
)),
2272 EXTRACT_16BITS(opt
+i
+cap_offset
),
2273 tok2strbuf(bgp_safi_values
,"Unknown",
2274 opt
[i
+cap_offset
+2],
2275 tokbuf2
, sizeof(tokbuf2
)),
2276 opt
[i
+cap_offset
+2],
2277 ((opt
[i
+cap_offset
+3])&0x80) ? "yes" : "no" ));
2282 case BGP_CAPCODE_RR
:
2283 case BGP_CAPCODE_RR_CISCO
:
2285 case BGP_CAPCODE_AS_NEW
:
2288 * Extract the 4 byte AS number encoded.
2291 ND_PRINT((ndo
, "\n\t\t 4 Byte AS %s",
2292 as_printf(ndo
, astostr
, sizeof(astostr
),
2293 EXTRACT_32BITS(opt
+ i
+ 2))));
2297 ND_PRINT((ndo
, "\n\t\tno decoder for Capability %u",
2299 if (ndo
->ndo_vflag
<= 1)
2300 print_unknown_data(ndo
, &opt
[i
+2], "\n\t\t", cap_len
);
2303 if (ndo
->ndo_vflag
> 1 && cap_len
> 0) {
2304 print_unknown_data(ndo
, &opt
[i
+2], "\n\t\t", cap_len
);
2306 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2311 ND_PRINT((ndo
, "[|BGP]"));
2315 bgp_open_print(netdissect_options
*ndo
,
2316 const u_char
*dat
, int length
)
2318 struct bgp_open bgpo
;
2319 struct bgp_opt bgpopt
;
2322 char tokbuf
[TOKBUFSIZE
];
2324 ND_TCHECK2(dat
[0], BGP_OPEN_SIZE
);
2325 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
2327 ND_PRINT((ndo
, "\n\t Version %d, ", bgpo
.bgpo_version
));
2328 ND_PRINT((ndo
, "my AS %s, ",
2329 as_printf(ndo
, astostr
, sizeof(astostr
), ntohs(bgpo
.bgpo_myas
))));
2330 ND_PRINT((ndo
, "Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
)));
2331 ND_PRINT((ndo
, "ID %s", getname(ndo
, (u_char
*)&bgpo
.bgpo_id
)));
2332 ND_PRINT((ndo
, "\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
));
2334 /* some little sanity checking */
2335 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
2339 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
2343 while (i
< bgpo
.bgpo_optlen
) {
2344 ND_TCHECK2(opt
[i
], BGP_OPT_SIZE
);
2345 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
2346 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
2347 ND_PRINT((ndo
, "\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
));
2351 ND_PRINT((ndo
, "\n\t Option %s (%u), length: %u",
2352 tok2strbuf(bgp_opt_values
,"Unknown",
2354 tokbuf
, sizeof(tokbuf
)),
2356 bgpopt
.bgpopt_len
));
2358 /* now let's decode the options we know*/
2359 switch(bgpopt
.bgpopt_type
) {
2362 bgp_capabilities_print(ndo
, &opt
[i
+BGP_OPT_SIZE
],
2368 ND_PRINT((ndo
, "\n\t no decoder for option %u",
2369 bgpopt
.bgpopt_type
));
2372 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
2376 ND_PRINT((ndo
, "[|BGP]"));
2380 bgp_update_print(netdissect_options
*ndo
,
2381 const u_char
*dat
, int length
)
2385 int withdrawn_routes_len
;
2388 char tokbuf
[TOKBUFSIZE
];
2390 char buf
[MAXHOSTNAMELEN
+ 100];
2394 ND_TCHECK2(dat
[0], BGP_SIZE
);
2395 if (length
< BGP_SIZE
)
2397 memcpy(&bgp
, dat
, BGP_SIZE
);
2398 p
= dat
+ BGP_SIZE
; /*XXX*/
2401 /* Unfeasible routes */
2402 ND_TCHECK2(p
[0], 2);
2405 withdrawn_routes_len
= EXTRACT_16BITS(p
);
2408 if (withdrawn_routes_len
) {
2410 * Without keeping state from the original NLRI message,
2411 * it's not possible to tell if this a v4 or v6 route,
2412 * so only try to decode it if we're not v6 enabled.
2414 ND_TCHECK2(p
[0], withdrawn_routes_len
);
2415 if (length
< withdrawn_routes_len
)
2418 ND_PRINT((ndo
, "\n\t Withdrawn routes: %d bytes", withdrawn_routes_len
));
2419 p
+= withdrawn_routes_len
;
2420 length
-= withdrawn_routes_len
;
2422 if (withdrawn_routes_len
< 2)
2425 withdrawn_routes_len
-= 2;
2428 ND_PRINT((ndo
, "\n\t Withdrawn routes:"));
2430 while(withdrawn_routes_len
> 0) {
2431 wpfx
= decode_prefix4(ndo
, p
, withdrawn_routes_len
, buf
, sizeof(buf
));
2433 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2435 } else if (wpfx
== -2)
2437 else if (wpfx
== -3)
2438 goto trunc
; /* bytes left, but not enough */
2440 ND_PRINT((ndo
, "\n\t %s", buf
));
2443 withdrawn_routes_len
-= wpfx
;
2449 ND_TCHECK2(p
[0], 2);
2452 len
= EXTRACT_16BITS(p
);
2456 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2457 /* No withdrawn routes, no path attributes, no NLRI */
2458 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
2463 /* do something more useful!*/
2465 int aflags
, atype
, alenlen
, alen
;
2467 ND_TCHECK2(p
[0], 2);
2477 alenlen
= bgp_attr_lenlen(aflags
, p
);
2478 ND_TCHECK2(p
[0], alenlen
);
2481 if (length
< alenlen
)
2483 alen
= bgp_attr_len(aflags
, p
);
2488 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2489 tok2strbuf(bgp_attr_values
, "Unknown Attribute",
2491 tokbuf
, sizeof(tokbuf
)),
2496 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2497 aflags
& 0x80 ? "O" : "",
2498 aflags
& 0x40 ? "T" : "",
2499 aflags
& 0x20 ? "P" : "",
2500 aflags
& 0x10 ? "E" : ""));
2502 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2503 ND_PRINT((ndo
, "]: "));
2509 if (!bgp_attr_print(ndo
, atype
, p
, alen
))
2519 * XXX - what if they're using the "Advertisement of
2520 * Multiple Paths in BGP" feature:
2522 * https://datatracker.ietf.org/doc/draft-ietf-idr-add-paths/
2524 * http://tools.ietf.org/html/draft-ietf-idr-add-paths-06
2526 ND_PRINT((ndo
, "\n\t Updated routes:"));
2528 char buf
[MAXHOSTNAMELEN
+ 100];
2529 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2531 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2536 goto trunc
; /* bytes left, but not enough */
2538 ND_PRINT((ndo
, "\n\t %s", buf
));
2546 ND_PRINT((ndo
, "[|BGP]"));
2550 bgp_notification_print(netdissect_options
*ndo
,
2551 const u_char
*dat
, int length
)
2553 struct bgp_notification bgpn
;
2555 char tokbuf
[TOKBUFSIZE
];
2556 char tokbuf2
[TOKBUFSIZE
];
2558 ND_TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
2559 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
2561 /* some little sanity checking */
2562 if (length
<BGP_NOTIFICATION_SIZE
)
2565 ND_PRINT((ndo
, ", %s (%u)",
2566 tok2strbuf(bgp_notify_major_values
, "Unknown Error",
2567 bgpn
.bgpn_major
, tokbuf
, sizeof(tokbuf
)),
2570 switch (bgpn
.bgpn_major
) {
2572 case BGP_NOTIFY_MAJOR_MSG
:
2573 ND_PRINT((ndo
, ", subcode %s (%u)",
2574 tok2strbuf(bgp_notify_minor_msg_values
, "Unknown",
2575 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2578 case BGP_NOTIFY_MAJOR_OPEN
:
2579 ND_PRINT((ndo
, ", subcode %s (%u)",
2580 tok2strbuf(bgp_notify_minor_open_values
, "Unknown",
2581 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2584 case BGP_NOTIFY_MAJOR_UPDATE
:
2585 ND_PRINT((ndo
, ", subcode %s (%u)",
2586 tok2strbuf(bgp_notify_minor_update_values
, "Unknown",
2587 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2590 case BGP_NOTIFY_MAJOR_CAP
:
2591 ND_PRINT((ndo
, " subcode %s (%u)",
2592 tok2strbuf(bgp_notify_minor_cap_values
, "Unknown",
2593 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2595 case BGP_NOTIFY_MAJOR_CEASE
:
2596 ND_PRINT((ndo
, ", subcode %s (%u)",
2597 tok2strbuf(bgp_notify_minor_cease_values
, "Unknown",
2598 bgpn
.bgpn_minor
, tokbuf
, sizeof(tokbuf
)),
2601 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2602 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2604 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2605 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2606 ND_TCHECK2(*tptr
, 7);
2607 ND_PRINT((ndo
, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2608 tok2strbuf(af_values
, "Unknown",
2609 EXTRACT_16BITS(tptr
), tokbuf
, sizeof(tokbuf
)),
2610 EXTRACT_16BITS(tptr
),
2611 tok2strbuf(bgp_safi_values
, "Unknown", *(tptr
+2),
2612 tokbuf2
, sizeof(tokbuf
)),
2614 EXTRACT_32BITS(tptr
+3)));
2623 ND_PRINT((ndo
, "[|BGP]"));
2627 bgp_route_refresh_print(netdissect_options
*ndo
,
2628 const u_char
*pptr
, int len
)
2630 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2631 char tokbuf
[TOKBUFSIZE
];
2632 char tokbuf2
[TOKBUFSIZE
];
2634 ND_TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
2636 /* some little sanity checking */
2637 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2640 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2642 ND_PRINT((ndo
, "\n\t AFI %s (%u), SAFI %s (%u)",
2643 tok2strbuf(af_values
,"Unknown",
2644 /* this stinks but the compiler pads the structure
2646 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2647 tokbuf
, sizeof(tokbuf
)),
2648 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2649 tok2strbuf(bgp_safi_values
,"Unknown",
2650 bgp_route_refresh_header
->safi
,
2651 tokbuf2
, sizeof(tokbuf2
)),
2652 bgp_route_refresh_header
->safi
));
2654 if (ndo
->ndo_vflag
> 1) {
2655 ND_TCHECK2(*pptr
, len
);
2656 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2661 ND_PRINT((ndo
, "[|BGP]"));
2665 bgp_header_print(netdissect_options
*ndo
,
2666 const u_char
*dat
, int length
)
2669 char tokbuf
[TOKBUFSIZE
];
2671 ND_TCHECK2(dat
[0], BGP_SIZE
);
2672 memcpy(&bgp
, dat
, BGP_SIZE
);
2673 ND_PRINT((ndo
, "\n\t%s Message (%u), length: %u",
2674 tok2strbuf(bgp_msg_values
, "Unknown", bgp
.bgp_type
,
2675 tokbuf
, sizeof(tokbuf
)),
2679 switch (bgp
.bgp_type
) {
2681 bgp_open_print(ndo
, dat
, length
);
2684 bgp_update_print(ndo
, dat
, length
);
2686 case BGP_NOTIFICATION
:
2687 bgp_notification_print(ndo
, dat
, length
);
2691 case BGP_ROUTE_REFRESH
:
2692 bgp_route_refresh_print(ndo
, dat
, length
);
2695 /* we have no decoder for the BGP message */
2696 ND_TCHECK2(*dat
, length
);
2697 ND_PRINT((ndo
, "\n\t no Message %u decoder", bgp
.bgp_type
));
2698 print_unknown_data(ndo
, dat
, "\n\t ", length
);
2703 ND_PRINT((ndo
, "[|BGP]"));
2708 bgp_print(netdissect_options
*ndo
,
2709 const u_char
*dat
, int length
)
2713 const u_char
*start
;
2714 const u_char marker
[] = {
2715 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2716 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2720 char tokbuf
[TOKBUFSIZE
];
2723 if (ndo
->ndo_snapend
< dat
+ length
)
2724 ep
= ndo
->ndo_snapend
;
2726 ND_PRINT((ndo
, ": BGP"));
2728 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
2734 if (!ND_TTEST2(p
[0], 1))
2741 if (!ND_TTEST2(p
[0], sizeof(marker
)))
2743 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2748 /* found BGP header */
2749 ND_TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2750 memcpy(&bgp
, p
, BGP_SIZE
);
2753 ND_PRINT((ndo
, " [|BGP]"));
2755 hlen
= ntohs(bgp
.bgp_len
);
2756 if (hlen
< BGP_SIZE
) {
2757 ND_PRINT((ndo
, "\n[|BGP Bogus header length %u < %u]", hlen
,
2762 if (ND_TTEST2(p
[0], hlen
)) {
2763 if (!bgp_header_print(ndo
, p
, hlen
))
2768 ND_PRINT((ndo
, "\n[|BGP %s]",
2769 tok2strbuf(bgp_msg_values
,
2770 "Unknown Message Type",
2772 tokbuf
, sizeof(tokbuf
))));
2780 ND_PRINT((ndo
, " [|BGP]"));
2785 * c-style: whitesmith