2 * Copyright (C) 1999 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Extensively modified by Hannes Gredler (hannes@gredler.at) for more
30 * complete BGP support.
33 /* \summary: Border Gateway Protocol (BGP) printer */
39 #include <netdissect-stdinc.h>
44 #include "netdissect.h"
45 #include "addrtoname.h"
50 static const char tstr[] = "[|BGP]";
53 uint8_t bgp_marker[16];
57 #define BGP_SIZE 19 /* unaligned */
61 #define BGP_NOTIFICATION 3
62 #define BGP_KEEPALIVE 4
63 #define BGP_ROUTE_REFRESH 5
65 static const struct tok bgp_msg_values[] = {
67 { BGP_UPDATE, "Update"},
68 { BGP_NOTIFICATION, "Notification"},
69 { BGP_KEEPALIVE, "Keepalive"},
70 { BGP_ROUTE_REFRESH, "Route Refresh"},
75 uint8_t bgpo_marker[16];
80 uint16_t bgpo_holdtime;
83 /* options should follow */
85 #define BGP_OPEN_SIZE 29 /* unaligned */
92 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
93 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
95 struct bgp_notification {
96 uint8_t bgpn_marker[16];
102 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
104 struct bgp_route_refresh {
105 uint8_t bgp_marker[16];
108 uint8_t afi[2]; /* the compiler messes this structure up */
109 uint8_t res; /* when doing misaligned sequences of int8 and int16 */
110 uint8_t safi; /* afi should be int16 - so we have to access it using */
111 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
112 #define BGP_ROUTE_REFRESH_SIZE 23
114 #define bgp_attr_lenlen(flags, p) \
115 (((flags) & 0x10) ? 2 : 1)
116 #define bgp_attr_len(flags, p) \
117 (((flags) & 0x10) ? EXTRACT_16BITS(p) : *(p))
119 #define BGPTYPE_ORIGIN 1
120 #define BGPTYPE_AS_PATH 2
121 #define BGPTYPE_NEXT_HOP 3
122 #define BGPTYPE_MULTI_EXIT_DISC 4
123 #define BGPTYPE_LOCAL_PREF 5
124 #define BGPTYPE_ATOMIC_AGGREGATE 6
125 #define BGPTYPE_AGGREGATOR 7
126 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
127 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC4456 */
128 #define BGPTYPE_CLUSTER_LIST 10 /* RFC4456 */
129 #define BGPTYPE_DPA 11 /* deprecated, draft-ietf-idr-bgp-dpa */
130 #define BGPTYPE_ADVERTISERS 12 /* deprecated RFC1863 */
131 #define BGPTYPE_RCID_PATH 13 /* deprecated RFC1863 */
132 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */
133 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */
134 #define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */
135 #define BGPTYPE_AS4_PATH 17 /* RFC6793 */
136 #define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */
137 #define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */
138 #define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */
139 #define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */
140 #define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */
141 #define BGPTYPE_AIGP 26 /* RFC7311 */
142 #define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */
143 #define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */
144 #define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */
145 #define BGPTYPE_ATTR_SET 128 /* RFC6368 */
147 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
149 static const struct tok bgp_attr_values[] = {
150 { BGPTYPE_ORIGIN, "Origin"},
151 { BGPTYPE_AS_PATH, "AS Path"},
152 { BGPTYPE_AS4_PATH, "AS4 Path"},
153 { BGPTYPE_NEXT_HOP, "Next Hop"},
154 { BGPTYPE_MULTI_EXIT_DISC, "Multi Exit Discriminator"},
155 { BGPTYPE_LOCAL_PREF, "Local Preference"},
156 { BGPTYPE_ATOMIC_AGGREGATE, "Atomic Aggregate"},
157 { BGPTYPE_AGGREGATOR, "Aggregator"},
158 { BGPTYPE_AGGREGATOR4, "Aggregator4"},
159 { BGPTYPE_COMMUNITIES, "Community"},
160 { BGPTYPE_ORIGINATOR_ID, "Originator ID"},
161 { BGPTYPE_CLUSTER_LIST, "Cluster List"},
162 { BGPTYPE_DPA, "DPA"},
163 { BGPTYPE_ADVERTISERS, "Advertisers"},
164 { BGPTYPE_RCID_PATH, "RCID Path / Cluster ID"},
165 { BGPTYPE_MP_REACH_NLRI, "Multi-Protocol Reach NLRI"},
166 { BGPTYPE_MP_UNREACH_NLRI, "Multi-Protocol Unreach NLRI"},
167 { BGPTYPE_EXTD_COMMUNITIES, "Extended Community"},
168 { BGPTYPE_PMSI_TUNNEL, "PMSI Tunnel"},
169 { BGPTYPE_TUNNEL_ENCAP, "Tunnel Encapsulation"},
170 { BGPTYPE_TRAFFIC_ENG, "Traffic Engineering"},
171 { BGPTYPE_IPV6_EXTD_COMMUNITIES, "IPv6 Extended Community"},
172 { BGPTYPE_AIGP, "Accumulated IGP Metric"},
173 { BGPTYPE_PE_DISTINGUISHER_LABEL, "PE Distinguisher Label"},
174 { BGPTYPE_ENTROPY_LABEL, "Entropy Label"},
175 { BGPTYPE_LARGE_COMMUNITY, "Large Community"},
176 { BGPTYPE_ATTR_SET, "Attribute Set"},
177 { 255, "Reserved for development"},
182 #define BGP_AS_SEQUENCE 2
183 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
184 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
186 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
187 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
189 static const struct tok bgp_as_path_segment_open_values[] = {
190 { BGP_AS_SEQUENCE, ""},
192 { BGP_CONFED_AS_SEQUENCE, "( "},
193 { BGP_CONFED_AS_SET, "({ "},
197 static const struct tok bgp_as_path_segment_close_values[] = {
198 { BGP_AS_SEQUENCE, ""},
200 { BGP_CONFED_AS_SEQUENCE, ")"},
201 { BGP_CONFED_AS_SET, "})"},
205 #define BGP_OPT_AUTH 1
206 #define BGP_OPT_CAP 2
208 static const struct tok bgp_opt_values[] = {
209 { BGP_OPT_AUTH, "Authentication Information"},
210 { BGP_OPT_CAP, "Capabilities Advertisement"},
214 #define BGP_CAPCODE_MP 1 /* RFC2858 */
215 #define BGP_CAPCODE_RR 2 /* RFC2918 */
216 #define BGP_CAPCODE_ORF 3 /* RFC5291 */
217 #define BGP_CAPCODE_MR 4 /* RFC3107 */
218 #define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */
219 #define BGP_CAPCODE_RESTART 64 /* RFC4724 */
220 #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */
221 #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */
222 #define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */
223 #define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */
224 #define BGP_CAPCODE_ENH_RR 70 /* draft-keyur-bgp-enhanced-route-refresh */
225 #define BGP_CAPCODE_RR_CISCO 128
227 static const struct tok bgp_capcode_values[] = {
228 { BGP_CAPCODE_MP, "Multiprotocol Extensions"},
229 { BGP_CAPCODE_RR, "Route Refresh"},
230 { BGP_CAPCODE_ORF, "Cooperative Route Filtering"},
231 { BGP_CAPCODE_MR, "Multiple Routes to a Destination"},
232 { BGP_CAPCODE_EXT_NH, "Extended Next Hop Encoding"},
233 { BGP_CAPCODE_RESTART, "Graceful Restart"},
234 { BGP_CAPCODE_AS_NEW, "32-Bit AS Number"},
235 { BGP_CAPCODE_DYN_CAP, "Dynamic Capability"},
236 { BGP_CAPCODE_MULTISESS, "Multisession BGP"},
237 { BGP_CAPCODE_ADD_PATH, "Multiple Paths"},
238 { BGP_CAPCODE_ENH_RR, "Enhanced Route Refresh"},
239 { BGP_CAPCODE_RR_CISCO, "Route Refresh (Cisco)"},
243 #define BGP_NOTIFY_MAJOR_MSG 1
244 #define BGP_NOTIFY_MAJOR_OPEN 2
245 #define BGP_NOTIFY_MAJOR_UPDATE 3
246 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
247 #define BGP_NOTIFY_MAJOR_FSM 5
248 #define BGP_NOTIFY_MAJOR_CEASE 6
249 #define BGP_NOTIFY_MAJOR_CAP 7
251 static const struct tok bgp_notify_major_values[] = {
252 { BGP_NOTIFY_MAJOR_MSG, "Message Header Error"},
253 { BGP_NOTIFY_MAJOR_OPEN, "OPEN Message Error"},
254 { BGP_NOTIFY_MAJOR_UPDATE, "UPDATE Message Error"},
255 { BGP_NOTIFY_MAJOR_HOLDTIME,"Hold Timer Expired"},
256 { BGP_NOTIFY_MAJOR_FSM, "Finite State Machine Error"},
257 { BGP_NOTIFY_MAJOR_CEASE, "Cease"},
258 { BGP_NOTIFY_MAJOR_CAP, "Capability Message Error"},
262 /* draft-ietf-idr-cease-subcode-02 */
263 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
264 static const struct tok bgp_notify_minor_cease_values[] = {
265 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX, "Maximum Number of Prefixes Reached"},
266 { 2, "Administratively Shutdown"},
267 { 3, "Peer Unconfigured"},
268 { 4, "Administratively Reset"},
269 { 5, "Connection Rejected"},
270 { 6, "Other Configuration Change"},
271 { 7, "Connection Collision Resolution"},
275 static const struct tok bgp_notify_minor_msg_values[] = {
276 { 1, "Connection Not Synchronized"},
277 { 2, "Bad Message Length"},
278 { 3, "Bad Message Type"},
282 static const struct tok bgp_notify_minor_open_values[] = {
283 { 1, "Unsupported Version Number"},
285 { 3, "Bad BGP Identifier"},
286 { 4, "Unsupported Optional Parameter"},
287 { 5, "Authentication Failure"},
288 { 6, "Unacceptable Hold Time"},
289 { 7, "Capability Message Error"},
293 static const struct tok bgp_notify_minor_update_values[] = {
294 { 1, "Malformed Attribute List"},
295 { 2, "Unrecognized Well-known Attribute"},
296 { 3, "Missing Well-known Attribute"},
297 { 4, "Attribute Flags Error"},
298 { 5, "Attribute Length Error"},
299 { 6, "Invalid ORIGIN Attribute"},
300 { 7, "AS Routing Loop"},
301 { 8, "Invalid NEXT_HOP Attribute"},
302 { 9, "Optional Attribute Error"},
303 { 10, "Invalid Network Field"},
304 { 11, "Malformed AS_PATH"},
308 static const struct tok bgp_notify_minor_fsm_values[] = {
309 { 1, "In OpenSent State"},
310 { 2, "In OpenConfirm State"},
311 { 3, "In Established State"},
315 static const struct tok bgp_notify_minor_cap_values[] = {
316 { 1, "Invalid Action Value" },
317 { 2, "Invalid Capability Length" },
318 { 3, "Malformed Capability Value" },
319 { 4, "Unsupported Capability Code" },
323 static const struct tok bgp_origin_values[] = {
330 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
331 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
332 #define BGP_PMSI_TUNNEL_PIM_SSM 3
333 #define BGP_PMSI_TUNNEL_PIM_SM 4
334 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
335 #define BGP_PMSI_TUNNEL_INGRESS 6
336 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
338 static const struct tok bgp_pmsi_tunnel_values[] = {
339 { BGP_PMSI_TUNNEL_RSVP_P2MP, "RSVP-TE P2MP LSP"},
340 { BGP_PMSI_TUNNEL_LDP_P2MP, "LDP P2MP LSP"},
341 { BGP_PMSI_TUNNEL_PIM_SSM, "PIM-SSM Tree"},
342 { BGP_PMSI_TUNNEL_PIM_SM, "PIM-SM Tree"},
343 { BGP_PMSI_TUNNEL_PIM_BIDIR, "PIM-Bidir Tree"},
344 { BGP_PMSI_TUNNEL_INGRESS, "Ingress Replication"},
345 { BGP_PMSI_TUNNEL_LDP_MP2MP, "LDP MP2MP LSP"},
349 static const struct tok bgp_pmsi_flag_values[] = {
350 { 0x01, "Leaf Information required"},
354 #define BGP_AIGP_TLV 1
356 static const struct tok bgp_aigp_values[] = {
357 { BGP_AIGP_TLV, "AIGP"},
361 /* Subsequent address family identifier, RFC2283 section 7 */
363 #define SAFNUM_UNICAST 1
364 #define SAFNUM_MULTICAST 2
365 #define SAFNUM_UNIMULTICAST 3 /* deprecated now */
366 /* labeled BGP RFC3107 */
367 #define SAFNUM_LABUNICAST 4
369 #define SAFNUM_MULTICAST_VPN 5
370 /* draft-nalawade-kapoor-tunnel-safi */
371 #define SAFNUM_TUNNEL 64
373 #define SAFNUM_VPLS 65
375 #define SAFNUM_MDT 66
377 #define SAFNUM_VPNUNICAST 128
379 #define SAFNUM_VPNMULTICAST 129
380 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
382 #define SAFNUM_RT_ROUTING_INFO 132
384 #define BGP_VPN_RD_LEN 8
386 static const struct tok bgp_safi_values[] = {
387 { SAFNUM_RES, "Reserved"},
388 { SAFNUM_UNICAST, "Unicast"},
389 { SAFNUM_MULTICAST, "Multicast"},
390 { SAFNUM_UNIMULTICAST, "Unicast+Multicast"},
391 { SAFNUM_LABUNICAST, "labeled Unicast"},
392 { SAFNUM_TUNNEL, "Tunnel"},
393 { SAFNUM_VPLS, "VPLS"},
394 { SAFNUM_MDT, "MDT"},
395 { SAFNUM_VPNUNICAST, "labeled VPN Unicast"},
396 { SAFNUM_VPNMULTICAST, "labeled VPN Multicast"},
397 { SAFNUM_VPNUNIMULTICAST, "labeled VPN Unicast+Multicast"},
398 { SAFNUM_RT_ROUTING_INFO, "Route Target Routing Information"},
399 { SAFNUM_MULTICAST_VPN, "Multicast VPN"},
403 /* well-known community */
404 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
405 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
406 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
408 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
409 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
410 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
411 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
412 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
413 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
414 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
415 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
416 /* rfc2547 bgp-mpls-vpns */
417 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
418 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
419 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
420 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
422 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
423 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
425 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
426 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
428 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
430 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
431 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
432 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
433 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
435 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
436 #define BGP_EXT_COM_EIGRP_GEN 0x8800
437 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
438 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
439 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
440 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
441 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
443 static const struct tok bgp_extd_comm_flag_values[] = {
444 { 0x8000, "vendor-specific"},
445 { 0x4000, "non-transitive"},
449 static const struct tok bgp_extd_comm_subtype_values[] = {
450 { BGP_EXT_COM_RT_0, "target"},
451 { BGP_EXT_COM_RT_1, "target"},
452 { BGP_EXT_COM_RT_2, "target"},
453 { BGP_EXT_COM_RO_0, "origin"},
454 { BGP_EXT_COM_RO_1, "origin"},
455 { BGP_EXT_COM_RO_2, "origin"},
456 { BGP_EXT_COM_LINKBAND, "link-BW"},
457 { BGP_EXT_COM_VPN_ORIGIN, "ospf-domain"},
458 { BGP_EXT_COM_VPN_ORIGIN2, "ospf-domain"},
459 { BGP_EXT_COM_VPN_ORIGIN3, "ospf-domain"},
460 { BGP_EXT_COM_VPN_ORIGIN4, "ospf-domain"},
461 { BGP_EXT_COM_OSPF_RTYPE, "ospf-route-type"},
462 { BGP_EXT_COM_OSPF_RTYPE2, "ospf-route-type"},
463 { BGP_EXT_COM_OSPF_RID, "ospf-router-id"},
464 { BGP_EXT_COM_OSPF_RID2, "ospf-router-id"},
465 { BGP_EXT_COM_L2INFO, "layer2-info"},
466 { BGP_EXT_COM_EIGRP_GEN , "eigrp-general-route (flag, tag)" },
467 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY , "eigrp-route-metric (AS, delay)" },
468 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW , "eigrp-route-metric (reliability, nexthop, bandwidth)" },
469 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU , "eigrp-route-metric (load, MTU)" },
470 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID , "eigrp-external-route (remote-AS, remote-ID)" },
471 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC , "eigrp-external-route (remote-proto, remote-metric)" },
472 { BGP_EXT_COM_SOURCE_AS, "source-AS" },
473 { BGP_EXT_COM_VRF_RT_IMP, "vrf-route-import"},
474 { BGP_EXT_COM_L2VPN_RT_0, "l2vpn-id"},
475 { BGP_EXT_COM_L2VPN_RT_1, "l2vpn-id"},
479 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
480 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
481 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
482 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
483 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
484 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
485 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
486 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
488 static const struct tok bgp_extd_comm_ospf_rtype_values[] = {
489 { BGP_OSPF_RTYPE_RTR, "Router" },
490 { BGP_OSPF_RTYPE_NET, "Network" },
491 { BGP_OSPF_RTYPE_SUM, "Summary" },
492 { BGP_OSPF_RTYPE_EXT, "External" },
493 { BGP_OSPF_RTYPE_NSSA,"NSSA External" },
494 { BGP_OSPF_RTYPE_SHAM,"MPLS-VPN Sham" },
498 /* ADD-PATH Send/Receive field values */
499 static const struct tok bgp_add_path_recvsend[] = {
506 static char astostr[20];
511 * Convert an AS number into a string and return string pointer.
513 * Depending on bflag is set or not, AS number is converted into ASDOT notation
514 * or plain number notation.
518 as_printf(netdissect_options *ndo,
519 char *str, int size, u_int asnum)
521 if (!ndo->ndo_bflag || asnum <= 0xFFFF) {
522 snprintf(str, size, "%u", asnum);
524 snprintf(str, size, "%u.%u", asnum >> 16, asnum & 0xFFFF);
529 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
532 decode_prefix4(netdissect_options *ndo,
533 const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
536 u_int plen, plenbytes;
545 memset(&addr, 0, sizeof(addr));
546 plenbytes = (plen + 7) / 8;
547 ND_TCHECK2(pptr[1], plenbytes);
548 ITEMCHECK(plenbytes);
549 memcpy(&addr, &pptr[1], plenbytes);
551 ((u_char *)&addr)[plenbytes - 1] &=
552 ((0xff00 >> (plen % 8)) & 0xff);
554 snprintf(buf, buflen, "%s/%d", ipaddr_string(ndo, &addr), plen);
555 return 1 + plenbytes;
565 decode_labeled_prefix4(netdissect_options *ndo,
566 const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
569 u_int plen, plenbytes;
571 /* prefix length and label = 4 bytes */
572 ND_TCHECK2(pptr[0], 4);
574 plen = pptr[0]; /* get prefix length */
576 /* this is one of the weirdnesses of rfc3107
577 the label length (actually the label + COS bits)
578 is added to the prefix length;
579 we also do only read out just one label -
580 there is no real application for advertisement of
581 stacked labels in a single BGP message
587 plen-=24; /* adjust prefixlen - labellength */
593 memset(&addr, 0, sizeof(addr));
594 plenbytes = (plen + 7) / 8;
595 ND_TCHECK2(pptr[4], plenbytes);
596 ITEMCHECK(plenbytes);
597 memcpy(&addr, &pptr[4], plenbytes);
599 ((u_char *)&addr)[plenbytes - 1] &=
600 ((0xff00 >> (plen % 8)) & 0xff);
602 /* the label may get offsetted by 4 bits so lets shift it right */
603 snprintf(buf, buflen, "%s/%d, label:%u %s",
604 ipaddr_string(ndo, &addr),
606 EXTRACT_24BITS(pptr+1)>>4,
607 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
609 return 4 + plenbytes;
621 * print an ipv4 or ipv6 address into a buffer dependend on address length.
624 bgp_vpn_ip_print(netdissect_options *ndo,
625 const u_char *pptr, u_int addr_length)
628 /* worst case string is s fully formatted v6 address */
629 static char addr[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
632 switch(addr_length) {
633 case (sizeof(struct in_addr) << 3): /* 32 */
634 ND_TCHECK2(pptr[0], sizeof(struct in_addr));
635 snprintf(pos, sizeof(addr), "%s", ipaddr_string(ndo, pptr));
637 case (sizeof(struct in6_addr) << 3): /* 128 */
638 ND_TCHECK2(pptr[0], sizeof(struct in6_addr));
639 snprintf(pos, sizeof(addr), "%s", ip6addr_string(ndo, pptr));
642 snprintf(pos, sizeof(addr), "bogus address length %u", addr_length);
655 * print an multicast s,g entry into a buffer.
656 * the s,g entry is encoded like this.
658 * +-----------------------------------+
659 * | Multicast Source Length (1 octet) |
660 * +-----------------------------------+
661 * | Multicast Source (Variable) |
662 * +-----------------------------------+
663 * | Multicast Group Length (1 octet) |
664 * +-----------------------------------+
665 * | Multicast Group (Variable) |
666 * +-----------------------------------+
668 * return the number of bytes read from the wire.
671 bgp_vpn_sg_print(netdissect_options *ndo,
672 const u_char *pptr, char *buf, u_int buflen)
675 u_int total_length, offset;
679 /* Source address length, encoded in bits */
680 ND_TCHECK2(pptr[0], 1);
681 addr_length = *pptr++;
684 ND_TCHECK2(pptr[0], (addr_length >> 3));
685 total_length += (addr_length >> 3) + 1;
686 offset = strlen(buf);
688 snprintf(buf + offset, buflen - offset, ", Source %s",
689 bgp_vpn_ip_print(ndo, pptr, addr_length));
690 pptr += (addr_length >> 3);
693 /* Group address length, encoded in bits */
694 ND_TCHECK2(pptr[0], 1);
695 addr_length = *pptr++;
698 ND_TCHECK2(pptr[0], (addr_length >> 3));
699 total_length += (addr_length >> 3) + 1;
700 offset = strlen(buf);
702 snprintf(buf + offset, buflen - offset, ", Group %s",
703 bgp_vpn_ip_print(ndo, pptr, addr_length));
704 pptr += (addr_length >> 3);
708 return (total_length);
711 /* RDs and RTs share the same semantics
712 * we use bgp_vpn_rd_print for
713 * printing route targets inside a NLRI */
715 bgp_vpn_rd_print(netdissect_options *ndo,
718 /* allocate space for the largest possible string */
719 static char rd[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
722 /* ok lets load the RD format */
723 switch (EXTRACT_16BITS(pptr)) {
725 /* 2-byte-AS:number fmt*/
727 snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u (= %u.%u.%u.%u)",
728 EXTRACT_16BITS(pptr+2),
729 EXTRACT_32BITS(pptr+4),
730 *(pptr+4), *(pptr+5), *(pptr+6), *(pptr+7));
732 /* IP-address:AS fmt*/
735 snprintf(pos, sizeof(rd) - (pos - rd), "%u.%u.%u.%u:%u",
736 *(pptr+2), *(pptr+3), *(pptr+4), *(pptr+5), EXTRACT_16BITS(pptr+6));
739 /* 4-byte-AS:number fmt*/
741 snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)",
742 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(pptr+2)),
743 EXTRACT_16BITS(pptr+6), *(pptr+2), *(pptr+3), *(pptr+4),
744 *(pptr+5), EXTRACT_16BITS(pptr+6));
747 snprintf(pos, sizeof(rd) - (pos - rd), "unknown RD format");
756 decode_rt_routing_info(netdissect_options *ndo,
757 const u_char *pptr, char *buf, u_int buflen)
759 uint8_t route_target[8];
761 char asbuf[sizeof(astostr)]; /* bgp_vpn_rd_print() overwrites astostr */
763 /* NLRI "prefix length" from RFC 2858 Section 4. */
765 plen = pptr[0]; /* get prefix length */
767 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
768 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
769 * target" fields inside the "prefix" depending on its length.
772 /* Without "origin AS", without "route target". */
773 snprintf(buf, buflen, "default route target");
780 /* With at least "origin AS", possibly with "route target". */
781 ND_TCHECK_32BITS(pptr + 1);
782 as_printf(ndo, asbuf, sizeof(asbuf), EXTRACT_32BITS(pptr + 1));
784 plen-=32; /* adjust prefix length */
789 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
790 * and gives the number of octets in the variable-length "route
791 * target" field inside this NLRI "prefix". Look for it.
793 memset(&route_target, 0, sizeof(route_target));
794 ND_TCHECK2(pptr[5], (plen + 7) / 8);
795 memcpy(&route_target, &pptr[5], (plen + 7) / 8);
796 /* Which specification says to do this? */
798 ((u_char *)&route_target)[(plen + 7) / 8 - 1] &=
799 ((0xff00 >> (plen % 8)) & 0xff);
801 snprintf(buf, buflen, "origin AS: %s, route target %s",
803 bgp_vpn_rd_print(ndo, (u_char *)&route_target));
805 return 5 + (plen + 7) / 8;
812 decode_labeled_vpn_prefix4(netdissect_options *ndo,
813 const u_char *pptr, char *buf, u_int buflen)
819 plen = pptr[0]; /* get prefix length */
824 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
829 memset(&addr, 0, sizeof(addr));
830 ND_TCHECK2(pptr[12], (plen + 7) / 8);
831 memcpy(&addr, &pptr[12], (plen + 7) / 8);
833 ((u_char *)&addr)[(plen + 7) / 8 - 1] &=
834 ((0xff00 >> (plen % 8)) & 0xff);
836 /* the label may get offsetted by 4 bits so lets shift it right */
837 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
838 bgp_vpn_rd_print(ndo, pptr+4),
839 ipaddr_string(ndo, &addr),
841 EXTRACT_24BITS(pptr+1)>>4,
842 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
844 return 12 + (plen + 7) / 8;
851 * +-------------------------------+
853 * | RD:IPv4-address (12 octets) |
855 * +-------------------------------+
856 * | MDT Group-address (4 octets) |
857 * +-------------------------------+
860 #define MDT_VPN_NLRI_LEN 16
863 decode_mdt_vpn_nlri(netdissect_options *ndo,
864 const u_char *pptr, char *buf, u_int buflen)
868 const u_char *vpn_ip;
872 /* if the NLRI is not predefined length, quit.*/
873 if (*pptr != MDT_VPN_NLRI_LEN * 8)
878 ND_TCHECK2(pptr[0], 8);
883 ND_TCHECK2(pptr[0], sizeof(struct in_addr));
885 pptr+=sizeof(struct in_addr);
887 /* MDT Group Address */
888 ND_TCHECK2(pptr[0], sizeof(struct in_addr));
890 snprintf(buf, buflen, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
891 bgp_vpn_rd_print(ndo, rd), ipaddr_string(ndo, vpn_ip), ipaddr_string(ndo, pptr));
893 return MDT_VPN_NLRI_LEN + 1;
900 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
901 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
902 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
903 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
904 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
905 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
906 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
908 static const struct tok bgp_multicast_vpn_route_type_values[] = {
909 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI, "Intra-AS I-PMSI"},
910 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI, "Inter-AS I-PMSI"},
911 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI, "S-PMSI"},
912 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF, "Intra-AS Segment-Leaf"},
913 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE, "Source-Active"},
914 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN, "Shared Tree Join"},
915 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN, "Source Tree Join"},
920 decode_multicast_vpn(netdissect_options *ndo,
921 const u_char *pptr, char *buf, u_int buflen)
923 uint8_t route_type, route_length, addr_length, sg_length;
926 ND_TCHECK2(pptr[0], 2);
927 route_type = *pptr++;
928 route_length = *pptr++;
930 snprintf(buf, buflen, "Route-Type: %s (%u), length: %u",
931 tok2str(bgp_multicast_vpn_route_type_values,
932 "Unknown", route_type),
933 route_type, route_length);
936 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI:
937 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
938 offset = strlen(buf);
939 snprintf(buf + offset, buflen - offset, ", RD: %s, Originator %s",
940 bgp_vpn_rd_print(ndo, pptr),
941 bgp_vpn_ip_print(ndo, pptr + BGP_VPN_RD_LEN,
942 (route_length - BGP_VPN_RD_LEN) << 3));
944 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI:
945 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN + 4);
946 offset = strlen(buf);
947 snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
948 bgp_vpn_rd_print(ndo, pptr),
949 as_printf(ndo, astostr, sizeof(astostr),
950 EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN)));
953 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI:
954 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
955 offset = strlen(buf);
956 snprintf(buf + offset, buflen - offset, ", RD: %s",
957 bgp_vpn_rd_print(ndo, pptr));
958 pptr += BGP_VPN_RD_LEN;
960 sg_length = bgp_vpn_sg_print(ndo, pptr, buf, buflen);
961 addr_length = route_length - sg_length;
963 ND_TCHECK2(pptr[0], addr_length);
964 offset = strlen(buf);
965 snprintf(buf + offset, buflen - offset, ", Originator %s",
966 bgp_vpn_ip_print(ndo, pptr, addr_length << 3));
969 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE:
970 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
971 offset = strlen(buf);
972 snprintf(buf + offset, buflen - offset, ", RD: %s",
973 bgp_vpn_rd_print(ndo, pptr));
974 pptr += BGP_VPN_RD_LEN;
976 bgp_vpn_sg_print(ndo, pptr, buf, buflen);
979 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN: /* fall through */
980 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN:
981 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN + 4);
982 offset = strlen(buf);
983 snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
984 bgp_vpn_rd_print(ndo, pptr),
985 as_printf(ndo, astostr, sizeof(astostr),
986 EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN)));
987 pptr += BGP_VPN_RD_LEN + 4;
989 bgp_vpn_sg_print(ndo, pptr, buf, buflen);
993 * no per route-type printing yet.
995 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF:
1000 return route_length + 2;
1007 * As I remember, some versions of systems have an snprintf() that
1008 * returns -1 if the buffer would have overflowed. If the return
1009 * value is negative, set buflen to 0, to indicate that we've filled
1012 * If the return value is greater than buflen, that means that
1013 * the buffer would have overflowed; again, set buflen to 0 in
1016 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1019 else if ((u_int)stringlen>buflen) \
1022 buflen-=stringlen; \
1027 decode_labeled_vpn_l2(netdissect_options *ndo,
1028 const u_char *pptr, char *buf, u_int buflen)
1030 int plen,tlen,stringlen,tlv_type,tlv_len,ttlv_len;
1032 ND_TCHECK2(pptr[0], 2);
1033 plen=EXTRACT_16BITS(pptr);
1036 /* Old and new L2VPN NLRI share AFI/SAFI
1037 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1038 * and > 17 as old format. Complain for the middle case
1041 /* assume AD-only with RD, BGPNH */
1042 ND_TCHECK2(pptr[0],12);
1044 stringlen=snprintf(buf, buflen, "RD: %s, BGPNH: %s",
1045 bgp_vpn_rd_print(ndo, pptr),
1046 ipaddr_string(ndo, pptr+8)
1048 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1052 } else if (plen>17) {
1053 /* assume old format */
1054 /* RD, ID, LBLKOFF, LBLBASE */
1056 ND_TCHECK2(pptr[0],15);
1058 stringlen=snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1059 bgp_vpn_rd_print(ndo, pptr),
1060 EXTRACT_16BITS(pptr+8),
1061 EXTRACT_16BITS(pptr+10),
1062 EXTRACT_24BITS(pptr+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1063 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1067 /* ok now the variable part - lets read out TLVs*/
1071 ND_TCHECK2(pptr[0], 3);
1073 tlv_len=EXTRACT_16BITS(pptr);
1080 stringlen=snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1083 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1085 ttlv_len=ttlv_len/8+1; /* how many bytes do we need to read ? */
1086 while (ttlv_len>0) {
1089 stringlen=snprintf(buf,buflen, "%02x",*pptr++);
1090 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1097 stringlen=snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u",
1100 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1104 tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it right */
1109 /* complain bitterly ? */
1119 decode_prefix6(netdissect_options *ndo,
1120 const u_char *pd, u_int itemlen, char *buf, u_int buflen)
1122 struct in6_addr addr;
1123 u_int plen, plenbytes;
1132 memset(&addr, 0, sizeof(addr));
1133 plenbytes = (plen + 7) / 8;
1134 ND_TCHECK2(pd[1], plenbytes);
1135 ITEMCHECK(plenbytes);
1136 memcpy(&addr, &pd[1], plenbytes);
1138 addr.s6_addr[plenbytes - 1] &=
1139 ((0xff00 >> (plen % 8)) & 0xff);
1141 snprintf(buf, buflen, "%s/%d", ip6addr_string(ndo, &addr), plen);
1142 return 1 + plenbytes;
1152 decode_labeled_prefix6(netdissect_options *ndo,
1153 const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
1155 struct in6_addr addr;
1156 u_int plen, plenbytes;
1158 /* prefix length and label = 4 bytes */
1159 ND_TCHECK2(pptr[0], 4);
1161 plen = pptr[0]; /* get prefix length */
1166 plen-=24; /* adjust prefixlen - labellength */
1172 memset(&addr, 0, sizeof(addr));
1173 plenbytes = (plen + 7) / 8;
1174 ND_TCHECK2(pptr[4], plenbytes);
1175 memcpy(&addr, &pptr[4], plenbytes);
1177 addr.s6_addr[plenbytes - 1] &=
1178 ((0xff00 >> (plen % 8)) & 0xff);
1180 /* the label may get offsetted by 4 bits so lets shift it right */
1181 snprintf(buf, buflen, "%s/%d, label:%u %s",
1182 ip6addr_string(ndo, &addr),
1184 EXTRACT_24BITS(pptr+1)>>4,
1185 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1187 return 4 + plenbytes;
1197 decode_labeled_vpn_prefix6(netdissect_options *ndo,
1198 const u_char *pptr, char *buf, u_int buflen)
1200 struct in6_addr addr;
1204 plen = pptr[0]; /* get prefix length */
1209 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
1214 memset(&addr, 0, sizeof(addr));
1215 ND_TCHECK2(pptr[12], (plen + 7) / 8);
1216 memcpy(&addr, &pptr[12], (plen + 7) / 8);
1218 addr.s6_addr[(plen + 7) / 8 - 1] &=
1219 ((0xff00 >> (plen % 8)) & 0xff);
1221 /* the label may get offsetted by 4 bits so lets shift it right */
1222 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
1223 bgp_vpn_rd_print(ndo, pptr+4),
1224 ip6addr_string(ndo, &addr),
1226 EXTRACT_24BITS(pptr+1)>>4,
1227 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1229 return 12 + (plen + 7) / 8;
1236 decode_clnp_prefix(netdissect_options *ndo,
1237 const u_char *pptr, char *buf, u_int buflen)
1243 plen = pptr[0]; /* get prefix length */
1248 memset(&addr, 0, sizeof(addr));
1249 ND_TCHECK2(pptr[4], (plen + 7) / 8);
1250 memcpy(&addr, &pptr[4], (plen + 7) / 8);
1252 addr[(plen + 7) / 8 - 1] &=
1253 ((0xff00 >> (plen % 8)) & 0xff);
1255 snprintf(buf, buflen, "%s/%d",
1256 isonsap_string(ndo, addr,(plen + 7) / 8),
1259 return 1 + (plen + 7) / 8;
1266 decode_labeled_vpn_clnp_prefix(netdissect_options *ndo,
1267 const u_char *pptr, char *buf, u_int buflen)
1273 plen = pptr[0]; /* get prefix length */
1278 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
1283 memset(&addr, 0, sizeof(addr));
1284 ND_TCHECK2(pptr[12], (plen + 7) / 8);
1285 memcpy(&addr, &pptr[12], (plen + 7) / 8);
1287 addr[(plen + 7) / 8 - 1] &=
1288 ((0xff00 >> (plen % 8)) & 0xff);
1290 /* the label may get offsetted by 4 bits so lets shift it right */
1291 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
1292 bgp_vpn_rd_print(ndo, pptr+4),
1293 isonsap_string(ndo, addr,(plen + 7) / 8),
1295 EXTRACT_24BITS(pptr+1)>>4,
1296 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1298 return 12 + (plen + 7) / 8;
1305 * bgp_attr_get_as_size
1307 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1308 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1309 * support, exchange AS-Path with the same path-attribute type value 0x02.
1312 bgp_attr_get_as_size(netdissect_options *ndo,
1313 uint8_t bgpa_type, const u_char *pptr, int len)
1315 const u_char *tptr = pptr;
1318 * If the path attribute is the optional AS4 path type, then we already
1319 * know, that ASs must be encoded in 4 byte format.
1321 if (bgpa_type == BGPTYPE_AS4_PATH) {
1326 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1327 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1330 while (tptr < pptr + len) {
1334 * If we do not find a valid segment type, our guess might be wrong.
1336 if (tptr[0] < BGP_AS_SEG_TYPE_MIN || tptr[0] > BGP_AS_SEG_TYPE_MAX) {
1340 tptr += 2 + tptr[1] * 2;
1344 * If we correctly reached end of the AS path attribute data content,
1345 * then most likely ASs were indeed encoded as 2 bytes.
1347 if (tptr == pptr + len) {
1354 * We can come here, either we did not have enough data, or if we
1355 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1356 * so that calller can try to decode each AS as of 4 bytes. If indeed
1357 * there was not enough data, it will crib and end the parse anyways.
1363 bgp_attr_print(netdissect_options *ndo,
1364 u_int atype, const u_char *pptr, u_int len, const unsigned attr_set_level)
1368 uint8_t safi, snpa, nhlen;
1369 union { /* copy buffer for bandwidth values */
1376 char buf[MAXHOSTNAMELEN + 100];
1383 case BGPTYPE_ORIGIN:
1385 ND_PRINT((ndo, "invalid len"));
1388 ND_PRINT((ndo, "%s", tok2str(bgp_origin_values,
1389 "Unknown Origin Typecode",
1395 * Process AS4 byte path and AS2 byte path attributes here.
1397 case BGPTYPE_AS4_PATH:
1398 case BGPTYPE_AS_PATH:
1400 ND_PRINT((ndo, "invalid len"));
1404 ND_PRINT((ndo, "empty"));
1409 * BGP updates exchanged between New speakers that support 4
1410 * byte AS, ASs are always encoded in 4 bytes. There is no
1411 * definitive way to find this, just by the packet's
1412 * contents. So, check for packet's TLV's sanity assuming
1413 * 2 bytes first, and it does not pass, assume that ASs are
1414 * encoded in 4 bytes format and move on.
1416 as_size = bgp_attr_get_as_size(ndo, atype, pptr, len);
1418 while (tptr < pptr + len) {
1420 ND_PRINT((ndo, "%s", tok2str(bgp_as_path_segment_open_values,
1423 for (i = 0; i < tptr[1] * as_size; i += as_size) {
1424 ND_TCHECK2(tptr[2 + i], as_size);
1425 ND_PRINT((ndo, "%s ",
1426 as_printf(ndo, astostr, sizeof(astostr),
1428 EXTRACT_16BITS(&tptr[2 + i]) :
1429 EXTRACT_32BITS(&tptr[2 + i]))));
1432 ND_PRINT((ndo, "%s", tok2str(bgp_as_path_segment_close_values,
1435 tptr += 2 + tptr[1] * as_size;
1438 case BGPTYPE_NEXT_HOP:
1440 ND_PRINT((ndo, "invalid len"));
1442 ND_TCHECK2(tptr[0], 4);
1443 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr)));
1446 case BGPTYPE_MULTI_EXIT_DISC:
1447 case BGPTYPE_LOCAL_PREF:
1449 ND_PRINT((ndo, "invalid len"));
1451 ND_TCHECK2(tptr[0], 4);
1452 ND_PRINT((ndo, "%u", EXTRACT_32BITS(tptr)));
1455 case BGPTYPE_ATOMIC_AGGREGATE:
1457 ND_PRINT((ndo, "invalid len"));
1459 case BGPTYPE_AGGREGATOR:
1462 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1463 * the length of this PA can be either 6 bytes or 8 bytes.
1465 if (len != 6 && len != 8) {
1466 ND_PRINT((ndo, "invalid len"));
1469 ND_TCHECK2(tptr[0], len);
1471 ND_PRINT((ndo, " AS #%s, origin %s",
1472 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_16BITS(tptr)),
1473 ipaddr_string(ndo, tptr + 2)));
1475 ND_PRINT((ndo, " AS #%s, origin %s",
1476 as_printf(ndo, astostr, sizeof(astostr),
1477 EXTRACT_32BITS(tptr)), ipaddr_string(ndo, tptr + 4)));
1480 case BGPTYPE_AGGREGATOR4:
1482 ND_PRINT((ndo, "invalid len"));
1485 ND_TCHECK2(tptr[0], 8);
1486 ND_PRINT((ndo, " AS #%s, origin %s",
1487 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(tptr)),
1488 ipaddr_string(ndo, tptr + 4)));
1490 case BGPTYPE_COMMUNITIES:
1492 ND_PRINT((ndo, "invalid len"));
1497 ND_TCHECK2(tptr[0], 4);
1498 comm = EXTRACT_32BITS(tptr);
1500 case BGP_COMMUNITY_NO_EXPORT:
1501 ND_PRINT((ndo, " NO_EXPORT"));
1503 case BGP_COMMUNITY_NO_ADVERT:
1504 ND_PRINT((ndo, " NO_ADVERTISE"));
1506 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED:
1507 ND_PRINT((ndo, " NO_EXPORT_SUBCONFED"));
1510 ND_PRINT((ndo, "%u:%u%s",
1511 (comm >> 16) & 0xffff,
1513 (tlen>4) ? ", " : ""));
1520 case BGPTYPE_ORIGINATOR_ID:
1522 ND_PRINT((ndo, "invalid len"));
1525 ND_TCHECK2(tptr[0], 4);
1526 ND_PRINT((ndo, "%s",ipaddr_string(ndo, tptr)));
1528 case BGPTYPE_CLUSTER_LIST:
1530 ND_PRINT((ndo, "invalid len"));
1534 ND_TCHECK2(tptr[0], 4);
1535 ND_PRINT((ndo, "%s%s",
1536 ipaddr_string(ndo, tptr),
1537 (tlen>4) ? ", " : ""));
1542 case BGPTYPE_MP_REACH_NLRI:
1543 ND_TCHECK2(tptr[0], 3);
1544 af = EXTRACT_16BITS(tptr);
1547 ND_PRINT((ndo, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1548 tok2str(af_values, "Unknown AFI", af),
1550 (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1551 tok2str(bgp_safi_values, "Unknown SAFI", safi),
1554 switch(af<<8 | safi) {
1555 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1556 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1557 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1558 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1559 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
1560 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1561 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1562 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1563 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN):
1564 case (AFNUM_INET<<8 | SAFNUM_MDT):
1565 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1566 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1567 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1568 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1569 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1570 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1571 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1572 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1573 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1574 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1575 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1576 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1577 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1578 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1579 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1580 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1581 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1584 ND_TCHECK2(tptr[0], tlen);
1585 ND_PRINT((ndo, "\n\t no AFI %u / SAFI %u decoder", af, safi));
1586 if (ndo->ndo_vflag <= 1)
1587 print_unknown_data(ndo, tptr, "\n\t ", tlen);
1601 ND_PRINT((ndo, "\n\t nexthop: "));
1604 ND_PRINT((ndo, ", " ));
1606 switch(af<<8 | safi) {
1607 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1608 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1609 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1610 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1611 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
1612 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN):
1613 case (AFNUM_INET<<8 | SAFNUM_MDT):
1614 if (tlen < (int)sizeof(struct in_addr)) {
1615 ND_PRINT((ndo, "invalid len"));
1618 ND_TCHECK2(tptr[0], sizeof(struct in_addr));
1619 ND_PRINT((ndo, "%s",ipaddr_string(ndo, tptr)));
1620 tlen -= sizeof(struct in_addr);
1621 tptr += sizeof(struct in_addr);
1624 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1625 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1626 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1627 if (tlen < (int)(sizeof(struct in_addr)+BGP_VPN_RD_LEN)) {
1628 ND_PRINT((ndo, "invalid len"));
1631 ND_TCHECK2(tptr[0], sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1632 ND_PRINT((ndo, "RD: %s, %s",
1633 bgp_vpn_rd_print(ndo, tptr),
1634 ipaddr_string(ndo, tptr+BGP_VPN_RD_LEN)));
1635 tlen -= (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1636 tptr += (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1639 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1640 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1641 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1642 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1643 if (tlen < (int)sizeof(struct in6_addr)) {
1644 ND_PRINT((ndo, "invalid len"));
1647 ND_TCHECK2(tptr[0], sizeof(struct in6_addr));
1648 ND_PRINT((ndo, "%s", ip6addr_string(ndo, tptr)));
1649 tlen -= sizeof(struct in6_addr);
1650 tptr += sizeof(struct in6_addr);
1653 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1654 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1655 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1656 if (tlen < (int)(sizeof(struct in6_addr)+BGP_VPN_RD_LEN)) {
1657 ND_PRINT((ndo, "invalid len"));
1660 ND_TCHECK2(tptr[0], sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1661 ND_PRINT((ndo, "RD: %s, %s",
1662 bgp_vpn_rd_print(ndo, tptr),
1663 ip6addr_string(ndo, tptr+BGP_VPN_RD_LEN)));
1664 tlen -= (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1665 tptr += (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1668 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1669 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1670 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1671 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1672 if (tlen < (int)sizeof(struct in_addr)) {
1673 ND_PRINT((ndo, "invalid len"));
1676 ND_TCHECK2(tptr[0], sizeof(struct in_addr));
1677 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr)));
1678 tlen -= (sizeof(struct in_addr));
1679 tptr += (sizeof(struct in_addr));
1682 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1683 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1684 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1685 ND_TCHECK2(tptr[0], tlen);
1686 ND_PRINT((ndo, "%s", isonsap_string(ndo, tptr, tlen)));
1691 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1692 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1693 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1694 if (tlen < BGP_VPN_RD_LEN+1) {
1695 ND_PRINT((ndo, "invalid len"));
1698 ND_TCHECK2(tptr[0], tlen);
1699 ND_PRINT((ndo, "RD: %s, %s",
1700 bgp_vpn_rd_print(ndo, tptr),
1701 isonsap_string(ndo, tptr+BGP_VPN_RD_LEN,tlen-BGP_VPN_RD_LEN)));
1702 /* rfc986 mapped IPv4 address ? */
1703 if (tlen == BGP_VPN_RD_LEN + 4 + sizeof(struct in_addr)
1704 && EXTRACT_32BITS(tptr+BGP_VPN_RD_LEN) == 0x47000601)
1705 ND_PRINT((ndo, " = %s", ipaddr_string(ndo, tptr+BGP_VPN_RD_LEN+4)));
1706 /* rfc1888 mapped IPv6 address ? */
1707 else if (tlen == BGP_VPN_RD_LEN + 3 + sizeof(struct in6_addr)
1708 && EXTRACT_24BITS(tptr+BGP_VPN_RD_LEN) == 0x350000)
1709 ND_PRINT((ndo, " = %s", ip6addr_string(ndo, tptr+BGP_VPN_RD_LEN+3)));
1715 ND_TCHECK2(tptr[0], tlen);
1716 ND_PRINT((ndo, "no AFI %u/SAFI %u decoder", af, safi));
1717 if (ndo->ndo_vflag <= 1)
1718 print_unknown_data(ndo, tptr, "\n\t ", tlen);
1726 ND_PRINT((ndo, ", nh-length: %u", nhlen));
1734 ND_PRINT((ndo, "\n\t %u SNPA", snpa));
1735 for (/*nothing*/; snpa > 0; snpa--) {
1737 ND_PRINT((ndo, "\n\t %d bytes", tptr[0]));
1738 tptr += tptr[0] + 1;
1741 ND_PRINT((ndo, ", no SNPA"));
1744 while (tptr < pptr + len) {
1745 switch (af<<8 | safi) {
1746 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1747 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1748 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1749 advance = decode_prefix4(ndo, tptr, len, buf, sizeof(buf));
1751 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1752 else if (advance == -2)
1754 else if (advance == -3)
1755 break; /* bytes left, but not enough */
1757 ND_PRINT((ndo, "\n\t %s", buf));
1759 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1760 advance = decode_labeled_prefix4(ndo, tptr, len, buf, sizeof(buf));
1762 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1763 else if (advance == -2)
1765 else if (advance == -3)
1766 break; /* bytes left, but not enough */
1768 ND_PRINT((ndo, "\n\t %s", buf));
1770 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1771 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1772 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1773 advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, sizeof(buf));
1775 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1776 else if (advance == -2)
1779 ND_PRINT((ndo, "\n\t %s", buf));
1781 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
1782 advance = decode_rt_routing_info(ndo, tptr, buf, sizeof(buf));
1784 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1785 else if (advance == -2)
1788 ND_PRINT((ndo, "\n\t %s", buf));
1790 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */
1791 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN):
1792 advance = decode_multicast_vpn(ndo, tptr, buf, sizeof(buf));
1794 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1795 else if (advance == -2)
1798 ND_PRINT((ndo, "\n\t %s", buf));
1801 case (AFNUM_INET<<8 | SAFNUM_MDT):
1802 advance = decode_mdt_vpn_nlri(ndo, tptr, buf, sizeof(buf));
1804 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1805 else if (advance == -2)
1808 ND_PRINT((ndo, "\n\t %s", buf));
1810 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1811 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1812 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1813 advance = decode_prefix6(ndo, tptr, len, buf, sizeof(buf));
1815 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1816 else if (advance == -2)
1818 else if (advance == -3)
1819 break; /* bytes left, but not enough */
1821 ND_PRINT((ndo, "\n\t %s", buf));
1823 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1824 advance = decode_labeled_prefix6(ndo, tptr, len, buf, sizeof(buf));
1826 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1827 else if (advance == -2)
1829 else if (advance == -3)
1830 break; /* bytes left, but not enough */
1832 ND_PRINT((ndo, "\n\t %s", buf));
1834 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1835 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1836 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1837 advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, sizeof(buf));
1839 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1840 else if (advance == -2)
1843 ND_PRINT((ndo, "\n\t %s", buf));
1845 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1846 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1847 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1848 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1849 advance = decode_labeled_vpn_l2(ndo, tptr, buf, sizeof(buf));
1851 ND_PRINT((ndo, "\n\t (illegal length)"));
1852 else if (advance == -2)
1855 ND_PRINT((ndo, "\n\t %s", buf));
1857 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1858 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1859 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1860 advance = decode_clnp_prefix(ndo, tptr, buf, sizeof(buf));
1862 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1863 else if (advance == -2)
1866 ND_PRINT((ndo, "\n\t %s", buf));
1868 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1869 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1870 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1871 advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, sizeof(buf));
1873 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1874 else if (advance == -2)
1877 ND_PRINT((ndo, "\n\t %s", buf));
1880 ND_TCHECK2(*tptr,tlen);
1881 ND_PRINT((ndo, "\n\t no AFI %u / SAFI %u decoder", af, safi));
1882 if (ndo->ndo_vflag <= 1)
1883 print_unknown_data(ndo, tptr, "\n\t ", tlen);
1895 case BGPTYPE_MP_UNREACH_NLRI:
1896 ND_TCHECK2(tptr[0], BGP_MP_NLRI_MINSIZE);
1897 af = EXTRACT_16BITS(tptr);
1900 ND_PRINT((ndo, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1901 tok2str(af_values, "Unknown AFI", af),
1903 (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1904 tok2str(bgp_safi_values, "Unknown SAFI", safi),
1907 if (len == BGP_MP_NLRI_MINSIZE)
1908 ND_PRINT((ndo, "\n\t End-of-Rib Marker (empty NLRI)"));
1912 while (tptr < pptr + len) {
1913 switch (af<<8 | safi) {
1914 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1915 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1916 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1917 advance = decode_prefix4(ndo, tptr, len, buf, sizeof(buf));
1919 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1920 else if (advance == -2)
1922 else if (advance == -3)
1923 break; /* bytes left, but not enough */
1925 ND_PRINT((ndo, "\n\t %s", buf));
1927 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1928 advance = decode_labeled_prefix4(ndo, tptr, len, buf, sizeof(buf));
1930 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1931 else if (advance == -2)
1933 else if (advance == -3)
1934 break; /* bytes left, but not enough */
1936 ND_PRINT((ndo, "\n\t %s", buf));
1938 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1939 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1940 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1941 advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, sizeof(buf));
1943 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1944 else if (advance == -2)
1947 ND_PRINT((ndo, "\n\t %s", buf));
1949 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1950 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1951 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1952 advance = decode_prefix6(ndo, tptr, len, buf, sizeof(buf));
1954 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1955 else if (advance == -2)
1957 else if (advance == -3)
1958 break; /* bytes left, but not enough */
1960 ND_PRINT((ndo, "\n\t %s", buf));
1962 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1963 advance = decode_labeled_prefix6(ndo, tptr, len, buf, sizeof(buf));
1965 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1966 else if (advance == -2)
1968 else if (advance == -3)
1969 break; /* bytes left, but not enough */
1971 ND_PRINT((ndo, "\n\t %s", buf));
1973 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1974 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1975 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1976 advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, sizeof(buf));
1978 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1979 else if (advance == -2)
1982 ND_PRINT((ndo, "\n\t %s", buf));
1984 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1985 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1986 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1987 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1988 advance = decode_labeled_vpn_l2(ndo, tptr, buf, sizeof(buf));
1990 ND_PRINT((ndo, "\n\t (illegal length)"));
1991 else if (advance == -2)
1994 ND_PRINT((ndo, "\n\t %s", buf));
1996 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1997 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1998 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1999 advance = decode_clnp_prefix(ndo, tptr, buf, sizeof(buf));
2001 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
2002 else if (advance == -2)
2005 ND_PRINT((ndo, "\n\t %s", buf));
2007 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
2008 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
2009 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
2010 advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, sizeof(buf));
2012 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
2013 else if (advance == -2)
2016 ND_PRINT((ndo, "\n\t %s", buf));
2018 case (AFNUM_INET<<8 | SAFNUM_MDT):
2019 advance = decode_mdt_vpn_nlri(ndo, tptr, buf, sizeof(buf));
2021 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
2022 else if (advance == -2)
2025 ND_PRINT((ndo, "\n\t %s", buf));
2027 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */
2028 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN):
2029 advance = decode_multicast_vpn(ndo, tptr, buf, sizeof(buf));
2031 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
2032 else if (advance == -2)
2035 ND_PRINT((ndo, "\n\t %s", buf));
2038 ND_TCHECK2(*(tptr-3),tlen);
2039 ND_PRINT((ndo, "no AFI %u / SAFI %u decoder", af, safi));
2040 if (ndo->ndo_vflag <= 1)
2041 print_unknown_data(ndo, tptr-3, "\n\t ", tlen);
2051 case BGPTYPE_EXTD_COMMUNITIES:
2053 ND_PRINT((ndo, "invalid len"));
2059 ND_TCHECK2(tptr[0], 2);
2060 extd_comm=EXTRACT_16BITS(tptr);
2062 ND_PRINT((ndo, "\n\t %s (0x%04x), Flags [%s]",
2063 tok2str(bgp_extd_comm_subtype_values,
2064 "unknown extd community typecode",
2067 bittok2str(bgp_extd_comm_flag_values, "none", extd_comm)));
2069 ND_TCHECK2(*(tptr+2), 6);
2071 case BGP_EXT_COM_RT_0:
2072 case BGP_EXT_COM_RO_0:
2073 case BGP_EXT_COM_L2VPN_RT_0:
2074 ND_PRINT((ndo, ": %u:%u (= %s)",
2075 EXTRACT_16BITS(tptr+2),
2076 EXTRACT_32BITS(tptr+4),
2077 ipaddr_string(ndo, tptr+4)));
2079 case BGP_EXT_COM_RT_1:
2080 case BGP_EXT_COM_RO_1:
2081 case BGP_EXT_COM_L2VPN_RT_1:
2082 case BGP_EXT_COM_VRF_RT_IMP:
2083 ND_PRINT((ndo, ": %s:%u",
2084 ipaddr_string(ndo, tptr+2),
2085 EXTRACT_16BITS(tptr+6)));
2087 case BGP_EXT_COM_RT_2:
2088 case BGP_EXT_COM_RO_2:
2089 ND_PRINT((ndo, ": %s:%u",
2090 as_printf(ndo, astostr, sizeof(astostr),
2091 EXTRACT_32BITS(tptr+2)), EXTRACT_16BITS(tptr+6)));
2093 case BGP_EXT_COM_LINKBAND:
2094 bw.i = EXTRACT_32BITS(tptr+2);
2095 ND_PRINT((ndo, ": bandwidth: %.3f Mbps",
2098 case BGP_EXT_COM_VPN_ORIGIN:
2099 case BGP_EXT_COM_VPN_ORIGIN2:
2100 case BGP_EXT_COM_VPN_ORIGIN3:
2101 case BGP_EXT_COM_VPN_ORIGIN4:
2102 case BGP_EXT_COM_OSPF_RID:
2103 case BGP_EXT_COM_OSPF_RID2:
2104 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr+2)));
2106 case BGP_EXT_COM_OSPF_RTYPE:
2107 case BGP_EXT_COM_OSPF_RTYPE2:
2108 ND_PRINT((ndo, ": area:%s, router-type:%s, metric-type:%s%s",
2109 ipaddr_string(ndo, tptr+2),
2110 tok2str(bgp_extd_comm_ospf_rtype_values,
2113 (*(tptr+7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? "E2" : "",
2114 ((*(tptr+6) == BGP_OSPF_RTYPE_EXT) || (*(tptr+6) == BGP_OSPF_RTYPE_NSSA)) ? "E1" : ""));
2116 case BGP_EXT_COM_L2INFO:
2117 ND_PRINT((ndo, ": %s Control Flags [0x%02x]:MTU %u",
2118 tok2str(l2vpn_encaps_values,
2122 EXTRACT_16BITS(tptr+4)));
2124 case BGP_EXT_COM_SOURCE_AS:
2125 ND_PRINT((ndo, ": AS %u", EXTRACT_16BITS(tptr+2)));
2128 ND_TCHECK2(*tptr,8);
2129 print_unknown_data(ndo, tptr, "\n\t ", 8);
2137 case BGPTYPE_PMSI_TUNNEL:
2139 uint8_t tunnel_type, flags;
2141 ND_TCHECK2(tptr[0], 5);
2142 tunnel_type = *(tptr+1);
2146 ND_PRINT((ndo, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2147 tok2str(bgp_pmsi_tunnel_values, "Unknown", tunnel_type),
2149 bittok2str(bgp_pmsi_flag_values, "none", flags),
2150 EXTRACT_24BITS(tptr+2)>>4));
2155 switch (tunnel_type) {
2156 case BGP_PMSI_TUNNEL_PIM_SM: /* fall through */
2157 case BGP_PMSI_TUNNEL_PIM_BIDIR:
2158 ND_TCHECK2(tptr[0], 8);
2159 ND_PRINT((ndo, "\n\t Sender %s, P-Group %s",
2160 ipaddr_string(ndo, tptr),
2161 ipaddr_string(ndo, tptr+4)));
2164 case BGP_PMSI_TUNNEL_PIM_SSM:
2165 ND_TCHECK2(tptr[0], 8);
2166 ND_PRINT((ndo, "\n\t Root-Node %s, P-Group %s",
2167 ipaddr_string(ndo, tptr),
2168 ipaddr_string(ndo, tptr+4)));
2170 case BGP_PMSI_TUNNEL_INGRESS:
2171 ND_TCHECK2(tptr[0], 4);
2172 ND_PRINT((ndo, "\n\t Tunnel-Endpoint %s",
2173 ipaddr_string(ndo, tptr)));
2175 case BGP_PMSI_TUNNEL_LDP_P2MP: /* fall through */
2176 case BGP_PMSI_TUNNEL_LDP_MP2MP:
2177 ND_TCHECK2(tptr[0], 8);
2178 ND_PRINT((ndo, "\n\t Root-Node %s, LSP-ID 0x%08x",
2179 ipaddr_string(ndo, tptr),
2180 EXTRACT_32BITS(tptr+4)));
2182 case BGP_PMSI_TUNNEL_RSVP_P2MP:
2183 ND_TCHECK2(tptr[0], 8);
2184 ND_PRINT((ndo, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2185 ipaddr_string(ndo, tptr),
2186 EXTRACT_32BITS(tptr+4)));
2189 if (ndo->ndo_vflag <= 1) {
2190 print_unknown_data(ndo, tptr, "\n\t ", tlen);
2204 ND_TCHECK2(tptr[0], 3);
2207 length = EXTRACT_16BITS(tptr+1);
2211 ND_PRINT((ndo, "\n\t %s TLV (%u), length %u",
2212 tok2str(bgp_aigp_values, "Unknown", type),
2220 * Check if we can read the TLV data.
2222 ND_TCHECK2(tptr[3], length);
2229 ND_PRINT((ndo, ", metric %" PRIu64,
2230 EXTRACT_64BITS(tptr)));
2234 if (ndo->ndo_vflag <= 1) {
2235 print_unknown_data(ndo, tptr,"\n\t ", length);
2244 case BGPTYPE_ATTR_SET:
2245 ND_TCHECK2(tptr[0], 4);
2248 ND_PRINT((ndo, "\n\t Origin AS: %s",
2249 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(tptr))));
2254 u_int aflags, alenlen, alen;
2256 ND_TCHECK2(tptr[0], 2);
2260 atype = *(tptr + 1);
2263 alenlen = bgp_attr_lenlen(aflags, tptr);
2264 ND_TCHECK2(tptr[0], alenlen);
2267 alen = bgp_attr_len(aflags, tptr);
2271 ND_PRINT((ndo, "\n\t %s (%u), length: %u",
2272 tok2str(bgp_attr_values,
2273 "Unknown Attribute", atype),
2278 ND_PRINT((ndo, ", Flags [%s%s%s%s",
2279 aflags & 0x80 ? "O" : "",
2280 aflags & 0x40 ? "T" : "",
2281 aflags & 0x20 ? "P" : "",
2282 aflags & 0x10 ? "E" : ""));
2284 ND_PRINT((ndo, "+%x", aflags & 0xf));
2285 ND_PRINT((ndo, "]: "));
2287 /* The protocol encoding per se allows ATTR_SET to be nested as many times
2288 * as the message can accommodate. This printer used to be able to recurse
2289 * into ATTR_SET contents until the stack exhaustion, but now there is a
2290 * limit on that (if live protocol exchange goes that many levels deep,
2291 * something is probably wrong anyway). Feel free to refine this value if
2292 * you can find the spec with respective normative text.
2294 if (attr_set_level == 10)
2295 ND_PRINT((ndo, "(too many nested levels, not recursing)"));
2296 else if (!bgp_attr_print(ndo, atype, tptr, alen, attr_set_level + 1))
2303 case BGPTYPE_LARGE_COMMUNITY:
2304 if (len == 0 || len % 12) {
2305 ND_PRINT((ndo, "invalid len"));
2308 ND_PRINT((ndo, "\n\t "));
2310 ND_TCHECK2(*tptr, 12);
2311 ND_PRINT((ndo, "%u:%u:%u%s",
2312 EXTRACT_32BITS(tptr),
2313 EXTRACT_32BITS(tptr + 4),
2314 EXTRACT_32BITS(tptr + 8),
2315 (len > 12) ? ", " : ""));
2321 ND_TCHECK2(*pptr,len);
2322 ND_PRINT((ndo, "\n\t no Attribute %u decoder", atype)); /* we have no decoder for the attribute */
2323 if (ndo->ndo_vflag <= 1)
2324 print_unknown_data(ndo, pptr, "\n\t ", len);
2327 if (ndo->ndo_vflag > 1 && len) { /* omit zero length attributes*/
2328 ND_TCHECK2(*pptr,len);
2329 print_unknown_data(ndo, pptr, "\n\t ", len);
2338 bgp_capabilities_print(netdissect_options *ndo,
2339 const u_char *opt, int caps_len)
2341 int cap_type, cap_len, tcap_len, cap_offset;
2344 while (i < caps_len) {
2345 ND_TCHECK2(opt[i], BGP_CAP_HEADER_SIZE);
2349 ND_PRINT((ndo, "\n\t %s (%u), length: %u",
2350 tok2str(bgp_capcode_values, "Unknown",
2354 ND_TCHECK2(opt[i+2], cap_len);
2356 case BGP_CAPCODE_MP:
2357 /* AFI (16 bits), Reserved (8 bits), SAFI (8 bits) */
2358 ND_TCHECK_8BITS(opt + i + 5);
2359 ND_PRINT((ndo, "\n\t\tAFI %s (%u), SAFI %s (%u)",
2360 tok2str(af_values, "Unknown",
2361 EXTRACT_16BITS(opt+i+2)),
2362 EXTRACT_16BITS(opt+i+2),
2363 tok2str(bgp_safi_values, "Unknown",
2367 case BGP_CAPCODE_RESTART:
2368 /* Restart Flags (4 bits), Restart Time in seconds (12 bits) */
2369 ND_TCHECK_16BITS(opt + i + 2);
2370 ND_PRINT((ndo, "\n\t\tRestart Flags: [%s], Restart Time %us",
2371 ((opt[i+2])&0x80) ? "R" : "none",
2372 EXTRACT_16BITS(opt+i+2)&0xfff));
2375 while(tcap_len>=4) {
2376 ND_TCHECK_8BITS(opt + i + cap_offset + 3);
2377 ND_PRINT((ndo, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2378 tok2str(af_values,"Unknown",
2379 EXTRACT_16BITS(opt+i+cap_offset)),
2380 EXTRACT_16BITS(opt+i+cap_offset),
2381 tok2str(bgp_safi_values,"Unknown",
2382 opt[i+cap_offset+2]),
2383 opt[i+cap_offset+2],
2384 ((opt[i+cap_offset+3])&0x80) ? "yes" : "no" ));
2389 case BGP_CAPCODE_RR:
2390 case BGP_CAPCODE_RR_CISCO:
2392 case BGP_CAPCODE_AS_NEW:
2395 * Extract the 4 byte AS number encoded.
2398 ND_PRINT((ndo, "\n\t\t 4 Byte AS %s",
2399 as_printf(ndo, astostr, sizeof(astostr),
2400 EXTRACT_32BITS(opt + i + 2))));
2403 case BGP_CAPCODE_ADD_PATH:
2405 if (tcap_len == 0) {
2406 ND_PRINT((ndo, " (bogus)")); /* length */
2409 while (tcap_len > 0) {
2411 ND_PRINT((ndo, "\n\t\t(invalid)"));
2414 ND_PRINT((ndo, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2415 tok2str(af_values,"Unknown",EXTRACT_16BITS(opt+i+cap_offset)),
2416 EXTRACT_16BITS(opt+i+cap_offset),
2417 tok2str(bgp_safi_values,"Unknown",opt[i+cap_offset+2]),
2418 opt[i+cap_offset+2],
2419 tok2str(bgp_add_path_recvsend,"Bogus (0x%02x)",opt[i+cap_offset+3])
2426 ND_PRINT((ndo, "\n\t\tno decoder for Capability %u",
2428 if (ndo->ndo_vflag <= 1)
2429 print_unknown_data(ndo, &opt[i+2], "\n\t\t", cap_len);
2432 if (ndo->ndo_vflag > 1 && cap_len > 0) {
2433 print_unknown_data(ndo, &opt[i+2], "\n\t\t", cap_len);
2435 i += BGP_CAP_HEADER_SIZE + cap_len;
2440 ND_PRINT((ndo, "%s", tstr));
2444 bgp_open_print(netdissect_options *ndo,
2445 const u_char *dat, int length)
2447 struct bgp_open bgpo;
2448 struct bgp_opt bgpopt;
2452 ND_TCHECK2(dat[0], BGP_OPEN_SIZE);
2453 memcpy(&bgpo, dat, BGP_OPEN_SIZE);
2455 ND_PRINT((ndo, "\n\t Version %d, ", bgpo.bgpo_version));
2456 ND_PRINT((ndo, "my AS %s, ",
2457 as_printf(ndo, astostr, sizeof(astostr), ntohs(bgpo.bgpo_myas))));
2458 ND_PRINT((ndo, "Holdtime %us, ", ntohs(bgpo.bgpo_holdtime)));
2459 ND_PRINT((ndo, "ID %s", ipaddr_string(ndo, &bgpo.bgpo_id)));
2460 ND_PRINT((ndo, "\n\t Optional parameters, length: %u", bgpo.bgpo_optlen));
2462 /* some little sanity checking */
2463 if (length < bgpo.bgpo_optlen+BGP_OPEN_SIZE)
2467 opt = &((const struct bgp_open *)dat)->bgpo_optlen;
2471 while (i < bgpo.bgpo_optlen) {
2472 ND_TCHECK2(opt[i], BGP_OPT_SIZE);
2473 memcpy(&bgpopt, &opt[i], BGP_OPT_SIZE);
2474 if (i + 2 + bgpopt.bgpopt_len > bgpo.bgpo_optlen) {
2475 ND_PRINT((ndo, "\n\t Option %d, length: %u", bgpopt.bgpopt_type, bgpopt.bgpopt_len));
2479 ND_PRINT((ndo, "\n\t Option %s (%u), length: %u",
2480 tok2str(bgp_opt_values,"Unknown",
2481 bgpopt.bgpopt_type),
2483 bgpopt.bgpopt_len));
2485 /* now let's decode the options we know*/
2486 switch(bgpopt.bgpopt_type) {
2489 bgp_capabilities_print(ndo, &opt[i+BGP_OPT_SIZE],
2495 ND_PRINT((ndo, "\n\t no decoder for option %u",
2496 bgpopt.bgpopt_type));
2499 i += BGP_OPT_SIZE + bgpopt.bgpopt_len;
2503 ND_PRINT((ndo, "%s", tstr));
2507 bgp_update_print(netdissect_options *ndo,
2508 const u_char *dat, int length)
2512 int withdrawn_routes_len;
2516 ND_TCHECK2(dat[0], BGP_SIZE);
2517 if (length < BGP_SIZE)
2519 memcpy(&bgp, dat, BGP_SIZE);
2520 p = dat + BGP_SIZE; /*XXX*/
2523 /* Unfeasible routes */
2524 ND_TCHECK2(p[0], 2);
2527 withdrawn_routes_len = EXTRACT_16BITS(p);
2530 if (withdrawn_routes_len) {
2532 * Without keeping state from the original NLRI message,
2533 * it's not possible to tell if this a v4 or v6 route,
2534 * so only try to decode it if we're not v6 enabled.
2536 ND_TCHECK2(p[0], withdrawn_routes_len);
2537 if (length < withdrawn_routes_len)
2539 ND_PRINT((ndo, "\n\t Withdrawn routes: %d bytes", withdrawn_routes_len));
2540 p += withdrawn_routes_len;
2541 length -= withdrawn_routes_len;
2544 ND_TCHECK2(p[0], 2);
2547 len = EXTRACT_16BITS(p);
2551 if (withdrawn_routes_len == 0 && len == 0 && length == 0) {
2552 /* No withdrawn routes, no path attributes, no NLRI */
2553 ND_PRINT((ndo, "\n\t End-of-Rib Marker (empty NLRI)"));
2558 /* do something more useful!*/
2560 int aflags, atype, alenlen, alen;
2562 ND_TCHECK2(p[0], 2);
2572 alenlen = bgp_attr_lenlen(aflags, p);
2573 ND_TCHECK2(p[0], alenlen);
2576 if (length < alenlen)
2578 alen = bgp_attr_len(aflags, p);
2583 ND_PRINT((ndo, "\n\t %s (%u), length: %u",
2584 tok2str(bgp_attr_values, "Unknown Attribute",
2590 ND_PRINT((ndo, ", Flags [%s%s%s%s",
2591 aflags & 0x80 ? "O" : "",
2592 aflags & 0x40 ? "T" : "",
2593 aflags & 0x20 ? "P" : "",
2594 aflags & 0x10 ? "E" : ""));
2596 ND_PRINT((ndo, "+%x", aflags & 0xf));
2597 ND_PRINT((ndo, "]: "));
2603 if (!bgp_attr_print(ndo, atype, p, alen, 0))
2613 * XXX - what if they're using the "Advertisement of
2614 * Multiple Paths in BGP" feature:
2616 * https://datatracker.ietf.org/doc/draft-ietf-idr-add-paths/
2618 * http://tools.ietf.org/html/draft-ietf-idr-add-paths-06
2620 ND_PRINT((ndo, "\n\t Updated routes:"));
2622 char buf[MAXHOSTNAMELEN + 100];
2623 i = decode_prefix4(ndo, p, length, buf, sizeof(buf));
2625 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
2630 goto trunc; /* bytes left, but not enough */
2632 ND_PRINT((ndo, "\n\t %s", buf));
2640 ND_PRINT((ndo, "%s", tstr));
2644 bgp_notification_print(netdissect_options *ndo,
2645 const u_char *dat, int length)
2647 struct bgp_notification bgpn;
2650 ND_TCHECK2(dat[0], BGP_NOTIFICATION_SIZE);
2651 memcpy(&bgpn, dat, BGP_NOTIFICATION_SIZE);
2653 /* some little sanity checking */
2654 if (length<BGP_NOTIFICATION_SIZE)
2657 ND_PRINT((ndo, ", %s (%u)",
2658 tok2str(bgp_notify_major_values, "Unknown Error",
2662 switch (bgpn.bgpn_major) {
2664 case BGP_NOTIFY_MAJOR_MSG:
2665 ND_PRINT((ndo, ", subcode %s (%u)",
2666 tok2str(bgp_notify_minor_msg_values, "Unknown",
2670 case BGP_NOTIFY_MAJOR_OPEN:
2671 ND_PRINT((ndo, ", subcode %s (%u)",
2672 tok2str(bgp_notify_minor_open_values, "Unknown",
2676 case BGP_NOTIFY_MAJOR_UPDATE:
2677 ND_PRINT((ndo, ", subcode %s (%u)",
2678 tok2str(bgp_notify_minor_update_values, "Unknown",
2682 case BGP_NOTIFY_MAJOR_FSM:
2683 ND_PRINT((ndo, " subcode %s (%u)",
2684 tok2str(bgp_notify_minor_fsm_values, "Unknown",
2688 case BGP_NOTIFY_MAJOR_CAP:
2689 ND_PRINT((ndo, " subcode %s (%u)",
2690 tok2str(bgp_notify_minor_cap_values, "Unknown",
2694 case BGP_NOTIFY_MAJOR_CEASE:
2695 ND_PRINT((ndo, ", subcode %s (%u)",
2696 tok2str(bgp_notify_minor_cease_values, "Unknown",
2700 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2701 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2703 if(bgpn.bgpn_minor == BGP_NOTIFY_MINOR_CEASE_MAXPRFX && length >= BGP_NOTIFICATION_SIZE + 7) {
2704 tptr = dat + BGP_NOTIFICATION_SIZE;
2705 ND_TCHECK2(*tptr, 7);
2706 ND_PRINT((ndo, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2707 tok2str(af_values, "Unknown",
2708 EXTRACT_16BITS(tptr)),
2709 EXTRACT_16BITS(tptr),
2710 tok2str(bgp_safi_values, "Unknown", *(tptr+2)),
2712 EXTRACT_32BITS(tptr+3)));
2721 ND_PRINT((ndo, "%s", tstr));
2725 bgp_route_refresh_print(netdissect_options *ndo,
2726 const u_char *pptr, int len)
2728 const struct bgp_route_refresh *bgp_route_refresh_header;
2730 ND_TCHECK2(pptr[0], BGP_ROUTE_REFRESH_SIZE);
2732 /* some little sanity checking */
2733 if (len<BGP_ROUTE_REFRESH_SIZE)
2736 bgp_route_refresh_header = (const struct bgp_route_refresh *)pptr;
2738 ND_PRINT((ndo, "\n\t AFI %s (%u), SAFI %s (%u)",
2739 tok2str(af_values,"Unknown",
2740 /* this stinks but the compiler pads the structure
2742 EXTRACT_16BITS(&bgp_route_refresh_header->afi)),
2743 EXTRACT_16BITS(&bgp_route_refresh_header->afi),
2744 tok2str(bgp_safi_values,"Unknown",
2745 bgp_route_refresh_header->safi),
2746 bgp_route_refresh_header->safi));
2748 if (ndo->ndo_vflag > 1) {
2749 ND_TCHECK2(*pptr, len);
2750 print_unknown_data(ndo, pptr, "\n\t ", len);
2755 ND_PRINT((ndo, "%s", tstr));
2759 bgp_header_print(netdissect_options *ndo,
2760 const u_char *dat, int length)
2764 ND_TCHECK2(dat[0], BGP_SIZE);
2765 memcpy(&bgp, dat, BGP_SIZE);
2766 ND_PRINT((ndo, "\n\t%s Message (%u), length: %u",
2767 tok2str(bgp_msg_values, "Unknown", bgp.bgp_type),
2771 switch (bgp.bgp_type) {
2773 bgp_open_print(ndo, dat, length);
2776 bgp_update_print(ndo, dat, length);
2778 case BGP_NOTIFICATION:
2779 bgp_notification_print(ndo, dat, length);
2783 case BGP_ROUTE_REFRESH:
2784 bgp_route_refresh_print(ndo, dat, length);
2787 /* we have no decoder for the BGP message */
2788 ND_TCHECK2(*dat, length);
2789 ND_PRINT((ndo, "\n\t no Message %u decoder", bgp.bgp_type));
2790 print_unknown_data(ndo, dat, "\n\t ", length);
2795 ND_PRINT((ndo, "%s", tstr));
2800 bgp_print(netdissect_options *ndo,
2801 const u_char *dat, int length)
2805 const u_char *start;
2806 const u_char marker[] = {
2807 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2808 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2814 if (ndo->ndo_snapend < dat + length)
2815 ep = ndo->ndo_snapend;
2817 ND_PRINT((ndo, ": BGP"));
2819 if (ndo->ndo_vflag < 1) /* lets be less chatty */
2825 if (!ND_TTEST2(p[0], 1))
2832 if (!ND_TTEST2(p[0], sizeof(marker)))
2834 if (memcmp(p, marker, sizeof(marker)) != 0) {
2839 /* found BGP header */
2840 ND_TCHECK2(p[0], BGP_SIZE); /*XXX*/
2841 memcpy(&bgp, p, BGP_SIZE);
2844 ND_PRINT((ndo, " %s", tstr));
2846 hlen = ntohs(bgp.bgp_len);
2847 if (hlen < BGP_SIZE) {
2848 ND_PRINT((ndo, "\n[|BGP Bogus header length %u < %u]", hlen,
2853 if (ND_TTEST2(p[0], hlen)) {
2854 if (!bgp_header_print(ndo, p, hlen))
2859 ND_PRINT((ndo, "\n[|BGP %s]",
2860 tok2str(bgp_msg_values,
2861 "Unknown Message Type",
2870 ND_PRINT((ndo, "%s", tstr));
2875 * c-style: whitesmith