2 * Copyright (C) 1999 WIDE Project.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Extensively modified by Hannes Gredler (hannes@gredler.at) for more
30 * complete BGP support.
33 /* \summary: Border Gateway Protocol (BGP) printer */
39 #include <netdissect-stdinc.h>
44 #include "netdissect.h"
45 #include "addrtoname.h"
51 uint8_t bgp_marker[16];
55 #define BGP_SIZE 19 /* unaligned */
59 #define BGP_NOTIFICATION 3
60 #define BGP_KEEPALIVE 4
61 #define BGP_ROUTE_REFRESH 5
63 static const struct tok bgp_msg_values[] = {
65 { BGP_UPDATE, "Update"},
66 { BGP_NOTIFICATION, "Notification"},
67 { BGP_KEEPALIVE, "Keepalive"},
68 { BGP_ROUTE_REFRESH, "Route Refresh"},
73 uint8_t bgpo_marker[16];
78 uint16_t bgpo_holdtime;
81 /* options should follow */
83 #define BGP_OPEN_SIZE 29 /* unaligned */
90 #define BGP_OPT_SIZE 2 /* some compilers may pad to 4 bytes */
91 #define BGP_CAP_HEADER_SIZE 2 /* some compilers may pad to 4 bytes */
93 struct bgp_notification {
94 uint8_t bgpn_marker[16];
100 #define BGP_NOTIFICATION_SIZE 21 /* unaligned */
102 struct bgp_route_refresh {
103 uint8_t bgp_marker[16];
106 uint8_t afi[2]; /* the compiler messes this structure up */
107 uint8_t res; /* when doing misaligned sequences of int8 and int16 */
108 uint8_t safi; /* afi should be int16 - so we have to access it using */
109 }; /* EXTRACT_16BITS(&bgp_route_refresh->afi) (sigh) */
110 #define BGP_ROUTE_REFRESH_SIZE 23
112 #define bgp_attr_lenlen(flags, p) \
113 (((flags) & 0x10) ? 2 : 1)
114 #define bgp_attr_len(flags, p) \
115 (((flags) & 0x10) ? EXTRACT_16BITS(p) : *(p))
117 #define BGPTYPE_ORIGIN 1
118 #define BGPTYPE_AS_PATH 2
119 #define BGPTYPE_NEXT_HOP 3
120 #define BGPTYPE_MULTI_EXIT_DISC 4
121 #define BGPTYPE_LOCAL_PREF 5
122 #define BGPTYPE_ATOMIC_AGGREGATE 6
123 #define BGPTYPE_AGGREGATOR 7
124 #define BGPTYPE_COMMUNITIES 8 /* RFC1997 */
125 #define BGPTYPE_ORIGINATOR_ID 9 /* RFC4456 */
126 #define BGPTYPE_CLUSTER_LIST 10 /* RFC4456 */
127 #define BGPTYPE_DPA 11 /* deprecated, draft-ietf-idr-bgp-dpa */
128 #define BGPTYPE_ADVERTISERS 12 /* deprecated RFC1863 */
129 #define BGPTYPE_RCID_PATH 13 /* deprecated RFC1863 */
130 #define BGPTYPE_MP_REACH_NLRI 14 /* RFC4760 */
131 #define BGPTYPE_MP_UNREACH_NLRI 15 /* RFC4760 */
132 #define BGPTYPE_EXTD_COMMUNITIES 16 /* RFC4360 */
133 #define BGPTYPE_AS4_PATH 17 /* RFC6793 */
134 #define BGPTYPE_AGGREGATOR4 18 /* RFC6793 */
135 #define BGPTYPE_PMSI_TUNNEL 22 /* RFC6514 */
136 #define BGPTYPE_TUNNEL_ENCAP 23 /* RFC5512 */
137 #define BGPTYPE_TRAFFIC_ENG 24 /* RFC5543 */
138 #define BGPTYPE_IPV6_EXTD_COMMUNITIES 25 /* RFC5701 */
139 #define BGPTYPE_AIGP 26 /* RFC7311 */
140 #define BGPTYPE_PE_DISTINGUISHER_LABEL 27 /* RFC6514 */
141 #define BGPTYPE_ENTROPY_LABEL 28 /* RFC6790 */
142 #define BGPTYPE_LARGE_COMMUNITY 32 /* draft-ietf-idr-large-community-05 */
143 #define BGPTYPE_ATTR_SET 128 /* RFC6368 */
145 #define BGP_MP_NLRI_MINSIZE 3 /* End of RIB Marker detection */
147 static const struct tok bgp_attr_values[] = {
148 { BGPTYPE_ORIGIN, "Origin"},
149 { BGPTYPE_AS_PATH, "AS Path"},
150 { BGPTYPE_AS4_PATH, "AS4 Path"},
151 { BGPTYPE_NEXT_HOP, "Next Hop"},
152 { BGPTYPE_MULTI_EXIT_DISC, "Multi Exit Discriminator"},
153 { BGPTYPE_LOCAL_PREF, "Local Preference"},
154 { BGPTYPE_ATOMIC_AGGREGATE, "Atomic Aggregate"},
155 { BGPTYPE_AGGREGATOR, "Aggregator"},
156 { BGPTYPE_AGGREGATOR4, "Aggregator4"},
157 { BGPTYPE_COMMUNITIES, "Community"},
158 { BGPTYPE_ORIGINATOR_ID, "Originator ID"},
159 { BGPTYPE_CLUSTER_LIST, "Cluster List"},
160 { BGPTYPE_DPA, "DPA"},
161 { BGPTYPE_ADVERTISERS, "Advertisers"},
162 { BGPTYPE_RCID_PATH, "RCID Path / Cluster ID"},
163 { BGPTYPE_MP_REACH_NLRI, "Multi-Protocol Reach NLRI"},
164 { BGPTYPE_MP_UNREACH_NLRI, "Multi-Protocol Unreach NLRI"},
165 { BGPTYPE_EXTD_COMMUNITIES, "Extended Community"},
166 { BGPTYPE_PMSI_TUNNEL, "PMSI Tunnel"},
167 { BGPTYPE_TUNNEL_ENCAP, "Tunnel Encapsulation"},
168 { BGPTYPE_TRAFFIC_ENG, "Traffic Engineering"},
169 { BGPTYPE_IPV6_EXTD_COMMUNITIES, "IPv6 Extended Community"},
170 { BGPTYPE_AIGP, "Accumulated IGP Metric"},
171 { BGPTYPE_PE_DISTINGUISHER_LABEL, "PE Distinguisher Label"},
172 { BGPTYPE_ENTROPY_LABEL, "Entropy Label"},
173 { BGPTYPE_LARGE_COMMUNITY, "Large Community"},
174 { BGPTYPE_ATTR_SET, "Attribute Set"},
175 { 255, "Reserved for development"},
180 #define BGP_AS_SEQUENCE 2
181 #define BGP_CONFED_AS_SEQUENCE 3 /* draft-ietf-idr-rfc3065bis-01 */
182 #define BGP_CONFED_AS_SET 4 /* draft-ietf-idr-rfc3065bis-01 */
184 #define BGP_AS_SEG_TYPE_MIN BGP_AS_SET
185 #define BGP_AS_SEG_TYPE_MAX BGP_CONFED_AS_SET
187 static const struct tok bgp_as_path_segment_open_values[] = {
188 { BGP_AS_SEQUENCE, ""},
190 { BGP_CONFED_AS_SEQUENCE, "( "},
191 { BGP_CONFED_AS_SET, "({ "},
195 static const struct tok bgp_as_path_segment_close_values[] = {
196 { BGP_AS_SEQUENCE, ""},
198 { BGP_CONFED_AS_SEQUENCE, ")"},
199 { BGP_CONFED_AS_SET, "})"},
203 #define BGP_OPT_AUTH 1
204 #define BGP_OPT_CAP 2
206 static const struct tok bgp_opt_values[] = {
207 { BGP_OPT_AUTH, "Authentication Information"},
208 { BGP_OPT_CAP, "Capabilities Advertisement"},
212 #define BGP_CAPCODE_MP 1 /* RFC2858 */
213 #define BGP_CAPCODE_RR 2 /* RFC2918 */
214 #define BGP_CAPCODE_ORF 3 /* RFC5291 */
215 #define BGP_CAPCODE_MR 4 /* RFC3107 */
216 #define BGP_CAPCODE_EXT_NH 5 /* RFC5549 */
217 #define BGP_CAPCODE_RESTART 64 /* RFC4724 */
218 #define BGP_CAPCODE_AS_NEW 65 /* RFC6793 */
219 #define BGP_CAPCODE_DYN_CAP 67 /* draft-ietf-idr-dynamic-cap */
220 #define BGP_CAPCODE_MULTISESS 68 /* draft-ietf-idr-bgp-multisession */
221 #define BGP_CAPCODE_ADD_PATH 69 /* RFC7911 */
222 #define BGP_CAPCODE_ENH_RR 70 /* draft-keyur-bgp-enhanced-route-refresh */
223 #define BGP_CAPCODE_RR_CISCO 128
225 static const struct tok bgp_capcode_values[] = {
226 { BGP_CAPCODE_MP, "Multiprotocol Extensions"},
227 { BGP_CAPCODE_RR, "Route Refresh"},
228 { BGP_CAPCODE_ORF, "Cooperative Route Filtering"},
229 { BGP_CAPCODE_MR, "Multiple Routes to a Destination"},
230 { BGP_CAPCODE_EXT_NH, "Extended Next Hop Encoding"},
231 { BGP_CAPCODE_RESTART, "Graceful Restart"},
232 { BGP_CAPCODE_AS_NEW, "32-Bit AS Number"},
233 { BGP_CAPCODE_DYN_CAP, "Dynamic Capability"},
234 { BGP_CAPCODE_MULTISESS, "Multisession BGP"},
235 { BGP_CAPCODE_ADD_PATH, "Multiple Paths"},
236 { BGP_CAPCODE_ENH_RR, "Enhanced Route Refresh"},
237 { BGP_CAPCODE_RR_CISCO, "Route Refresh (Cisco)"},
241 #define BGP_NOTIFY_MAJOR_MSG 1
242 #define BGP_NOTIFY_MAJOR_OPEN 2
243 #define BGP_NOTIFY_MAJOR_UPDATE 3
244 #define BGP_NOTIFY_MAJOR_HOLDTIME 4
245 #define BGP_NOTIFY_MAJOR_FSM 5
246 #define BGP_NOTIFY_MAJOR_CEASE 6
247 #define BGP_NOTIFY_MAJOR_CAP 7
249 static const struct tok bgp_notify_major_values[] = {
250 { BGP_NOTIFY_MAJOR_MSG, "Message Header Error"},
251 { BGP_NOTIFY_MAJOR_OPEN, "OPEN Message Error"},
252 { BGP_NOTIFY_MAJOR_UPDATE, "UPDATE Message Error"},
253 { BGP_NOTIFY_MAJOR_HOLDTIME,"Hold Timer Expired"},
254 { BGP_NOTIFY_MAJOR_FSM, "Finite State Machine Error"},
255 { BGP_NOTIFY_MAJOR_CEASE, "Cease"},
256 { BGP_NOTIFY_MAJOR_CAP, "Capability Message Error"},
260 /* draft-ietf-idr-cease-subcode-02 */
261 #define BGP_NOTIFY_MINOR_CEASE_MAXPRFX 1
262 static const struct tok bgp_notify_minor_cease_values[] = {
263 { BGP_NOTIFY_MINOR_CEASE_MAXPRFX, "Maximum Number of Prefixes Reached"},
264 { 2, "Administratively Shutdown"},
265 { 3, "Peer Unconfigured"},
266 { 4, "Administratively Reset"},
267 { 5, "Connection Rejected"},
268 { 6, "Other Configuration Change"},
269 { 7, "Connection Collision Resolution"},
273 static const struct tok bgp_notify_minor_msg_values[] = {
274 { 1, "Connection Not Synchronized"},
275 { 2, "Bad Message Length"},
276 { 3, "Bad Message Type"},
280 static const struct tok bgp_notify_minor_open_values[] = {
281 { 1, "Unsupported Version Number"},
283 { 3, "Bad BGP Identifier"},
284 { 4, "Unsupported Optional Parameter"},
285 { 5, "Authentication Failure"},
286 { 6, "Unacceptable Hold Time"},
287 { 7, "Capability Message Error"},
291 static const struct tok bgp_notify_minor_update_values[] = {
292 { 1, "Malformed Attribute List"},
293 { 2, "Unrecognized Well-known Attribute"},
294 { 3, "Missing Well-known Attribute"},
295 { 4, "Attribute Flags Error"},
296 { 5, "Attribute Length Error"},
297 { 6, "Invalid ORIGIN Attribute"},
298 { 7, "AS Routing Loop"},
299 { 8, "Invalid NEXT_HOP Attribute"},
300 { 9, "Optional Attribute Error"},
301 { 10, "Invalid Network Field"},
302 { 11, "Malformed AS_PATH"},
306 static const struct tok bgp_notify_minor_fsm_values[] = {
307 { 1, "In OpenSent State"},
308 { 2, "In OpenConfirm State"},
309 { 3, "In Established State"},
313 static const struct tok bgp_notify_minor_cap_values[] = {
314 { 1, "Invalid Action Value" },
315 { 2, "Invalid Capability Length" },
316 { 3, "Malformed Capability Value" },
317 { 4, "Unsupported Capability Code" },
321 static const struct tok bgp_origin_values[] = {
328 #define BGP_PMSI_TUNNEL_RSVP_P2MP 1
329 #define BGP_PMSI_TUNNEL_LDP_P2MP 2
330 #define BGP_PMSI_TUNNEL_PIM_SSM 3
331 #define BGP_PMSI_TUNNEL_PIM_SM 4
332 #define BGP_PMSI_TUNNEL_PIM_BIDIR 5
333 #define BGP_PMSI_TUNNEL_INGRESS 6
334 #define BGP_PMSI_TUNNEL_LDP_MP2MP 7
336 static const struct tok bgp_pmsi_tunnel_values[] = {
337 { BGP_PMSI_TUNNEL_RSVP_P2MP, "RSVP-TE P2MP LSP"},
338 { BGP_PMSI_TUNNEL_LDP_P2MP, "LDP P2MP LSP"},
339 { BGP_PMSI_TUNNEL_PIM_SSM, "PIM-SSM Tree"},
340 { BGP_PMSI_TUNNEL_PIM_SM, "PIM-SM Tree"},
341 { BGP_PMSI_TUNNEL_PIM_BIDIR, "PIM-Bidir Tree"},
342 { BGP_PMSI_TUNNEL_INGRESS, "Ingress Replication"},
343 { BGP_PMSI_TUNNEL_LDP_MP2MP, "LDP MP2MP LSP"},
347 static const struct tok bgp_pmsi_flag_values[] = {
348 { 0x01, "Leaf Information required"},
352 #define BGP_AIGP_TLV 1
354 static const struct tok bgp_aigp_values[] = {
355 { BGP_AIGP_TLV, "AIGP"},
359 /* Subsequent address family identifier, RFC2283 section 7 */
361 #define SAFNUM_UNICAST 1
362 #define SAFNUM_MULTICAST 2
363 #define SAFNUM_UNIMULTICAST 3 /* deprecated now */
364 /* labeled BGP RFC3107 */
365 #define SAFNUM_LABUNICAST 4
367 #define SAFNUM_MULTICAST_VPN 5
368 /* draft-nalawade-kapoor-tunnel-safi */
369 #define SAFNUM_TUNNEL 64
371 #define SAFNUM_VPLS 65
373 #define SAFNUM_MDT 66
375 #define SAFNUM_VPNUNICAST 128
377 #define SAFNUM_VPNMULTICAST 129
378 #define SAFNUM_VPNUNIMULTICAST 130 /* deprecated now */
380 #define SAFNUM_RT_ROUTING_INFO 132
382 #define BGP_VPN_RD_LEN 8
384 static const struct tok bgp_safi_values[] = {
385 { SAFNUM_RES, "Reserved"},
386 { SAFNUM_UNICAST, "Unicast"},
387 { SAFNUM_MULTICAST, "Multicast"},
388 { SAFNUM_UNIMULTICAST, "Unicast+Multicast"},
389 { SAFNUM_LABUNICAST, "labeled Unicast"},
390 { SAFNUM_TUNNEL, "Tunnel"},
391 { SAFNUM_VPLS, "VPLS"},
392 { SAFNUM_MDT, "MDT"},
393 { SAFNUM_VPNUNICAST, "labeled VPN Unicast"},
394 { SAFNUM_VPNMULTICAST, "labeled VPN Multicast"},
395 { SAFNUM_VPNUNIMULTICAST, "labeled VPN Unicast+Multicast"},
396 { SAFNUM_RT_ROUTING_INFO, "Route Target Routing Information"},
397 { SAFNUM_MULTICAST_VPN, "Multicast VPN"},
401 /* well-known community */
402 #define BGP_COMMUNITY_NO_EXPORT 0xffffff01
403 #define BGP_COMMUNITY_NO_ADVERT 0xffffff02
404 #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03
406 /* Extended community type - draft-ietf-idr-bgp-ext-communities-05 */
407 #define BGP_EXT_COM_RT_0 0x0002 /* Route Target,Format AS(2bytes):AN(4bytes) */
408 #define BGP_EXT_COM_RT_1 0x0102 /* Route Target,Format IP address:AN(2bytes) */
409 #define BGP_EXT_COM_RT_2 0x0202 /* Route Target,Format AN(4bytes):local(2bytes) */
410 #define BGP_EXT_COM_RO_0 0x0003 /* Route Origin,Format AS(2bytes):AN(4bytes) */
411 #define BGP_EXT_COM_RO_1 0x0103 /* Route Origin,Format IP address:AN(2bytes) */
412 #define BGP_EXT_COM_RO_2 0x0203 /* Route Origin,Format AN(4bytes):local(2bytes) */
413 #define BGP_EXT_COM_LINKBAND 0x4004 /* Link Bandwidth,Format AS(2B):Bandwidth(4B) */
414 /* rfc2547 bgp-mpls-vpns */
415 #define BGP_EXT_COM_VPN_ORIGIN 0x0005 /* OSPF Domain ID / VPN of Origin - draft-rosen-vpns-ospf-bgp-mpls */
416 #define BGP_EXT_COM_VPN_ORIGIN2 0x0105 /* duplicate - keep for backwards compatability */
417 #define BGP_EXT_COM_VPN_ORIGIN3 0x0205 /* duplicate - keep for backwards compatability */
418 #define BGP_EXT_COM_VPN_ORIGIN4 0x8005 /* duplicate - keep for backwards compatability */
420 #define BGP_EXT_COM_OSPF_RTYPE 0x0306 /* OSPF Route Type,Format Area(4B):RouteType(1B):Options(1B) */
421 #define BGP_EXT_COM_OSPF_RTYPE2 0x8000 /* duplicate - keep for backwards compatability */
423 #define BGP_EXT_COM_OSPF_RID 0x0107 /* OSPF Router ID,Format RouterID(4B):Unused(2B) */
424 #define BGP_EXT_COM_OSPF_RID2 0x8001 /* duplicate - keep for backwards compatability */
426 #define BGP_EXT_COM_L2INFO 0x800a /* draft-kompella-ppvpn-l2vpn */
428 #define BGP_EXT_COM_SOURCE_AS 0x0009 /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
429 #define BGP_EXT_COM_VRF_RT_IMP 0x010b /* RFC-ietf-l3vpn-2547bis-mcast-bgp-08.txt */
430 #define BGP_EXT_COM_L2VPN_RT_0 0x000a /* L2VPN Identifier,Format AS(2bytes):AN(4bytes) */
431 #define BGP_EXT_COM_L2VPN_RT_1 0xF10a /* L2VPN Identifier,Format IP address:AN(2bytes) */
433 /* http://www.cisco.com/en/US/tech/tk436/tk428/technologies_tech_note09186a00801eb09a.shtml */
434 #define BGP_EXT_COM_EIGRP_GEN 0x8800
435 #define BGP_EXT_COM_EIGRP_METRIC_AS_DELAY 0x8801
436 #define BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW 0x8802
437 #define BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU 0x8803
438 #define BGP_EXT_COM_EIGRP_EXT_REMAS_REMID 0x8804
439 #define BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC 0x8805
441 static const struct tok bgp_extd_comm_flag_values[] = {
442 { 0x8000, "vendor-specific"},
443 { 0x4000, "non-transitive"},
447 static const struct tok bgp_extd_comm_subtype_values[] = {
448 { BGP_EXT_COM_RT_0, "target"},
449 { BGP_EXT_COM_RT_1, "target"},
450 { BGP_EXT_COM_RT_2, "target"},
451 { BGP_EXT_COM_RO_0, "origin"},
452 { BGP_EXT_COM_RO_1, "origin"},
453 { BGP_EXT_COM_RO_2, "origin"},
454 { BGP_EXT_COM_LINKBAND, "link-BW"},
455 { BGP_EXT_COM_VPN_ORIGIN, "ospf-domain"},
456 { BGP_EXT_COM_VPN_ORIGIN2, "ospf-domain"},
457 { BGP_EXT_COM_VPN_ORIGIN3, "ospf-domain"},
458 { BGP_EXT_COM_VPN_ORIGIN4, "ospf-domain"},
459 { BGP_EXT_COM_OSPF_RTYPE, "ospf-route-type"},
460 { BGP_EXT_COM_OSPF_RTYPE2, "ospf-route-type"},
461 { BGP_EXT_COM_OSPF_RID, "ospf-router-id"},
462 { BGP_EXT_COM_OSPF_RID2, "ospf-router-id"},
463 { BGP_EXT_COM_L2INFO, "layer2-info"},
464 { BGP_EXT_COM_EIGRP_GEN , "eigrp-general-route (flag, tag)" },
465 { BGP_EXT_COM_EIGRP_METRIC_AS_DELAY , "eigrp-route-metric (AS, delay)" },
466 { BGP_EXT_COM_EIGRP_METRIC_REL_NH_BW , "eigrp-route-metric (reliability, nexthop, bandwidth)" },
467 { BGP_EXT_COM_EIGRP_METRIC_LOAD_MTU , "eigrp-route-metric (load, MTU)" },
468 { BGP_EXT_COM_EIGRP_EXT_REMAS_REMID , "eigrp-external-route (remote-AS, remote-ID)" },
469 { BGP_EXT_COM_EIGRP_EXT_REMPROTO_REMMETRIC , "eigrp-external-route (remote-proto, remote-metric)" },
470 { BGP_EXT_COM_SOURCE_AS, "source-AS" },
471 { BGP_EXT_COM_VRF_RT_IMP, "vrf-route-import"},
472 { BGP_EXT_COM_L2VPN_RT_0, "l2vpn-id"},
473 { BGP_EXT_COM_L2VPN_RT_1, "l2vpn-id"},
477 /* OSPF codes for BGP_EXT_COM_OSPF_RTYPE draft-rosen-vpns-ospf-bgp-mpls */
478 #define BGP_OSPF_RTYPE_RTR 1 /* OSPF Router LSA */
479 #define BGP_OSPF_RTYPE_NET 2 /* OSPF Network LSA */
480 #define BGP_OSPF_RTYPE_SUM 3 /* OSPF Summary LSA */
481 #define BGP_OSPF_RTYPE_EXT 5 /* OSPF External LSA, note that ASBR doesn't apply to MPLS-VPN */
482 #define BGP_OSPF_RTYPE_NSSA 7 /* OSPF NSSA External*/
483 #define BGP_OSPF_RTYPE_SHAM 129 /* OSPF-MPLS-VPN Sham link */
484 #define BGP_OSPF_RTYPE_METRIC_TYPE 0x1 /* LSB of RTYPE Options Field */
486 static const struct tok bgp_extd_comm_ospf_rtype_values[] = {
487 { BGP_OSPF_RTYPE_RTR, "Router" },
488 { BGP_OSPF_RTYPE_NET, "Network" },
489 { BGP_OSPF_RTYPE_SUM, "Summary" },
490 { BGP_OSPF_RTYPE_EXT, "External" },
491 { BGP_OSPF_RTYPE_NSSA,"NSSA External" },
492 { BGP_OSPF_RTYPE_SHAM,"MPLS-VPN Sham" },
496 /* ADD-PATH Send/Receive field values */
497 static const struct tok bgp_add_path_recvsend[] = {
504 static char astostr[20];
509 * Convert an AS number into a string and return string pointer.
511 * Depending on bflag is set or not, AS number is converted into ASDOT notation
512 * or plain number notation.
516 as_printf(netdissect_options *ndo,
517 char *str, int size, u_int asnum)
519 if (!ndo->ndo_bflag || asnum <= 0xFFFF) {
520 snprintf(str, size, "%u", asnum);
522 snprintf(str, size, "%u.%u", asnum >> 16, asnum & 0xFFFF);
527 #define ITEMCHECK(minlen) if (itemlen < minlen) goto badtlv;
530 decode_prefix4(netdissect_options *ndo,
531 const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
534 u_int plen, plenbytes;
543 memset(&addr, 0, sizeof(addr));
544 plenbytes = (plen + 7) / 8;
545 ND_TCHECK2(pptr[1], plenbytes);
546 ITEMCHECK(plenbytes);
547 memcpy(&addr, &pptr[1], plenbytes);
549 ((u_char *)&addr)[plenbytes - 1] &=
550 ((0xff00 >> (plen % 8)) & 0xff);
552 snprintf(buf, buflen, "%s/%d", ipaddr_string(ndo, &addr), plen);
553 return 1 + plenbytes;
563 decode_labeled_prefix4(netdissect_options *ndo,
564 const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
567 u_int plen, plenbytes;
569 /* prefix length and label = 4 bytes */
570 ND_TCHECK2(pptr[0], 4);
572 plen = pptr[0]; /* get prefix length */
574 /* this is one of the weirdnesses of rfc3107
575 the label length (actually the label + COS bits)
576 is added to the prefix length;
577 we also do only read out just one label -
578 there is no real application for advertisement of
579 stacked labels in a single BGP message
585 plen-=24; /* adjust prefixlen - labellength */
591 memset(&addr, 0, sizeof(addr));
592 plenbytes = (plen + 7) / 8;
593 ND_TCHECK2(pptr[4], plenbytes);
594 ITEMCHECK(plenbytes);
595 memcpy(&addr, &pptr[4], plenbytes);
597 ((u_char *)&addr)[plenbytes - 1] &=
598 ((0xff00 >> (plen % 8)) & 0xff);
600 /* the label may get offsetted by 4 bits so lets shift it right */
601 snprintf(buf, buflen, "%s/%d, label:%u %s",
602 ipaddr_string(ndo, &addr),
604 EXTRACT_24BITS(pptr+1)>>4,
605 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
607 return 4 + plenbytes;
619 * print an ipv4 or ipv6 address into a buffer dependend on address length.
622 bgp_vpn_ip_print(netdissect_options *ndo,
623 const u_char *pptr, u_int addr_length)
626 /* worst case string is s fully formatted v6 address */
627 static char addr[sizeof("1234:5678:89ab:cdef:1234:5678:89ab:cdef")];
630 switch(addr_length) {
631 case (sizeof(struct in_addr) << 3): /* 32 */
632 ND_TCHECK2(pptr[0], sizeof(struct in_addr));
633 snprintf(pos, sizeof(addr), "%s", ipaddr_string(ndo, pptr));
635 case (sizeof(struct in6_addr) << 3): /* 128 */
636 ND_TCHECK2(pptr[0], sizeof(struct in6_addr));
637 snprintf(pos, sizeof(addr), "%s", ip6addr_string(ndo, pptr));
640 snprintf(pos, sizeof(addr), "bogus address length %u", addr_length);
653 * print an multicast s,g entry into a buffer.
654 * the s,g entry is encoded like this.
656 * +-----------------------------------+
657 * | Multicast Source Length (1 octet) |
658 * +-----------------------------------+
659 * | Multicast Source (Variable) |
660 * +-----------------------------------+
661 * | Multicast Group Length (1 octet) |
662 * +-----------------------------------+
663 * | Multicast Group (Variable) |
664 * +-----------------------------------+
666 * return the number of bytes read from the wire.
669 bgp_vpn_sg_print(netdissect_options *ndo,
670 const u_char *pptr, char *buf, u_int buflen)
673 u_int total_length, offset;
677 /* Source address length, encoded in bits */
678 ND_TCHECK2(pptr[0], 1);
679 addr_length = *pptr++;
682 ND_TCHECK2(pptr[0], (addr_length >> 3));
683 total_length += (addr_length >> 3) + 1;
684 offset = strlen(buf);
686 snprintf(buf + offset, buflen - offset, ", Source %s",
687 bgp_vpn_ip_print(ndo, pptr, addr_length));
688 pptr += (addr_length >> 3);
691 /* Group address length, encoded in bits */
692 ND_TCHECK2(pptr[0], 1);
693 addr_length = *pptr++;
696 ND_TCHECK2(pptr[0], (addr_length >> 3));
697 total_length += (addr_length >> 3) + 1;
698 offset = strlen(buf);
700 snprintf(buf + offset, buflen - offset, ", Group %s",
701 bgp_vpn_ip_print(ndo, pptr, addr_length));
702 pptr += (addr_length >> 3);
706 return (total_length);
709 /* RDs and RTs share the same semantics
710 * we use bgp_vpn_rd_print for
711 * printing route targets inside a NLRI */
713 bgp_vpn_rd_print(netdissect_options *ndo,
716 /* allocate space for the largest possible string */
717 static char rd[sizeof("xxxxxxxxxx:xxxxx (xxx.xxx.xxx.xxx:xxxxx)")];
720 /* ok lets load the RD format */
721 switch (EXTRACT_16BITS(pptr)) {
723 /* 2-byte-AS:number fmt*/
725 snprintf(pos, sizeof(rd) - (pos - rd), "%u:%u (= %u.%u.%u.%u)",
726 EXTRACT_16BITS(pptr+2),
727 EXTRACT_32BITS(pptr+4),
728 *(pptr+4), *(pptr+5), *(pptr+6), *(pptr+7));
730 /* IP-address:AS fmt*/
733 snprintf(pos, sizeof(rd) - (pos - rd), "%u.%u.%u.%u:%u",
734 *(pptr+2), *(pptr+3), *(pptr+4), *(pptr+5), EXTRACT_16BITS(pptr+6));
737 /* 4-byte-AS:number fmt*/
739 snprintf(pos, sizeof(rd) - (pos - rd), "%s:%u (%u.%u.%u.%u:%u)",
740 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(pptr+2)),
741 EXTRACT_16BITS(pptr+6), *(pptr+2), *(pptr+3), *(pptr+4),
742 *(pptr+5), EXTRACT_16BITS(pptr+6));
745 snprintf(pos, sizeof(rd) - (pos - rd), "unknown RD format");
754 decode_rt_routing_info(netdissect_options *ndo,
755 const u_char *pptr, char *buf, u_int buflen)
757 uint8_t route_target[8];
759 char asbuf[sizeof(astostr)]; /* bgp_vpn_rd_print() overwrites astostr */
761 /* NLRI "prefix length" from RFC 2858 Section 4. */
763 plen = pptr[0]; /* get prefix length */
765 /* NLRI "prefix" (ibid), valid lengths are { 0, 32, 33, ..., 96 } bits.
766 * RFC 4684 Section 4 defines the layout of "origin AS" and "route
767 * target" fields inside the "prefix" depending on its length.
770 /* Without "origin AS", without "route target". */
771 snprintf(buf, buflen, "default route target");
778 /* With at least "origin AS", possibly with "route target". */
779 ND_TCHECK_32BITS(pptr + 1);
780 as_printf(ndo, asbuf, sizeof(asbuf), EXTRACT_32BITS(pptr + 1));
782 plen-=32; /* adjust prefix length */
787 /* From now on (plen + 7) / 8 evaluates to { 0, 1, 2, ..., 8 }
788 * and gives the number of octets in the variable-length "route
789 * target" field inside this NLRI "prefix". Look for it.
791 memset(&route_target, 0, sizeof(route_target));
792 ND_TCHECK2(pptr[5], (plen + 7) / 8);
793 memcpy(&route_target, &pptr[5], (plen + 7) / 8);
794 /* Which specification says to do this? */
796 ((u_char *)&route_target)[(plen + 7) / 8 - 1] &=
797 ((0xff00 >> (plen % 8)) & 0xff);
799 snprintf(buf, buflen, "origin AS: %s, route target %s",
801 bgp_vpn_rd_print(ndo, (u_char *)&route_target));
803 return 5 + (plen + 7) / 8;
810 decode_labeled_vpn_prefix4(netdissect_options *ndo,
811 const u_char *pptr, char *buf, u_int buflen)
817 plen = pptr[0]; /* get prefix length */
822 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
827 memset(&addr, 0, sizeof(addr));
828 ND_TCHECK2(pptr[12], (plen + 7) / 8);
829 memcpy(&addr, &pptr[12], (plen + 7) / 8);
831 ((u_char *)&addr)[(plen + 7) / 8 - 1] &=
832 ((0xff00 >> (plen % 8)) & 0xff);
834 /* the label may get offsetted by 4 bits so lets shift it right */
835 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
836 bgp_vpn_rd_print(ndo, pptr+4),
837 ipaddr_string(ndo, &addr),
839 EXTRACT_24BITS(pptr+1)>>4,
840 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
842 return 12 + (plen + 7) / 8;
849 * +-------------------------------+
851 * | RD:IPv4-address (12 octets) |
853 * +-------------------------------+
854 * | MDT Group-address (4 octets) |
855 * +-------------------------------+
858 #define MDT_VPN_NLRI_LEN 16
861 decode_mdt_vpn_nlri(netdissect_options *ndo,
862 const u_char *pptr, char *buf, u_int buflen)
866 const u_char *vpn_ip;
870 /* if the NLRI is not predefined length, quit.*/
871 if (*pptr != MDT_VPN_NLRI_LEN * 8)
876 ND_TCHECK2(pptr[0], 8);
881 ND_TCHECK2(pptr[0], sizeof(struct in_addr));
883 pptr+=sizeof(struct in_addr);
885 /* MDT Group Address */
886 ND_TCHECK2(pptr[0], sizeof(struct in_addr));
888 snprintf(buf, buflen, "RD: %s, VPN IP Address: %s, MC Group Address: %s",
889 bgp_vpn_rd_print(ndo, rd), ipaddr_string(ndo, vpn_ip), ipaddr_string(ndo, pptr));
891 return MDT_VPN_NLRI_LEN + 1;
898 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI 1
899 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI 2
900 #define BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI 3
901 #define BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF 4
902 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE 5
903 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN 6
904 #define BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN 7
906 static const struct tok bgp_multicast_vpn_route_type_values[] = {
907 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI, "Intra-AS I-PMSI"},
908 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI, "Inter-AS I-PMSI"},
909 { BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI, "S-PMSI"},
910 { BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF, "Intra-AS Segment-Leaf"},
911 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE, "Source-Active"},
912 { BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN, "Shared Tree Join"},
913 { BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN, "Source Tree Join"},
918 decode_multicast_vpn(netdissect_options *ndo,
919 const u_char *pptr, char *buf, u_int buflen)
921 uint8_t route_type, route_length, addr_length, sg_length;
924 ND_TCHECK2(pptr[0], 2);
925 route_type = *pptr++;
926 route_length = *pptr++;
928 snprintf(buf, buflen, "Route-Type: %s (%u), length: %u",
929 tok2str(bgp_multicast_vpn_route_type_values,
930 "Unknown", route_type),
931 route_type, route_length);
934 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_I_PMSI:
935 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
936 offset = strlen(buf);
937 snprintf(buf + offset, buflen - offset, ", RD: %s, Originator %s",
938 bgp_vpn_rd_print(ndo, pptr),
939 bgp_vpn_ip_print(ndo, pptr + BGP_VPN_RD_LEN,
940 (route_length - BGP_VPN_RD_LEN) << 3));
942 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTER_AS_I_PMSI:
943 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN + 4);
944 offset = strlen(buf);
945 snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
946 bgp_vpn_rd_print(ndo, pptr),
947 as_printf(ndo, astostr, sizeof(astostr),
948 EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN)));
951 case BGP_MULTICAST_VPN_ROUTE_TYPE_S_PMSI:
952 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
953 offset = strlen(buf);
954 snprintf(buf + offset, buflen - offset, ", RD: %s",
955 bgp_vpn_rd_print(ndo, pptr));
956 pptr += BGP_VPN_RD_LEN;
958 sg_length = bgp_vpn_sg_print(ndo, pptr, buf, buflen);
959 addr_length = route_length - sg_length;
961 ND_TCHECK2(pptr[0], addr_length);
962 offset = strlen(buf);
963 snprintf(buf + offset, buflen - offset, ", Originator %s",
964 bgp_vpn_ip_print(ndo, pptr, addr_length << 3));
967 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_ACTIVE:
968 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN);
969 offset = strlen(buf);
970 snprintf(buf + offset, buflen - offset, ", RD: %s",
971 bgp_vpn_rd_print(ndo, pptr));
972 pptr += BGP_VPN_RD_LEN;
974 bgp_vpn_sg_print(ndo, pptr, buf, buflen);
977 case BGP_MULTICAST_VPN_ROUTE_TYPE_SHARED_TREE_JOIN: /* fall through */
978 case BGP_MULTICAST_VPN_ROUTE_TYPE_SOURCE_TREE_JOIN:
979 ND_TCHECK2(pptr[0], BGP_VPN_RD_LEN + 4);
980 offset = strlen(buf);
981 snprintf(buf + offset, buflen - offset, ", RD: %s, Source-AS %s",
982 bgp_vpn_rd_print(ndo, pptr),
983 as_printf(ndo, astostr, sizeof(astostr),
984 EXTRACT_32BITS(pptr + BGP_VPN_RD_LEN)));
985 pptr += BGP_VPN_RD_LEN + 4;
987 bgp_vpn_sg_print(ndo, pptr, buf, buflen);
991 * no per route-type printing yet.
993 case BGP_MULTICAST_VPN_ROUTE_TYPE_INTRA_AS_SEG_LEAF:
998 return route_length + 2;
1005 * As I remember, some versions of systems have an snprintf() that
1006 * returns -1 if the buffer would have overflowed. If the return
1007 * value is negative, set buflen to 0, to indicate that we've filled
1010 * If the return value is greater than buflen, that means that
1011 * the buffer would have overflowed; again, set buflen to 0 in
1014 #define UPDATE_BUF_BUFLEN(buf, buflen, stringlen) \
1017 else if ((u_int)stringlen>buflen) \
1020 buflen-=stringlen; \
1025 decode_labeled_vpn_l2(netdissect_options *ndo,
1026 const u_char *pptr, char *buf, u_int buflen)
1028 int plen,tlen,stringlen,tlv_type,tlv_len,ttlv_len;
1030 ND_TCHECK2(pptr[0], 2);
1031 plen=EXTRACT_16BITS(pptr);
1034 /* Old and new L2VPN NLRI share AFI/SAFI
1035 * -> Assume a 12 Byte-length NLRI is auto-discovery-only
1036 * and > 17 as old format. Complain for the middle case
1039 /* assume AD-only with RD, BGPNH */
1040 ND_TCHECK2(pptr[0],12);
1042 stringlen=snprintf(buf, buflen, "RD: %s, BGPNH: %s",
1043 bgp_vpn_rd_print(ndo, pptr),
1044 ipaddr_string(ndo, pptr+8)
1046 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1050 } else if (plen>17) {
1051 /* assume old format */
1052 /* RD, ID, LBLKOFF, LBLBASE */
1054 ND_TCHECK2(pptr[0],15);
1056 stringlen=snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u",
1057 bgp_vpn_rd_print(ndo, pptr),
1058 EXTRACT_16BITS(pptr+8),
1059 EXTRACT_16BITS(pptr+10),
1060 EXTRACT_24BITS(pptr+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */
1061 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1065 /* ok now the variable part - lets read out TLVs*/
1069 ND_TCHECK2(pptr[0], 3);
1071 tlv_len=EXTRACT_16BITS(pptr);
1078 stringlen=snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x",
1081 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1083 ttlv_len=ttlv_len/8+1; /* how many bytes do we need to read ? */
1084 while (ttlv_len>0) {
1087 stringlen=snprintf(buf,buflen, "%02x",*pptr++);
1088 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1095 stringlen=snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u",
1098 UPDATE_BUF_BUFLEN(buf, buflen, stringlen);
1102 tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it right */
1107 /* complain bitterly ? */
1117 decode_prefix6(netdissect_options *ndo,
1118 const u_char *pd, u_int itemlen, char *buf, u_int buflen)
1120 struct in6_addr addr;
1121 u_int plen, plenbytes;
1130 memset(&addr, 0, sizeof(addr));
1131 plenbytes = (plen + 7) / 8;
1132 ND_TCHECK2(pd[1], plenbytes);
1133 ITEMCHECK(plenbytes);
1134 memcpy(&addr, &pd[1], plenbytes);
1136 addr.s6_addr[plenbytes - 1] &=
1137 ((0xff00 >> (plen % 8)) & 0xff);
1139 snprintf(buf, buflen, "%s/%d", ip6addr_string(ndo, &addr), plen);
1140 return 1 + plenbytes;
1150 decode_labeled_prefix6(netdissect_options *ndo,
1151 const u_char *pptr, u_int itemlen, char *buf, u_int buflen)
1153 struct in6_addr addr;
1154 u_int plen, plenbytes;
1156 /* prefix length and label = 4 bytes */
1157 ND_TCHECK2(pptr[0], 4);
1159 plen = pptr[0]; /* get prefix length */
1164 plen-=24; /* adjust prefixlen - labellength */
1170 memset(&addr, 0, sizeof(addr));
1171 plenbytes = (plen + 7) / 8;
1172 ND_TCHECK2(pptr[4], plenbytes);
1173 memcpy(&addr, &pptr[4], plenbytes);
1175 addr.s6_addr[plenbytes - 1] &=
1176 ((0xff00 >> (plen % 8)) & 0xff);
1178 /* the label may get offsetted by 4 bits so lets shift it right */
1179 snprintf(buf, buflen, "%s/%d, label:%u %s",
1180 ip6addr_string(ndo, &addr),
1182 EXTRACT_24BITS(pptr+1)>>4,
1183 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1185 return 4 + plenbytes;
1195 decode_labeled_vpn_prefix6(netdissect_options *ndo,
1196 const u_char *pptr, char *buf, u_int buflen)
1198 struct in6_addr addr;
1202 plen = pptr[0]; /* get prefix length */
1207 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
1212 memset(&addr, 0, sizeof(addr));
1213 ND_TCHECK2(pptr[12], (plen + 7) / 8);
1214 memcpy(&addr, &pptr[12], (plen + 7) / 8);
1216 addr.s6_addr[(plen + 7) / 8 - 1] &=
1217 ((0xff00 >> (plen % 8)) & 0xff);
1219 /* the label may get offsetted by 4 bits so lets shift it right */
1220 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
1221 bgp_vpn_rd_print(ndo, pptr+4),
1222 ip6addr_string(ndo, &addr),
1224 EXTRACT_24BITS(pptr+1)>>4,
1225 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1227 return 12 + (plen + 7) / 8;
1234 decode_clnp_prefix(netdissect_options *ndo,
1235 const u_char *pptr, char *buf, u_int buflen)
1241 plen = pptr[0]; /* get prefix length */
1246 memset(&addr, 0, sizeof(addr));
1247 ND_TCHECK2(pptr[4], (plen + 7) / 8);
1248 memcpy(&addr, &pptr[4], (plen + 7) / 8);
1250 addr[(plen + 7) / 8 - 1] &=
1251 ((0xff00 >> (plen % 8)) & 0xff);
1253 snprintf(buf, buflen, "%s/%d",
1254 isonsap_string(ndo, addr,(plen + 7) / 8),
1257 return 1 + (plen + 7) / 8;
1264 decode_labeled_vpn_clnp_prefix(netdissect_options *ndo,
1265 const u_char *pptr, char *buf, u_int buflen)
1271 plen = pptr[0]; /* get prefix length */
1276 plen-=(24+64); /* adjust prefixlen - labellength - RD len*/
1281 memset(&addr, 0, sizeof(addr));
1282 ND_TCHECK2(pptr[12], (plen + 7) / 8);
1283 memcpy(&addr, &pptr[12], (plen + 7) / 8);
1285 addr[(plen + 7) / 8 - 1] &=
1286 ((0xff00 >> (plen % 8)) & 0xff);
1288 /* the label may get offsetted by 4 bits so lets shift it right */
1289 snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
1290 bgp_vpn_rd_print(ndo, pptr+4),
1291 isonsap_string(ndo, addr,(plen + 7) / 8),
1293 EXTRACT_24BITS(pptr+1)>>4,
1294 ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
1296 return 12 + (plen + 7) / 8;
1303 * bgp_attr_get_as_size
1305 * Try to find the size of the ASs encoded in an as-path. It is not obvious, as
1306 * both Old speakers that do not support 4 byte AS, and the new speakers that do
1307 * support, exchange AS-Path with the same path-attribute type value 0x02.
1310 bgp_attr_get_as_size(netdissect_options *ndo,
1311 uint8_t bgpa_type, const u_char *pptr, int len)
1313 const u_char *tptr = pptr;
1316 * If the path attribute is the optional AS4 path type, then we already
1317 * know, that ASs must be encoded in 4 byte format.
1319 if (bgpa_type == BGPTYPE_AS4_PATH) {
1324 * Let us assume that ASs are of 2 bytes in size, and check if the AS-Path
1325 * TLV is good. If not, ask the caller to try with AS encoded as 4 bytes
1328 while (tptr < pptr + len) {
1332 * If we do not find a valid segment type, our guess might be wrong.
1334 if (tptr[0] < BGP_AS_SEG_TYPE_MIN || tptr[0] > BGP_AS_SEG_TYPE_MAX) {
1338 tptr += 2 + tptr[1] * 2;
1342 * If we correctly reached end of the AS path attribute data content,
1343 * then most likely ASs were indeed encoded as 2 bytes.
1345 if (tptr == pptr + len) {
1352 * We can come here, either we did not have enough data, or if we
1353 * try to decode 4 byte ASs in 2 byte format. Either way, return 4,
1354 * so that calller can try to decode each AS as of 4 bytes. If indeed
1355 * there was not enough data, it will crib and end the parse anyways.
1361 bgp_attr_print(netdissect_options *ndo,
1362 u_int atype, const u_char *pptr, u_int len)
1366 uint8_t safi, snpa, nhlen;
1367 union { /* copy buffer for bandwidth values */
1374 char buf[MAXHOSTNAMELEN + 100];
1381 case BGPTYPE_ORIGIN:
1383 ND_PRINT((ndo, "invalid len"));
1386 ND_PRINT((ndo, "%s", tok2str(bgp_origin_values,
1387 "Unknown Origin Typecode",
1393 * Process AS4 byte path and AS2 byte path attributes here.
1395 case BGPTYPE_AS4_PATH:
1396 case BGPTYPE_AS_PATH:
1398 ND_PRINT((ndo, "invalid len"));
1402 ND_PRINT((ndo, "empty"));
1407 * BGP updates exchanged between New speakers that support 4
1408 * byte AS, ASs are always encoded in 4 bytes. There is no
1409 * definitive way to find this, just by the packet's
1410 * contents. So, check for packet's TLV's sanity assuming
1411 * 2 bytes first, and it does not pass, assume that ASs are
1412 * encoded in 4 bytes format and move on.
1414 as_size = bgp_attr_get_as_size(ndo, atype, pptr, len);
1416 while (tptr < pptr + len) {
1418 ND_PRINT((ndo, "%s", tok2str(bgp_as_path_segment_open_values,
1421 for (i = 0; i < tptr[1] * as_size; i += as_size) {
1422 ND_TCHECK2(tptr[2 + i], as_size);
1423 ND_PRINT((ndo, "%s ",
1424 as_printf(ndo, astostr, sizeof(astostr),
1426 EXTRACT_16BITS(&tptr[2 + i]) :
1427 EXTRACT_32BITS(&tptr[2 + i]))));
1430 ND_PRINT((ndo, "%s", tok2str(bgp_as_path_segment_close_values,
1433 tptr += 2 + tptr[1] * as_size;
1436 case BGPTYPE_NEXT_HOP:
1438 ND_PRINT((ndo, "invalid len"));
1440 ND_TCHECK2(tptr[0], 4);
1441 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr)));
1444 case BGPTYPE_MULTI_EXIT_DISC:
1445 case BGPTYPE_LOCAL_PREF:
1447 ND_PRINT((ndo, "invalid len"));
1449 ND_TCHECK2(tptr[0], 4);
1450 ND_PRINT((ndo, "%u", EXTRACT_32BITS(tptr)));
1453 case BGPTYPE_ATOMIC_AGGREGATE:
1455 ND_PRINT((ndo, "invalid len"));
1457 case BGPTYPE_AGGREGATOR:
1460 * Depending on the AS encoded is of 2 bytes or of 4 bytes,
1461 * the length of this PA can be either 6 bytes or 8 bytes.
1463 if (len != 6 && len != 8) {
1464 ND_PRINT((ndo, "invalid len"));
1467 ND_TCHECK2(tptr[0], len);
1469 ND_PRINT((ndo, " AS #%s, origin %s",
1470 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_16BITS(tptr)),
1471 ipaddr_string(ndo, tptr + 2)));
1473 ND_PRINT((ndo, " AS #%s, origin %s",
1474 as_printf(ndo, astostr, sizeof(astostr),
1475 EXTRACT_32BITS(tptr)), ipaddr_string(ndo, tptr + 4)));
1478 case BGPTYPE_AGGREGATOR4:
1480 ND_PRINT((ndo, "invalid len"));
1483 ND_TCHECK2(tptr[0], 8);
1484 ND_PRINT((ndo, " AS #%s, origin %s",
1485 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(tptr)),
1486 ipaddr_string(ndo, tptr + 4)));
1488 case BGPTYPE_COMMUNITIES:
1490 ND_PRINT((ndo, "invalid len"));
1495 ND_TCHECK2(tptr[0], 4);
1496 comm = EXTRACT_32BITS(tptr);
1498 case BGP_COMMUNITY_NO_EXPORT:
1499 ND_PRINT((ndo, " NO_EXPORT"));
1501 case BGP_COMMUNITY_NO_ADVERT:
1502 ND_PRINT((ndo, " NO_ADVERTISE"));
1504 case BGP_COMMUNITY_NO_EXPORT_SUBCONFED:
1505 ND_PRINT((ndo, " NO_EXPORT_SUBCONFED"));
1508 ND_PRINT((ndo, "%u:%u%s",
1509 (comm >> 16) & 0xffff,
1511 (tlen>4) ? ", " : ""));
1518 case BGPTYPE_ORIGINATOR_ID:
1520 ND_PRINT((ndo, "invalid len"));
1523 ND_TCHECK2(tptr[0], 4);
1524 ND_PRINT((ndo, "%s",ipaddr_string(ndo, tptr)));
1526 case BGPTYPE_CLUSTER_LIST:
1528 ND_PRINT((ndo, "invalid len"));
1532 ND_TCHECK2(tptr[0], 4);
1533 ND_PRINT((ndo, "%s%s",
1534 ipaddr_string(ndo, tptr),
1535 (tlen>4) ? ", " : ""));
1540 case BGPTYPE_MP_REACH_NLRI:
1541 ND_TCHECK2(tptr[0], 3);
1542 af = EXTRACT_16BITS(tptr);
1545 ND_PRINT((ndo, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1546 tok2str(af_values, "Unknown AFI", af),
1548 (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1549 tok2str(bgp_safi_values, "Unknown SAFI", safi),
1552 switch(af<<8 | safi) {
1553 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1554 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1555 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1556 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1557 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
1558 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1559 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1560 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1561 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN):
1562 case (AFNUM_INET<<8 | SAFNUM_MDT):
1563 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1564 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1565 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1566 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1567 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1568 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1569 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1570 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1571 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1572 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1573 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1574 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1575 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1576 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1577 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1578 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1579 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1582 ND_TCHECK2(tptr[0], tlen);
1583 ND_PRINT((ndo, "\n\t no AFI %u / SAFI %u decoder", af, safi));
1584 if (ndo->ndo_vflag <= 1)
1585 print_unknown_data(ndo, tptr, "\n\t ", tlen);
1599 ND_PRINT((ndo, "\n\t nexthop: "));
1602 ND_PRINT((ndo, ", " ));
1604 switch(af<<8 | safi) {
1605 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1606 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1607 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1608 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1609 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
1610 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN):
1611 case (AFNUM_INET<<8 | SAFNUM_MDT):
1612 if (tlen < (int)sizeof(struct in_addr)) {
1613 ND_PRINT((ndo, "invalid len"));
1616 ND_TCHECK2(tptr[0], sizeof(struct in_addr));
1617 ND_PRINT((ndo, "%s",ipaddr_string(ndo, tptr)));
1618 tlen -= sizeof(struct in_addr);
1619 tptr += sizeof(struct in_addr);
1622 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1623 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1624 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1625 if (tlen < (int)(sizeof(struct in_addr)+BGP_VPN_RD_LEN)) {
1626 ND_PRINT((ndo, "invalid len"));
1629 ND_TCHECK2(tptr[0], sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1630 ND_PRINT((ndo, "RD: %s, %s",
1631 bgp_vpn_rd_print(ndo, tptr),
1632 ipaddr_string(ndo, tptr+BGP_VPN_RD_LEN)));
1633 tlen -= (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1634 tptr += (sizeof(struct in_addr)+BGP_VPN_RD_LEN);
1637 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1638 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1639 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1640 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1641 if (tlen < (int)sizeof(struct in6_addr)) {
1642 ND_PRINT((ndo, "invalid len"));
1645 ND_TCHECK2(tptr[0], sizeof(struct in6_addr));
1646 ND_PRINT((ndo, "%s", ip6addr_string(ndo, tptr)));
1647 tlen -= sizeof(struct in6_addr);
1648 tptr += sizeof(struct in6_addr);
1651 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1652 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1653 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1654 if (tlen < (int)(sizeof(struct in6_addr)+BGP_VPN_RD_LEN)) {
1655 ND_PRINT((ndo, "invalid len"));
1658 ND_TCHECK2(tptr[0], sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1659 ND_PRINT((ndo, "RD: %s, %s",
1660 bgp_vpn_rd_print(ndo, tptr),
1661 ip6addr_string(ndo, tptr+BGP_VPN_RD_LEN)));
1662 tlen -= (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1663 tptr += (sizeof(struct in6_addr)+BGP_VPN_RD_LEN);
1666 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1667 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1668 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1669 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1670 if (tlen < (int)sizeof(struct in_addr)) {
1671 ND_PRINT((ndo, "invalid len"));
1674 ND_TCHECK2(tptr[0], sizeof(struct in_addr));
1675 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr)));
1676 tlen -= (sizeof(struct in_addr));
1677 tptr += (sizeof(struct in_addr));
1680 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1681 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1682 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1683 ND_TCHECK2(tptr[0], tlen);
1684 ND_PRINT((ndo, "%s", isonsap_string(ndo, tptr, tlen)));
1689 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1690 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1691 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1692 if (tlen < BGP_VPN_RD_LEN+1) {
1693 ND_PRINT((ndo, "invalid len"));
1696 ND_TCHECK2(tptr[0], tlen);
1697 ND_PRINT((ndo, "RD: %s, %s",
1698 bgp_vpn_rd_print(ndo, tptr),
1699 isonsap_string(ndo, tptr+BGP_VPN_RD_LEN,tlen-BGP_VPN_RD_LEN)));
1700 /* rfc986 mapped IPv4 address ? */
1701 if (EXTRACT_32BITS(tptr+BGP_VPN_RD_LEN) == 0x47000601)
1702 ND_PRINT((ndo, " = %s", ipaddr_string(ndo, tptr+BGP_VPN_RD_LEN+4)));
1703 /* rfc1888 mapped IPv6 address ? */
1704 else if (EXTRACT_24BITS(tptr+BGP_VPN_RD_LEN) == 0x350000)
1705 ND_PRINT((ndo, " = %s", ip6addr_string(ndo, tptr+BGP_VPN_RD_LEN+3)));
1711 ND_TCHECK2(tptr[0], tlen);
1712 ND_PRINT((ndo, "no AFI %u/SAFI %u decoder", af, safi));
1713 if (ndo->ndo_vflag <= 1)
1714 print_unknown_data(ndo, tptr, "\n\t ", tlen);
1722 ND_PRINT((ndo, ", nh-length: %u", nhlen));
1730 ND_PRINT((ndo, "\n\t %u SNPA", snpa));
1731 for (/*nothing*/; snpa > 0; snpa--) {
1733 ND_PRINT((ndo, "\n\t %d bytes", tptr[0]));
1734 tptr += tptr[0] + 1;
1737 ND_PRINT((ndo, ", no SNPA"));
1740 while (tptr < pptr + len) {
1741 switch (af<<8 | safi) {
1742 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1743 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1744 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1745 advance = decode_prefix4(ndo, tptr, len, buf, sizeof(buf));
1747 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1748 else if (advance == -2)
1750 else if (advance == -3)
1751 break; /* bytes left, but not enough */
1753 ND_PRINT((ndo, "\n\t %s", buf));
1755 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1756 advance = decode_labeled_prefix4(ndo, tptr, len, buf, sizeof(buf));
1758 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1759 else if (advance == -2)
1761 else if (advance == -3)
1762 break; /* bytes left, but not enough */
1764 ND_PRINT((ndo, "\n\t %s", buf));
1766 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1767 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1768 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1769 advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, sizeof(buf));
1771 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1772 else if (advance == -2)
1775 ND_PRINT((ndo, "\n\t %s", buf));
1777 case (AFNUM_INET<<8 | SAFNUM_RT_ROUTING_INFO):
1778 advance = decode_rt_routing_info(ndo, tptr, buf, sizeof(buf));
1780 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1781 else if (advance == -2)
1784 ND_PRINT((ndo, "\n\t %s", buf));
1786 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */
1787 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN):
1788 advance = decode_multicast_vpn(ndo, tptr, buf, sizeof(buf));
1790 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1791 else if (advance == -2)
1794 ND_PRINT((ndo, "\n\t %s", buf));
1797 case (AFNUM_INET<<8 | SAFNUM_MDT):
1798 advance = decode_mdt_vpn_nlri(ndo, tptr, buf, sizeof(buf));
1800 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1801 else if (advance == -2)
1804 ND_PRINT((ndo, "\n\t %s", buf));
1806 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1807 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1808 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1809 advance = decode_prefix6(ndo, tptr, len, buf, sizeof(buf));
1811 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1812 else if (advance == -2)
1814 else if (advance == -3)
1815 break; /* bytes left, but not enough */
1817 ND_PRINT((ndo, "\n\t %s", buf));
1819 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1820 advance = decode_labeled_prefix6(ndo, tptr, len, buf, sizeof(buf));
1822 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1823 else if (advance == -2)
1825 else if (advance == -3)
1826 break; /* bytes left, but not enough */
1828 ND_PRINT((ndo, "\n\t %s", buf));
1830 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1831 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1832 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1833 advance = decode_labeled_vpn_prefix6(ndo, tptr, buf, sizeof(buf));
1835 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1836 else if (advance == -2)
1839 ND_PRINT((ndo, "\n\t %s", buf));
1841 case (AFNUM_VPLS<<8 | SAFNUM_VPLS):
1842 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1843 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1844 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1845 advance = decode_labeled_vpn_l2(ndo, tptr, buf, sizeof(buf));
1847 ND_PRINT((ndo, "\n\t (illegal length)"));
1848 else if (advance == -2)
1851 ND_PRINT((ndo, "\n\t %s", buf));
1853 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1854 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1855 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1856 advance = decode_clnp_prefix(ndo, tptr, buf, sizeof(buf));
1858 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1859 else if (advance == -2)
1862 ND_PRINT((ndo, "\n\t %s", buf));
1864 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
1865 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
1866 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
1867 advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, sizeof(buf));
1869 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1870 else if (advance == -2)
1873 ND_PRINT((ndo, "\n\t %s", buf));
1876 ND_TCHECK2(*tptr,tlen);
1877 ND_PRINT((ndo, "\n\t no AFI %u / SAFI %u decoder", af, safi));
1878 if (ndo->ndo_vflag <= 1)
1879 print_unknown_data(ndo, tptr, "\n\t ", tlen);
1891 case BGPTYPE_MP_UNREACH_NLRI:
1892 ND_TCHECK2(tptr[0], BGP_MP_NLRI_MINSIZE);
1893 af = EXTRACT_16BITS(tptr);
1896 ND_PRINT((ndo, "\n\t AFI: %s (%u), %sSAFI: %s (%u)",
1897 tok2str(af_values, "Unknown AFI", af),
1899 (safi>128) ? "vendor specific " : "", /* 128 is meanwhile wellknown */
1900 tok2str(bgp_safi_values, "Unknown SAFI", safi),
1903 if (len == BGP_MP_NLRI_MINSIZE)
1904 ND_PRINT((ndo, "\n\t End-of-Rib Marker (empty NLRI)"));
1908 while (tptr < pptr + len) {
1909 switch (af<<8 | safi) {
1910 case (AFNUM_INET<<8 | SAFNUM_UNICAST):
1911 case (AFNUM_INET<<8 | SAFNUM_MULTICAST):
1912 case (AFNUM_INET<<8 | SAFNUM_UNIMULTICAST):
1913 advance = decode_prefix4(ndo, tptr, len, buf, sizeof(buf));
1915 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1916 else if (advance == -2)
1918 else if (advance == -3)
1919 break; /* bytes left, but not enough */
1921 ND_PRINT((ndo, "\n\t %s", buf));
1923 case (AFNUM_INET<<8 | SAFNUM_LABUNICAST):
1924 advance = decode_labeled_prefix4(ndo, tptr, len, buf, sizeof(buf));
1926 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1927 else if (advance == -2)
1929 else if (advance == -3)
1930 break; /* bytes left, but not enough */
1932 ND_PRINT((ndo, "\n\t %s", buf));
1934 case (AFNUM_INET<<8 | SAFNUM_VPNUNICAST):
1935 case (AFNUM_INET<<8 | SAFNUM_VPNMULTICAST):
1936 case (AFNUM_INET<<8 | SAFNUM_VPNUNIMULTICAST):
1937 advance = decode_labeled_vpn_prefix4(ndo, tptr, buf, sizeof(buf));
1939 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1940 else if (advance == -2)
1943 ND_PRINT((ndo, "\n\t %s", buf));
1945 case (AFNUM_INET6<<8 | SAFNUM_UNICAST):
1946 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST):
1947 case (AFNUM_INET6<<8 | SAFNUM_UNIMULTICAST):
1948 advance = decode_prefix6(ndo, tptr, len, buf, sizeof(buf));
1950 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1951 else if (advance == -2)
1953 else if (advance == -3)
1954 break; /* bytes left, but not enough */
1956 ND_PRINT((ndo, "\n\t %s", buf));
1958 case (AFNUM_INET6<<8 | SAFNUM_LABUNICAST):
1959 advance = decode_labeled_prefix6(ndo, tptr, len, buf, sizeof(buf));
1961 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1962 else if (advance == -2)
1964 else if (advance == -3)
1965 break; /* bytes left, but not enough */
1967 ND_PRINT((ndo, "\n\t %s", buf));
1969 case (AFNUM_INET6<<8 | SAFNUM_VPNUNICAST):
1970 case (AFNUM_INET6<<8 | SAFNUM_VPNMULTICAST):
1971 case (AFNUM_INET6<<8 | SAFNUM_VPNUNIMULTICAST):
1972 advance = decode_labeled_vpn_prefix6(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_VPLS<<8 | SAFNUM_VPLS):
1981 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNICAST):
1982 case (AFNUM_L2VPN<<8 | SAFNUM_VPNMULTICAST):
1983 case (AFNUM_L2VPN<<8 | SAFNUM_VPNUNIMULTICAST):
1984 advance = decode_labeled_vpn_l2(ndo, tptr, buf, sizeof(buf));
1986 ND_PRINT((ndo, "\n\t (illegal length)"));
1987 else if (advance == -2)
1990 ND_PRINT((ndo, "\n\t %s", buf));
1992 case (AFNUM_NSAP<<8 | SAFNUM_UNICAST):
1993 case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
1994 case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
1995 advance = decode_clnp_prefix(ndo, tptr, buf, sizeof(buf));
1997 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
1998 else if (advance == -2)
2001 ND_PRINT((ndo, "\n\t %s", buf));
2003 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNICAST):
2004 case (AFNUM_NSAP<<8 | SAFNUM_VPNMULTICAST):
2005 case (AFNUM_NSAP<<8 | SAFNUM_VPNUNIMULTICAST):
2006 advance = decode_labeled_vpn_clnp_prefix(ndo, tptr, buf, sizeof(buf));
2008 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
2009 else if (advance == -2)
2012 ND_PRINT((ndo, "\n\t %s", buf));
2014 case (AFNUM_INET<<8 | SAFNUM_MDT):
2015 advance = decode_mdt_vpn_nlri(ndo, tptr, buf, sizeof(buf));
2017 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
2018 else if (advance == -2)
2021 ND_PRINT((ndo, "\n\t %s", buf));
2023 case (AFNUM_INET<<8 | SAFNUM_MULTICAST_VPN): /* fall through */
2024 case (AFNUM_INET6<<8 | SAFNUM_MULTICAST_VPN):
2025 advance = decode_multicast_vpn(ndo, tptr, buf, sizeof(buf));
2027 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
2028 else if (advance == -2)
2031 ND_PRINT((ndo, "\n\t %s", buf));
2034 ND_TCHECK2(*(tptr-3),tlen);
2035 ND_PRINT((ndo, "no AFI %u / SAFI %u decoder", af, safi));
2036 if (ndo->ndo_vflag <= 1)
2037 print_unknown_data(ndo, tptr-3, "\n\t ", tlen);
2047 case BGPTYPE_EXTD_COMMUNITIES:
2049 ND_PRINT((ndo, "invalid len"));
2055 ND_TCHECK2(tptr[0], 2);
2056 extd_comm=EXTRACT_16BITS(tptr);
2058 ND_PRINT((ndo, "\n\t %s (0x%04x), Flags [%s]",
2059 tok2str(bgp_extd_comm_subtype_values,
2060 "unknown extd community typecode",
2063 bittok2str(bgp_extd_comm_flag_values, "none", extd_comm)));
2065 ND_TCHECK2(*(tptr+2), 6);
2067 case BGP_EXT_COM_RT_0:
2068 case BGP_EXT_COM_RO_0:
2069 case BGP_EXT_COM_L2VPN_RT_0:
2070 ND_PRINT((ndo, ": %u:%u (= %s)",
2071 EXTRACT_16BITS(tptr+2),
2072 EXTRACT_32BITS(tptr+4),
2073 ipaddr_string(ndo, tptr+4)));
2075 case BGP_EXT_COM_RT_1:
2076 case BGP_EXT_COM_RO_1:
2077 case BGP_EXT_COM_L2VPN_RT_1:
2078 case BGP_EXT_COM_VRF_RT_IMP:
2079 ND_PRINT((ndo, ": %s:%u",
2080 ipaddr_string(ndo, tptr+2),
2081 EXTRACT_16BITS(tptr+6)));
2083 case BGP_EXT_COM_RT_2:
2084 case BGP_EXT_COM_RO_2:
2085 ND_PRINT((ndo, ": %s:%u",
2086 as_printf(ndo, astostr, sizeof(astostr),
2087 EXTRACT_32BITS(tptr+2)), EXTRACT_16BITS(tptr+6)));
2089 case BGP_EXT_COM_LINKBAND:
2090 bw.i = EXTRACT_32BITS(tptr+2);
2091 ND_PRINT((ndo, ": bandwidth: %.3f Mbps",
2094 case BGP_EXT_COM_VPN_ORIGIN:
2095 case BGP_EXT_COM_VPN_ORIGIN2:
2096 case BGP_EXT_COM_VPN_ORIGIN3:
2097 case BGP_EXT_COM_VPN_ORIGIN4:
2098 case BGP_EXT_COM_OSPF_RID:
2099 case BGP_EXT_COM_OSPF_RID2:
2100 ND_PRINT((ndo, "%s", ipaddr_string(ndo, tptr+2)));
2102 case BGP_EXT_COM_OSPF_RTYPE:
2103 case BGP_EXT_COM_OSPF_RTYPE2:
2104 ND_PRINT((ndo, ": area:%s, router-type:%s, metric-type:%s%s",
2105 ipaddr_string(ndo, tptr+2),
2106 tok2str(bgp_extd_comm_ospf_rtype_values,
2109 (*(tptr+7) & BGP_OSPF_RTYPE_METRIC_TYPE) ? "E2" : "",
2110 ((*(tptr+6) == BGP_OSPF_RTYPE_EXT) || (*(tptr+6) == BGP_OSPF_RTYPE_NSSA)) ? "E1" : ""));
2112 case BGP_EXT_COM_L2INFO:
2113 ND_PRINT((ndo, ": %s Control Flags [0x%02x]:MTU %u",
2114 tok2str(l2vpn_encaps_values,
2118 EXTRACT_16BITS(tptr+4)));
2120 case BGP_EXT_COM_SOURCE_AS:
2121 ND_PRINT((ndo, ": AS %u", EXTRACT_16BITS(tptr+2)));
2124 ND_TCHECK2(*tptr,8);
2125 print_unknown_data(ndo, tptr, "\n\t ", 8);
2133 case BGPTYPE_PMSI_TUNNEL:
2135 uint8_t tunnel_type, flags;
2137 ND_TCHECK2(tptr[0], 5);
2138 tunnel_type = *(tptr+1);
2142 ND_PRINT((ndo, "\n\t Tunnel-type %s (%u), Flags [%s], MPLS Label %u",
2143 tok2str(bgp_pmsi_tunnel_values, "Unknown", tunnel_type),
2145 bittok2str(bgp_pmsi_flag_values, "none", flags),
2146 EXTRACT_24BITS(tptr+2)>>4));
2151 switch (tunnel_type) {
2152 case BGP_PMSI_TUNNEL_PIM_SM: /* fall through */
2153 case BGP_PMSI_TUNNEL_PIM_BIDIR:
2154 ND_TCHECK2(tptr[0], 8);
2155 ND_PRINT((ndo, "\n\t Sender %s, P-Group %s",
2156 ipaddr_string(ndo, tptr),
2157 ipaddr_string(ndo, tptr+4)));
2160 case BGP_PMSI_TUNNEL_PIM_SSM:
2161 ND_TCHECK2(tptr[0], 8);
2162 ND_PRINT((ndo, "\n\t Root-Node %s, P-Group %s",
2163 ipaddr_string(ndo, tptr),
2164 ipaddr_string(ndo, tptr+4)));
2166 case BGP_PMSI_TUNNEL_INGRESS:
2167 ND_TCHECK2(tptr[0], 4);
2168 ND_PRINT((ndo, "\n\t Tunnel-Endpoint %s",
2169 ipaddr_string(ndo, tptr)));
2171 case BGP_PMSI_TUNNEL_LDP_P2MP: /* fall through */
2172 case BGP_PMSI_TUNNEL_LDP_MP2MP:
2173 ND_TCHECK2(tptr[0], 8);
2174 ND_PRINT((ndo, "\n\t Root-Node %s, LSP-ID 0x%08x",
2175 ipaddr_string(ndo, tptr),
2176 EXTRACT_32BITS(tptr+4)));
2178 case BGP_PMSI_TUNNEL_RSVP_P2MP:
2179 ND_TCHECK2(tptr[0], 8);
2180 ND_PRINT((ndo, "\n\t Extended-Tunnel-ID %s, P2MP-ID 0x%08x",
2181 ipaddr_string(ndo, tptr),
2182 EXTRACT_32BITS(tptr+4)));
2185 if (ndo->ndo_vflag <= 1) {
2186 print_unknown_data(ndo, tptr, "\n\t ", tlen);
2200 ND_TCHECK2(tptr[0], 3);
2203 length = EXTRACT_16BITS(tptr+1);
2207 ND_PRINT((ndo, "\n\t %s TLV (%u), length %u",
2208 tok2str(bgp_aigp_values, "Unknown", type),
2216 * Check if we can read the TLV data.
2218 ND_TCHECK2(tptr[3], length);
2225 ND_PRINT((ndo, ", metric %" PRIu64,
2226 EXTRACT_64BITS(tptr)));
2230 if (ndo->ndo_vflag <= 1) {
2231 print_unknown_data(ndo, tptr,"\n\t ", length);
2240 case BGPTYPE_ATTR_SET:
2241 ND_TCHECK2(tptr[0], 4);
2244 ND_PRINT((ndo, "\n\t Origin AS: %s",
2245 as_printf(ndo, astostr, sizeof(astostr), EXTRACT_32BITS(tptr))));
2250 u_int aflags, alenlen, alen;
2252 ND_TCHECK2(tptr[0], 2);
2256 atype = *(tptr + 1);
2259 alenlen = bgp_attr_lenlen(aflags, tptr);
2260 ND_TCHECK2(tptr[0], alenlen);
2263 alen = bgp_attr_len(aflags, tptr);
2267 ND_PRINT((ndo, "\n\t %s (%u), length: %u",
2268 tok2str(bgp_attr_values,
2269 "Unknown Attribute", atype),
2274 ND_PRINT((ndo, ", Flags [%s%s%s%s",
2275 aflags & 0x80 ? "O" : "",
2276 aflags & 0x40 ? "T" : "",
2277 aflags & 0x20 ? "P" : "",
2278 aflags & 0x10 ? "E" : ""));
2280 ND_PRINT((ndo, "+%x", aflags & 0xf));
2281 ND_PRINT((ndo, "]: "));
2283 /* FIXME check for recursion */
2284 if (!bgp_attr_print(ndo, atype, tptr, alen))
2291 case BGPTYPE_LARGE_COMMUNITY:
2292 if (len == 0 || len % 12) {
2293 ND_PRINT((ndo, "invalid len"));
2296 ND_PRINT((ndo, "\n\t "));
2298 ND_TCHECK2(*tptr, 12);
2299 ND_PRINT((ndo, "%u:%u:%u%s",
2300 EXTRACT_32BITS(tptr),
2301 EXTRACT_32BITS(tptr + 4),
2302 EXTRACT_32BITS(tptr + 8),
2303 (len > 12) ? ", " : ""));
2309 ND_TCHECK2(*pptr,len);
2310 ND_PRINT((ndo, "\n\t no Attribute %u decoder", atype)); /* we have no decoder for the attribute */
2311 if (ndo->ndo_vflag <= 1)
2312 print_unknown_data(ndo, pptr, "\n\t ", len);
2315 if (ndo->ndo_vflag > 1 && len) { /* omit zero length attributes*/
2316 ND_TCHECK2(*pptr,len);
2317 print_unknown_data(ndo, pptr, "\n\t ", len);
2326 bgp_capabilities_print(netdissect_options *ndo,
2327 const u_char *opt, int caps_len)
2329 int cap_type, cap_len, tcap_len, cap_offset;
2332 while (i < caps_len) {
2333 ND_TCHECK2(opt[i], BGP_CAP_HEADER_SIZE);
2337 ND_PRINT((ndo, "\n\t %s (%u), length: %u",
2338 tok2str(bgp_capcode_values, "Unknown",
2342 ND_TCHECK2(opt[i+2], cap_len);
2344 case BGP_CAPCODE_MP:
2345 ND_PRINT((ndo, "\n\t\tAFI %s (%u), SAFI %s (%u)",
2346 tok2str(af_values, "Unknown",
2347 EXTRACT_16BITS(opt+i+2)),
2348 EXTRACT_16BITS(opt+i+2),
2349 tok2str(bgp_safi_values, "Unknown",
2353 case BGP_CAPCODE_RESTART:
2354 ND_PRINT((ndo, "\n\t\tRestart Flags: [%s], Restart Time %us",
2355 ((opt[i+2])&0x80) ? "R" : "none",
2356 EXTRACT_16BITS(opt+i+2)&0xfff));
2359 while(tcap_len>=4) {
2360 ND_PRINT((ndo, "\n\t\t AFI %s (%u), SAFI %s (%u), Forwarding state preserved: %s",
2361 tok2str(af_values,"Unknown",
2362 EXTRACT_16BITS(opt+i+cap_offset)),
2363 EXTRACT_16BITS(opt+i+cap_offset),
2364 tok2str(bgp_safi_values,"Unknown",
2365 opt[i+cap_offset+2]),
2366 opt[i+cap_offset+2],
2367 ((opt[i+cap_offset+3])&0x80) ? "yes" : "no" ));
2372 case BGP_CAPCODE_RR:
2373 case BGP_CAPCODE_RR_CISCO:
2375 case BGP_CAPCODE_AS_NEW:
2378 * Extract the 4 byte AS number encoded.
2381 ND_PRINT((ndo, "\n\t\t 4 Byte AS %s",
2382 as_printf(ndo, astostr, sizeof(astostr),
2383 EXTRACT_32BITS(opt + i + 2))));
2386 case BGP_CAPCODE_ADD_PATH:
2388 if (tcap_len == 0) {
2389 ND_PRINT((ndo, " (bogus)")); /* length */
2392 while (tcap_len > 0) {
2394 ND_PRINT((ndo, "\n\t\t(invalid)"));
2397 ND_PRINT((ndo, "\n\t\tAFI %s (%u), SAFI %s (%u), Send/Receive: %s",
2398 tok2str(af_values,"Unknown",EXTRACT_16BITS(opt+i+cap_offset)),
2399 EXTRACT_16BITS(opt+i+cap_offset),
2400 tok2str(bgp_safi_values,"Unknown",opt[i+cap_offset+2]),
2401 opt[i+cap_offset+2],
2402 tok2str(bgp_add_path_recvsend,"Bogus (0x%02x)",opt[i+cap_offset+3])
2409 ND_PRINT((ndo, "\n\t\tno decoder for Capability %u",
2411 if (ndo->ndo_vflag <= 1)
2412 print_unknown_data(ndo, &opt[i+2], "\n\t\t", cap_len);
2415 if (ndo->ndo_vflag > 1 && cap_len > 0) {
2416 print_unknown_data(ndo, &opt[i+2], "\n\t\t", cap_len);
2418 i += BGP_CAP_HEADER_SIZE + cap_len;
2423 ND_PRINT((ndo, "[|BGP]"));
2427 bgp_open_print(netdissect_options *ndo,
2428 const u_char *dat, int length)
2430 struct bgp_open bgpo;
2431 struct bgp_opt bgpopt;
2435 ND_TCHECK2(dat[0], BGP_OPEN_SIZE);
2436 memcpy(&bgpo, dat, BGP_OPEN_SIZE);
2438 ND_PRINT((ndo, "\n\t Version %d, ", bgpo.bgpo_version));
2439 ND_PRINT((ndo, "my AS %s, ",
2440 as_printf(ndo, astostr, sizeof(astostr), ntohs(bgpo.bgpo_myas))));
2441 ND_PRINT((ndo, "Holdtime %us, ", ntohs(bgpo.bgpo_holdtime)));
2442 ND_PRINT((ndo, "ID %s", ipaddr_string(ndo, &bgpo.bgpo_id)));
2443 ND_PRINT((ndo, "\n\t Optional parameters, length: %u", bgpo.bgpo_optlen));
2445 /* some little sanity checking */
2446 if (length < bgpo.bgpo_optlen+BGP_OPEN_SIZE)
2450 opt = &((const struct bgp_open *)dat)->bgpo_optlen;
2454 while (i < bgpo.bgpo_optlen) {
2455 ND_TCHECK2(opt[i], BGP_OPT_SIZE);
2456 memcpy(&bgpopt, &opt[i], BGP_OPT_SIZE);
2457 if (i + 2 + bgpopt.bgpopt_len > bgpo.bgpo_optlen) {
2458 ND_PRINT((ndo, "\n\t Option %d, length: %u", bgpopt.bgpopt_type, bgpopt.bgpopt_len));
2462 ND_PRINT((ndo, "\n\t Option %s (%u), length: %u",
2463 tok2str(bgp_opt_values,"Unknown",
2464 bgpopt.bgpopt_type),
2466 bgpopt.bgpopt_len));
2468 /* now let's decode the options we know*/
2469 switch(bgpopt.bgpopt_type) {
2472 bgp_capabilities_print(ndo, &opt[i+BGP_OPT_SIZE],
2478 ND_PRINT((ndo, "\n\t no decoder for option %u",
2479 bgpopt.bgpopt_type));
2482 i += BGP_OPT_SIZE + bgpopt.bgpopt_len;
2486 ND_PRINT((ndo, "[|BGP]"));
2490 bgp_update_print(netdissect_options *ndo,
2491 const u_char *dat, int length)
2495 int withdrawn_routes_len;
2499 ND_TCHECK2(dat[0], BGP_SIZE);
2500 if (length < BGP_SIZE)
2502 memcpy(&bgp, dat, BGP_SIZE);
2503 p = dat + BGP_SIZE; /*XXX*/
2506 /* Unfeasible routes */
2507 ND_TCHECK2(p[0], 2);
2510 withdrawn_routes_len = EXTRACT_16BITS(p);
2513 if (withdrawn_routes_len) {
2515 * Without keeping state from the original NLRI message,
2516 * it's not possible to tell if this a v4 or v6 route,
2517 * so only try to decode it if we're not v6 enabled.
2519 ND_TCHECK2(p[0], withdrawn_routes_len);
2520 if (length < withdrawn_routes_len)
2522 ND_PRINT((ndo, "\n\t Withdrawn routes: %d bytes", withdrawn_routes_len));
2523 p += withdrawn_routes_len;
2524 length -= withdrawn_routes_len;
2527 ND_TCHECK2(p[0], 2);
2530 len = EXTRACT_16BITS(p);
2534 if (withdrawn_routes_len == 0 && len == 0 && length == 0) {
2535 /* No withdrawn routes, no path attributes, no NLRI */
2536 ND_PRINT((ndo, "\n\t End-of-Rib Marker (empty NLRI)"));
2541 /* do something more useful!*/
2543 int aflags, atype, alenlen, alen;
2545 ND_TCHECK2(p[0], 2);
2555 alenlen = bgp_attr_lenlen(aflags, p);
2556 ND_TCHECK2(p[0], alenlen);
2559 if (length < alenlen)
2561 alen = bgp_attr_len(aflags, p);
2566 ND_PRINT((ndo, "\n\t %s (%u), length: %u",
2567 tok2str(bgp_attr_values, "Unknown Attribute",
2573 ND_PRINT((ndo, ", Flags [%s%s%s%s",
2574 aflags & 0x80 ? "O" : "",
2575 aflags & 0x40 ? "T" : "",
2576 aflags & 0x20 ? "P" : "",
2577 aflags & 0x10 ? "E" : ""));
2579 ND_PRINT((ndo, "+%x", aflags & 0xf));
2580 ND_PRINT((ndo, "]: "));
2586 if (!bgp_attr_print(ndo, atype, p, alen))
2596 * XXX - what if they're using the "Advertisement of
2597 * Multiple Paths in BGP" feature:
2599 * https://datatracker.ietf.org/doc/draft-ietf-idr-add-paths/
2601 * http://tools.ietf.org/html/draft-ietf-idr-add-paths-06
2603 ND_PRINT((ndo, "\n\t Updated routes:"));
2605 char buf[MAXHOSTNAMELEN + 100];
2606 i = decode_prefix4(ndo, p, length, buf, sizeof(buf));
2608 ND_PRINT((ndo, "\n\t (illegal prefix length)"));
2613 goto trunc; /* bytes left, but not enough */
2615 ND_PRINT((ndo, "\n\t %s", buf));
2623 ND_PRINT((ndo, "[|BGP]"));
2627 bgp_notification_print(netdissect_options *ndo,
2628 const u_char *dat, int length)
2630 struct bgp_notification bgpn;
2633 ND_TCHECK2(dat[0], BGP_NOTIFICATION_SIZE);
2634 memcpy(&bgpn, dat, BGP_NOTIFICATION_SIZE);
2636 /* some little sanity checking */
2637 if (length<BGP_NOTIFICATION_SIZE)
2640 ND_PRINT((ndo, ", %s (%u)",
2641 tok2str(bgp_notify_major_values, "Unknown Error",
2645 switch (bgpn.bgpn_major) {
2647 case BGP_NOTIFY_MAJOR_MSG:
2648 ND_PRINT((ndo, ", subcode %s (%u)",
2649 tok2str(bgp_notify_minor_msg_values, "Unknown",
2653 case BGP_NOTIFY_MAJOR_OPEN:
2654 ND_PRINT((ndo, ", subcode %s (%u)",
2655 tok2str(bgp_notify_minor_open_values, "Unknown",
2659 case BGP_NOTIFY_MAJOR_UPDATE:
2660 ND_PRINT((ndo, ", subcode %s (%u)",
2661 tok2str(bgp_notify_minor_update_values, "Unknown",
2665 case BGP_NOTIFY_MAJOR_FSM:
2666 ND_PRINT((ndo, " subcode %s (%u)",
2667 tok2str(bgp_notify_minor_fsm_values, "Unknown",
2671 case BGP_NOTIFY_MAJOR_CAP:
2672 ND_PRINT((ndo, " subcode %s (%u)",
2673 tok2str(bgp_notify_minor_cap_values, "Unknown",
2677 case BGP_NOTIFY_MAJOR_CEASE:
2678 ND_PRINT((ndo, ", subcode %s (%u)",
2679 tok2str(bgp_notify_minor_cease_values, "Unknown",
2683 /* draft-ietf-idr-cease-subcode-02 mentions optionally 7 bytes
2684 * for the maxprefix subtype, which may contain AFI, SAFI and MAXPREFIXES
2686 if(bgpn.bgpn_minor == BGP_NOTIFY_MINOR_CEASE_MAXPRFX && length >= BGP_NOTIFICATION_SIZE + 7) {
2687 tptr = dat + BGP_NOTIFICATION_SIZE;
2688 ND_TCHECK2(*tptr, 7);
2689 ND_PRINT((ndo, ", AFI %s (%u), SAFI %s (%u), Max Prefixes: %u",
2690 tok2str(af_values, "Unknown",
2691 EXTRACT_16BITS(tptr)),
2692 EXTRACT_16BITS(tptr),
2693 tok2str(bgp_safi_values, "Unknown", *(tptr+2)),
2695 EXTRACT_32BITS(tptr+3)));
2704 ND_PRINT((ndo, "[|BGP]"));
2708 bgp_route_refresh_print(netdissect_options *ndo,
2709 const u_char *pptr, int len)
2711 const struct bgp_route_refresh *bgp_route_refresh_header;
2713 ND_TCHECK2(pptr[0], BGP_ROUTE_REFRESH_SIZE);
2715 /* some little sanity checking */
2716 if (len<BGP_ROUTE_REFRESH_SIZE)
2719 bgp_route_refresh_header = (const struct bgp_route_refresh *)pptr;
2721 ND_PRINT((ndo, "\n\t AFI %s (%u), SAFI %s (%u)",
2722 tok2str(af_values,"Unknown",
2723 /* this stinks but the compiler pads the structure
2725 EXTRACT_16BITS(&bgp_route_refresh_header->afi)),
2726 EXTRACT_16BITS(&bgp_route_refresh_header->afi),
2727 tok2str(bgp_safi_values,"Unknown",
2728 bgp_route_refresh_header->safi),
2729 bgp_route_refresh_header->safi));
2731 if (ndo->ndo_vflag > 1) {
2732 ND_TCHECK2(*pptr, len);
2733 print_unknown_data(ndo, pptr, "\n\t ", len);
2738 ND_PRINT((ndo, "[|BGP]"));
2742 bgp_header_print(netdissect_options *ndo,
2743 const u_char *dat, int length)
2747 ND_TCHECK2(dat[0], BGP_SIZE);
2748 memcpy(&bgp, dat, BGP_SIZE);
2749 ND_PRINT((ndo, "\n\t%s Message (%u), length: %u",
2750 tok2str(bgp_msg_values, "Unknown", bgp.bgp_type),
2754 switch (bgp.bgp_type) {
2756 bgp_open_print(ndo, dat, length);
2759 bgp_update_print(ndo, dat, length);
2761 case BGP_NOTIFICATION:
2762 bgp_notification_print(ndo, dat, length);
2766 case BGP_ROUTE_REFRESH:
2767 bgp_route_refresh_print(ndo, dat, length);
2770 /* we have no decoder for the BGP message */
2771 ND_TCHECK2(*dat, length);
2772 ND_PRINT((ndo, "\n\t no Message %u decoder", bgp.bgp_type));
2773 print_unknown_data(ndo, dat, "\n\t ", length);
2778 ND_PRINT((ndo, "[|BGP]"));
2783 bgp_print(netdissect_options *ndo,
2784 const u_char *dat, int length)
2788 const u_char *start;
2789 const u_char marker[] = {
2790 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2791 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2797 if (ndo->ndo_snapend < dat + length)
2798 ep = ndo->ndo_snapend;
2800 ND_PRINT((ndo, ": BGP"));
2802 if (ndo->ndo_vflag < 1) /* lets be less chatty */
2808 if (!ND_TTEST2(p[0], 1))
2815 if (!ND_TTEST2(p[0], sizeof(marker)))
2817 if (memcmp(p, marker, sizeof(marker)) != 0) {
2822 /* found BGP header */
2823 ND_TCHECK2(p[0], BGP_SIZE); /*XXX*/
2824 memcpy(&bgp, p, BGP_SIZE);
2827 ND_PRINT((ndo, " [|BGP]"));
2829 hlen = ntohs(bgp.bgp_len);
2830 if (hlen < BGP_SIZE) {
2831 ND_PRINT((ndo, "\n[|BGP Bogus header length %u < %u]", hlen,
2836 if (ND_TTEST2(p[0], hlen)) {
2837 if (!bgp_header_print(ndo, p, hlen))
2842 ND_PRINT((ndo, "\n[|BGP %s]",
2843 tok2str(bgp_msg_values,
2844 "Unknown Message Type",
2853 ND_PRINT((ndo, " [|BGP]"));
2858 * c-style: whitesmith