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 /* \summary: Border Gateway Protocol (BGP) printer */
39 #include <netdissect-stdinc.h>
44 #include "netdissect.h"
45 #include "addrtoname.h"
51 uint8_t bgp_marker
[16];
55 #define BGP_SIZE 19 /* unaligned */
59 #define BGP_NOTIFICATION 3
60 #define BGP_KEEPALIVE 4
61 #define BGP_ROUTE_REFRESH 5
63 static const struct tok bgp_msg_values
[] = {
65 { BGP_UPDATE
, "Update"},
66 { BGP_NOTIFICATION
, "Notification"},
67 { BGP_KEEPALIVE
, "Keepalive"},
68 { BGP_ROUTE_REFRESH
, "Route Refresh"},
73 uint8_t bgpo_marker
[16];
78 uint16_t bgpo_holdtime
;
81 /* options should follow */
83 #define BGP_OPEN_SIZE 29 /* unaligned */
90 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
91 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
93 struct bgp_notification
{
94 uint8_t bgpn_marker
[16];
100 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
102 struct bgp_route_refresh
{
103 uint8_t bgp_marker
[16];
106 uint8_t afi
[2]; /* the compiler messes this structure up */
107 uint8_t res
; /* when doing misaligned sequences of int8 and int16 */
108 uint8_t safi
; /* afi should be int16 - so we have to access it using */
109 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
110 #define BGP_ROUTE_REFRESH_SIZE 23
112 #define bgp_attr_lenlen(flags, p) \
113 (((flags) & 0x10) ? 2 : 1)
114 #define bgp_attr_len(flags, p) \
115 (((flags) & 0x10) ? EXTRACT_16BITS(p) : *(p))
117 #define BGPTYPE_ORIGIN 1
118 #define BGPTYPE_AS_PATH 2
119 #define BGPTYPE_NEXT_HOP 3
120 #define BGPTYPE_MULTI_EXIT_DISC 4
121 #define BGPTYPE_LOCAL_PREF 5
122 #define BGPTYPE_ATOMIC_AGGREGATE 6
123 #define BGPTYPE_AGGREGATOR 7
124 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
125 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC1998 */
126 #define BGPTYPE_CLUSTER_LIST 10 /* RFC1998 */
127 #define BGPTYPE_DPA 11 /* draft-ietf-idr-bgp-dpa */
128 #define BGPTYPE_ADVERTISERS 12 /* RFC1863 */
129 #define BGPTYPE_RCID_PATH 13 /* RFC1863 */
130 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC2283 */
131 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC2283 */
132 #define BGPTYPE_EXTD_COMMUNITIES 16 /* draft-ietf-idr-bgp-ext-communities */
133 #define BGPTYPE_AS4_PATH 17 /* RFC4893 */
134 #define BGPTYPE_AGGREGATOR4 18 /* RFC4893 */
135 #define BGPTYPE_PMSI_TUNNEL 22 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
136 #define BGPTYPE_AIGP 26 /* RFC7311 */
137 #define BGPTYPE_ATTR_SET 128 /* draft-marques-ppvpn-ibgp */
139 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
141 static const struct tok bgp_attr_values
[] = {
142 { BGPTYPE_ORIGIN
, "Origin"},
143 { BGPTYPE_AS_PATH
, "AS Path"},
144 { BGPTYPE_AS4_PATH
, "AS4 Path"},
145 { BGPTYPE_NEXT_HOP
, "Next Hop"},
146 { BGPTYPE_MULTI_EXIT_DISC
, "Multi Exit Discriminator"},
147 { BGPTYPE_LOCAL_PREF
, "Local Preference"},
148 { BGPTYPE_ATOMIC_AGGREGATE
, "Atomic Aggregate"},
149 { BGPTYPE_AGGREGATOR
, "Aggregator"},
150 { BGPTYPE_AGGREGATOR4
, "Aggregator4"},
151 { BGPTYPE_COMMUNITIES
, "Community"},
152 { BGPTYPE_ORIGINATOR_ID
, "Originator ID"},
153 { BGPTYPE_CLUSTER_LIST
, "Cluster List"},
154 { BGPTYPE_DPA
, "DPA"},
155 { BGPTYPE_ADVERTISERS
, "Advertisers"},
156 { BGPTYPE_RCID_PATH
, "RCID Path / Cluster ID"},
157 { BGPTYPE_MP_REACH_NLRI
, "Multi-Protocol Reach NLRI"},
158 { BGPTYPE_MP_UNREACH_NLRI
, "Multi-Protocol Unreach NLRI"},
159 { BGPTYPE_EXTD_COMMUNITIES
, "Extended Community"},
160 { BGPTYPE_PMSI_TUNNEL
, "PMSI Tunnel"},
161 { BGPTYPE_AIGP
, "Accumulated IGP Metric"},
162 { BGPTYPE_ATTR_SET
, "Attribute Set"},
163 { 255, "Reserved for development"},
168 #define BGP_AS_SEQUENCE 2
169 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
170 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
172 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
173 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
175 static const struct tok bgp_as_path_segment_open_values
[] = {
176 { BGP_AS_SEQUENCE
, ""},
178 { BGP_CONFED_AS_SEQUENCE
, "( "},
179 { BGP_CONFED_AS_SET
, "({ "},
183 static const struct tok bgp_as_path_segment_close_values
[] = {
184 { BGP_AS_SEQUENCE
, ""},
186 { BGP_CONFED_AS_SEQUENCE
, ")"},
187 { BGP_CONFED_AS_SET
, "})"},
191 #define BGP_OPT_AUTH 1
192 #define BGP_OPT_CAP 2
195 static const struct tok bgp_opt_values
[] = {
196 { BGP_OPT_AUTH
, "Authentication Information"},
197 { BGP_OPT_CAP
, "Capabilities Advertisement"},
201 #define BGP_CAPCODE_MP 1
202 #define BGP_CAPCODE_RR 2
203 #define BGP_CAPCODE_ORF 3 /* XXX */
204 #define BGP_CAPCODE_RESTART 64 /* draft-ietf-idr-restart-05 */
205 #define BGP_CAPCODE_AS_NEW 65 /* XXX */
206 #define BGP_CAPCODE_DYN_CAP 67 /* XXX */
207 #define BGP_CAPCODE_ADD_PATH 69 /* draft-ietf-idr-add-paths-10 */
208 #define BGP_CAPCODE_RR_CISCO 128
210 static const struct tok bgp_capcode_values
[] = {
211 { BGP_CAPCODE_MP
, "Multiprotocol Extensions"},
212 { BGP_CAPCODE_RR
, "Route Refresh"},
213 { BGP_CAPCODE_ORF
, "Cooperative Route Filtering"},
214 { BGP_CAPCODE_RESTART
, "Graceful Restart"},
215 { BGP_CAPCODE_AS_NEW
, "32-Bit AS Number"},
216 { BGP_CAPCODE_DYN_CAP
, "Dynamic Capability"},
217 { BGP_CAPCODE_ADD_PATH
, "Multiple Paths"},
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"},
326 #define BGP_AIGP_TLV 1
328 static const struct tok bgp_aigp_values
[] = {
329 { BGP_AIGP_TLV
, "AIGP"},
334 /* Subsequent address family identifier, RFC2283 section 7 */
336 #define SAFNUM_UNICAST 1
337 #define SAFNUM_MULTICAST 2
338 #define SAFNUM_UNIMULTICAST 3
339 /* labeled BGP RFC3107 */
340 #define SAFNUM_LABUNICAST 4
341 /* draft-ietf-l3vpn-2547bis-mcast-bgp-02.txt */
342 #define SAFNUM_MULTICAST_VPN 5
343 #define SAFNUM_TUNNEL 64 /* XXX */
344 #define SAFNUM_VPLS 65 /* XXX */
345 /* draft-nalawade-idr-mdt-safi-03 */
346 #define SAFNUM_MDT 66
347 /* Section 4.3.4 of draft-rosen-rfc2547bis-03.txt */
348 #define SAFNUM_VPNUNICAST 128
349 #define SAFNUM_VPNMULTICAST 129
350 #define SAFNUM_VPNUNIMULTICAST 130
351 /* draft-marques-ppvpn-rt-constrain-01.txt */
352 #define SAFNUM_RT_ROUTING_INFO 132
354 #define BGP_VPN_RD_LEN 8
356 static const struct tok bgp_safi_values
[] = {
357 { SAFNUM_RES
, "Reserved"},
358 { SAFNUM_UNICAST
, "Unicast"},
359 { SAFNUM_MULTICAST
, "Multicast"},
360 { SAFNUM_UNIMULTICAST
, "Unicast+Multicast"},
361 { SAFNUM_LABUNICAST
, "labeled Unicast"},
362 { SAFNUM_TUNNEL
, "Tunnel"},
363 { SAFNUM_VPLS
, "VPLS"},
364 { SAFNUM_MDT
, "MDT"},
365 { SAFNUM_VPNUNICAST
, "labeled VPN Unicast"},
366 { SAFNUM_VPNMULTICAST
, "labeled VPN Multicast"},
367 { SAFNUM_VPNUNIMULTICAST
, "labeled VPN Unicast+Multicast"},
368 { SAFNUM_RT_ROUTING_INFO
, "Route Target Routing Information"},
369 { SAFNUM_MULTICAST_VPN
, "Multicast VPN"},
373 /* well-known community */
374 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
375 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
376 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
378 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
379 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
380 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
381 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
382 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
383 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
384 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
385 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
386 /* rfc2547 bgp-mpls-vpns */
387 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
388 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
389 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
390 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
392 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
393 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
395 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
396 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
398 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
400 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
401 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
402 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
403 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
406 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
407 #define BGP_EXT_COM_EIGRP_GEN 0x8800
408 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
409 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
410 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
411 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
412 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
414 static const struct tok bgp_extd_comm_flag_values
[] = {
415 { 0x8000, "vendor-specific"},
416 { 0x4000, "non-transitive"},
420 static const struct tok bgp_extd_comm_subtype_values
[] = {
421 { BGP_EXT_COM_RT_0
, "target"},
422 { BGP_EXT_COM_RT_1
, "target"},
423 { BGP_EXT_COM_RT_2
, "target"},
424 { BGP_EXT_COM_RO_0
, "origin"},
425 { BGP_EXT_COM_RO_1
, "origin"},
426 { BGP_EXT_COM_RO_2
, "origin"},
427 { BGP_EXT_COM_LINKBAND
, "link-BW"},
428 { BGP_EXT_COM_VPN_ORIGIN
, "ospf-domain"},
429 { BGP_EXT_COM_VPN_ORIGIN2
, "ospf-domain"},
430 { BGP_EXT_COM_VPN_ORIGIN3
, "ospf-domain"},
431 { BGP_EXT_COM_VPN_ORIGIN4
, "ospf-domain"},
432 { BGP_EXT_COM_OSPF_RTYPE
, "ospf-route-type"},
433 { BGP_EXT_COM_OSPF_RTYPE2
, "ospf-route-type"},
434 { BGP_EXT_COM_OSPF_RID
, "ospf-router-id"},
435 { BGP_EXT_COM_OSPF_RID2
, "ospf-router-id"},
436 { BGP_EXT_COM_L2INFO
, "layer2-info"},
437 { BGP_EXT_COM_EIGRP_GEN
, "eigrp-general-route (flag, tag)" },
438 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY
, "eigrp-route-metric (AS, delay)" },
439 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW
, "eigrp-route-metric (reliability, nexthop, bandwidth)" },
440 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU
, "eigrp-route-metric (load, MTU)" },
441 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID
, "eigrp-external-route (remote-AS, remote-ID)" },
442 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC
, "eigrp-external-route (remote-proto, remote-metric)" },
443 { BGP_EXT_COM_SOURCE_AS
, "source-AS" },
444 { BGP_EXT_COM_VRF_RT_IMP
, "vrf-route-import"},
445 { BGP_EXT_COM_L2VPN_RT_0
, "l2vpn-id"},
446 { BGP_EXT_COM_L2VPN_RT_1
, "l2vpn-id"},
450 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
451 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
452 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
453 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
454 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
455 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
456 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
457 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
459 static const struct tok bgp_extd_comm_ospf_rtype_values
[] = {
460 { BGP_OSPF_RTYPE_RTR
, "Router" },
461 { BGP_OSPF_RTYPE_NET
, "Network" },
462 { BGP_OSPF_RTYPE_SUM
, "Summary" },
463 { BGP_OSPF_RTYPE_EXT
, "External" },
464 { BGP_OSPF_RTYPE_NSSA
,"NSSA External" },
465 { BGP_OSPF_RTYPE_SHAM
,"MPLS-VPN Sham" },
469 /* ADD-PATH Send/Receive field values */
470 static const struct tok bgp_add_path_recvsend
[] = {
477 static char astostr
[20];
482 * Convert an AS number into a string and return string pointer.
484 * Depending on bflag is set or not, AS number is converted into ASDOT notation
485 * or plain number notation.
489 as_printf(netdissect_options
*ndo
,
490 char *str
, int size
, u_int asnum
)
492 if (!ndo
->ndo_bflag
|| asnum
<= 0xFFFF) {
493 snprintf(str
, size
, "%u", asnum
);
495 snprintf(str
, size
, "%u.%u", asnum
>> 16, asnum
& 0xFFFF);
500 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
503 decode_prefix4(netdissect_options
*ndo
,
504 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
507 u_int plen
, plenbytes
;
516 memset(&addr
, 0, sizeof(addr
));
517 plenbytes
= (plen
+ 7) / 8;
518 ND_TCHECK2(pptr
[1], plenbytes
);
519 ITEMCHECK(plenbytes
);
520 memcpy(&addr
, &pptr
[1], plenbytes
);
522 ((u_char
*)&addr
)[plenbytes
- 1] &=
523 ((0xff00 >> (plen
% 8)) & 0xff);
525 snprintf(buf
, buflen
, "%s/%d", ipaddr_string(ndo
, &addr
), plen
);
526 return 1 + plenbytes
;
536 decode_labeled_prefix4(netdissect_options
*ndo
,
537 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
540 u_int plen
, plenbytes
;
542 /* prefix length and label = 4 bytes */
543 ND_TCHECK2(pptr
[0], 4);
545 plen
= pptr
[0]; /* get prefix length */
547 /* this is one of the weirdnesses of rfc3107
548 the label length (actually the label + COS bits)
549 is added to the prefix length;
550 we also do only read out just one label -
551 there is no real application for advertisement of
552 stacked labels in a single BGP message
558 plen
-=24; /* adjust prefixlen - labellength */
564 memset(&addr
, 0, sizeof(addr
));
565 plenbytes
= (plen
+ 7) / 8;
566 ND_TCHECK2(pptr
[4], plenbytes
);
567 ITEMCHECK(plenbytes
);
568 memcpy(&addr
, &pptr
[4], plenbytes
);
570 ((u_char
*)&addr
)[plenbytes
- 1] &=
571 ((0xff00 >> (plen
% 8)) & 0xff);
573 /* the label may get offsetted by 4 bits so lets shift it right */
574 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
575 ipaddr_string(ndo
, &addr
),
577 EXTRACT_24BITS(pptr
+1)>>4,
578 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
580 return 4 + plenbytes
;
592 * print an ipv4 or ipv6 address into a buffer dependend on address length.
595 bgp_vpn_ip_print(netdissect_options
*ndo
,
596 const u_char
*pptr
, u_int addr_length
)
599 /* worst case string is s fully formatted v6 address */
600 static char addr
[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
603 switch(addr_length
) {
604 case (sizeof(struct in_addr
) << 3): /* 32 */
605 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
606 snprintf(pos
, sizeof(addr
), "%s", ipaddr_string(ndo
, pptr
));
608 case (sizeof(struct in6_addr
) << 3): /* 128 */
609 ND_TCHECK2(pptr
[0], sizeof(struct in6_addr
));
610 snprintf(pos
, sizeof(addr
), "%s", ip6addr_string(ndo
, pptr
));
613 snprintf(pos
, sizeof(addr
), "bogus address length %u", addr_length
);
626 * print an multicast s,g entry into a buffer.
627 * the s,g entry is encoded like this.
629 * +-----------------------------------+
630 * | Multicast Source Length (1 octet) |
631 * +-----------------------------------+
632 * | Multicast Source (Variable) |
633 * +-----------------------------------+
634 * | Multicast Group Length (1 octet) |
635 * +-----------------------------------+
636 * | Multicast Group (Variable) |
637 * +-----------------------------------+
639 * return the number of bytes read from the wire.
642 bgp_vpn_sg_print(netdissect_options
*ndo
,
643 const u_char
*pptr
, char *buf
, u_int buflen
)
646 u_int total_length
, offset
;
650 /* Source address length, encoded in bits */
651 ND_TCHECK2(pptr
[0], 1);
652 addr_length
= *pptr
++;
655 ND_TCHECK2(pptr
[0], (addr_length
>> 3));
656 total_length
+= (addr_length
>> 3) + 1;
657 offset
= strlen(buf
);
659 snprintf(buf
+ offset
, buflen
- offset
, ", Source %s",
660 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
661 pptr
+= (addr_length
>> 3);
664 /* Group address length, encoded in bits */
665 ND_TCHECK2(pptr
[0], 1);
666 addr_length
= *pptr
++;
669 ND_TCHECK2(pptr
[0], (addr_length
>> 3));
670 total_length
+= (addr_length
>> 3) + 1;
671 offset
= strlen(buf
);
673 snprintf(buf
+ offset
, buflen
- offset
, ", Group %s",
674 bgp_vpn_ip_print(ndo
, pptr
, addr_length
));
675 pptr
+= (addr_length
>> 3);
679 return (total_length
);
683 /* RDs and RTs share the same semantics
684 * we use bgp_vpn_rd_print for
685 * printing route targets inside a NLRI */
687 bgp_vpn_rd_print(netdissect_options
*ndo
,
690 /* allocate space for the largest possible string */
691 static char rd
[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
694 /* ok lets load the RD format */
695 switch (EXTRACT_16BITS(pptr
)) {
697 /* 2-byte-AS:number fmt*/
699 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u:%u (= %u.%u.%u.%u)",
700 EXTRACT_16BITS(pptr
+2),
701 EXTRACT_32BITS(pptr
+4),
702 *(pptr
+4), *(pptr
+5), *(pptr
+6), *(pptr
+7));
704 /* IP-address:AS fmt*/
707 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%u.%u.%u.%u:%u",
708 *(pptr
+2), *(pptr
+3), *(pptr
+4), *(pptr
+5), EXTRACT_16BITS(pptr
+6));
711 /* 4-byte-AS:number fmt*/
713 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "%s:%u (%u.%u.%u.%u:%u)",
714 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(pptr
+2)),
715 EXTRACT_16BITS(pptr
+6), *(pptr
+2), *(pptr
+3), *(pptr
+4),
716 *(pptr
+5), EXTRACT_16BITS(pptr
+6));
719 snprintf(pos
, sizeof(rd
) - (pos
- rd
), "unknown RD format");
728 decode_rt_routing_info(netdissect_options
*ndo
,
729 const u_char
*pptr
, char *buf
, u_int buflen
)
731 uint8_t route_target
[8];
735 plen
= pptr
[0]; /* get prefix length */
738 snprintf(buf
, buflen
, "default route target");
745 plen
-=32; /* adjust prefix length */
750 memset(&route_target
, 0, sizeof(route_target
));
751 ND_TCHECK2(pptr
[1], (plen
+ 7) / 8);
752 memcpy(&route_target
, &pptr
[1], (plen
+ 7) / 8);
754 ((u_char
*)&route_target
)[(plen
+ 7) / 8 - 1] &=
755 ((0xff00 >> (plen
% 8)) & 0xff);
757 snprintf(buf
, buflen
, "origin AS: %s, route target %s",
758 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(pptr
+1)),
759 bgp_vpn_rd_print(ndo
, (u_char
*)&route_target
));
761 return 5 + (plen
+ 7) / 8;
768 decode_labeled_vpn_prefix4(netdissect_options
*ndo
,
769 const u_char
*pptr
, char *buf
, u_int buflen
)
775 plen
= pptr
[0]; /* get prefix length */
780 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
785 memset(&addr
, 0, sizeof(addr
));
786 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
787 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
789 ((u_char
*)&addr
)[(plen
+ 7) / 8 - 1] &=
790 ((0xff00 >> (plen
% 8)) & 0xff);
792 /* the label may get offsetted by 4 bits so lets shift it right */
793 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
794 bgp_vpn_rd_print(ndo
, pptr
+4),
795 ipaddr_string(ndo
, &addr
),
797 EXTRACT_24BITS(pptr
+1)>>4,
798 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
800 return 12 + (plen
+ 7) / 8;
807 * +-------------------------------+
809 * | RD:IPv4-address (12 octets) |
811 * +-------------------------------+
812 * | MDT Group-address (4 octets) |
813 * +-------------------------------+
816 #define MDT_VPN_NLRI_LEN 16
819 decode_mdt_vpn_nlri(netdissect_options
*ndo
,
820 const u_char
*pptr
, char *buf
, u_int buflen
)
824 const u_char
*vpn_ip
;
828 /* if the NLRI is not predefined length, quit.*/
829 if (*pptr
!= MDT_VPN_NLRI_LEN
* 8)
834 ND_TCHECK2(pptr
[0], 8);
839 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
841 pptr
+=sizeof(struct in_addr
);
843 /* MDT Group Address */
844 ND_TCHECK2(pptr
[0], sizeof(struct in_addr
));
846 snprintf(buf
, buflen
, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
847 bgp_vpn_rd_print(ndo
, rd
), ipaddr_string(ndo
, vpn_ip
), ipaddr_string(ndo
, pptr
));
849 return MDT_VPN_NLRI_LEN
+ 1;
856 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
857 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
858 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
859 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
860 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
861 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
862 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
864 static const struct tok bgp_multicast_vpn_route_type_values
[] = {
865 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
, "Intra-AS I-PMSI"},
866 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
, "Inter-AS I-PMSI"},
867 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
, "S-PMSI"},
868 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
, "Intra-AS Segment-Leaf"},
869 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
, "Source-Active"},
870 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
, "Shared Tree Join"},
871 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
, "Source Tree Join"},
875 decode_multicast_vpn(netdissect_options
*ndo
,
876 const u_char
*pptr
, char *buf
, u_int buflen
)
878 uint8_t route_type
, route_length
, addr_length
, sg_length
;
881 ND_TCHECK2(pptr
[0], 2);
882 route_type
= *pptr
++;
883 route_length
= *pptr
++;
885 snprintf(buf
, buflen
, "Route-Type: %s (%u), length: %u",
886 tok2str(bgp_multicast_vpn_route_type_values
,
887 "Unknown", route_type
),
888 route_type
, route_length
);
891 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI
:
892 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
893 offset
= strlen(buf
);
894 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Originator %s",
895 bgp_vpn_rd_print(ndo
, pptr
),
896 bgp_vpn_ip_print(ndo
, pptr
+ BGP_VPN_RD_LEN
,
897 (route_length
- BGP_VPN_RD_LEN
) << 3));
899 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI
:
900 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
+ 4);
901 offset
= strlen(buf
);
902 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
903 bgp_vpn_rd_print(ndo
, pptr
),
904 as_printf(ndo
, astostr
, sizeof(astostr
),
905 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
908 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI
:
909 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
910 offset
= strlen(buf
);
911 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
912 bgp_vpn_rd_print(ndo
, pptr
));
913 pptr
+= BGP_VPN_RD_LEN
;
915 sg_length
= bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
916 addr_length
= route_length
- sg_length
;
918 ND_TCHECK2(pptr
[0], addr_length
);
919 offset
= strlen(buf
);
920 snprintf(buf
+ offset
, buflen
- offset
, ", Originator %s",
921 bgp_vpn_ip_print(ndo
, pptr
, addr_length
<< 3));
924 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE
:
925 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
926 offset
= strlen(buf
);
927 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s",
928 bgp_vpn_rd_print(ndo
, pptr
));
929 pptr
+= BGP_VPN_RD_LEN
;
931 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
934 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN
: /* fall through */
935 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN
:
936 ND_TCHECK2(pptr
[0], BGP_VPN_RD_LEN
);
937 offset
= strlen(buf
);
938 snprintf(buf
+ offset
, buflen
- offset
, ", RD: %s, Source-AS %s",
939 bgp_vpn_rd_print(ndo
, pptr
),
940 as_printf(ndo
, astostr
, sizeof(astostr
),
941 EXTRACT_32BITS(pptr
+ BGP_VPN_RD_LEN
)));
942 pptr
+= BGP_VPN_RD_LEN
;
944 bgp_vpn_sg_print(ndo
, pptr
, buf
, buflen
);
948 * no per route-type printing yet.
950 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF
:
955 return route_length
+ 2;
962 * As I remember, some versions of systems have an snprintf() that
963 * returns -1 if the buffer would have overflowed. If the return
964 * value is negative, set buflen to 0, to indicate that we've filled
967 * If the return value is greater than buflen, that means that
968 * the buffer would have overflowed; again, set buflen to 0 in
971 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
974 else if ((u_int)stringlen>buflen) \
982 decode_labeled_vpn_l2(netdissect_options
*ndo
,
983 const u_char
*pptr
, char *buf
, u_int buflen
)
985 int plen
,tlen
,stringlen
,tlv_type
,tlv_len
,ttlv_len
;
987 ND_TCHECK2(pptr
[0], 2);
988 plen
=EXTRACT_16BITS(pptr
);
991 /* Old and new L2VPN NLRI share AFI/SAFI
992 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
993 * and > 17 as old format. Complain for the middle case
996 /* assume AD-only with RD, BGPNH */
997 ND_TCHECK2(pptr
[0],12);
999 stringlen
=snprintf(buf
, buflen
, "RD: %s, BGPNH: %s",
1000 bgp_vpn_rd_print(ndo
, pptr
),
1001 ipaddr_string(ndo
, pptr
+8)
1003 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1007 } else if (plen
>17) {
1008 /* assume old format */
1009 /* RD, ID, LBLKOFF, LBLBASE */
1011 ND_TCHECK2(pptr
[0],15);
1013 stringlen
=snprintf(buf
, buflen
, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1014 bgp_vpn_rd_print(ndo
, pptr
),
1015 EXTRACT_16BITS(pptr
+8),
1016 EXTRACT_16BITS(pptr
+10),
1017 EXTRACT_24BITS(pptr
+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1018 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1022 /* ok now the variable part - lets read out TLVs*/
1026 ND_TCHECK2(pptr
[0], 3);
1028 tlv_len
=EXTRACT_16BITS(pptr
);
1035 stringlen
=snprintf(buf
,buflen
, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1038 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1040 ttlv_len
=ttlv_len
/8+1; /* how many bytes do we need to read ? */
1041 while (ttlv_len
>0) {
1044 stringlen
=snprintf(buf
,buflen
, "%02x",*pptr
++);
1045 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1052 stringlen
=snprintf(buf
,buflen
, "\n\t\tunknown TLV #%u, length: %u",
1055 UPDATE_BUF_BUFLEN(buf
, buflen
, stringlen
);
1059 tlen
-=(tlv_len
<<3); /* the tlv-length is expressed in bits so lets shift it right */
1064 /* complain bitterly ? */
1074 decode_prefix6(netdissect_options
*ndo
,
1075 const u_char
*pd
, u_int itemlen
, char *buf
, u_int buflen
)
1077 struct in6_addr addr
;
1078 u_int plen
, plenbytes
;
1087 memset(&addr
, 0, sizeof(addr
));
1088 plenbytes
= (plen
+ 7) / 8;
1089 ND_TCHECK2(pd
[1], plenbytes
);
1090 ITEMCHECK(plenbytes
);
1091 memcpy(&addr
, &pd
[1], plenbytes
);
1093 addr
.s6_addr
[plenbytes
- 1] &=
1094 ((0xff00 >> (plen
% 8)) & 0xff);
1096 snprintf(buf
, buflen
, "%s/%d", ip6addr_string(ndo
, &addr
), plen
);
1097 return 1 + plenbytes
;
1107 decode_labeled_prefix6(netdissect_options
*ndo
,
1108 const u_char
*pptr
, u_int itemlen
, char *buf
, u_int buflen
)
1110 struct in6_addr addr
;
1111 u_int plen
, plenbytes
;
1113 /* prefix length and label = 4 bytes */
1114 ND_TCHECK2(pptr
[0], 4);
1116 plen
= pptr
[0]; /* get prefix length */
1121 plen
-=24; /* adjust prefixlen - labellength */
1127 memset(&addr
, 0, sizeof(addr
));
1128 plenbytes
= (plen
+ 7) / 8;
1129 ND_TCHECK2(pptr
[4], plenbytes
);
1130 memcpy(&addr
, &pptr
[4], plenbytes
);
1132 addr
.s6_addr
[plenbytes
- 1] &=
1133 ((0xff00 >> (plen
% 8)) & 0xff);
1135 /* the label may get offsetted by 4 bits so lets shift it right */
1136 snprintf(buf
, buflen
, "%s/%d, label:%u %s",
1137 ip6addr_string(ndo
, &addr
),
1139 EXTRACT_24BITS(pptr
+1)>>4,
1140 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1142 return 4 + plenbytes
;
1152 decode_labeled_vpn_prefix6(netdissect_options
*ndo
,
1153 const u_char
*pptr
, char *buf
, u_int buflen
)
1155 struct in6_addr addr
;
1159 plen
= pptr
[0]; /* get prefix length */
1164 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1169 memset(&addr
, 0, sizeof(addr
));
1170 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
1171 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1173 addr
.s6_addr
[(plen
+ 7) / 8 - 1] &=
1174 ((0xff00 >> (plen
% 8)) & 0xff);
1176 /* the label may get offsetted by 4 bits so lets shift it right */
1177 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1178 bgp_vpn_rd_print(ndo
, pptr
+4),
1179 ip6addr_string(ndo
, &addr
),
1181 EXTRACT_24BITS(pptr
+1)>>4,
1182 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1184 return 12 + (plen
+ 7) / 8;
1191 decode_clnp_prefix(netdissect_options
*ndo
,
1192 const u_char
*pptr
, char *buf
, u_int buflen
)
1198 plen
= pptr
[0]; /* get prefix length */
1203 memset(&addr
, 0, sizeof(addr
));
1204 ND_TCHECK2(pptr
[4], (plen
+ 7) / 8);
1205 memcpy(&addr
, &pptr
[4], (plen
+ 7) / 8);
1207 addr
[(plen
+ 7) / 8 - 1] &=
1208 ((0xff00 >> (plen
% 8)) & 0xff);
1210 snprintf(buf
, buflen
, "%s/%d",
1211 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1214 return 1 + (plen
+ 7) / 8;
1221 decode_labeled_vpn_clnp_prefix(netdissect_options
*ndo
,
1222 const u_char
*pptr
, char *buf
, u_int buflen
)
1228 plen
= pptr
[0]; /* get prefix length */
1233 plen
-=(24+64); /* adjust prefixlen - labellength - RD len*/
1238 memset(&addr
, 0, sizeof(addr
));
1239 ND_TCHECK2(pptr
[12], (plen
+ 7) / 8);
1240 memcpy(&addr
, &pptr
[12], (plen
+ 7) / 8);
1242 addr
[(plen
+ 7) / 8 - 1] &=
1243 ((0xff00 >> (plen
% 8)) & 0xff);
1245 /* the label may get offsetted by 4 bits so lets shift it right */
1246 snprintf(buf
, buflen
, "RD: %s, %s/%d, label:%u %s",
1247 bgp_vpn_rd_print(ndo
, pptr
+4),
1248 isonsap_string(ndo
, addr
,(plen
+ 7) / 8),
1250 EXTRACT_24BITS(pptr
+1)>>4,
1251 ((pptr
[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1253 return 12 + (plen
+ 7) / 8;
1260 * bgp_attr_get_as_size
1262 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1263 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1264 * support, exchange AS-Path with the same path-attribute type value 0x02.
1267 bgp_attr_get_as_size(netdissect_options
*ndo
,
1268 uint8_t bgpa_type
, const u_char
*pptr
, int len
)
1270 const u_char
*tptr
= pptr
;
1273 * If the path attribute is the optional AS4 path type, then we already
1274 * know, that ASs must be encoded in 4 byte format.
1276 if (bgpa_type
== BGPTYPE_AS4_PATH
) {
1281 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1282 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1285 while (tptr
< pptr
+ len
) {
1289 * If we do not find a valid segment type, our guess might be wrong.
1291 if (tptr
[0] < BGP_AS_SEG_TYPE_MIN
|| tptr
[0] > BGP_AS_SEG_TYPE_MAX
) {
1295 tptr
+= 2 + tptr
[1] * 2;
1299 * If we correctly reached end of the AS path attribute data content,
1300 * then most likely ASs were indeed encoded as 2 bytes.
1302 if (tptr
== pptr
+ len
) {
1309 * We can come here, either we did not have enough data, or if we
1310 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1311 * so that calller can try to decode each AS as of 4 bytes. If indeed
1312 * there was not enough data, it will crib and end the parse anyways.
1318 bgp_attr_print(netdissect_options
*ndo
,
1319 u_int atype
, const u_char
*pptr
, u_int len
)
1323 uint8_t safi
, snpa
, nhlen
;
1324 union { /* copy buffer for bandwidth values */
1331 char buf
[MAXHOSTNAMELEN
+ 100];
1338 case BGPTYPE_ORIGIN
:
1340 ND_PRINT((ndo
, "invalid len"));
1343 ND_PRINT((ndo
, "%s", tok2str(bgp_origin_values
,
1344 "Unknown Origin Typecode",
1351 * Process AS4 byte path and AS2 byte path attributes here.
1353 case BGPTYPE_AS4_PATH
:
1354 case BGPTYPE_AS_PATH
:
1356 ND_PRINT((ndo
, "invalid len"));
1360 ND_PRINT((ndo
, "empty"));
1365 * BGP updates exchanged between New speakers that support 4
1366 * byte AS, ASs are always encoded in 4 bytes. There is no
1367 * definitive way to find this, just by the packet's
1368 * contents. So, check for packet's TLV's sanity assuming
1369 * 2 bytes first, and it does not pass, assume that ASs are
1370 * encoded in 4 bytes format and move on.
1372 as_size
= bgp_attr_get_as_size(ndo
, atype
, pptr
, len
);
1374 while (tptr
< pptr
+ len
) {
1376 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_open_values
,
1378 for (i
= 0; i
< tptr
[1] * as_size
; i
+= as_size
) {
1379 ND_TCHECK2(tptr
[2 + i
], as_size
);
1380 ND_PRINT((ndo
, "%s ",
1381 as_printf(ndo
, astostr
, sizeof(astostr
),
1383 EXTRACT_16BITS(&tptr
[2 + i
]) :
1384 EXTRACT_32BITS(&tptr
[2 + i
]))));
1387 ND_PRINT((ndo
, "%s", tok2str(bgp_as_path_segment_close_values
,
1390 tptr
+= 2 + tptr
[1] * as_size
;
1393 case BGPTYPE_NEXT_HOP
:
1395 ND_PRINT((ndo
, "invalid len"));
1397 ND_TCHECK2(tptr
[0], 4);
1398 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1401 case BGPTYPE_MULTI_EXIT_DISC
:
1402 case BGPTYPE_LOCAL_PREF
:
1404 ND_PRINT((ndo
, "invalid len"));
1406 ND_TCHECK2(tptr
[0], 4);
1407 ND_PRINT((ndo
, "%u", EXTRACT_32BITS(tptr
)));
1410 case BGPTYPE_ATOMIC_AGGREGATE
:
1412 ND_PRINT((ndo
, "invalid len"));
1414 case BGPTYPE_AGGREGATOR
:
1417 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1418 * the length of this PA can be either 6 bytes or 8 bytes.
1420 if (len
!= 6 && len
!= 8) {
1421 ND_PRINT((ndo
, "invalid len"));
1424 ND_TCHECK2(tptr
[0], len
);
1426 ND_PRINT((ndo
, " AS #%s, origin %s",
1427 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_16BITS(tptr
)),
1428 ipaddr_string(ndo
, tptr
+ 2)));
1430 ND_PRINT((ndo
, " AS #%s, origin %s",
1431 as_printf(ndo
, astostr
, sizeof(astostr
),
1432 EXTRACT_32BITS(tptr
)), ipaddr_string(ndo
, tptr
+ 4)));
1435 case BGPTYPE_AGGREGATOR4
:
1437 ND_PRINT((ndo
, "invalid len"));
1440 ND_TCHECK2(tptr
[0], 8);
1441 ND_PRINT((ndo
, " AS #%s, origin %s",
1442 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(tptr
)),
1443 ipaddr_string(ndo
, tptr
+ 4)));
1445 case BGPTYPE_COMMUNITIES
:
1447 ND_PRINT((ndo
, "invalid len"));
1452 ND_TCHECK2(tptr
[0], 4);
1453 comm
= EXTRACT_32BITS(tptr
);
1455 case BGP_COMMUNITY_NO_EXPORT
:
1456 ND_PRINT((ndo
, " NO_EXPORT"));
1458 case BGP_COMMUNITY_NO_ADVERT
:
1459 ND_PRINT((ndo
, " NO_ADVERTISE"));
1461 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED
:
1462 ND_PRINT((ndo
, " NO_EXPORT_SUBCONFED"));
1465 ND_PRINT((ndo
, "%u:%u%s",
1466 (comm
>> 16) & 0xffff,
1468 (tlen
>4) ? ", " : ""));
1475 case BGPTYPE_ORIGINATOR_ID
:
1477 ND_PRINT((ndo
, "invalid len"));
1480 ND_TCHECK2(tptr
[0], 4);
1481 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1483 case BGPTYPE_CLUSTER_LIST
:
1485 ND_PRINT((ndo
, "invalid len"));
1489 ND_TCHECK2(tptr
[0], 4);
1490 ND_PRINT((ndo
, "%s%s",
1491 ipaddr_string(ndo
, tptr
),
1492 (tlen
>4) ? ", " : ""));
1497 case BGPTYPE_MP_REACH_NLRI
:
1498 ND_TCHECK2(tptr
[0], 3);
1499 af
= EXTRACT_16BITS(tptr
);
1502 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1503 tok2str(af_values
, "Unknown AFI", af
),
1505 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1506 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1509 switch(af
<<8 | safi
) {
1510 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1511 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1512 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1513 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1514 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1515 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1516 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1517 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1518 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1519 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1520 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1521 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1522 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1523 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1524 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1525 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1526 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1527 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1528 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1529 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1530 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1531 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1532 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1533 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1534 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1535 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1536 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1539 ND_TCHECK2(tptr
[0], tlen
);
1540 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1541 if (ndo
->ndo_vflag
<= 1)
1542 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1556 ND_PRINT((ndo
, "\n\t nexthop: "));
1559 ND_PRINT((ndo
, ", " ));
1561 switch(af
<<8 | safi
) {
1562 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1563 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1564 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1565 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1566 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1567 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
):
1568 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1569 if (tlen
< (int)sizeof(struct in_addr
)) {
1570 ND_PRINT((ndo
, "invalid len"));
1573 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1574 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, tptr
)));
1575 tlen
-= sizeof(struct in_addr
);
1576 tptr
+= sizeof(struct in_addr
);
1579 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1580 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1581 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1582 if (tlen
< (int)(sizeof(struct in_addr
)+BGP_VPN_RD_LEN
)) {
1583 ND_PRINT((ndo
, "invalid len"));
1586 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1587 ND_PRINT((ndo
, "RD: %s, %s",
1588 bgp_vpn_rd_print(ndo
, tptr
),
1589 ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
)));
1590 tlen
-= (sizeof(struct in_addr
)+BGP_VPN_RD_LEN
);
1591 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", ip6addr_string(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 ip6addr_string(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
);
1623 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1624 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1625 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1626 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1627 if (tlen
< (int)sizeof(struct in_addr
)) {
1628 ND_PRINT((ndo
, "invalid len"));
1631 ND_TCHECK2(tptr
[0], sizeof(struct in_addr
));
1632 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
)));
1633 tlen
-= (sizeof(struct in_addr
));
1634 tptr
+= (sizeof(struct in_addr
));
1637 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1638 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1639 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1640 ND_TCHECK2(tptr
[0], tlen
);
1641 ND_PRINT((ndo
, "%s", isonsap_string(ndo
, tptr
, tlen
)));
1646 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1647 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1648 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1649 if (tlen
< BGP_VPN_RD_LEN
+1) {
1650 ND_PRINT((ndo
, "invalid len"));
1653 ND_TCHECK2(tptr
[0], tlen
);
1654 ND_PRINT((ndo
, "RD: %s, %s",
1655 bgp_vpn_rd_print(ndo
, tptr
),
1656 isonsap_string(ndo
, tptr
+BGP_VPN_RD_LEN
,tlen
-BGP_VPN_RD_LEN
)));
1657 /* rfc986 mapped IPv4 address ? */
1658 if (EXTRACT_32BITS(tptr
+BGP_VPN_RD_LEN
) == 0x47000601)
1659 ND_PRINT((ndo
, " = %s", ipaddr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+4)));
1660 /* rfc1888 mapped IPv6 address ? */
1661 else if (EXTRACT_24BITS(tptr
+BGP_VPN_RD_LEN
) == 0x350000)
1662 ND_PRINT((ndo
, " = %s", ip6addr_string(ndo
, tptr
+BGP_VPN_RD_LEN
+3)));
1668 ND_TCHECK2(tptr
[0], tlen
);
1669 ND_PRINT((ndo
, "no AFI %u/SAFI %u decoder", af
, safi
));
1670 if (ndo
->ndo_vflag
<= 1)
1671 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1679 ND_PRINT((ndo
, ", nh-length: %u", nhlen
));
1687 ND_PRINT((ndo
, "\n\t %u SNPA", snpa
));
1688 for (/*nothing*/; snpa
> 0; snpa
--) {
1690 ND_PRINT((ndo
, "\n\t %d bytes", tptr
[0]));
1691 tptr
+= tptr
[0] + 1;
1694 ND_PRINT((ndo
, ", no SNPA"));
1697 while (len
- (tptr
- pptr
) > 0) {
1698 switch (af
<<8 | safi
) {
1699 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1700 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1701 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1702 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1704 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1705 else if (advance
== -2)
1707 else if (advance
== -3)
1708 break; /* bytes left, but not enough */
1710 ND_PRINT((ndo
, "\n\t %s", buf
));
1712 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1713 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1715 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1716 else if (advance
== -2)
1718 else if (advance
== -3)
1719 break; /* bytes left, but not enough */
1721 ND_PRINT((ndo
, "\n\t %s", buf
));
1723 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1724 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1725 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1726 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1728 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1729 else if (advance
== -2)
1732 ND_PRINT((ndo
, "\n\t %s", buf
));
1734 case (AFNUM_INET
<<8 | SAFNUM_RT_ROUTING_INFO
):
1735 advance
= decode_rt_routing_info(ndo
, tptr
, buf
, sizeof(buf
));
1737 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1738 else if (advance
== -2)
1741 ND_PRINT((ndo
, "\n\t %s", buf
));
1743 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST_VPN
): /* fall through */
1744 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1745 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1747 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1748 else if (advance
== -2)
1751 ND_PRINT((ndo
, "\n\t %s", buf
));
1754 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1755 advance
= decode_mdt_vpn_nlri(ndo
, tptr
, buf
, sizeof(buf
));
1757 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1758 else if (advance
== -2)
1761 ND_PRINT((ndo
, "\n\t %s", buf
));
1763 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1764 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1765 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1766 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1768 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1769 else if (advance
== -2)
1771 else if (advance
== -3)
1772 break; /* bytes left, but not enough */
1774 ND_PRINT((ndo
, "\n\t %s", buf
));
1776 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1777 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1779 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1780 else if (advance
== -2)
1782 else if (advance
== -3)
1783 break; /* bytes left, but not enough */
1785 ND_PRINT((ndo
, "\n\t %s", buf
));
1787 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1788 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1789 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1790 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1792 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1793 else if (advance
== -2)
1796 ND_PRINT((ndo
, "\n\t %s", buf
));
1798 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1799 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1800 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1801 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1802 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1804 ND_PRINT((ndo
, "\n\t (illegal length)"));
1805 else if (advance
== -2)
1808 ND_PRINT((ndo
, "\n\t %s", buf
));
1810 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1811 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1812 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1813 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1815 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1816 else if (advance
== -2)
1819 ND_PRINT((ndo
, "\n\t %s", buf
));
1821 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1822 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1823 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1824 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1826 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1827 else if (advance
== -2)
1830 ND_PRINT((ndo
, "\n\t %s", buf
));
1833 ND_TCHECK2(*tptr
,tlen
);
1834 ND_PRINT((ndo
, "\n\t no AFI %u / SAFI %u decoder", af
, safi
));
1835 if (ndo
->ndo_vflag
<= 1)
1836 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
1848 case BGPTYPE_MP_UNREACH_NLRI
:
1849 ND_TCHECK2(tptr
[0], BGP_MP_NLRI_MINSIZE
);
1850 af
= EXTRACT_16BITS(tptr
);
1853 ND_PRINT((ndo
, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1854 tok2str(af_values
, "Unknown AFI", af
),
1856 (safi
>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1857 tok2str(bgp_safi_values
, "Unknown SAFI", safi
),
1860 if (len
== BGP_MP_NLRI_MINSIZE
)
1861 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
1865 while (len
- (tptr
- pptr
) > 0) {
1866 switch (af
<<8 | safi
) {
1867 case (AFNUM_INET
<<8 | SAFNUM_UNICAST
):
1868 case (AFNUM_INET
<<8 | SAFNUM_MULTICAST
):
1869 case (AFNUM_INET
<<8 | SAFNUM_UNIMULTICAST
):
1870 advance
= decode_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1872 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1873 else if (advance
== -2)
1875 else if (advance
== -3)
1876 break; /* bytes left, but not enough */
1878 ND_PRINT((ndo
, "\n\t %s", buf
));
1880 case (AFNUM_INET
<<8 | SAFNUM_LABUNICAST
):
1881 advance
= decode_labeled_prefix4(ndo
, tptr
, len
, buf
, sizeof(buf
));
1883 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1884 else if (advance
== -2)
1886 else if (advance
== -3)
1887 break; /* bytes left, but not enough */
1889 ND_PRINT((ndo
, "\n\t %s", buf
));
1891 case (AFNUM_INET
<<8 | SAFNUM_VPNUNICAST
):
1892 case (AFNUM_INET
<<8 | SAFNUM_VPNMULTICAST
):
1893 case (AFNUM_INET
<<8 | SAFNUM_VPNUNIMULTICAST
):
1894 advance
= decode_labeled_vpn_prefix4(ndo
, tptr
, buf
, sizeof(buf
));
1896 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1897 else if (advance
== -2)
1900 ND_PRINT((ndo
, "\n\t %s", buf
));
1902 case (AFNUM_INET6
<<8 | SAFNUM_UNICAST
):
1903 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST
):
1904 case (AFNUM_INET6
<<8 | SAFNUM_UNIMULTICAST
):
1905 advance
= decode_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1907 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1908 else if (advance
== -2)
1910 else if (advance
== -3)
1911 break; /* bytes left, but not enough */
1913 ND_PRINT((ndo
, "\n\t %s", buf
));
1915 case (AFNUM_INET6
<<8 | SAFNUM_LABUNICAST
):
1916 advance
= decode_labeled_prefix6(ndo
, tptr
, len
, buf
, sizeof(buf
));
1918 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1919 else if (advance
== -2)
1921 else if (advance
== -3)
1922 break; /* bytes left, but not enough */
1924 ND_PRINT((ndo
, "\n\t %s", buf
));
1926 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNICAST
):
1927 case (AFNUM_INET6
<<8 | SAFNUM_VPNMULTICAST
):
1928 case (AFNUM_INET6
<<8 | SAFNUM_VPNUNIMULTICAST
):
1929 advance
= decode_labeled_vpn_prefix6(ndo
, tptr
, buf
, sizeof(buf
));
1931 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1932 else if (advance
== -2)
1935 ND_PRINT((ndo
, "\n\t %s", buf
));
1937 case (AFNUM_VPLS
<<8 | SAFNUM_VPLS
):
1938 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNICAST
):
1939 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNMULTICAST
):
1940 case (AFNUM_L2VPN
<<8 | SAFNUM_VPNUNIMULTICAST
):
1941 advance
= decode_labeled_vpn_l2(ndo
, tptr
, buf
, sizeof(buf
));
1943 ND_PRINT((ndo
, "\n\t (illegal length)"));
1944 else if (advance
== -2)
1947 ND_PRINT((ndo
, "\n\t %s", buf
));
1949 case (AFNUM_NSAP
<<8 | SAFNUM_UNICAST
):
1950 case (AFNUM_NSAP
<<8 | SAFNUM_MULTICAST
):
1951 case (AFNUM_NSAP
<<8 | SAFNUM_UNIMULTICAST
):
1952 advance
= decode_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1954 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1955 else if (advance
== -2)
1958 ND_PRINT((ndo
, "\n\t %s", buf
));
1960 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNICAST
):
1961 case (AFNUM_NSAP
<<8 | SAFNUM_VPNMULTICAST
):
1962 case (AFNUM_NSAP
<<8 | SAFNUM_VPNUNIMULTICAST
):
1963 advance
= decode_labeled_vpn_clnp_prefix(ndo
, tptr
, buf
, sizeof(buf
));
1965 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1966 else if (advance
== -2)
1969 ND_PRINT((ndo
, "\n\t %s", buf
));
1971 case (AFNUM_INET
<<8 | SAFNUM_MDT
):
1972 advance
= decode_mdt_vpn_nlri(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_MULTICAST_VPN
): /* fall through */
1981 case (AFNUM_INET6
<<8 | SAFNUM_MULTICAST_VPN
):
1982 advance
= decode_multicast_vpn(ndo
, tptr
, buf
, sizeof(buf
));
1984 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
1985 else if (advance
== -2)
1988 ND_PRINT((ndo
, "\n\t %s", buf
));
1991 ND_TCHECK2(*(tptr
-3),tlen
);
1992 ND_PRINT((ndo
, "no AFI %u / SAFI %u decoder", af
, safi
));
1993 if (ndo
->ndo_vflag
<= 1)
1994 print_unknown_data(ndo
, tptr
-3, "\n\t ", tlen
);
2004 case BGPTYPE_EXTD_COMMUNITIES
:
2006 ND_PRINT((ndo
, "invalid len"));
2012 ND_TCHECK2(tptr
[0], 2);
2013 extd_comm
=EXTRACT_16BITS(tptr
);
2015 ND_PRINT((ndo
, "\n\t %s (0x%04x), Flags [%s]",
2016 tok2str(bgp_extd_comm_subtype_values
,
2017 "unknown extd community typecode",
2020 bittok2str(bgp_extd_comm_flag_values
, "none", extd_comm
)));
2022 ND_TCHECK2(*(tptr
+2), 6);
2024 case BGP_EXT_COM_RT_0
:
2025 case BGP_EXT_COM_RO_0
:
2026 case BGP_EXT_COM_L2VPN_RT_0
:
2027 ND_PRINT((ndo
, ": %u:%u (= %s)",
2028 EXTRACT_16BITS(tptr
+2),
2029 EXTRACT_32BITS(tptr
+4),
2030 ipaddr_string(ndo
, tptr
+4)));
2032 case BGP_EXT_COM_RT_1
:
2033 case BGP_EXT_COM_RO_1
:
2034 case BGP_EXT_COM_L2VPN_RT_1
:
2035 case BGP_EXT_COM_VRF_RT_IMP
:
2036 ND_PRINT((ndo
, ": %s:%u",
2037 ipaddr_string(ndo
, tptr
+2),
2038 EXTRACT_16BITS(tptr
+6)));
2040 case BGP_EXT_COM_RT_2
:
2041 case BGP_EXT_COM_RO_2
:
2042 ND_PRINT((ndo
, ": %s:%u",
2043 as_printf(ndo
, astostr
, sizeof(astostr
),
2044 EXTRACT_32BITS(tptr
+2)), EXTRACT_16BITS(tptr
+6)));
2046 case BGP_EXT_COM_LINKBAND
:
2047 bw
.i
= EXTRACT_32BITS(tptr
+2);
2048 ND_PRINT((ndo
, ": bandwidth: %.3f Mbps",
2051 case BGP_EXT_COM_VPN_ORIGIN
:
2052 case BGP_EXT_COM_VPN_ORIGIN2
:
2053 case BGP_EXT_COM_VPN_ORIGIN3
:
2054 case BGP_EXT_COM_VPN_ORIGIN4
:
2055 case BGP_EXT_COM_OSPF_RID
:
2056 case BGP_EXT_COM_OSPF_RID2
:
2057 ND_PRINT((ndo
, "%s", ipaddr_string(ndo
, tptr
+2)));
2059 case BGP_EXT_COM_OSPF_RTYPE
:
2060 case BGP_EXT_COM_OSPF_RTYPE2
:
2061 ND_PRINT((ndo
, ": area:%s, router-type:%s, metric-type:%s%s",
2062 ipaddr_string(ndo
, tptr
+2),
2063 tok2str(bgp_extd_comm_ospf_rtype_values
,
2066 (*(tptr
+7) & BGP_OSPF_RTYPE_METRIC_TYPE
) ? "E2" : "",
2067 ((*(tptr
+6) == BGP_OSPF_RTYPE_EXT
) || (*(tptr
+6) == BGP_OSPF_RTYPE_NSSA
)) ? "E1" : ""));
2069 case BGP_EXT_COM_L2INFO
:
2070 ND_PRINT((ndo
, ": %s Control Flags [0x%02x]:MTU %u",
2071 tok2str(l2vpn_encaps_values
,
2075 EXTRACT_16BITS(tptr
+4)));
2077 case BGP_EXT_COM_SOURCE_AS
:
2078 ND_PRINT((ndo
, ": AS %u", EXTRACT_16BITS(tptr
+2)));
2081 ND_TCHECK2(*tptr
,8);
2082 print_unknown_data(ndo
, tptr
, "\n\t ", 8);
2090 case BGPTYPE_PMSI_TUNNEL
:
2092 uint8_t tunnel_type
, flags
;
2094 tunnel_type
= *(tptr
+1);
2098 ND_TCHECK2(tptr
[0], 5);
2099 ND_PRINT((ndo
, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2100 tok2str(bgp_pmsi_tunnel_values
, "Unknown", tunnel_type
),
2102 bittok2str(bgp_pmsi_flag_values
, "none", flags
),
2103 EXTRACT_24BITS(tptr
+2)>>4));
2108 switch (tunnel_type
) {
2109 case BGP_PMSI_TUNNEL_PIM_SM
: /* fall through */
2110 case BGP_PMSI_TUNNEL_PIM_BIDIR
:
2111 ND_TCHECK2(tptr
[0], 8);
2112 ND_PRINT((ndo
, "\n\t Sender %s, P-Group %s",
2113 ipaddr_string(ndo
, tptr
),
2114 ipaddr_string(ndo
, tptr
+4)));
2117 case BGP_PMSI_TUNNEL_PIM_SSM
:
2118 ND_TCHECK2(tptr
[0], 8);
2119 ND_PRINT((ndo
, "\n\t Root-Node %s, P-Group %s",
2120 ipaddr_string(ndo
, tptr
),
2121 ipaddr_string(ndo
, tptr
+4)));
2123 case BGP_PMSI_TUNNEL_INGRESS
:
2124 ND_TCHECK2(tptr
[0], 4);
2125 ND_PRINT((ndo
, "\n\t Tunnel-Endpoint %s",
2126 ipaddr_string(ndo
, tptr
)));
2128 case BGP_PMSI_TUNNEL_LDP_P2MP
: /* fall through */
2129 case BGP_PMSI_TUNNEL_LDP_MP2MP
:
2130 ND_TCHECK2(tptr
[0], 8);
2131 ND_PRINT((ndo
, "\n\t Root-Node %s, LSP-ID 0x%08x",
2132 ipaddr_string(ndo
, tptr
),
2133 EXTRACT_32BITS(tptr
+4)));
2135 case BGP_PMSI_TUNNEL_RSVP_P2MP
:
2136 ND_TCHECK2(tptr
[0], 8);
2137 ND_PRINT((ndo
, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2138 ipaddr_string(ndo
, tptr
),
2139 EXTRACT_32BITS(tptr
+4)));
2142 if (ndo
->ndo_vflag
<= 1) {
2143 print_unknown_data(ndo
, tptr
, "\n\t ", tlen
);
2153 ND_TCHECK2(tptr
[0], 3);
2160 length
= EXTRACT_16BITS(tptr
+1);
2162 ND_PRINT((ndo
, "\n\t %s TLV (%u), length %u",
2163 tok2str(bgp_aigp_values
, "Unknown", type
),
2168 * Check if we can read the TLV data.
2170 ND_TCHECK2(tptr
[3], length
- 3);
2175 ND_TCHECK2(tptr
[3], 8);
2176 ND_PRINT((ndo
, ", metric %" PRIu64
,
2177 EXTRACT_64BITS(tptr
+3)));
2181 if (ndo
->ndo_vflag
<= 1) {
2182 print_unknown_data(ndo
, tptr
+3,"\n\t ", length
-3);
2191 case BGPTYPE_ATTR_SET
:
2192 ND_TCHECK2(tptr
[0], 4);
2195 ND_PRINT((ndo
, "\n\t Origin AS: %s",
2196 as_printf(ndo
, astostr
, sizeof(astostr
), EXTRACT_32BITS(tptr
))));
2201 u_int aflags
, alenlen
, alen
;
2203 ND_TCHECK2(tptr
[0], 2);
2207 atype
= *(tptr
+ 1);
2210 alenlen
= bgp_attr_lenlen(aflags
, tptr
);
2211 ND_TCHECK2(tptr
[0], alenlen
);
2214 alen
= bgp_attr_len(aflags
, tptr
);
2218 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2219 tok2str(bgp_attr_values
,
2220 "Unknown Attribute", atype
),
2225 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2226 aflags
& 0x80 ? "O" : "",
2227 aflags
& 0x40 ? "T" : "",
2228 aflags
& 0x20 ? "P" : "",
2229 aflags
& 0x10 ? "E" : ""));
2231 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2232 ND_PRINT((ndo
, "]: "));
2234 /* FIXME check for recursion */
2235 if (!bgp_attr_print(ndo
, atype
, tptr
, alen
))
2244 ND_TCHECK2(*pptr
,len
);
2245 ND_PRINT((ndo
, "\n\t no Attribute %u decoder", atype
)); /* we have no decoder for the attribute */
2246 if (ndo
->ndo_vflag
<= 1)
2247 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2250 if (ndo
->ndo_vflag
> 1 && len
) { /* omit zero length attributes*/
2251 ND_TCHECK2(*pptr
,len
);
2252 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2261 bgp_capabilities_print(netdissect_options
*ndo
,
2262 const u_char
*opt
, int caps_len
)
2264 int cap_type
, cap_len
, tcap_len
, cap_offset
;
2267 while (i
< caps_len
) {
2268 ND_TCHECK2(opt
[i
], BGP_CAP_HEADER_SIZE
);
2272 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2273 tok2str(bgp_capcode_values
, "Unknown",
2277 ND_TCHECK2(opt
[i
+2], cap_len
);
2279 case BGP_CAPCODE_MP
:
2280 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u)",
2281 tok2str(af_values
, "Unknown",
2282 EXTRACT_16BITS(opt
+i
+2)),
2283 EXTRACT_16BITS(opt
+i
+2),
2284 tok2str(bgp_safi_values
, "Unknown",
2288 case BGP_CAPCODE_RESTART
:
2289 ND_PRINT((ndo
, "\n\t\tRestart Flags: [%s], Restart Time %us",
2290 ((opt
[i
+2])&0x80) ? "R" : "none",
2291 EXTRACT_16BITS(opt
+i
+2)&0xfff));
2294 while(tcap_len
>=4) {
2295 ND_PRINT((ndo
, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2296 tok2str(af_values
,"Unknown",
2297 EXTRACT_16BITS(opt
+i
+cap_offset
)),
2298 EXTRACT_16BITS(opt
+i
+cap_offset
),
2299 tok2str(bgp_safi_values
,"Unknown",
2300 opt
[i
+cap_offset
+2]),
2301 opt
[i
+cap_offset
+2],
2302 ((opt
[i
+cap_offset
+3])&0x80) ? "yes" : "no" ));
2307 case BGP_CAPCODE_RR
:
2308 case BGP_CAPCODE_RR_CISCO
:
2310 case BGP_CAPCODE_AS_NEW
:
2313 * Extract the 4 byte AS number encoded.
2316 ND_PRINT((ndo
, "\n\t\t 4 Byte AS %s",
2317 as_printf(ndo
, astostr
, sizeof(astostr
),
2318 EXTRACT_32BITS(opt
+ i
+ 2))));
2321 case BGP_CAPCODE_ADD_PATH
:
2323 if (tcap_len
== 0) {
2324 ND_PRINT((ndo
, " (bogus)")); /* length */
2327 while (tcap_len
> 0) {
2329 ND_PRINT((ndo
, "\n\t\t(invalid)"));
2332 ND_PRINT((ndo
, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2333 tok2str(af_values
,"Unknown",EXTRACT_16BITS(opt
+i
+cap_offset
)),
2334 EXTRACT_16BITS(opt
+i
+cap_offset
),
2335 tok2str(bgp_safi_values
,"Unknown",opt
[i
+cap_offset
+2]),
2336 opt
[i
+cap_offset
+2],
2337 tok2str(bgp_add_path_recvsend
,"Bogus (0x%02x)",opt
[i
+cap_offset
+3])
2344 ND_PRINT((ndo
, "\n\t\tno decoder for Capability %u",
2346 if (ndo
->ndo_vflag
<= 1)
2347 print_unknown_data(ndo
, &opt
[i
+2], "\n\t\t", cap_len
);
2350 if (ndo
->ndo_vflag
> 1 && cap_len
> 0) {
2351 print_unknown_data(ndo
, &opt
[i
+2], "\n\t\t", cap_len
);
2353 i
+= BGP_CAP_HEADER_SIZE
+ cap_len
;
2358 ND_PRINT((ndo
, "[|BGP]"));
2362 bgp_open_print(netdissect_options
*ndo
,
2363 const u_char
*dat
, int length
)
2365 struct bgp_open bgpo
;
2366 struct bgp_opt bgpopt
;
2370 ND_TCHECK2(dat
[0], BGP_OPEN_SIZE
);
2371 memcpy(&bgpo
, dat
, BGP_OPEN_SIZE
);
2373 ND_PRINT((ndo
, "\n\t Version %d, ", bgpo
.bgpo_version
));
2374 ND_PRINT((ndo
, "my AS %s, ",
2375 as_printf(ndo
, astostr
, sizeof(astostr
), ntohs(bgpo
.bgpo_myas
))));
2376 ND_PRINT((ndo
, "Holdtime %us, ", ntohs(bgpo
.bgpo_holdtime
)));
2377 ND_PRINT((ndo
, "ID %s", ipaddr_string(ndo
, &bgpo
.bgpo_id
)));
2378 ND_PRINT((ndo
, "\n\t Optional parameters, length: %u", bgpo
.bgpo_optlen
));
2380 /* some little sanity checking */
2381 if (length
< bgpo
.bgpo_optlen
+BGP_OPEN_SIZE
)
2385 opt
= &((const struct bgp_open
*)dat
)->bgpo_optlen
;
2389 while (i
< bgpo
.bgpo_optlen
) {
2390 ND_TCHECK2(opt
[i
], BGP_OPT_SIZE
);
2391 memcpy(&bgpopt
, &opt
[i
], BGP_OPT_SIZE
);
2392 if (i
+ 2 + bgpopt
.bgpopt_len
> bgpo
.bgpo_optlen
) {
2393 ND_PRINT((ndo
, "\n\t Option %d, length: %u", bgpopt
.bgpopt_type
, bgpopt
.bgpopt_len
));
2397 ND_PRINT((ndo
, "\n\t Option %s (%u), length: %u",
2398 tok2str(bgp_opt_values
,"Unknown",
2399 bgpopt
.bgpopt_type
),
2401 bgpopt
.bgpopt_len
));
2403 /* now let's decode the options we know*/
2404 switch(bgpopt
.bgpopt_type
) {
2407 bgp_capabilities_print(ndo
, &opt
[i
+BGP_OPT_SIZE
],
2413 ND_PRINT((ndo
, "\n\t no decoder for option %u",
2414 bgpopt
.bgpopt_type
));
2417 i
+= BGP_OPT_SIZE
+ bgpopt
.bgpopt_len
;
2421 ND_PRINT((ndo
, "[|BGP]"));
2425 bgp_update_print(netdissect_options
*ndo
,
2426 const u_char
*dat
, int length
)
2430 int withdrawn_routes_len
;
2434 ND_TCHECK2(dat
[0], BGP_SIZE
);
2435 if (length
< BGP_SIZE
)
2437 memcpy(&bgp
, dat
, BGP_SIZE
);
2438 p
= dat
+ BGP_SIZE
; /*XXX*/
2441 /* Unfeasible routes */
2442 ND_TCHECK2(p
[0], 2);
2445 withdrawn_routes_len
= EXTRACT_16BITS(p
);
2448 if (withdrawn_routes_len
) {
2450 * Without keeping state from the original NLRI message,
2451 * it's not possible to tell if this a v4 or v6 route,
2452 * so only try to decode it if we're not v6 enabled.
2454 ND_TCHECK2(p
[0], withdrawn_routes_len
);
2455 if (length
< withdrawn_routes_len
)
2457 ND_PRINT((ndo
, "\n\t Withdrawn routes: %d bytes", withdrawn_routes_len
));
2458 p
+= withdrawn_routes_len
;
2459 length
-= withdrawn_routes_len
;
2462 ND_TCHECK2(p
[0], 2);
2465 len
= EXTRACT_16BITS(p
);
2469 if (withdrawn_routes_len
== 0 && len
== 0 && length
== 0) {
2470 /* No withdrawn routes, no path attributes, no NLRI */
2471 ND_PRINT((ndo
, "\n\t End-of-Rib Marker (empty NLRI)"));
2476 /* do something more useful!*/
2478 int aflags
, atype
, alenlen
, alen
;
2480 ND_TCHECK2(p
[0], 2);
2490 alenlen
= bgp_attr_lenlen(aflags
, p
);
2491 ND_TCHECK2(p
[0], alenlen
);
2494 if (length
< alenlen
)
2496 alen
= bgp_attr_len(aflags
, p
);
2501 ND_PRINT((ndo
, "\n\t %s (%u), length: %u",
2502 tok2str(bgp_attr_values
, "Unknown Attribute",
2508 ND_PRINT((ndo
, ", Flags [%s%s%s%s",
2509 aflags
& 0x80 ? "O" : "",
2510 aflags
& 0x40 ? "T" : "",
2511 aflags
& 0x20 ? "P" : "",
2512 aflags
& 0x10 ? "E" : ""));
2514 ND_PRINT((ndo
, "+%x", aflags
& 0xf));
2515 ND_PRINT((ndo
, "]: "));
2521 if (!bgp_attr_print(ndo
, atype
, p
, alen
))
2531 * XXX - what if they're using the "Advertisement of
2532 * Multiple Paths in BGP" feature:
2534 * https://datatracker.ietf.org/doc/draft-ietf-idr-add-paths/
2536 * http://tools.ietf.org/html/draft-ietf-idr-add-paths-06
2538 ND_PRINT((ndo
, "\n\t Updated routes:"));
2540 char buf
[MAXHOSTNAMELEN
+ 100];
2541 i
= decode_prefix4(ndo
, p
, length
, buf
, sizeof(buf
));
2543 ND_PRINT((ndo
, "\n\t (illegal prefix length)"));
2548 goto trunc
; /* bytes left, but not enough */
2550 ND_PRINT((ndo
, "\n\t %s", buf
));
2558 ND_PRINT((ndo
, "[|BGP]"));
2562 bgp_notification_print(netdissect_options
*ndo
,
2563 const u_char
*dat
, int length
)
2565 struct bgp_notification bgpn
;
2568 ND_TCHECK2(dat
[0], BGP_NOTIFICATION_SIZE
);
2569 memcpy(&bgpn
, dat
, BGP_NOTIFICATION_SIZE
);
2571 /* some little sanity checking */
2572 if (length
<BGP_NOTIFICATION_SIZE
)
2575 ND_PRINT((ndo
, ", %s (%u)",
2576 tok2str(bgp_notify_major_values
, "Unknown Error",
2580 switch (bgpn
.bgpn_major
) {
2582 case BGP_NOTIFY_MAJOR_MSG
:
2583 ND_PRINT((ndo
, ", subcode %s (%u)",
2584 tok2str(bgp_notify_minor_msg_values
, "Unknown",
2588 case BGP_NOTIFY_MAJOR_OPEN
:
2589 ND_PRINT((ndo
, ", subcode %s (%u)",
2590 tok2str(bgp_notify_minor_open_values
, "Unknown",
2594 case BGP_NOTIFY_MAJOR_UPDATE
:
2595 ND_PRINT((ndo
, ", subcode %s (%u)",
2596 tok2str(bgp_notify_minor_update_values
, "Unknown",
2600 case BGP_NOTIFY_MAJOR_CAP
:
2601 ND_PRINT((ndo
, " subcode %s (%u)",
2602 tok2str(bgp_notify_minor_cap_values
, "Unknown",
2605 case BGP_NOTIFY_MAJOR_CEASE
:
2606 ND_PRINT((ndo
, ", subcode %s (%u)",
2607 tok2str(bgp_notify_minor_cease_values
, "Unknown",
2611 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2612 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2614 if(bgpn
.bgpn_minor
== BGP_NOTIFY_MINOR_CEASE_MAXPRFX
&& length
>= BGP_NOTIFICATION_SIZE
+ 7) {
2615 tptr
= dat
+ BGP_NOTIFICATION_SIZE
;
2616 ND_TCHECK2(*tptr
, 7);
2617 ND_PRINT((ndo
, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2618 tok2str(af_values
, "Unknown",
2619 EXTRACT_16BITS(tptr
)),
2620 EXTRACT_16BITS(tptr
),
2621 tok2str(bgp_safi_values
, "Unknown", *(tptr
+2)),
2623 EXTRACT_32BITS(tptr
+3)));
2632 ND_PRINT((ndo
, "[|BGP]"));
2636 bgp_route_refresh_print(netdissect_options
*ndo
,
2637 const u_char
*pptr
, int len
)
2639 const struct bgp_route_refresh
*bgp_route_refresh_header
;
2641 ND_TCHECK2(pptr
[0], BGP_ROUTE_REFRESH_SIZE
);
2643 /* some little sanity checking */
2644 if (len
<BGP_ROUTE_REFRESH_SIZE
)
2647 bgp_route_refresh_header
= (const struct bgp_route_refresh
*)pptr
;
2649 ND_PRINT((ndo
, "\n\t AFI %s (%u), SAFI %s (%u)",
2650 tok2str(af_values
,"Unknown",
2651 /* this stinks but the compiler pads the structure
2653 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
)),
2654 EXTRACT_16BITS(&bgp_route_refresh_header
->afi
),
2655 tok2str(bgp_safi_values
,"Unknown",
2656 bgp_route_refresh_header
->safi
),
2657 bgp_route_refresh_header
->safi
));
2659 if (ndo
->ndo_vflag
> 1) {
2660 ND_TCHECK2(*pptr
, len
);
2661 print_unknown_data(ndo
, pptr
, "\n\t ", len
);
2666 ND_PRINT((ndo
, "[|BGP]"));
2670 bgp_header_print(netdissect_options
*ndo
,
2671 const u_char
*dat
, int length
)
2675 ND_TCHECK2(dat
[0], BGP_SIZE
);
2676 memcpy(&bgp
, dat
, BGP_SIZE
);
2677 ND_PRINT((ndo
, "\n\t%s Message (%u), length: %u",
2678 tok2str(bgp_msg_values
, "Unknown", bgp
.bgp_type
),
2682 switch (bgp
.bgp_type
) {
2684 bgp_open_print(ndo
, dat
, length
);
2687 bgp_update_print(ndo
, dat
, length
);
2689 case BGP_NOTIFICATION
:
2690 bgp_notification_print(ndo
, dat
, length
);
2694 case BGP_ROUTE_REFRESH
:
2695 bgp_route_refresh_print(ndo
, dat
, length
);
2698 /* we have no decoder for the BGP message */
2699 ND_TCHECK2(*dat
, length
);
2700 ND_PRINT((ndo
, "\n\t no Message %u decoder", bgp
.bgp_type
));
2701 print_unknown_data(ndo
, dat
, "\n\t ", length
);
2706 ND_PRINT((ndo
, "[|BGP]"));
2711 bgp_print(netdissect_options
*ndo
,
2712 const u_char
*dat
, int length
)
2716 const u_char
*start
;
2717 const u_char marker
[] = {
2718 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2719 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2725 if (ndo
->ndo_snapend
< dat
+ length
)
2726 ep
= ndo
->ndo_snapend
;
2728 ND_PRINT((ndo
, ": BGP"));
2730 if (ndo
->ndo_vflag
< 1) /* lets be less chatty */
2736 if (!ND_TTEST2(p
[0], 1))
2743 if (!ND_TTEST2(p
[0], sizeof(marker
)))
2745 if (memcmp(p
, marker
, sizeof(marker
)) != 0) {
2750 /* found BGP header */
2751 ND_TCHECK2(p
[0], BGP_SIZE
); /*XXX*/
2752 memcpy(&bgp
, p
, BGP_SIZE
);
2755 ND_PRINT((ndo
, " [|BGP]"));
2757 hlen
= ntohs(bgp
.bgp_len
);
2758 if (hlen
< BGP_SIZE
) {
2759 ND_PRINT((ndo
, "\n[|BGP Bogus header length %u < %u]", hlen
,
2764 if (ND_TTEST2(p
[0], hlen
)) {
2765 if (!bgp_header_print(ndo
, p
, hlen
))
2770 ND_PRINT((ndo
, "\n[|BGP %s]",
2771 tok2str(bgp_msg_values
,
2772 "Unknown Message Type",
2781 ND_PRINT((ndo
, " [|BGP]"));
2786 * c-style: whitesmith