2 * Routines for BGP packet dissection.
3 * Copyright 1999, Jun-ichiro itojun Hagino <itojun@itojun.org>
8 * RFC1771 A Border Gateway Protocol 4 (BGP-4)
9 * RFC1965 Autonomous System Confederations for BGP
10 * RFC1997 BGP Communities Attribute
11 * RFC2547 BGP/MPLS VPNs
12 * RFC2796 BGP Route Reflection An alternative to full mesh IBGP
13 * RFC2842 Capabilities Advertisement with BGP-4
14 * RFC2858 Multiprotocol Extensions for BGP-4
15 * RFC2918 Route Refresh Capability for BGP-4
16 * RFC3107 Carrying Label Information in BGP-4
17 * draft-ietf-idr-as4bytes-06
18 * draft-ietf-idr-dynamic-cap-03
19 * draft-ietf-idr-bgp-ext-communities-05
22 * Destination Preference Attribute for BGP (work in progress)
23 * RFC1863 A BGP/IDRP Route Server alternative to a full mesh routing
25 * Wireshark - Network traffic analyzer
26 * By Gerald Combs <gerald@wireshark.org>
27 * Copyright 1998 Gerald Combs
29 * This program is free software; you can redistribute it and/or
30 * modify it under the terms of the GNU General Public License
31 * as published by the Free Software Foundation; either version 2
32 * of the License, or (at your option) any later version.
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
54 #include <epan/packet.h>
55 #include <epan/addr_and_mask.h>
56 #include "packet-bgp.h"
57 #include "packet-ipv6.h"
58 #include "packet-frame.h"
60 #include <epan/prefs.h>
61 #include <epan/emem.h>
63 #define MAX_STR_LEN 256
65 static const value_string bgptypevals[] = {
66 { BGP_OPEN, "OPEN Message" },
67 { BGP_UPDATE, "UPDATE Message" },
68 { BGP_NOTIFICATION, "NOTIFICATION Message" },
69 { BGP_KEEPALIVE, "KEEPALIVE Message" },
70 { BGP_ROUTE_REFRESH, "ROUTE-REFRESH Message" },
71 { BGP_CAPABILITY, "CAPABILITY Message" },
72 { BGP_ROUTE_REFRESH_CISCO, "Cisco ROUTE-REFRESH Message" },
76 static const value_string bgpnotify_major[] = {
77 { 1, "Message Header Error" },
78 { 2, "OPEN Message Error" },
79 { 3, "UPDATE Message Error" },
80 { 4, "Hold Timer Expired" },
81 { 5, "Finite State Machine Error" },
83 { 7, "CAPABILITY Message Error" },
87 static const value_string bgpnotify_minor_1[] = {
88 { 1, "Connection Not Synchronized" },
89 { 2, "Bad Message Length" },
90 { 3, "Bad Message Type" },
94 static const value_string bgpnotify_minor_2[] = {
95 { 1, "Unsupported Version Number" },
97 { 3, "Bad BGP Identifier" },
98 { 4, "Unsupported Optional Parameter" },
99 { 5, "Authentication Failure" },
100 { 6, "Unacceptable Hold Time" },
101 { 7, "Unsupported Capability" },
105 static const value_string bgpnotify_minor_3[] = {
106 { 1, "Malformed Attribute List" },
107 { 2, "Unrecognized Well-known Attribute" },
108 { 3, "Missing Well-known Attribute" },
109 { 4, "Attribute Flags Error" },
110 { 5, "Attribute Length Error" },
111 { 6, "Invalid ORIGIN Attribute" },
112 { 7, "AS Routing Loop" },
113 { 8, "Invalid NEXT_HOP Attribute" },
114 { 9, "Optional Attribute Error" },
115 { 10, "Invalid Network Field" },
116 { 11, "Malformed AS_PATH" },
120 /* draft-ietf-idr-cease-subcode-02 */
121 static const value_string bgpnotify_minor_6[] = {
122 { 1, "Maximum Number of Prefixes Reached"},
123 { 2, "Administratively Shutdown"},
124 { 3, "Peer Unconfigured"},
125 { 4, "Administratively Reset"},
126 { 5, "Connection Rejected"},
127 { 6, "Other Configuration Change"},
128 { 7, "Connection Collision Resolution"},
132 static const value_string bgpnotify_minor_7[] = {
133 { 1, "Invalid Action Value" },
134 { 2, "Invalid Capability Length" },
135 { 3, "Malformed Capability Value" },
136 { 4, "Unsupported Capability Code" },
140 static const value_string *bgpnotify_minor[] = {
142 bgpnotify_minor_1, /* open */
143 bgpnotify_minor_2, /* update */
144 bgpnotify_minor_3, /* notification */
145 NULL, /* hold-timer expired */
146 NULL, /* FSM error */
147 bgpnotify_minor_6, /* cease */
148 bgpnotify_minor_7 /* capability */
151 static const value_string bgpattr_origin[] = {
158 static const value_string as_segment_type[] = {
160 { 2, "AS_SEQUENCE" },
161 /* RFC1965 has the wrong values, corrected in */
162 /* draft-ietf-idr-bgp-confed-rfc1965bis-01.txt */
163 { 4, "AS_CONFED_SET" },
164 { 3, "AS_CONFED_SEQUENCE" },
168 static const value_string bgpattr_type[] = {
169 { BGPTYPE_ORIGIN, "ORIGIN" },
170 { BGPTYPE_AS_PATH, "AS_PATH" },
171 { BGPTYPE_NEXT_HOP, "NEXT_HOP" },
172 { BGPTYPE_MULTI_EXIT_DISC, "MULTI_EXIT_DISC" },
173 { BGPTYPE_LOCAL_PREF, "LOCAL_PREF" },
174 { BGPTYPE_ATOMIC_AGGREGATE, "ATOMIC_AGGREGATE" },
175 { BGPTYPE_AGGREGATOR, "AGGREGATOR" },
176 { BGPTYPE_COMMUNITIES, "COMMUNITIES" },
177 { BGPTYPE_ORIGINATOR_ID, "ORIGINATOR_ID" },
178 { BGPTYPE_CLUSTER_LIST, "CLUSTER_LIST" },
179 { BGPTYPE_MP_REACH_NLRI, "MP_REACH_NLRI" },
180 { BGPTYPE_MP_UNREACH_NLRI, "MP_UNREACH_NLRI" },
181 { BGPTYPE_EXTENDED_COMMUNITY, "EXTENDED_COMMUNITIES" },
182 { BGPTYPE_NEW_AS_PATH, "NEW_AS_PATH" },
183 { BGPTYPE_NEW_AGGREGATOR, "NEW_AGGREGATOR" },
184 { BGPTYPE_SAFI_SPECIFIC_ATTR, "SAFI_SPECIFIC_ATTRIBUTE" },
188 static const value_string bgpext_com_type[] = {
189 { BGP_EXT_COM_RT_0, "Route Target" },
190 { BGP_EXT_COM_RT_1, "Route Target" },
191 { BGP_EXT_COM_RT_2, "Route Target" },
192 { BGP_EXT_COM_RO_0, "Route Origin" },
193 { BGP_EXT_COM_RO_1, "Route Origin" },
194 { BGP_EXT_COM_RO_2, "Route Origin" },
195 { BGP_EXT_COM_LINKBAND, "Link Bandwidth" },
196 { BGP_EXT_COM_VPN_ORIGIN, "OSPF Domain" },
197 { BGP_EXT_COM_OSPF_RTYPE, "OSPF Route Type" },
198 { BGP_EXT_COM_OSPF_RID, "OSPF Router ID" },
199 { BGP_EXT_COM_L2INFO, "Layer 2 Information" },
203 static const value_string bgp_ssa_type[] = {
204 { BGP_SSA_L2TPv3 , "L2TPv3 Tunnel" },
205 { BGP_SSA_mGRE , "mGRE Tunnel" },
206 { BGP_SSA_IPSec , "IPSec Tunnel" },
207 { BGP_SSA_MPLS , "MPLS Tunnel" },
211 static const value_string bgp_l2vpn_encaps[] = {
214 { 2, "ATM AAL5 VCC transport"},
215 { 3, "ATM transparent cell transport"},
216 { 4, "Ethernet VLAN"},
221 { 9, "ATM VCC cell transport"},
222 { 10, "ATM VPC cell transport"},
225 { 64, "IP-interworking"},
229 static const value_string bgpext_ospf_rtype[] = {
230 { BGP_OSPF_RTYPE_RTR, "Router" },
231 { BGP_OSPF_RTYPE_NET, "Network" },
232 { BGP_OSPF_RTYPE_SUM, "Summary" },
233 { BGP_OSPF_RTYPE_EXT, "External" },
234 { BGP_OSPF_RTYPE_NSSA,"NSSA External" },
235 { BGP_OSPF_RTYPE_SHAM,"MPLS-VPN Sham" },
239 /* Subsequent address family identifier, RFC2858 */
240 static const value_string bgpattr_nlri_safi[] = {
242 { SAFNUM_UNICAST, "Unicast" },
243 { SAFNUM_MULCAST, "Multicast" },
244 { SAFNUM_UNIMULC, "Unicast+Multicast" },
245 { SAFNUM_MPLS_LABEL, "Labeled Unicast"},
246 { SAFNUM_TUNNEL, "Tunnel"},
247 { SAFNUM_VPLS, "VPLS"},
248 { SAFNUM_LAB_VPNUNICAST, "Labeled VPN Unicast" }, /* draft-rosen-rfc2547bis-03 */
249 { SAFNUM_LAB_VPNMULCAST, "Labeled VPN Multicast" },
250 { SAFNUM_LAB_VPNUNIMULC, "Labeled VPN Unicast+Multicast" },
254 /* ORF Type, draft-ietf-idr-route-filter-04.txt */
255 static const value_string orf_type_vals[] = {
256 { 2, "Communities ORF-Type" },
257 { 3, "Extended Communities ORF-Type" },
258 { 128, "Cisco PrefixList ORF-Type" },
259 { 129, "Cisco CommunityList ORF-Type" },
260 { 130, "Cisco Extended CommunityList ORF-Type" },
261 { 131, "Cisco AsPathList ORF-Type" },
265 /* ORF Send/Receive, draft-ietf-idr-route-filter-04.txt */
266 static const value_string orf_send_recv_vals[] = {
273 /* ORF Send/Receive, draft-ietf-idr-route-filter-04.txt */
274 static const value_string orf_when_vals[] = {
280 static const value_string orf_entry_action_vals[] = {
283 { 0x80, "RemoveAll" },
287 static const value_string orf_entry_match_vals[] = {
293 static const value_string capability_vals[] = {
294 { BGP_CAPABILITY_RESERVED, "Reserved capability" },
295 { BGP_CAPABILITY_MULTIPROTOCOL, "Multiprotocol extensions capability" },
296 { BGP_CAPABILITY_ROUTE_REFRESH, "Route refresh capability" },
297 { BGP_CAPABILITY_COOPERATIVE_ROUTE_FILTERING, "Cooperative route filtering capability" },
298 { BGP_CAPABILITY_GRACEFUL_RESTART, "Graceful Restart capability" },
299 { BGP_CAPABILITY_4_OCTET_AS_NUMBER, "Support for 4-octet AS number capability" },
300 { BGP_CAPABILITY_DYNAMIC_CAPABILITY, "Support for Dynamic capability" },
301 { BGP_CAPABILITY_ROUTE_REFRESH_CISCO, "Route refresh capability" },
302 { BGP_CAPABILITY_ORF_CISCO, "Cooperative route filtering capability" },
306 /* Capability Message action code */
307 static const value_string bgpcap_action[] = {
308 { 0, "advertising a capability" },
309 { 1, "removing a capability" },
314 /* Maximal size of an IP address string */
315 #define MAX_SIZE_OF_IP_ADDR_STRING 16
317 static int proto_bgp = -1;
318 static int hf_bgp_type = -1;
319 static int hf_bgp_next_hop = -1;
320 static int hf_bgp_as_path = -1;
321 static int hf_bgp_cluster_identifier = -1;
322 static int hf_bgp_community_as = -1;
323 static int hf_bgp_community_value = -1;
324 static int hf_bgp_origin = -1;
325 static int hf_bgp_cluster_list = -1;
326 static int hf_bgp_originator_id = -1;
327 static int hf_bgp_ssa_t = -1;
328 static int hf_bgp_ssa_type = -1;
329 static int hf_bgp_ssa_len = -1;
330 static int hf_bgp_ssa_value = -1;
331 static int hf_bgp_ssa_l2tpv3_pref = -1;
332 static int hf_bgp_ssa_l2tpv3_s = -1;
333 static int hf_bgp_ssa_l2tpv3_unused = -1;
334 static int hf_bgp_ssa_l2tpv3_cookie_len = -1;
335 static int hf_bgp_ssa_l2tpv3_session_id = -1;
336 static int hf_bgp_ssa_l2tpv3_cookie = -1;
337 static int hf_bgp_local_pref = -1;
338 static int hf_bgp_multi_exit_disc = -1;
339 static int hf_bgp_aggregator_as = -1;
340 static int hf_bgp_aggregator_origin = -1;
341 static int hf_bgp_mp_reach_nlri_ipv4_prefix = -1;
342 static int hf_bgp_mp_unreach_nlri_ipv4_prefix = -1;
343 static int hf_bgp_mp_nlri_tnl_id = -1;
344 static int hf_bgp_withdrawn_prefix = -1;
345 static int hf_bgp_nlri_prefix = -1;
347 static gint ett_bgp = -1;
348 static gint ett_bgp_prefix = -1;
349 static gint ett_bgp_unfeas = -1;
350 static gint ett_bgp_attrs = -1;
351 static gint ett_bgp_attr = -1;
352 static gint ett_bgp_attr_flags = -1;
353 static gint ett_bgp_mp_nhna = -1;
354 static gint ett_bgp_mp_reach_nlri = -1;
355 static gint ett_bgp_mp_unreach_nlri = -1;
356 static gint ett_bgp_mp_snpa = -1;
357 static gint ett_bgp_nlri = -1;
358 static gint ett_bgp_open = -1;
359 static gint ett_bgp_update = -1;
360 static gint ett_bgp_notification = -1;
361 static gint ett_bgp_route_refresh = -1; /* ROUTE-REFRESH message tree */
362 static gint ett_bgp_capability = -1;
363 static gint ett_bgp_as_paths = -1;
364 static gint ett_bgp_as_path_segments = -1;
365 static gint ett_bgp_communities = -1;
366 static gint ett_bgp_cluster_list = -1; /* cluster list tree */
367 static gint ett_bgp_options = -1; /* optional parameters tree */
368 static gint ett_bgp_option = -1; /* an optional parameter tree */
369 static gint ett_bgp_extended_communities = -1 ; /* extended communities list tree */
370 static gint ett_bgp_ssa = -1; /* safi specific attribute */
371 static gint ett_bgp_ssa_subtree = -1; /* safi specific attribute Subtrees */
372 static gint ett_bgp_orf = -1; /* orf (outbound route filter) tree */
373 static gint ett_bgp_orf_entry = -1; /* orf entry tree */
376 static gboolean bgp_desegment = TRUE;
378 static gint bgp_asn_len = 0;
381 * Decode an IPv4 prefix.
384 decode_prefix4(proto_tree *tree, int hf_addr, tvbuff_t *tvb, gint offset,
385 guint16 tlen, const char *tag)
388 proto_tree *prefix_tree;
390 guint8 addr_bytes[4];
392 } ip_addr; /* IP address */
393 guint8 plen; /* prefix length */
394 int length; /* number of octets needed for prefix */
396 /* snarf length and prefix */
397 plen = tvb_get_guint8(tvb, offset);
398 length = ipv4_addr_and_mask(tvb, offset + 1, ip_addr.addr_bytes, plen);
400 proto_tree_add_text(tree, tvb, offset, 1, "%s length %u invalid (> 32)",
405 /* put prefix into protocol tree */
406 ti = proto_tree_add_text(tree, tvb, offset,
407 tlen != 0 ? tlen : 1 + length, "%s/%u",
408 ip_to_str(ip_addr.addr_bytes), plen);
409 prefix_tree = proto_item_add_subtree(ti, ett_bgp_prefix);
410 proto_tree_add_text(prefix_tree, tvb, offset, 1, "%s prefix length: %u",
413 proto_tree_add_ipv4(prefix_tree, hf_addr, tvb, offset + 1, length,
416 proto_tree_add_text(prefix_tree, tvb, offset + 1, length,
417 "%s prefix: %s", tag, ip_to_str(ip_addr.addr_bytes));
423 * Decode an IPv6 prefix.
426 decode_prefix6(proto_tree *tree, int hf_addr, tvbuff_t *tvb, gint offset,
427 guint16 tlen, const char *tag)
430 proto_tree *prefix_tree;
431 struct e_in6_addr addr; /* IPv6 address */
432 int plen; /* prefix length */
433 int length; /* number of octets needed for prefix */
435 /* snarf length and prefix */
436 plen = tvb_get_guint8(tvb, offset);
437 length = ipv6_addr_and_mask(tvb, offset + 1, &addr, plen);
439 proto_tree_add_text(tree, tvb, offset, 1, "%s length %u invalid",
444 /* put prefix into protocol tree */
445 ti = proto_tree_add_text(tree, tvb, offset,
446 tlen != 0 ? tlen : 1 + length, "%s/%u",
447 ip6_to_str(&addr), plen);
448 prefix_tree = proto_item_add_subtree(ti, ett_bgp_prefix);
449 proto_tree_add_text(prefix_tree, tvb, offset, 1, "%s prefix length: %u",
452 proto_tree_add_ipv6(prefix_tree, hf_addr, tvb, offset + 1, length,
455 proto_tree_add_text(prefix_tree, tvb, offset + 1, length,
456 "%s prefix: %s", tag, ip6_to_str(&addr));
464 * Decode an MPLS label stack
465 * XXX - We should change *buf to **buf, use ep_alloc() and drop the buflen
469 decode_MPLS_stack(tvbuff_t *tvb, gint offset, char *buf, size_t buflen)
471 guint32 label_entry; /* an MPLS label enrty (label + COS field + stack bit */
472 gint index; /* index for the label stack */
476 label_entry = 0x000000 ;
481 while ((label_entry & 0x000001) == 0) {
483 label_entry = tvb_get_ntoh24(tvb, index) ;
485 /* withdrawn routes may contain 0 or 0x800000 in the first label */
486 if((index-offset)==0&&(label_entry==0||label_entry==0x800000)) {
487 g_snprintf(bufptr, buflen-(bufptr-buf), "0 (withdrawn)");
491 bufptr+=MIN(buflen-(bufptr-buf),
492 (unsigned)g_snprintf(bufptr, buflen-(bufptr-buf), "%u%s",
494 ((label_entry & 0x000001) == 0) ? "," : " (bottom)"));
498 if ((label_entry & 0x000001) == 0) {
499 /* real MPLS multi-label stack in BGP? - maybe later; for now, it must be a bogus packet */
500 g_snprintf(bufptr, buflen-(bufptr-buf), " (BOGUS: Bottom of Stack NOT set!)");
505 return((index - offset) / 3);
509 * Decode a multiprotocol address
513 mp_addr_to_str (guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset, char *buf, int buf_len)
515 int length; /* length of the address in byte */
516 guint32 ip4addr,ip4addr2; /* IPv4 address */
517 guint16 rd_type; /* Route Distinguisher type */
518 struct e_in6_addr ip6addr; /* IPv6 address */
529 case SAFNUM_MPLS_LABEL:
532 ip4addr = tvb_get_ipv4(tvb, offset);
533 g_snprintf(buf, buf_len, "%s", ip_to_str((guint8 *)&ip4addr));
535 case SAFNUM_LAB_VPNUNICAST:
536 case SAFNUM_LAB_VPNMULCAST:
537 case SAFNUM_LAB_VPNUNIMULC:
538 rd_type=tvb_get_ntohs(tvb,offset) ;
541 length = 8 + sizeof(ip4addr);
542 ip4addr = tvb_get_ipv4(tvb, offset + 8); /* Next Hop */
543 g_snprintf(buf, buf_len, "Empty Label Stack RD=%u:%u IPv4=%s",
544 tvb_get_ntohs(tvb, offset + 2),
545 tvb_get_ntohl(tvb, offset + 4),
546 ip_to_str((guint8 *)&ip4addr));
549 length = 8 + sizeof(ip4addr);
550 ip4addr = tvb_get_ipv4(tvb, offset + 2); /* IP part of the RD */
551 ip4addr2 = tvb_get_ipv4(tvb, offset + 8); /* Next Hop */
552 g_snprintf(buf, buf_len, "Empty Label Stack RD=%s:%u IPv4=%s",
553 ip_to_str((guint8 *)&ip4addr),
554 tvb_get_ntohs(tvb, offset + 6),
555 ip_to_str((guint8 *)&ip4addr2));
559 g_snprintf(buf, buf_len, "Unknown (0x%04x) labeled VPN IPv4 address format",rd_type);
565 g_snprintf(buf, buf_len, "Unknown SAFI (%u) for AFI %u", safi, afi);
574 case SAFNUM_MPLS_LABEL:
577 tvb_get_ipv6(tvb, offset, &ip6addr);
578 g_snprintf(buf, buf_len, "%s", ip6_to_str(&ip6addr));
580 case SAFNUM_LAB_VPNUNICAST:
581 case SAFNUM_LAB_VPNMULCAST:
582 case SAFNUM_LAB_VPNUNIMULC:
583 rd_type=tvb_get_ntohs(tvb,offset) ;
587 tvb_get_ipv6(tvb, offset + 8, &ip6addr); /* Next Hop */
588 g_snprintf(buf, buf_len, "Empty Label Stack RD=%u:%u IPv6=%s",
589 tvb_get_ntohs(tvb, offset + 2),
590 tvb_get_ntohl(tvb, offset + 4),
591 ip6_to_str(&ip6addr));
595 ip4addr = tvb_get_ipv4(tvb, offset + 2); /* IP part of the RD */
596 tvb_get_ipv6(tvb, offset + 8, &ip6addr); /* Next Hop */
597 g_snprintf(buf, buf_len, "Empty Label Stack RD=%s:%u IPv6=%s",
598 ip_to_str((guint8 *)&ip4addr),
599 tvb_get_ntohs(tvb, offset + 6),
600 ip6_to_str(&ip6addr));
604 g_snprintf(buf, buf_len, "Unknown (0x%04x) labeled VPN IPv6 address format",rd_type);
610 g_snprintf(buf, buf_len, "Unknown SAFI (%u) for AFI %u", safi, afi);
615 case AFNUM_L2VPN_OLD:
617 case SAFNUM_LAB_VPNUNICAST: /* only labeles prefixes do make sense */
618 case SAFNUM_LAB_VPNMULCAST:
619 case SAFNUM_LAB_VPNUNIMULC:
621 length = 4; /* the next-hop is simply an ipv4 addr */
622 ip4addr = tvb_get_ipv4(tvb, offset + 0);
623 g_snprintf(buf, buf_len, "IPv4=%s",
624 ip_to_str((guint8 *)&ip4addr));
628 g_snprintf(buf, buf_len, "Unknown SAFI (%u) for AFI %u", safi, afi);
634 g_snprintf(buf, buf_len, "Unknown AFI (%u) value", afi);
641 * Decode a multiprotocol prefix
644 decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6,
645 guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset, const char *tag)
647 int start_offset = offset;
649 proto_tree *prefix_tree;
650 int total_length; /* length of the entire item */
651 int length; /* length of the prefix address, in bytes */
652 guint plen; /* length of the prefix address, in bits */
653 guint labnum; /* number of labels */
654 guint16 tnl_id; /* Tunnel Identifier */
655 int ce_id,labblk_off,labblk_size;
657 guint8 addr_bytes[4];
659 } ip4addr, ip4addr2; /* IPv4 address */
660 struct e_in6_addr ip6addr; /* IPv6 address */
661 guint16 rd_type; /* Route Distinguisher type */
662 char lab_stk[256]; /* label stack */
672 total_length = decode_prefix4(tree, hf_addr4, tvb, offset, 0, tag);
673 if (total_length < 0)
677 case SAFNUM_MPLS_LABEL:
678 plen = tvb_get_guint8(tvb, offset);
679 labnum = decode_MPLS_stack(tvb, offset + 1, lab_stk, sizeof(lab_stk));
681 offset += (1 + labnum * 3);
682 if (plen <= (labnum * 3*8)) {
683 proto_tree_add_text(tree, tvb, start_offset, 1,
684 "%s Labeled IPv4 prefix length %u invalid",
688 plen -= (labnum * 3*8);
689 length = ipv4_addr_and_mask(tvb, offset, ip4addr.addr_bytes, plen);
691 proto_tree_add_text(tree, tvb, start_offset, 1,
692 "%s Labeled IPv4 prefix length %u invalid",
693 tag, plen + (labnum * 3*8));
697 ti = proto_tree_add_text(tree, tvb, start_offset,
698 (offset + length) - start_offset,
699 "Label Stack=%s IPv4=%s/%u",
700 lab_stk, ip_to_str(ip4addr.addr_bytes), plen);
701 prefix_tree = proto_item_add_subtree(ti, ett_bgp_prefix);
702 proto_tree_add_text(prefix_tree, tvb, start_offset, 1, "%s Prefix length: %u",
703 tag, plen + labnum * 3 * 8);
704 proto_tree_add_text(prefix_tree, tvb, start_offset + 1, 3 * labnum, "%s Label Stack: %s",
706 if (hf_addr4 != -1) {
707 proto_tree_add_ipv4(prefix_tree, hf_addr4, tvb, offset,
708 length, ip4addr.addr);
710 proto_tree_add_text(prefix_tree, tvb, offset, length,
711 "%s IPv4 prefix: %s",
712 tag, ip_to_str(ip4addr.addr_bytes));
714 total_length = (1 + labnum*3) + length;
718 plen = tvb_get_guint8(tvb, offset);
720 proto_tree_add_text(tree, tvb, start_offset, 1,
721 "%s Tunnel IPv4 prefix length %u invalid",
725 tnl_id = tvb_get_ntohs(tvb, offset + 1);
726 offset += 3; /* Length + Tunnel Id */
727 plen -= 16; /* 2-octet Identifier */
728 length = ipv4_addr_and_mask(tvb, offset, ip4addr.addr_bytes, plen);
730 proto_tree_add_text(tree, tvb, start_offset, 1,
731 "%s Tunnel IPv4 prefix length %u invalid",
735 ti = proto_tree_add_text(tree, tvb, start_offset,
736 (offset + length) - start_offset,
737 "Tunnel Identifier=0x%x IPv4=%s/%u",
738 tnl_id, ip_to_str(ip4addr.addr_bytes), plen);
739 prefix_tree = proto_item_add_subtree(ti, ett_bgp_prefix);
741 proto_tree_add_text(prefix_tree, tvb, start_offset, 1, "%s Prefix length: %u",
743 proto_tree_add_item(prefix_tree, hf_bgp_mp_nlri_tnl_id, tvb,
744 start_offset + 1, 2, FALSE);
745 if (hf_addr4 != -1) {
746 proto_tree_add_ipv4(prefix_tree, hf_addr4, tvb, offset,
747 length, ip4addr.addr);
749 proto_tree_add_text(prefix_tree, tvb, offset, length,
750 "%s IPv4 prefix: %s",
751 tag, ip_to_str(ip4addr.addr_bytes));
753 total_length = 1 + 2 + length; /* length field + Tunnel Id + IPv4 len */
756 case SAFNUM_LAB_VPNUNICAST:
757 case SAFNUM_LAB_VPNMULCAST:
758 case SAFNUM_LAB_VPNUNIMULC:
759 plen = tvb_get_guint8(tvb, offset);
760 labnum = decode_MPLS_stack(tvb, offset + 1, lab_stk, sizeof(lab_stk));
762 offset += (1 + labnum * 3);
763 if (plen <= (labnum * 3*8)) {
764 proto_tree_add_text(tree, tvb, start_offset, 1,
765 "%s Labeled VPN IPv4 prefix length %u invalid",
769 plen -= (labnum * 3*8);
771 rd_type = tvb_get_ntohs(tvb, offset);
773 proto_tree_add_text(tree, tvb, start_offset, 1,
774 "%s Labeled VPN IPv4 prefix length %u invalid",
775 tag, plen + (labnum * 3*8));
782 case FORMAT_AS2_LOC: /* Code borrowed from the decode_prefix4 function */
783 length = ipv4_addr_and_mask(tvb, offset + 8, ip4addr.addr_bytes, plen);
785 proto_tree_add_text(tree, tvb, start_offset, 1,
786 "%s Labeled VPN IPv4 prefix length %u invalid",
787 tag, plen + (labnum * 3*8) + 8*8);
791 ti = proto_tree_add_text(tree, tvb, start_offset,
792 (offset + 8 + length) - start_offset,
793 "Label Stack=%s RD=%u:%u, IPv4=%s/%u",
795 tvb_get_ntohs(tvb, offset + 2),
796 tvb_get_ntohl(tvb, offset + 4),
797 ip_to_str(ip4addr.addr_bytes), plen);
798 prefix_tree = proto_item_add_subtree(ti, ett_bgp_prefix);
799 proto_tree_add_text(prefix_tree, tvb, start_offset, 1, "%s Prefix length: %u",
800 tag, plen + labnum * 3 * 8 + 8 * 8);
801 proto_tree_add_text(prefix_tree, tvb, start_offset + 1, 3 * labnum,
802 "%s Label Stack: %s", tag, lab_stk);
803 proto_tree_add_text(prefix_tree, tvb, start_offset + 1 + 3 * labnum, 8,
804 "%s Route Distinguisher: %u:%u", tag, tvb_get_ntohs(tvb, offset + 2),
805 tvb_get_ntohl(tvb, offset + 4));
806 if (hf_addr4 != -1) {
807 proto_tree_add_ipv4(prefix_tree, hf_addr4, tvb,
808 offset + 8, length, ip4addr.addr);
810 proto_tree_add_text(prefix_tree, tvb, offset + 8,
811 length, "%s IPv4 prefix: %s", tag,
812 ip_to_str(ip4addr.addr_bytes));
814 total_length = (1 + labnum * 3 + 8) + length;
817 case FORMAT_IP_LOC: /* Code borrowed from the decode_prefix4 function */
818 tvb_memcpy(tvb, ip4addr.addr_bytes, offset + 2, 4);
820 length = ipv4_addr_and_mask(tvb, offset + 8, ip4addr2.addr_bytes, plen);
822 proto_tree_add_text(tree, tvb, start_offset, 1,
823 "%s Labeled VPN IPv4 prefix length %u invalid",
824 tag, plen + (labnum * 3*8) + 8*8);
828 ti = proto_tree_add_text(tree, tvb, start_offset,
829 (offset + 8 + length) - start_offset,
830 "Label Stack=%s RD=%s:%u, IPv4=%s/%u",
832 ip_to_str(ip4addr.addr_bytes),
833 tvb_get_ntohs(tvb, offset + 6),
834 ip_to_str(ip4addr2.addr_bytes),
836 prefix_tree = proto_item_add_subtree(ti, ett_bgp_prefix);
837 proto_tree_add_text(prefix_tree, tvb, start_offset, 1, "%s Prefix length: %u",
838 tag, plen + labnum * 3 * 8 + 8 * 8);
839 proto_tree_add_text(prefix_tree, tvb, start_offset + 1, 3 * labnum,
840 "%s Label Stack: %s", tag, lab_stk);
841 proto_tree_add_text(prefix_tree, tvb, start_offset + 1 + 3 * labnum, 8,
842 "%s Route Distinguisher: %s:%u", tag, ip_to_str(ip4addr.addr_bytes),
843 tvb_get_ntohs(tvb, offset + 6));
844 if (hf_addr4 != -1) {
845 proto_tree_add_ipv4(prefix_tree, hf_addr4, tvb,
846 offset + 8, length, ip4addr2.addr);
848 proto_tree_add_text(prefix_tree, tvb, offset + 8,
849 length, "%s IPv4 prefix: %s", tag,
850 ip_to_str(ip4addr2.addr_bytes));
852 total_length = (1 + labnum * 3 + 8) + length;
856 proto_tree_add_text(tree, tvb, start_offset,
857 (offset - start_offset) + 2,
858 "Unknown labeled VPN IPv4 address format %u", rd_type);
864 proto_tree_add_text(tree, tvb, start_offset, 0,
865 "Unknown SAFI (%u) for AFI %u", safi, afi);
876 total_length = decode_prefix6(tree, hf_addr6, tvb, offset, 0, tag);
877 if (total_length < 0)
881 case SAFNUM_MPLS_LABEL:
882 plen = tvb_get_guint8(tvb, offset);
883 labnum = decode_MPLS_stack(tvb, offset + 1, lab_stk, sizeof(lab_stk));
885 offset += (1 + labnum * 3);
886 if (plen <= (labnum * 3*8)) {
887 proto_tree_add_text(tree, tvb, start_offset, 1,
888 "%s Labeled IPv6 prefix length %u invalid", tag, plen);
891 plen -= (labnum * 3*8);
893 length = ipv6_addr_and_mask(tvb, offset, &ip6addr, plen);
895 proto_tree_add_text(tree, tvb, start_offset, 1,
896 "%s Labeled IPv6 prefix length %u invalid",
897 tag, plen + (labnum * 3*8));
901 ti = proto_tree_add_text(tree, tvb, start_offset,
902 (offset + length) - start_offset,
903 "Label Stack=%s, IPv6=%s/%u",
905 ip6_to_str(&ip6addr), plen);
906 total_length = (1 + labnum * 3) + length;
910 plen = tvb_get_guint8(tvb, offset);
912 proto_tree_add_text(tree, tvb, start_offset, 1,
913 "%s Tunnel IPv6 prefix length %u invalid",
917 tnl_id = tvb_get_ntohs(tvb, offset + 1);
918 offset += 3; /* Length + Tunnel Id */
919 plen -= 16; /* 2-octet Identifier */
920 length = ipv6_addr_and_mask(tvb, offset, &ip6addr, plen);
922 proto_tree_add_text(tree, tvb, start_offset, 1,
923 "%s Tunnel IPv6 prefix length %u invalid",
927 ti = proto_tree_add_text(tree, tvb, start_offset,
928 (offset + length) - start_offset,
929 "Tunnel Identifier=0x%x IPv6=%s/%u",
930 tnl_id, ip6_to_str(&ip6addr), plen);
931 total_length = (1 + 2) + length; /* length field + Tunnel Id + IPv4 len */
934 case SAFNUM_LAB_VPNUNICAST:
935 case SAFNUM_LAB_VPNMULCAST:
936 case SAFNUM_LAB_VPNUNIMULC:
937 plen = tvb_get_guint8(tvb, offset);
938 labnum = decode_MPLS_stack(tvb, offset + 1, lab_stk, sizeof(lab_stk));
940 offset += (1 + labnum * 3);
941 if (plen <= (labnum * 3*8)) {
942 proto_tree_add_text(tree, tvb, start_offset, 1,
943 "%s Labeled VPN IPv6 prefix length %u invalid", tag, plen);
946 plen -= (labnum * 3*8);
948 rd_type = tvb_get_ntohs(tvb,offset);
950 proto_tree_add_text(tree, tvb, start_offset, 1,
951 "%s Labeled VPN IPv6 prefix length %u invalid",
952 tag, plen + (labnum * 3*8));
960 length = ipv6_addr_and_mask(tvb, offset + 8, &ip6addr, plen);
962 proto_tree_add_text(tree, tvb, start_offset, 1,
963 "%s Labeled VPN IPv6 prefix length %u invalid",
964 tag, plen + (labnum * 3*8) + 8*8);
968 ti = proto_tree_add_text(tree, tvb, start_offset,
969 (offset + 8 + length) - start_offset,
970 "Label Stack=%s RD=%u:%u, IPv6=%s/%u",
972 tvb_get_ntohs(tvb, offset + 2),
973 tvb_get_ntohl(tvb, offset + 4),
974 ip6_to_str(&ip6addr), plen);
975 total_length = (1 + labnum * 3 + 8) + length;
979 tvb_memcpy(tvb, ip4addr.addr_bytes, offset + 2, 4);
981 length = ipv6_addr_and_mask(tvb, offset + 8, &ip6addr, plen);
983 proto_tree_add_text(tree, tvb, start_offset, 1,
984 "%s Labeled VPN IPv6 prefix length %u invalid",
985 tag, plen + (labnum * 3*8) + 8*8);
989 ti = proto_tree_add_text(tree, tvb, start_offset,
990 (offset + 8 + length) - start_offset,
991 "Label Stack=%s RD=%s:%u, IPv6=%s/%u",
993 ip_to_str(ip4addr.addr_bytes),
994 tvb_get_ntohs(tvb, offset + 6),
995 ip6_to_str(&ip6addr), plen);
996 total_length = (1 + labnum * 3 + 8) + length;
1000 proto_tree_add_text(tree, tvb, start_offset, 0,
1001 "Unknown labeled VPN IPv6 address format %u", rd_type);
1007 proto_tree_add_text(tree, tvb, start_offset, 0,
1008 "Unknown SAFI (%u) for AFI %u", safi, afi);
1014 case AFNUM_L2VPN_OLD:
1017 case SAFNUM_LAB_VPNUNICAST:
1018 case SAFNUM_LAB_VPNMULCAST:
1019 case SAFNUM_LAB_VPNUNIMULC:
1021 plen = tvb_get_ntohs(tvb,offset);
1022 rd_type=tvb_get_ntohs(tvb,offset+2);
1023 ce_id=tvb_get_ntohs(tvb,offset+10);
1024 labblk_off=tvb_get_ntohs(tvb,offset+12);
1025 labblk_size=tvb_get_ntohs(tvb,offset+14);
1026 labnum = decode_MPLS_stack(tvb, offset + 16, lab_stk, sizeof(lab_stk));
1030 case FORMAT_AS2_LOC:
1031 tvb_memcpy(tvb, ip4addr.addr_bytes, offset + 6, 4);
1032 proto_tree_add_text(tree, tvb, start_offset,
1033 (offset + plen + 1) - start_offset,
1034 "RD: %u:%s, CE-ID: %u, Label-Block Offset: %u, "
1035 "Label-Block Size: %u Label Base %s",
1036 tvb_get_ntohs(tvb, offset + 4),
1037 ip_to_str(ip4addr.addr_bytes),
1045 tvb_memcpy(tvb, ip4addr.addr_bytes, offset + 4, 4);
1046 proto_tree_add_text(tree, tvb, offset,
1047 (offset + plen + 1) - start_offset,
1048 "RD: %s:%u, CE-ID: %u, Label-Block Offset: %u, "
1049 "Label-Block Size: %u, Label Base %s",
1050 ip_to_str(ip4addr.addr_bytes),
1051 tvb_get_ntohs(tvb, offset + 8),
1059 proto_tree_add_text(tree, tvb, start_offset,
1060 (offset - start_offset) + 2,
1061 "Unknown labeled VPN address format %u", rd_type);
1064 /* FIXME there are subTLVs left to decode ... for now lets omit them */
1065 total_length = plen+2;
1069 proto_tree_add_text(tree, tvb, start_offset, 0,
1070 "Unknown SAFI (%u) for AFI %u", safi, afi);
1076 proto_tree_add_text(tree, tvb, start_offset, 0,
1077 "Unknown AFI (%u) value", afi);
1080 return(total_length);
1084 * Dissect a BGP capability.
1087 dissect_bgp_capability_item(tvbuff_t *tvb, int *p, proto_tree *tree, int ctype, int clen)
1089 proto_tree *subtree;
1091 guint8 orfnum; /* number of ORFs */
1092 guint8 orftype; /* ORF Type */
1093 guint8 orfsendrecv; /* ORF Send/Receive */
1094 int tclen; /* capability length */
1097 /* check the capability type */
1099 case BGP_CAPABILITY_RESERVED:
1100 proto_tree_add_text(tree, tvb, *p - 2, 1,
1101 "Capability code: %s (%d)", val_to_str(ctype,
1102 capability_vals, "Unknown capability"), ctype);
1103 proto_tree_add_text(tree, tvb, *p - 1,
1104 1, "Capability length: %u %s", clen,
1105 (clen == 1) ? "byte" : "bytes");
1107 proto_tree_add_text(tree, tvb, *p,
1108 clen, "Capability value: Unknown");
1112 case BGP_CAPABILITY_MULTIPROTOCOL:
1113 proto_tree_add_text(tree, tvb, *p - 2, 1,
1114 "Capability code: %s (%d)", val_to_str(ctype,
1115 capability_vals, "Unknown capability"), ctype);
1117 proto_tree_add_text(tree, tvb, *p - 1,
1118 1, "Capability length: Invalid");
1119 proto_tree_add_text(tree, tvb, *p,
1120 clen, "Capability value: Unknown");
1123 proto_tree_add_text(tree, tvb, *p - 1,
1124 1, "Capability length: %u %s", clen,
1125 (clen == 1) ? "byte" : "bytes");
1126 ti = proto_tree_add_text(tree, tvb, *p, clen, "Capability value");
1127 subtree = proto_item_add_subtree(ti, ett_bgp_option);
1129 i = tvb_get_ntohs(tvb, *p);
1130 proto_tree_add_text(subtree, tvb, *p,
1131 2, "Address family identifier: %s (%u)",
1132 val_to_str(i, afn_vals, "Unknown"), i);
1135 proto_tree_add_text(subtree, tvb, *p, 1, "Reserved: 1 byte");
1138 i = tvb_get_guint8(tvb, *p);
1139 proto_tree_add_text(subtree, tvb, *p,
1140 1, "Subsequent address family identifier: %s (%u)",
1141 val_to_str(i, bgpattr_nlri_safi,
1142 i >= 128 ? "Vendor specific" : "Unknown"), i);
1146 case BGP_CAPABILITY_GRACEFUL_RESTART:
1147 proto_tree_add_text(tree, tvb, *p - 2, 1,
1148 "Capability code: %s (%d)", val_to_str(ctype,
1149 capability_vals, "Unknown capability"), ctype);
1151 proto_tree_add_text(tree, tvb, *p,
1152 clen, "Capability value: Invalid");
1155 proto_tree_add_text(tree, tvb, *p - 1,
1156 1, "Capability length: %u %s", clen,
1157 (clen == 1) ? "byte" : "bytes");
1158 ti = proto_tree_add_text(tree, tvb, *p, clen, "Capability value");
1159 subtree = proto_item_add_subtree(ti, ett_bgp_option);
1161 i = tvb_get_ntohs(tvb, *p);
1162 proto_tree_add_text(subtree, tvb, *p,
1163 2, "Restart Flags: [%s], Restart Time %us",
1164 (i&0x8000) ? "R" : "none", i&0xfff);
1168 * what follows is alist of AFI/SAFI/flag triplets
1169 * read it until the TLV ends
1173 i = tvb_get_ntohs(tvb, *p);
1174 proto_tree_add_text(subtree, tvb, *p,
1175 2, "Address family identifier: %s (%u)",
1176 val_to_str(i, afn_vals, "Unknown"), i);
1179 i = tvb_get_guint8(tvb, *p);
1180 proto_tree_add_text(subtree, tvb, *p,
1181 1, "Subsequent address family identifier: %s (%u)",
1182 val_to_str(i, bgpattr_nlri_safi,
1183 i >= 128 ? "Vendor specific" : "Unknown"), i);
1186 i = tvb_get_guint8(tvb, *p);
1187 proto_tree_add_text(subtree, tvb, *p, 1,
1188 "Preserve forwarding state: %s",
1189 (i&0x80) ? "yes" : "no");
1196 case BGP_CAPABILITY_4_OCTET_AS_NUMBER:
1197 proto_tree_add_text(tree, tvb, *p - 2, 1,
1198 "Capability code: %s (%d)", val_to_str(ctype,
1199 capability_vals, "Unknown capability"), ctype);
1201 proto_tree_add_text(tree, tvb, *p,
1202 clen, "Capability value: Invalid");
1205 proto_tree_add_text(tree, tvb, *p - 1,
1206 1, "Capability length: %u %s", clen,
1207 (clen == 1) ? "byte" : "bytes");
1208 ti = proto_tree_add_text(tree, tvb, *p, clen, "Capability value");
1209 subtree = proto_item_add_subtree(ti, ett_bgp_option);
1210 proto_tree_add_text(subtree, tvb, *p, 4,
1211 "AS number: %d", tvb_get_ntohl(tvb, *p));
1215 case BGP_CAPABILITY_DYNAMIC_CAPABILITY:
1216 proto_tree_add_text(tree, tvb, *p - 2, 1,
1217 "Capability code: %s (%d)", val_to_str(ctype,
1218 capability_vals, "Unknown capability"), ctype);
1219 proto_tree_add_text(tree, tvb, *p - 1, 1,
1220 "Capability length: %u %s", clen,
1221 (clen == 1) ? "byte" : "bytes");
1223 ti = proto_tree_add_text(tree, tvb, *p, clen, "Capability value");
1224 subtree = proto_item_add_subtree(ti, ett_bgp_option);
1225 for (i = 0; (int)i <= clen; i++) {
1226 proto_tree_add_text(subtree, tvb, *p, 1,
1227 "Capability code: %s (%d)", val_to_str(ctype,
1228 capability_vals, "Unknown capability"),
1229 tvb_get_guint8(tvb, *p));
1234 case BGP_CAPABILITY_ROUTE_REFRESH_CISCO:
1235 case BGP_CAPABILITY_ROUTE_REFRESH:
1236 proto_tree_add_text(tree, tvb, *p - 2, 1,
1237 "Capability code: %s (%d)", val_to_str(ctype,
1238 capability_vals, "Unknown capability"), ctype);
1240 proto_tree_add_text(tree, tvb, *p,
1241 clen, "Capability value: Invalid");
1244 proto_tree_add_text(tree, tvb, *p - 1,
1245 1, "Capability length: %u %s", clen,
1246 (clen == 1) ? "byte" : "bytes");
1250 case BGP_CAPABILITY_ORF_CISCO:
1251 case BGP_CAPABILITY_COOPERATIVE_ROUTE_FILTERING:
1252 proto_tree_add_text(tree, tvb, *p - 2, 1,
1253 "Capability code: %s (%d)", val_to_str(ctype,
1254 capability_vals, "Unknown capability"), ctype);
1255 proto_tree_add_text(tree, tvb, *p - 1,
1256 1, "Capability length: %u %s", clen,
1257 (clen == 1) ? "byte" : "bytes");
1258 ti = proto_tree_add_text(tree, tvb, *p, clen, "Capability value");
1259 subtree = proto_item_add_subtree(ti, ett_bgp_option);
1261 i = tvb_get_ntohs(tvb, *p);
1262 proto_tree_add_text(subtree, tvb, *p,
1263 2, "Address family identifier: %s (%u)",
1264 val_to_str(i, afn_vals, "Unknown"), i);
1267 proto_tree_add_text(subtree, tvb, *p, 1, "Reserved: 1 byte");
1270 i = tvb_get_guint8(tvb, *p);
1271 proto_tree_add_text(subtree, tvb, *p,
1272 1, "Subsequent address family identifier: %s (%u)",
1273 val_to_str(i, bgpattr_nlri_safi,
1274 i >= 128 ? "Vendor specific" : "Unknown"), i);
1276 /* Number of ORFs */
1277 orfnum = tvb_get_guint8(tvb, *p);
1278 proto_tree_add_text(subtree, tvb, *p, 1, "Number of ORFs: %u", orfnum);
1280 for (i=0; i<orfnum; i++) {
1282 orftype = tvb_get_guint8(tvb, *p);
1283 proto_tree_add_text(subtree, tvb, *p, 1, "ORF Type: %s (%u)",
1284 val_to_str(orftype, orf_type_vals,"Unknown"), orftype);
1287 orfsendrecv = tvb_get_guint8(tvb, *p);
1288 proto_tree_add_text(subtree, tvb, *p,
1289 1, "Send/Receive: %s (%u)",
1290 val_to_str(orfsendrecv, orf_send_recv_vals,
1291 "Uknown"), orfsendrecv);
1295 /* unknown capability */
1297 proto_tree_add_text(tree, tvb, *p - 2, 1,
1298 "Capability code: %s (%d)", val_to_str(ctype,
1299 capability_vals, "Unknown capability"), ctype);
1300 proto_tree_add_text(tree, tvb, *p - 2,
1301 1, "Capability code: %s (%d)",
1302 ctype >= 128 ? "Private use" : "Unknown", ctype);
1303 proto_tree_add_text(tree, tvb, *p - 1,
1304 1, "Capability length: %u %s", clen,
1305 (clen == 1) ? "byte" : "bytes");
1307 proto_tree_add_text(tree, tvb, *p,
1308 clen, "Capability value: Unknown");
1317 * Dissect a BGP OPEN message.
1319 static const value_string community_vals[] = {
1320 { BGP_COMM_NO_EXPORT, "NO_EXPORT" },
1321 { BGP_COMM_NO_ADVERTISE, "NO_ADVERTISE" },
1322 { BGP_COMM_NO_EXPORT_SUBCONFED, "NO_EXPORT_SUBCONFED" },
1327 dissect_bgp_open(tvbuff_t *tvb, proto_tree *tree)
1329 struct bgp_open bgpo; /* BGP OPEN message */
1330 int hlen; /* message length */
1331 int ptype; /* parameter type */
1332 int plen; /* parameter length */
1333 int ctype; /* capability type */
1334 int clen; /* capability length */
1335 int cend; /* capabilities end */
1336 int ostart; /* options start */
1337 int oend; /* options end */
1338 int p; /* tvb offset counter */
1339 proto_item *ti; /* tree item */
1340 proto_tree *subtree; /* subtree for options */
1341 proto_tree *subtree1; /* subtree for an option */
1342 proto_tree *subtree2; /* subtree for an option */
1344 /* snarf OPEN message */
1345 tvb_memcpy(tvb, bgpo.bgpo_marker, 0, BGP_MIN_OPEN_MSG_SIZE);
1346 hlen = g_ntohs(bgpo.bgpo_len);
1348 proto_tree_add_text(tree, tvb,
1349 offsetof(struct bgp_open, bgpo_version), 1,
1350 "Version: %u", bgpo.bgpo_version);
1351 proto_tree_add_text(tree, tvb,
1352 offsetof(struct bgp_open, bgpo_myas), 2,
1353 "My AS: %u", g_ntohs(bgpo.bgpo_myas));
1354 proto_tree_add_text(tree, tvb,
1355 offsetof(struct bgp_open, bgpo_holdtime), 2,
1356 "Hold time: %u", g_ntohs(bgpo.bgpo_holdtime));
1357 proto_tree_add_text(tree, tvb,
1358 offsetof(struct bgp_open, bgpo_id), 4,
1359 "BGP identifier: %s", ip_to_str((guint8 *)&bgpo.bgpo_id));
1360 proto_tree_add_text(tree, tvb,
1361 offsetof(struct bgp_open, bgpo_optlen), 1,
1362 "Optional parameters length: %u %s", bgpo.bgpo_optlen,
1363 (bgpo.bgpo_optlen == 1) ? "byte" : "bytes");
1365 /* optional parameters */
1366 if (bgpo.bgpo_optlen > 0) {
1367 /* add a subtree and setup some offsets */
1368 ostart = BGP_MIN_OPEN_MSG_SIZE;
1369 ti = proto_tree_add_text(tree, tvb, ostart, bgpo.bgpo_optlen,
1370 "Optional parameters");
1371 subtree = proto_item_add_subtree(ti, ett_bgp_options);
1373 oend = p + bgpo.bgpo_optlen;
1375 /* step through all of the optional parameters */
1378 /* grab the type and length */
1379 ptype = tvb_get_guint8(tvb, p++);
1380 plen = tvb_get_guint8(tvb, p++);
1382 /* check the type */
1384 case BGP_OPTION_AUTHENTICATION:
1385 proto_tree_add_text(subtree, tvb, p - 2, 2 + plen,
1386 "Authentication information (%u %s)", plen,
1387 (plen == 1) ? "byte" : "bytes");
1389 case BGP_OPTION_CAPABILITY:
1390 /* grab the capability code */
1391 cend = p - 1 + plen;
1392 ctype = tvb_get_guint8(tvb, p++);
1393 clen = tvb_get_guint8(tvb, p++);
1394 ti = proto_tree_add_text(subtree, tvb, p - 4,
1395 2 + plen, "Capabilities Advertisement (%u bytes)",
1397 subtree1 = proto_item_add_subtree(ti, ett_bgp_option);
1398 proto_tree_add_text(subtree1, tvb, p - 4,
1399 1, "Parameter type: Capabilities (2)");
1400 proto_tree_add_text(subtree1, tvb, p - 3,
1401 1, "Parameter length: %u %s", plen,
1402 (plen == 1) ? "byte" : "bytes");
1405 /* step through all of the capabilities */
1407 ctype = tvb_get_guint8(tvb, p++);
1408 clen = tvb_get_guint8(tvb, p++);
1410 ti = proto_tree_add_text(subtree1, tvb, p - 2,
1411 2 + clen, "%s (%u %s)", val_to_str(ctype,
1412 capability_vals, "Unknown capability"),
1413 2 + clen, (clen == 1) ? "byte" : "bytes");
1414 subtree2 = proto_item_add_subtree(ti, ett_bgp_option);
1415 dissect_bgp_capability_item(tvb, &p,
1416 subtree2, ctype, clen);
1420 proto_tree_add_text(subtree, tvb, p - 2, 2 + plen,
1421 "Unknown optional parameter");
1429 * Dissect a BGP UPDATE message.
1432 dissect_bgp_update(tvbuff_t *tvb, proto_tree *tree)
1434 struct bgp_attr bgpa; /* path attributes */
1435 guint16 hlen; /* message length */
1436 gint o; /* packet offset */
1438 gint end; /* message end */
1439 guint16 ext_com; /* EXTENDED COMMUNITY type */
1440 guint16 len; /* tmp */
1441 int advance; /* tmp */
1442 proto_item *ti; /* tree item */
1443 proto_tree *subtree; /* subtree for attributes */
1444 proto_tree *subtree2; /* subtree for attributes */
1445 proto_tree *subtree3; /* subtree for attributes */
1446 proto_tree *subtree4; /* subtree for attributes */
1447 proto_tree *as_paths_tree; /* subtree for AS_PATHs */
1448 proto_tree *as_path_tree; /* subtree for AS_PATH */
1449 proto_tree *as_path_segment_tree; /* subtree for AS_PATH segments */
1450 proto_tree *communities_tree; /* subtree for COMMUNITIES */
1451 proto_tree *community_tree; /* subtree for a community */
1452 proto_tree *cluster_list_tree; /* subtree for CLUSTER_LIST */
1454 guint8 length; /* AS_PATH length */
1455 guint8 type; /* AS_PATH type */
1456 guint32 as_path_item; /* item in AS_PATH segment */
1457 static GString *as_path_gstr = NULL; /* AS_PATH GString */
1458 static GString *communities_gstr = NULL; /* COMMUNITIES GString */
1459 static GString *cluster_list_gstr = NULL; /* CLUSTER_LIST GString */
1460 char *junk_gbuf, *junk_gbuf_ptr; /* tmp */
1461 guint32 ipaddr; /* IPv4 address */
1462 guint32 aggregator_as;
1463 guint16 ssa_type; /* SSA T + Type */
1464 guint16 ssa_len; /* SSA TLV Length */
1465 guint8 ssa_v3_len; /* SSA L2TPv3 Cookie Length */
1466 gfloat linkband; /* Link bandwidth */
1468 hlen = tvb_get_ntohs(tvb, BGP_MARKER_SIZE);
1469 o = BGP_HEADER_SIZE;
1470 junk_gbuf=ep_alloc(MAX_STR_LEN);
1472 junk_gbuf_ptr=junk_gbuf;
1474 /* check for withdrawals */
1475 len = tvb_get_ntohs(tvb, o);
1476 proto_tree_add_text(tree, tvb, o, 2,
1477 "Unfeasible routes length: %u %s", len, (len == 1) ? "byte" : "bytes");
1480 /* parse unfeasible prefixes */
1482 ti = proto_tree_add_text(tree, tvb, o, len, "Withdrawn routes:");
1483 subtree = proto_item_add_subtree(ti, ett_bgp_unfeas);
1485 /* parse each prefix */
1488 i = decode_prefix4(subtree, hf_bgp_withdrawn_prefix, tvb, o, len,
1496 /* check for advertisements */
1497 len = tvb_get_ntohs(tvb, o);
1498 proto_tree_add_text(tree, tvb, o, 2, "Total path attribute length: %u %s",
1499 len, (len == 1) ? "byte" : "bytes");
1501 /* path attributes */
1503 ti = proto_tree_add_text(tree, tvb, o + 2, len, "Path attributes");
1504 subtree = proto_item_add_subtree(ti, ett_bgp_attrs);
1510 guint16 alen, tlen, aoff;
1516 tvb_memcpy(tvb, (guint8 *)&bgpa, o + i, sizeof(bgpa));
1517 /* check for the Extended Length bit */
1518 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_EXTENDED_LENGTH) {
1519 alen = tvb_get_ntohs(tvb, o + i + sizeof(bgpa));
1520 aoff = sizeof(bgpa) + 2;
1522 alen = tvb_get_guint8(tvb, o + i + sizeof(bgpa));
1523 aoff = sizeof(bgpa) + 1;
1527 /* This is kind of ugly - similar code appears twice, but it
1528 helps browsing attrs. */
1529 /* the first switch prints things in the title of the subtree */
1530 switch (bgpa.bgpa_type) {
1531 case BGPTYPE_ORIGIN:
1533 goto default_attribute_top;
1534 msg = val_to_str(tvb_get_guint8(tvb, o + i + aoff), bgpattr_origin, "Unknown");
1535 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1537 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1538 msg, tlen + aoff, (tlen + aoff == 1) ? "byte" :
1541 case BGPTYPE_AS_PATH:
1542 case BGPTYPE_NEW_AS_PATH:
1544 (o + current attribute + aoff bytes to first tuple) */
1547 /* must be freed by second switch! */
1548 /* "tlen * 11" (10 digits + space) should be a good estimate
1549 of how long the AS path string could be */
1550 if (as_path_gstr == NULL)
1551 as_path_gstr = g_string_sized_new((tlen + 1) * 11);
1552 if (as_path_gstr == NULL) break;
1553 g_string_truncate(as_path_gstr, 0);
1555 /* estimate the length of the AS number */
1556 if (bgpa.bgpa_type == BGPTYPE_NEW_AS_PATH)
1559 if (bgp_asn_len == 0) {
1563 length = tvb_get_guint8(tvb, k++);
1566 asn_len = (k == end) ? 2 : 4;
1569 asn_len = bgp_asn_len;
1573 /* snarf each AS path */
1575 type = tvb_get_guint8(tvb, q++);
1576 if (as_path_gstr->len > 1 &&
1577 as_path_gstr->str[as_path_gstr->len - 1] != ' ')
1578 g_string_append_c(as_path_gstr, ' ');
1579 if (type == AS_SET) {
1580 g_string_append_c(as_path_gstr, '{');
1582 else if (type == AS_CONFED_SET) {
1583 g_string_append_c(as_path_gstr, '[');
1585 else if (type == AS_CONFED_SEQUENCE) {
1586 g_string_append_c(as_path_gstr, '(');
1588 length = tvb_get_guint8(tvb, q++);
1590 /* snarf each value in path */
1591 for (j = 0; j < length; j++) {
1592 g_string_sprintfa(as_path_gstr, "%u%s",
1594 tvb_get_ntohs(tvb, q) : tvb_get_ntohl(tvb, q),
1595 (type == AS_SET || type == AS_CONFED_SET) ?
1600 /* cleanup end of string */
1601 if (type == AS_SET) {
1602 g_string_truncate(as_path_gstr, as_path_gstr->len - 2);
1603 g_string_append_c(as_path_gstr, '}');
1605 else if (type == AS_CONFED_SET) {
1606 g_string_truncate(as_path_gstr, as_path_gstr->len - 2);
1607 g_string_append_c(as_path_gstr, ']');
1609 else if (type == AS_CONFED_SEQUENCE) {
1610 g_string_truncate(as_path_gstr, as_path_gstr->len - 1);
1611 g_string_append_c(as_path_gstr, ')');
1614 g_string_truncate(as_path_gstr, as_path_gstr->len - 1);
1618 /* check for empty AS_PATH */
1620 g_string_sprintf(as_path_gstr, "empty");
1622 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1624 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1625 as_path_gstr->str, tlen + aoff,
1626 (tlen + aoff == 1) ? "byte" : "bytes");
1628 case BGPTYPE_NEXT_HOP:
1630 goto default_attribute_top;
1631 ipaddr = tvb_get_ipv4(tvb, o + i + aoff);
1632 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1634 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1635 ip_to_str((guint8 *)&ipaddr),
1636 tlen + aoff, (tlen + aoff == 1) ? "byte" : "bytes");
1638 case BGPTYPE_MULTI_EXIT_DISC:
1640 goto default_attribute_top;
1641 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1643 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1644 tvb_get_ntohl(tvb, o + i + aoff), tlen + aoff,
1645 (tlen + aoff == 1) ? "byte" : "bytes");
1647 case BGPTYPE_LOCAL_PREF:
1649 goto default_attribute_top;
1650 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1652 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1653 tvb_get_ntohl(tvb, o + i + aoff), tlen + aoff,
1654 (tlen + aoff == 1) ? "byte" : "bytes");
1656 case BGPTYPE_ATOMIC_AGGREGATE:
1658 goto default_attribute_top;
1659 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1661 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1662 tlen + aoff, (tlen + aoff == 1) ? "byte" : "bytes");
1664 case BGPTYPE_AGGREGATOR:
1665 if (tlen != 6 && tlen != 8)
1666 goto default_attribute_top;
1667 case BGPTYPE_NEW_AGGREGATOR:
1668 if (bgpa.bgpa_type == BGPTYPE_NEW_AGGREGATOR && tlen != 8)
1669 goto default_attribute_top;
1671 ipaddr = tvb_get_ipv4(tvb, o + i + aoff + asn_len);
1672 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1673 "%s: AS: %u origin: %s (%u %s)",
1674 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1675 (asn_len == 2) ? tvb_get_ntohs(tvb, o + i + aoff) :
1676 tvb_get_ntohl(tvb, o + i + aoff),
1677 ip_to_str((guint8 *)&ipaddr),
1678 tlen + aoff, (tlen + aoff == 1) ? "byte" : "bytes");
1680 case BGPTYPE_COMMUNITIES:
1682 goto default_attribute_top;
1685 (o + current attribute + aoff bytes to first tuple) */
1688 /* must be freed by second switch! */
1689 /* "tlen * 12" (5 digits, a :, 5 digits + space ) should be
1690 a good estimate of how long the communities string could
1692 if (communities_gstr == NULL)
1693 communities_gstr = g_string_sized_new((tlen + 1) * 12);
1694 if (communities_gstr == NULL) break;
1695 g_string_truncate(communities_gstr, 0);
1697 /* snarf each community */
1699 /* check for well-known communities */
1700 if (tvb_get_ntohl(tvb, q) == BGP_COMM_NO_EXPORT)
1701 g_string_append(communities_gstr, "NO_EXPORT ");
1702 else if (tvb_get_ntohl(tvb, q) == BGP_COMM_NO_ADVERTISE)
1703 g_string_append(communities_gstr, "NO_ADVERTISE ");
1704 else if (tvb_get_ntohl(tvb, q) == BGP_COMM_NO_EXPORT_SUBCONFED)
1705 g_string_append(communities_gstr, "NO_EXPORT_SUBCONFED ");
1707 g_string_sprintfa(communities_gstr, "%u:%u ",
1708 tvb_get_ntohs(tvb, q),
1709 tvb_get_ntohs(tvb, q + 2));
1713 /* cleanup end of string */
1714 g_string_truncate(communities_gstr, communities_gstr->len - 1);
1716 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1718 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1719 communities_gstr->str, tlen + aoff,
1720 (tlen + aoff == 1) ? "byte" : "bytes");
1722 case BGPTYPE_ORIGINATOR_ID:
1724 goto default_attribute_top;
1725 ipaddr = tvb_get_ipv4(tvb, o + i + aoff);
1726 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1728 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1729 ip_to_str((guint8 *)&ipaddr),
1730 tlen + aoff, (tlen + aoff == 1) ? "byte" : "bytes");
1732 case BGPTYPE_CLUSTER_LIST:
1734 goto default_attribute_top;
1737 (o + current attribute + aoff bytes to first tuple) */
1740 /* must be freed by second switch! */
1741 /* "tlen * 16" (12 digits, 3 dots + space ) should be
1742 a good estimate of how long the cluster_list string could
1744 if (cluster_list_gstr == NULL)
1745 cluster_list_gstr = g_string_sized_new((tlen + 1) * 16);
1746 if (cluster_list_gstr == NULL) break;
1747 g_string_truncate(cluster_list_gstr, 0);
1749 /* snarf each cluster list */
1751 ipaddr = tvb_get_ipv4(tvb, q);
1752 g_string_sprintfa(cluster_list_gstr, "%s ", ip_to_str((guint8 *)&ipaddr));
1755 /* cleanup end of string */
1756 g_string_truncate(cluster_list_gstr, cluster_list_gstr->len - 1);
1758 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1760 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1761 cluster_list_gstr->str, tlen + aoff,
1762 (tlen + aoff == 1) ? "byte" : "bytes");
1764 case BGPTYPE_EXTENDED_COMMUNITY:
1767 ti = proto_tree_add_text(subtree,tvb,o+i,tlen+aoff,
1769 val_to_str(bgpa.bgpa_type,bgpattr_type,"Unknown"),
1771 (tlen + aoff == 1) ? "byte" : "bytes");
1773 case BGPTYPE_SAFI_SPECIFIC_ATTR:
1774 ti = proto_tree_add_text(subtree,tvb,o+i,tlen+aoff,
1776 val_to_str(bgpa.bgpa_type,bgpattr_type,"Unknown"),
1778 (tlen + aoff == 1) ? "byte" : "bytes");
1782 default_attribute_top:
1783 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1785 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1786 tlen + aoff, (tlen + aoff == 1) ? "byte" : "bytes");
1787 } /* end of first switch */
1788 subtree2 = proto_item_add_subtree(ti, ett_bgp_attr);
1790 /* figure out flags */
1792 junk_gbuf_ptr=junk_gbuf;
1793 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_OPTIONAL) {
1794 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), "Optional, ");
1797 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), "Well-known, ");
1799 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_TRANSITIVE) {
1800 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), "Transitive, ");
1803 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), "Non-transitive, ");
1805 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_PARTIAL) {
1806 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), "Partial");
1809 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), "Complete");
1811 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_EXTENDED_LENGTH) {
1812 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), ", Extended Length");
1814 ti = proto_tree_add_text(subtree2, tvb,
1815 o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
1816 "Flags: 0x%02x (%s)", bgpa.bgpa_flags, junk_gbuf);
1817 subtree3 = proto_item_add_subtree(ti, ett_bgp_attr_flags);
1819 /* add flag bitfield subtrees */
1820 proto_tree_add_text(subtree3, tvb,
1821 o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
1822 "%s", decode_boolean_bitfield(bgpa.bgpa_flags,
1823 BGP_ATTR_FLAG_OPTIONAL, 8, "Optional", "Well-known"));
1824 proto_tree_add_text(subtree3, tvb,
1825 o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
1826 "%s", decode_boolean_bitfield(bgpa.bgpa_flags,
1827 BGP_ATTR_FLAG_TRANSITIVE, 8, "Transitive",
1829 proto_tree_add_text(subtree3, tvb,
1830 o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
1831 "%s", decode_boolean_bitfield(bgpa.bgpa_flags,
1832 BGP_ATTR_FLAG_PARTIAL, 8, "Partial", "Complete"));
1833 proto_tree_add_text(subtree3, tvb,
1834 o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
1835 "%s", decode_boolean_bitfield(bgpa.bgpa_flags,
1836 BGP_ATTR_FLAG_EXTENDED_LENGTH, 8, "Extended length",
1839 proto_tree_add_text(subtree2, tvb,
1840 o + i + offsetof(struct bgp_attr, bgpa_type), 1,
1841 "Type code: %s (%u)",
1842 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1845 proto_tree_add_text(subtree2, tvb, o + i + sizeof(bgpa),
1846 aoff - sizeof(bgpa), "Length: %d %s", tlen,
1847 (tlen == 1) ? "byte" : "bytes");
1849 /* the second switch prints things in the actual subtree of each
1851 switch (bgpa.bgpa_type) {
1852 case BGPTYPE_ORIGIN:
1854 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
1855 "Origin (invalid): %u %s", tlen,
1856 (tlen == 1) ? "byte" : "bytes");
1858 proto_tree_add_item(subtree2, hf_bgp_origin, tvb,
1859 o + i + aoff, 1, FALSE);
1862 case BGPTYPE_AS_PATH:
1863 case BGPTYPE_NEW_AS_PATH:
1864 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
1865 "AS path: %s", as_path_gstr->str);
1866 as_paths_tree = proto_item_add_subtree(ti, ett_bgp_as_paths);
1869 (o + current attribute + aoff bytes to first tuple) */
1873 /* snarf each AS path tuple, we have to step through each one
1874 again to make a separate subtree so we can't just reuse
1875 as_path_gstr from above */
1876 /* XXX - Can we use some g_string*() trickery instead, e.g.
1877 g_string_erase()? */
1879 g_string_truncate(as_path_gstr, 0);
1880 type = tvb_get_guint8(tvb, q++);
1881 if (type == AS_SET) {
1882 g_string_append_c(as_path_gstr, '{');
1884 else if (type == AS_CONFED_SET) {
1885 g_string_append_c(as_path_gstr, '[');
1887 else if (type == AS_CONFED_SEQUENCE) {
1888 g_string_append_c(as_path_gstr, '(');
1890 length = tvb_get_guint8(tvb, q++);
1892 /* snarf each value in path */
1893 for (j = 0; j < length; j++) {
1894 g_string_sprintfa(as_path_gstr, "%u%s",
1896 tvb_get_ntohs(tvb, q) : tvb_get_ntohl(tvb, q),
1897 (type == AS_SET || type == AS_CONFED_SET) ? ", " : " ");
1901 /* cleanup end of string */
1902 if (type == AS_SET) {
1903 g_string_truncate(as_path_gstr, as_path_gstr->len - 2);
1904 g_string_append_c(as_path_gstr, '}');
1906 else if (type == AS_CONFED_SET) {
1907 g_string_truncate(as_path_gstr, as_path_gstr->len - 2);
1908 g_string_append_c(as_path_gstr, ']');
1910 else if (type == AS_CONFED_SEQUENCE) {
1911 g_string_truncate(as_path_gstr, as_path_gstr->len - 1);
1912 g_string_append_c(as_path_gstr, ')');
1915 g_string_truncate(as_path_gstr, as_path_gstr->len - 1);
1918 /* length here means number of ASs, ie length * 2 bytes */
1919 ti = proto_tree_add_text(as_paths_tree, tvb,
1920 q - length * asn_len - 2,
1921 length * asn_len + 2, "AS path segment: %s", as_path_gstr->str);
1922 as_path_tree = proto_item_add_subtree(ti, ett_bgp_as_paths);
1923 proto_tree_add_text(as_path_tree, tvb, q - length * asn_len - 2,
1924 1, "Path segment type: %s (%u)",
1925 val_to_str(type, as_segment_type, "Unknown"), type);
1926 proto_tree_add_text(as_path_tree, tvb, q - length * asn_len - 1,
1927 1, "Path segment length: %u %s", length,
1928 (length == 1) ? "AS" : "ASs");
1930 /* backup and reprint path segment value(s) only */
1931 q -= asn_len * length;
1932 ti = proto_tree_add_text(as_path_tree, tvb, q,
1933 length * asn_len, "Path segment value:");
1934 as_path_segment_tree = proto_item_add_subtree(ti,
1935 ett_bgp_as_path_segments);
1936 for (j = 0; j < length; j++) {
1937 as_path_item = (asn_len == 2) ?
1938 tvb_get_ntohs(tvb, q) : tvb_get_ntohl(tvb, q);
1939 proto_item_append_text(ti, " %u", as_path_item);
1940 proto_tree_add_uint_hidden(as_path_tree, hf_bgp_as_path, tvb,
1941 q, asn_len, as_path_item);
1947 case BGPTYPE_NEXT_HOP:
1949 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
1950 "Next hop (invalid): %u %s", tlen,
1951 (tlen == 1) ? "byte" : "bytes");
1953 proto_tree_add_item(subtree2, hf_bgp_next_hop, tvb,
1954 o + i + aoff, tlen, FALSE);
1957 case BGPTYPE_MULTI_EXIT_DISC:
1959 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
1960 "Multiple exit discriminator (invalid): %u %s",
1961 tlen, (tlen == 1) ? "byte" : "bytes");
1963 proto_tree_add_item(subtree2, hf_bgp_multi_exit_disc, tvb,
1964 o + i + aoff, tlen, FALSE);
1967 case BGPTYPE_LOCAL_PREF:
1969 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
1970 "Local preference (invalid): %u %s", tlen,
1971 (tlen == 1) ? "byte" : "bytes");
1973 proto_tree_add_item(subtree2, hf_bgp_local_pref, tvb,
1974 o + i + aoff, tlen, FALSE);
1977 case BGPTYPE_ATOMIC_AGGREGATE:
1979 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
1980 "Atomic aggregate (invalid): %u %s", tlen,
1981 (tlen == 1) ? "byte" : "bytes");
1984 case BGPTYPE_AGGREGATOR:
1985 if (tlen != 6 && tlen != 8) {
1986 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
1987 "Aggregator (invalid): %u %s", tlen,
1988 (tlen == 1) ? "byte" : "bytes");
1991 case BGPTYPE_NEW_AGGREGATOR:
1992 if (bgpa.bgpa_type == BGPTYPE_NEW_AGGREGATOR && tlen != 8)
1993 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
1994 "Aggregator (invalid): %u %s", tlen,
1995 (tlen == 1) ? "byte" : "bytes");
1998 aggregator_as = (asn_len == 2) ?
1999 tvb_get_ntohs(tvb, o + i + aoff) :
2000 tvb_get_ntohl(tvb, o + i + aoff);
2001 proto_tree_add_uint(subtree2, hf_bgp_aggregator_as, tvb,
2002 o + i + aoff, asn_len, aggregator_as);
2003 proto_tree_add_item(subtree2, hf_bgp_aggregator_origin, tvb,
2004 o + i + aoff + asn_len, 4, FALSE);
2007 case BGPTYPE_COMMUNITIES:
2008 if (tlen % 4 != 0) {
2009 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2010 "Communities (invalid): %u %s", tlen,
2011 (tlen == 1) ? "byte" : "bytes");
2015 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2016 "Communities: %s", communities_gstr->str);
2017 communities_tree = proto_item_add_subtree(ti,
2018 ett_bgp_communities);
2021 (o + current attribute + aoff bytes to first tuple) */
2025 /* snarf each community */
2027 /* check for reserved values */
2028 guint32 community = tvb_get_ntohl(tvb, q);
2029 if ((community & 0xFFFF0000) == FOURHEX0 ||
2030 (community & 0xFFFF0000) == FOURHEXF) {
2031 proto_tree_add_text(communities_tree, tvb,
2033 "Community: %s (0x%08x)",
2034 val_to_str(community, community_vals, "(reserved)"),
2038 ti = proto_tree_add_text(communities_tree, tvb,
2039 q - 3 + aoff, 4, "Community: %u:%u",
2040 tvb_get_ntohs(tvb, q), tvb_get_ntohs(tvb, q + 2));
2041 community_tree = proto_item_add_subtree(ti,
2042 ett_bgp_communities);
2043 proto_tree_add_item(community_tree, hf_bgp_community_as,
2044 tvb, q - 3 + aoff, 2, FALSE);
2045 proto_tree_add_item(community_tree, hf_bgp_community_value,
2046 tvb, q - 1 + aoff, 2, FALSE);
2053 case BGPTYPE_ORIGINATOR_ID:
2055 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2056 "Originator identifier (invalid): %u %s", tlen,
2057 (tlen == 1) ? "byte" : "bytes");
2059 proto_tree_add_item(subtree2, hf_bgp_originator_id, tvb,
2060 o + i + aoff, tlen, FALSE);
2063 case BGPTYPE_MP_REACH_NLRI:
2065 * RFC 2545 specifies that there may be more than one
2066 * address in the MP_REACH_NLRI attribute in section
2067 * 3, "Constructing the Next Hop field".
2069 * Yes, RFC 2858 says you can't do that, and, yes, RFC
2070 * 2858 obsoletes RFC 2283, which says you can do that,
2071 * but that doesn't mean we shouldn't dissect packets
2072 * that conform to RFC 2283 but not RFC 2858, as some
2073 * device on the network might implement the 2283-style
2074 * BGP extensions rather than RFC 2858-style extensions.
2076 af = tvb_get_ntohs(tvb, o + i + aoff);
2077 proto_tree_add_text(subtree2, tvb, o + i + aoff, 2,
2078 "Address family: %s (%u)",
2079 val_to_str(af, afn_vals, "Unknown"), af);
2080 saf = tvb_get_guint8(tvb, o + i + aoff + 2) ;
2081 proto_tree_add_text(subtree2, tvb, o + i + aoff + 2, 1,
2082 "Subsequent address family identifier: %s (%u)",
2083 val_to_str(saf, bgpattr_nlri_safi, saf >= 128 ? "Vendor specific" : "Unknown"),
2085 nexthop_len = tvb_get_guint8(tvb, o + i + aoff + 3);
2086 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff + 3,
2088 "Next hop network address (%d %s)",
2089 nexthop_len, plurality(nexthop_len, "byte", "bytes"));
2090 subtree3 = proto_item_add_subtree(ti, ett_bgp_mp_nhna);
2093 * The addresses don't contain lengths, so if we
2094 * don't understand the address family type, we
2095 * cannot parse the subsequent addresses as we
2096 * don't know how long they are.
2100 proto_tree_add_text(subtree3, tvb, o + i + aoff + 4,
2101 nexthop_len, "Unknown Address Family");
2107 case AFNUM_L2VPN_OLD:
2110 while (j < nexthop_len) {
2111 advance = mp_addr_to_str(af, saf, tvb, o + i + aoff + 4 + j,
2112 junk_gbuf, MAX_STR_LEN) ;
2113 if (advance == 0) /* catch if this is a unknown AFI type*/
2115 if (j + advance > nexthop_len)
2117 proto_tree_add_text(subtree3, tvb,o + i + aoff + 4 + j,
2118 advance, "Next hop: %s (%u)", junk_gbuf, advance);
2124 tlen -= nexthop_len + 4;
2125 aoff += nexthop_len + 4 ;
2128 snpa = tvb_get_guint8(tvb, o + i + aoff);
2129 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, 1,
2130 "Subnetwork points of attachment: %u", snpa);
2133 subtree3 = proto_item_add_subtree(ti, ett_bgp_mp_snpa);
2134 for (/*nothing*/; snpa > 0; snpa--) {
2135 proto_tree_add_text(subtree3, tvb, o + i + aoff + off, 1,
2136 "SNPA length: %u", tvb_get_guint8(tvb, o + i + aoff + off));
2138 proto_tree_add_text(subtree3, tvb, o + i + aoff + off,
2139 tvb_get_guint8(tvb, o + i + aoff + off - 1),
2140 "SNPA (%u %s)", tvb_get_guint8(tvb, o + i + aoff + off - 1),
2141 (tvb_get_guint8(tvb, o + i + aoff + off - 1) == 1) ? "byte" : "bytes");
2142 off += tvb_get_guint8(tvb, o + i + aoff + off - 1);
2148 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2149 "Network layer reachability information (%u %s)",
2150 tlen, (tlen == 1) ? "byte" : "bytes");
2152 subtree3 = proto_item_add_subtree(ti,ett_bgp_mp_reach_nlri);
2153 if (af != AFNUM_INET && af != AFNUM_INET6 && af != AFNUM_L2VPN) {
2154 proto_tree_add_text(subtree3, tvb, o + i + aoff,
2155 tlen, "Unknown Address Family");
2158 advance = decode_prefix_MP(subtree3,
2159 hf_bgp_mp_reach_nlri_ipv4_prefix,
2162 tvb, o + i + aoff, "MP Reach NLRI");
2171 case BGPTYPE_MP_UNREACH_NLRI:
2172 af = tvb_get_ntohs(tvb, o + i + aoff);
2173 proto_tree_add_text(subtree2, tvb, o + i + aoff, 2,
2174 "Address family: %s (%u)",
2175 val_to_str(af, afn_vals, "Unknown"), af);
2176 saf = tvb_get_guint8(tvb, o + i + aoff + 2) ;
2177 proto_tree_add_text(subtree2, tvb, o + i + aoff + 2, 1,
2178 "Subsequent address family identifier: %s (%u)",
2179 val_to_str(saf, bgpattr_nlri_safi, saf >= 128 ? "Vendor specific" : "Unknown"),
2181 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff + 3,
2182 tlen - 3, "Withdrawn routes (%u %s)", tlen - 3,
2183 (tlen - 3 == 1) ? "byte" : "bytes");
2188 subtree3 = proto_item_add_subtree(ti,ett_bgp_mp_unreach_nlri);
2191 advance = decode_prefix_MP(subtree3,
2192 hf_bgp_mp_unreach_nlri_ipv4_prefix,
2195 tvb, o + i + aoff, "MP Unreach NLRI");
2203 case BGPTYPE_CLUSTER_LIST:
2204 if (tlen % 4 != 0) {
2205 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2206 "Cluster list (invalid): %u %s", tlen,
2207 (tlen == 1) ? "byte" : "bytes");
2211 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2212 "Cluster list: %s", cluster_list_gstr->str);
2213 cluster_list_tree = proto_item_add_subtree(ti,
2214 ett_bgp_cluster_list);
2217 (o + current attribute + aoff bytes to first tuple) */
2221 /* snarf each cluster identifier */
2223 proto_tree_add_item(cluster_list_tree, hf_bgp_cluster_list,
2224 tvb, q - 3 + aoff, 4, FALSE);
2229 case BGPTYPE_EXTENDED_COMMUNITY:
2231 proto_tree_add_text(subtree3, tvb, o + i + aoff, tlen, "Extended community (invalid) : %u %s", tlen,
2232 (tlen == 1) ? "byte" : "bytes") ;
2235 end = o + i + aoff + tlen ;
2236 ti = proto_tree_add_text(subtree2,tvb,q,tlen, "Carried Extended communities");
2237 subtree3 = proto_item_add_subtree(ti,ett_bgp_extended_communities) ;
2240 ext_com = tvb_get_ntohs(tvb,q) ;
2242 junk_gbuf_ptr=junk_gbuf;
2243 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), "%s",
2244 val_to_str(ext_com,bgpext_com_type,"Unknown"));
2246 case BGP_EXT_COM_RT_0:
2247 case BGP_EXT_COM_RT_2:
2248 case BGP_EXT_COM_RO_0:
2249 case BGP_EXT_COM_RO_2:
2250 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), ": %u%s%d",
2251 tvb_get_ntohs(tvb,q+2),":",tvb_get_ntohl(tvb,q+4));
2252 proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_gbuf);
2254 case BGP_EXT_COM_RT_1:
2255 case BGP_EXT_COM_RO_1:
2256 ipaddr = tvb_get_ipv4(tvb,q+2);
2257 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), ": %s%s%u",
2258 ip_to_str((guint8 *)&ipaddr),":",tvb_get_ntohs(tvb,q+6));
2259 proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_gbuf);
2261 case BGP_EXT_COM_VPN_ORIGIN:
2262 case BGP_EXT_COM_OSPF_RID:
2263 ipaddr = tvb_get_ipv4(tvb,q+2);
2264 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), ": %s", ip_to_str((guint8 *)&ipaddr));
2265 proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_gbuf);
2267 case BGP_EXT_COM_OSPF_RTYPE:
2268 ipaddr = tvb_get_ipv4(tvb,q+2);
2269 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), ": Area: %s, Type: %s", ip_to_str((guint8 *)&ipaddr),
2270 val_to_str(tvb_get_guint8(tvb,q+6),bgpext_ospf_rtype,"Unknown"));
2271 /* print OSPF Metric type if selected */
2272 /* always print E2 even if not external route -- receiving router should ignore */
2273 if ( (tvb_get_guint8(tvb,q+7)) & BGP_OSPF_RTYPE_METRIC_TYPE ) {
2274 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), " E2");
2275 } else if ((tvb_get_guint8(tvb,q+6)==BGP_OSPF_RTYPE_EXT) || (tvb_get_guint8(tvb,q+6)==BGP_OSPF_RTYPE_NSSA)) {
2276 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), " E1");
2278 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), ", no options");
2280 proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_gbuf);
2282 case BGP_EXT_COM_LINKBAND:
2283 linkband = tvb_get_ntohieee_float(tvb,q+2);
2284 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf), ": %.3f Mbps",
2285 linkband*8/1000000);
2286 proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_gbuf);
2288 case BGP_EXT_COM_L2INFO:
2289 junk_gbuf_ptr += g_snprintf(junk_gbuf_ptr, MAX_STR_LEN-(junk_gbuf_ptr-junk_gbuf),
2290 ": %s, Control Flags: %s%s%s%s%s, MTU: %u %s",
2291 val_to_str(tvb_get_guint8(tvb,q+2),bgp_l2vpn_encaps,"Unknown"),
2292 tvb_get_guint8(tvb,q+3) ? "" : "none",
2293 tvb_get_ntohs(tvb,q+3)&0x08 ? "Q" : "",
2294 tvb_get_ntohs(tvb,q+3)&0x04 ? "F" : "",
2295 tvb_get_ntohs(tvb,q+3)&0x02 ? "C" : "",
2296 tvb_get_ntohs(tvb,q+3)&0x01 ? "S" : "",
2297 tvb_get_ntohs(tvb,q+4),
2298 tvb_get_ntohs(tvb,q+4)==1 ? "byte" : "bytes");
2299 ti = proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_gbuf);
2301 subtree4 = proto_item_add_subtree(ti,ett_bgp_extended_communities) ;
2302 proto_tree_add_text(subtree4,tvb,q+2,1, "Encapsulation: %s",
2303 val_to_str(tvb_get_guint8(tvb,q+2),bgp_l2vpn_encaps,"Unknown"));
2304 proto_tree_add_text(subtree4,tvb,q+3,1, "Control Flags: %s%sControl Word %s required, Sequenced delivery %s required",
2305 tvb_get_ntohs(tvb,q+3)&0x08 ? "Q flag (Reserved) set" : "",
2306 tvb_get_ntohs(tvb,q+3)&0x04 ? "F flag (reserved) set" : "",
2307 tvb_get_ntohs(tvb,q+3)&0x02 ? "is" : "not",
2308 tvb_get_ntohs(tvb,q+3)&0x01 ? "is" : "not");
2309 proto_tree_add_text(subtree4,tvb,q+4,2, "MTU: %u %s",
2310 tvb_get_ntohs(tvb,q+4),
2311 tvb_get_ntohs(tvb,q+4)==1 ? "byte" : "bytes");
2314 proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_gbuf);
2321 case BGPTYPE_SAFI_SPECIFIC_ATTR:
2323 end = o + i + aoff + tlen ;
2326 ssa_type = tvb_get_ntohs(tvb, q) & BGP_SSA_TYPE;
2327 ssa_len = tvb_get_ntohs(tvb, q + 2);
2329 ti = proto_tree_add_text(subtree2, tvb, q, MIN(ssa_len + 4, end - q),
2331 val_to_str(ssa_type, bgp_ssa_type, "Unknown SSA"));
2332 subtree3 = proto_item_add_subtree(ti, ett_bgp_ssa);
2334 proto_tree_add_item(subtree3, hf_bgp_ssa_t, tvb,
2336 proto_tree_add_item_hidden(subtree3, hf_bgp_ssa_type, tvb,
2338 proto_tree_add_text(subtree3, tvb, q, 2,
2339 "Type: %s", val_to_str(ssa_type, bgp_ssa_type, "Unknown"));
2340 if ((ssa_len == 0) || (q + ssa_len > end)) {
2341 proto_tree_add_text(subtree3, tvb, q + 2, end - q - 2,
2342 "Invalid Length of %u", ssa_len);
2345 proto_tree_add_item(subtree3, hf_bgp_ssa_len, tvb,
2349 case BGP_SSA_L2TPv3:
2350 proto_tree_add_item(subtree3, hf_bgp_ssa_l2tpv3_pref, tvb,
2353 ti = proto_tree_add_text(subtree3, tvb, q + 6, 1, "Flags");
2354 subtree4 = proto_item_add_subtree(ti, ett_bgp_ssa_subtree) ;
2355 proto_tree_add_item(subtree4, hf_bgp_ssa_l2tpv3_s, tvb,
2357 proto_tree_add_item(subtree4, hf_bgp_ssa_l2tpv3_unused, tvb,
2360 ssa_v3_len = tvb_get_guint8(tvb, q + 7);
2361 if (ssa_v3_len + 8 == ssa_len){
2362 proto_tree_add_item(subtree3, hf_bgp_ssa_l2tpv3_cookie_len, tvb,
2365 proto_tree_add_text(subtree3, tvb, q + 7, 1,
2366 "Invalid Cookie Length of %u", ssa_v3_len);
2369 proto_tree_add_item(subtree3, hf_bgp_ssa_l2tpv3_session_id, tvb,
2372 proto_tree_add_item(subtree3, hf_bgp_ssa_l2tpv3_cookie, tvb,
2373 q + 12, ssa_v3_len, FALSE);
2379 proto_tree_add_item(subtree3, hf_bgp_ssa_value, tvb,
2380 q + 4, ssa_len, FALSE);
2383 q = q + ssa_len + 4; /* 4 from type and length */
2388 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2389 "Unknown (%d %s)", tlen, (tlen == 1) ? "byte" :
2392 } /* end of second switch */
2402 /* parse prefixes */
2404 ti = proto_tree_add_text(tree, tvb, o, len,
2405 "Network layer reachability information: %u %s", len,
2406 (len == 1) ? "byte" : "bytes");
2407 subtree = proto_item_add_subtree(ti, ett_bgp_nlri);
2410 i = decode_prefix4(subtree, hf_bgp_nlri_prefix, tvb, o, 0,
2421 * Dissect a BGP NOTIFICATION message.
2424 dissect_bgp_notification(tvbuff_t *tvb, proto_tree *tree)
2426 struct bgp_notification bgpn; /* BGP NOTIFICATION message */
2427 int hlen; /* message length */
2428 const char *p; /* string pointer */
2431 tvb_memcpy(tvb, bgpn.bgpn_marker, 0, BGP_MIN_NOTIFICATION_MSG_SIZE);
2432 hlen = g_ntohs(bgpn.bgpn_len);
2434 /* print error code */
2435 proto_tree_add_text(tree, tvb,
2436 offsetof(struct bgp_notification, bgpn_major), 1,
2437 "Error code: %s (%u)",
2438 val_to_str(bgpn.bgpn_major, bgpnotify_major, "Unknown"),
2441 /* print error subcode */
2442 if (bgpn.bgpn_major < array_length(bgpnotify_minor)
2443 && bgpnotify_minor[bgpn.bgpn_major] != NULL) {
2444 p = val_to_str(bgpn.bgpn_minor, bgpnotify_minor[bgpn.bgpn_major],
2446 } else if (bgpn.bgpn_minor == 0)
2450 proto_tree_add_text(tree, tvb,
2451 offsetof(struct bgp_notification, bgpn_minor), 1,
2452 "Error subcode: %s (%u)", p, bgpn.bgpn_minor);
2454 /* only print if there is optional data */
2455 if (hlen > BGP_MIN_NOTIFICATION_MSG_SIZE) {
2456 proto_tree_add_text(tree, tvb, BGP_MIN_NOTIFICATION_MSG_SIZE,
2457 hlen - BGP_MIN_NOTIFICATION_MSG_SIZE, "Data");
2462 * Dissect a BGP ROUTE-REFRESH message.
2465 dissect_bgp_route_refresh(tvbuff_t *tvb, proto_tree *tree)
2467 guint16 i; /* tmp */
2468 int p; /* tvb offset counter */
2469 int pend; /* end of list of entries for one orf type */
2470 guint16 hlen; /* tvb RR msg length */
2471 proto_item *ti; /* tree item */
2472 proto_item *ti1; /* tree item */
2473 proto_tree *subtree; /* tree for orf */
2474 proto_tree *subtree1; /* tree for orf entry */
2475 guint8 orftype; /* ORF Type */
2476 guint8 orfwhen; /* ORF flag: immediate, defer */
2477 guint16 orflen; /* ORF len */
2478 guint8 entryflag; /* ORF Entry flag: action(add,del,delall) match(permit,deny) */
2479 guint32 entryseq; /* ORF Entry sequence number */
2480 int entrylen; /* ORF Entry length */
2481 guint8 pfx_ge; /* ORF PrefixList mask lower bound */
2482 guint8 pfx_le; /* ORF PrefixList mask upper bound */
2483 int advance; /* tmp */
2489 00 01 00 01 afi,safi= ipv4-unicast
2490 02 80 00 01 defer, prefix-orf, len=1
2494 00 01 00 01 afi,saif= ipv4-unicast
2495 01 80 00 0a immediate, prefix-orf, len=10
2497 00 00 00 05 seqno = 5
2500 10 07 02 prefix = 7.2.0.0/16
2502 hlen = tvb_get_ntohs(tvb, BGP_MARKER_SIZE);
2503 p = BGP_HEADER_SIZE;
2505 i = tvb_get_ntohs(tvb, p);
2506 proto_tree_add_text(tree, tvb, p, 2,
2507 "Address family identifier: %s (%u)",
2508 val_to_str(i, afn_vals, "Unknown"), i);
2511 proto_tree_add_text(tree, tvb, p, 1,
2512 "Reserved: 1 byte");
2515 i = tvb_get_guint8(tvb, p);
2516 proto_tree_add_text(tree, tvb, p, 1,
2517 "Subsequent address family identifier: %s (%u)",
2518 val_to_str(i, bgpattr_nlri_safi,
2519 i >= 128 ? "Vendor specific" : "Unknown"),
2522 if ( hlen == BGP_HEADER_SIZE + 4 )
2526 orfwhen = tvb_get_guint8(tvb, p);
2527 orftype = tvb_get_guint8(tvb, p+1);
2528 orflen = tvb_get_ntohs(tvb, p+2);
2529 ti = proto_tree_add_text(tree, tvb, p , orflen + 4 , "ORF information (%u bytes)", orflen + 4);
2530 subtree = proto_item_add_subtree(ti, ett_bgp_orf);
2531 proto_tree_add_text(subtree, tvb, p , 1, "ORF flag: %s", val_to_str(orfwhen, orf_when_vals,"UNKNOWN"));
2532 proto_tree_add_text(subtree, tvb, p+1 , 1, "ORF type: %s", val_to_str(orftype, orf_type_vals,"UNKNOWN"));
2533 proto_tree_add_text(subtree, tvb, p+2 , 2, "ORF len: %u %s", orflen, (orflen == 1) ? "byte" : "bytes");
2536 if (orftype != BGP_ORF_PREFIX_CISCO) {
2537 proto_tree_add_text(subtree, tvb, p, orflen,
2538 "ORFEntry-Unknown (%u bytes)", orflen);
2544 entryflag = tvb_get_guint8(tvb, p);
2545 if ((entryflag & BGP_ORF_ACTION) == BGP_ORF_REMOVEALL) {
2546 ti1 = proto_tree_add_text(subtree, tvb, p, 1,
2547 "ORFEntry-PrefixList (1 byte)");
2548 subtree1 = proto_item_add_subtree(ti1, ett_bgp_orf_entry);
2549 proto_tree_add_text(subtree1, tvb, p , 1, "RemoveAll");
2552 ti1 = proto_tree_add_text(subtree, tvb, p, -1,
2553 "ORFEntry-PrefixList");
2554 subtree1 = proto_item_add_subtree(ti1, ett_bgp_orf_entry);
2555 proto_tree_add_text(subtree1, tvb, p, 1,
2556 "ACTION: %s MATCH: %s",
2557 val_to_str(entryflag&BGP_ORF_ACTION,
2558 orf_entry_action_vals, "UNKNOWN"),
2559 val_to_str(entryflag&BGP_ORF_MATCH,
2560 orf_entry_match_vals, "UNKNOWN"));
2562 entryseq = tvb_get_ntohl(tvb, p);
2563 proto_tree_add_text(subtree1, tvb, p, 4,
2564 "Entry Sequence No: %u", entryseq);
2566 pfx_ge = tvb_get_guint8(tvb, p);
2567 proto_tree_add_text(subtree1, tvb, p, 1,
2568 "PrefixMask length lower bound: %u", pfx_ge);
2570 pfx_le = tvb_get_guint8(tvb, p);
2571 proto_tree_add_text(subtree1, tvb, p, 1,
2572 "PrefixMask length upper bound: %u", pfx_le);
2575 advance = decode_prefix4(subtree1, -1, tvb, p, 0, "ORF");
2578 entrylen = 7 + 1 + advance;
2580 proto_item_append_text(ti1, " (%u bytes)", entrylen);
2581 proto_item_set_len(ti1, entrylen);
2589 * Dissect a BGP CAPABILITY message.
2592 dissect_bgp_capability(tvbuff_t *tvb, proto_tree *tree)
2596 proto_tree *subtree;
2602 mend = offset + tvb_get_ntohs(tvb, offset + BGP_MARKER_SIZE);
2603 offset += BGP_HEADER_SIZE;
2604 /* step through all of the capabilities */
2605 while (offset < mend) {
2606 action = tvb_get_guint8(tvb, offset++);
2607 ctype = tvb_get_guint8(tvb, offset++);
2608 clen = tvb_get_guint8(tvb, offset++);
2610 ti = proto_tree_add_text(tree, tvb, offset - 2, 2 + clen,
2611 "%s (%u %s)", val_to_str(ctype, capability_vals,
2612 "Unknown capability"), 2 + clen, (clen == 1) ? "byte" : "bytes");
2613 subtree = proto_item_add_subtree(ti, ett_bgp_option);
2614 proto_tree_add_text(subtree, tvb, offset-2, 1, "Action: %d (%s)",
2615 action, val_to_str(action, bgpcap_action, "Invalid action value"));
2616 dissect_bgp_capability_item(tvb, &offset, subtree, ctype, clen);
2621 dissect_bgp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
2624 guint16 bgp_len; /* Message length */
2625 guint8 bgp_type; /* Message type */
2626 const char *typ; /* Message type (string) */
2627 proto_item *ti; /* tree item */
2628 proto_tree *bgp_tree; /* BGP packet tree */
2629 proto_tree *bgp1_tree; /* BGP message tree */
2631 bgp_len = tvb_get_ntohs(tvb, BGP_MARKER_SIZE);
2632 bgp_type = tvb_get_guint8(tvb, BGP_MARKER_SIZE + 2);
2633 typ = val_to_str(bgp_type, bgptypevals, "Unknown message type (0x%02x)");
2635 if (check_col(pinfo->cinfo, COL_INFO)) {
2637 col_add_fstr(pinfo->cinfo, COL_INFO, "%s", typ);
2639 col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", typ);
2643 ti = proto_tree_add_item(tree, proto_bgp, tvb, 0, -1, FALSE);
2644 bgp_tree = proto_item_add_subtree(ti, ett_bgp);
2646 ti = proto_tree_add_text(bgp_tree, tvb, 0, -1, "%s", typ);
2648 /* add a different tree for each message type */
2651 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_open);
2654 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_update);
2656 case BGP_NOTIFICATION:
2657 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_notification);
2660 bgp1_tree = proto_item_add_subtree(ti, ett_bgp);
2662 case BGP_ROUTE_REFRESH_CISCO:
2663 case BGP_ROUTE_REFRESH:
2664 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_route_refresh);
2666 case BGP_CAPABILITY:
2667 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_capability);
2670 bgp1_tree = proto_item_add_subtree(ti, ett_bgp);
2674 proto_tree_add_text(bgp1_tree, tvb, 0, BGP_MARKER_SIZE,
2675 "Marker: 16 bytes");
2677 if (bgp_len < BGP_HEADER_SIZE || bgp_len > BGP_MAX_PACKET_SIZE) {
2678 proto_tree_add_text(bgp1_tree, tvb, BGP_MARKER_SIZE, 2,
2679 "Length (invalid): %u %s", bgp_len,
2680 (bgp_len == 1) ? "byte" : "bytes");
2683 proto_tree_add_text(bgp1_tree, tvb, BGP_MARKER_SIZE, 2,
2684 "Length: %u %s", bgp_len,
2685 (bgp_len == 1) ? "byte" : "bytes");
2688 proto_tree_add_uint(bgp1_tree, hf_bgp_type, tvb,
2689 BGP_MARKER_SIZE + 2, 1,
2694 dissect_bgp_open(tvb, bgp1_tree);
2697 dissect_bgp_update(tvb, bgp1_tree);
2699 case BGP_NOTIFICATION:
2700 dissect_bgp_notification(tvb, bgp1_tree);
2703 /* no data in KEEPALIVE messages */
2705 case BGP_ROUTE_REFRESH_CISCO:
2706 case BGP_ROUTE_REFRESH:
2707 dissect_bgp_route_refresh(tvb, bgp1_tree);
2709 case BGP_CAPABILITY:
2710 dissect_bgp_capability(tvb, bgp1_tree);
2719 * Dissect a BGP packet.
2722 dissect_bgp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2724 volatile int offset = 0; /* offset into the tvbuff */
2725 gint reported_length_remaining;
2726 guint8 bgp_marker[BGP_MARKER_SIZE]; /* Marker (should be all ones */
2727 static guchar marker[] = { /* BGP message marker */
2728 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2729 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2731 proto_item *ti; /* tree item */
2732 proto_tree *bgp_tree; /* BGP packet tree */
2733 guint16 bgp_len; /* Message length */
2735 guint length_remaining;
2737 volatile gboolean first = TRUE; /* TRUE for the first BGP message in packet */
2740 if (check_col(pinfo->cinfo, COL_PROTOCOL))
2741 col_set_str(pinfo->cinfo, COL_PROTOCOL, "BGP");
2742 if (check_col(pinfo->cinfo, COL_INFO))
2743 col_clear(pinfo->cinfo, COL_INFO);
2746 * Scan through the TCP payload looking for a BGP marker.
2748 while ((reported_length_remaining = tvb_reported_length_remaining(tvb, offset))
2751 * "reported_length_remaining" is the number of bytes of TCP payload
2752 * remaining. If it's more than the length of a BGP marker,
2753 * we check only the number of bytes in a BGP marker.
2755 if (reported_length_remaining > BGP_MARKER_SIZE)
2756 reported_length_remaining = BGP_MARKER_SIZE;
2759 * OK, is there a BGP marker starting at the specified offset -
2760 * or, at least, the beginning of a BGP marker running to the end
2761 * of the TCP payload?
2763 * This will throw an exception if the frame is short; that's what
2766 tvb_memcpy(tvb, bgp_marker, offset, reported_length_remaining);
2767 if (memcmp(bgp_marker, marker, reported_length_remaining) == 0) {
2769 * Yes - stop scanning and start processing BGP packets.
2775 * No - keep scanning through the tvbuff to try to find a marker.
2781 * If we skipped any bytes, mark it as a BGP continuation.
2784 ti = proto_tree_add_item(tree, proto_bgp, tvb, 0, -1, FALSE);
2785 bgp_tree = proto_item_add_subtree(ti, ett_bgp);
2787 proto_tree_add_text(bgp_tree, tvb, 0, offset, "Continuation");
2791 * Now process the BGP packets in the TCP payload.
2793 * XXX - perhaps "tcp_dissect_pdus()" should take a starting
2794 * offset, in which case we can replace the loop below with
2795 * a call to "tcp_dissect_pdus()".
2797 while (tvb_reported_length_remaining(tvb, offset) > 0) {
2799 * This will throw an exception if we don't have any data left.
2800 * That's what we want. (See "tcp_dissect_pdus()", which is
2803 length_remaining = tvb_ensure_length_remaining(tvb, offset);
2806 * Can we do reassembly?
2808 if (bgp_desegment && pinfo->can_desegment) {
2810 * Yes - would a BGP header starting at this offset be split
2811 * across segment boundaries?
2813 if (length_remaining < BGP_HEADER_SIZE) {
2815 * Yes. Tell the TCP dissector where the data for this
2816 * message starts in the data it handed us, and how many
2817 * more bytes we need, and return.
2819 pinfo->desegment_offset = offset;
2820 pinfo->desegment_len = BGP_HEADER_SIZE - length_remaining;
2826 * Get the length and type from the BGP header.
2828 bgp_len = tvb_get_ntohs(tvb, offset + BGP_MARKER_SIZE);
2829 if (bgp_len < BGP_HEADER_SIZE) {
2831 * The BGP length doesn't include the BGP header; report that
2834 show_reported_bounds_error(tvb, pinfo, tree);
2839 * Can we do reassembly?
2841 if (bgp_desegment && pinfo->can_desegment) {
2843 * Yes - is the PDU split across segment boundaries?
2845 if (length_remaining < bgp_len) {
2847 * Yes. Tell the TCP dissector where the data for this
2848 * message starts in the data it handed us, and how many
2849 * more bytes we need, and return.
2851 pinfo->desegment_offset = offset;
2852 pinfo->desegment_len = bgp_len - length_remaining;
2858 * Construct a tvbuff containing the amount of the payload we have
2859 * available. Make its reported length the amount of data in the PDU.
2861 * XXX - if reassembly isn't enabled. the subdissector will throw a
2862 * BoundsError exception, rather than a ReportedBoundsError exception.
2863 * We really want a tvbuff where the length is "length", the reported
2864 * length is "plen", and the "if the snapshot length were infinite"
2865 * length is the minimum of the reported length of the tvbuff handed
2866 * to us and "plen", with a new type of exception thrown if the offset
2867 * is within the reported length but beyond that third length, with
2868 * that exception getting the "Unreassembled Packet" error.
2870 length = length_remaining;
2871 if (length > bgp_len)
2873 next_tvb = tvb_new_subset(tvb, offset, length, bgp_len);
2878 * Catch the ReportedBoundsError exception; if this particular message
2879 * happens to get a ReportedBoundsError exception, that doesn't mean
2880 * that we should stop dissecting PDUs within this frame or chunk of
2883 * If it gets a BoundsError, we can stop, as there's nothing more to
2884 * see, so we just re-throw it.
2887 dissect_bgp_pdu(next_tvb, pinfo, tree, first);
2889 CATCH(BoundsError) {
2892 CATCH(ReportedBoundsError) {
2893 show_reported_bounds_error(tvb, pinfo, tree);
2900 * Step to the next PDU.
2901 * Make sure we don't overflow.
2903 offset_before = offset;
2905 if (offset <= offset_before)
2911 * Register ourselves.
2914 proto_register_bgp(void)
2917 static hf_register_info hf[] = {
2919 { "Type", "bgp.type", FT_UINT8, BASE_DEC,
2920 VALS(bgptypevals), 0x0, "BGP message type", HFILL }},
2921 { &hf_bgp_aggregator_as,
2922 { "Aggregator AS", "bgp.aggregator_as", FT_UINT16, BASE_DEC,
2923 NULL, 0x0, "", HFILL}},
2924 { &hf_bgp_aggregator_origin,
2925 { "Aggregator origin", "bgp.aggregator_origin", FT_IPv4, BASE_NONE,
2926 NULL, 0x0, "", HFILL}},
2928 { "AS Path", "bgp.as_path", FT_UINT16, BASE_DEC,
2929 NULL, 0x0, "", HFILL}},
2930 { &hf_bgp_cluster_identifier,
2931 { "Cluster identifier", "bgp.cluster_identifier", FT_IPv4, BASE_NONE,
2932 NULL, 0x0, "", HFILL}},
2933 { &hf_bgp_community_as,
2934 { "Community AS", "bgp.community_as", FT_UINT16, BASE_DEC,
2935 NULL, 0x0, "", HFILL}},
2936 { &hf_bgp_community_value,
2937 { "Community value", "bgp.community_value", FT_UINT16, BASE_DEC,
2938 NULL, 0x0, "", HFILL}},
2939 { &hf_bgp_local_pref,
2940 { "Local preference", "bgp.local_pref", FT_UINT32, BASE_DEC,
2941 NULL, 0x0, "", HFILL}},
2942 { &hf_bgp_mp_reach_nlri_ipv4_prefix,
2943 { "MP Reach NLRI IPv4 prefix", "bgp.mp_reach_nlri_ipv4_prefix", FT_IPv4, BASE_NONE,
2944 NULL, 0x0, "", HFILL}},
2945 { &hf_bgp_mp_unreach_nlri_ipv4_prefix,
2946 { "MP Unreach NLRI IPv4 prefix", "bgp.mp_unreach_nlri_ipv4_prefix", FT_IPv4, BASE_NONE,
2947 NULL, 0x0, "", HFILL}},
2948 { &hf_bgp_mp_nlri_tnl_id,
2949 { "MP Reach NLRI Tunnel Identifier", "bgp.mp_nlri_tnl_id", FT_UINT16, BASE_HEX,
2950 NULL, 0x0, "", HFILL}},
2951 { &hf_bgp_multi_exit_disc,
2952 { "Multiple exit discriminator", "bgp.multi_exit_disc", FT_UINT32, BASE_DEC,
2953 NULL, 0x0, "", HFILL}},
2955 { "Next hop", "bgp.next_hop", FT_IPv4, BASE_NONE,
2956 NULL, 0x0, "", HFILL}},
2957 { &hf_bgp_nlri_prefix,
2958 { "NLRI prefix", "bgp.nlri_prefix", FT_IPv4, BASE_NONE,
2959 NULL, 0x0, "", HFILL}},
2961 { "Origin", "bgp.origin", FT_UINT8, BASE_DEC,
2962 VALS(bgpattr_origin), 0x0, "", HFILL}},
2963 { &hf_bgp_originator_id,
2964 { "Originator identifier", "bgp.originator_id", FT_IPv4, BASE_NONE,
2965 NULL, 0x0, "", HFILL}},
2967 { "Transitive bit", "bgp.ssa_t", FT_BOOLEAN, 8,
2968 NULL, 0x80, "SSA Transitive bit", HFILL}},
2970 { "SSA Type", "bgp.ssa_type", FT_UINT16, BASE_DEC,
2971 VALS(bgp_ssa_type), 0x7FFF, "SSA Type", HFILL}},
2973 { "Length", "bgp.ssa_len", FT_UINT16, BASE_DEC,
2974 NULL, 0x0, "SSA Length", HFILL}},
2975 { &hf_bgp_ssa_value,
2976 { "Value", "bgp.ssa_value", FT_BYTES, BASE_HEX,
2977 NULL, 0x0, "SSA Value", HFILL}},
2978 { &hf_bgp_ssa_l2tpv3_pref,
2979 { "Preference", "bgp.ssa_l2tpv3_pref", FT_UINT16, BASE_DEC,
2980 NULL, 0x0, "Preference", HFILL}},
2981 { &hf_bgp_ssa_l2tpv3_s,
2982 { "Sequencing bit", "bgp.ssa_l2tpv3_s", FT_BOOLEAN, 8,
2983 NULL, 0x80, "Sequencing S-bit", HFILL}},
2984 { &hf_bgp_ssa_l2tpv3_unused,
2985 { "Unused", "bgp.ssa_l2tpv3_Unused", FT_BOOLEAN, 8,
2986 NULL, 0x7F, "Unused Flags", HFILL}},
2987 { &hf_bgp_ssa_l2tpv3_cookie_len,
2988 { "Cookie Length", "bgp.ssa_l2tpv3_cookie_len", FT_UINT8, BASE_DEC,
2989 NULL, 0x0, "Cookie Length", HFILL}},
2990 { &hf_bgp_ssa_l2tpv3_session_id,
2991 { "Session ID", "bgp.ssa_l2tpv3_session_id", FT_UINT32, BASE_DEC,
2992 NULL, 0x0, "Session ID", HFILL}},
2993 { &hf_bgp_ssa_l2tpv3_cookie,
2994 { "Cookie", "bgp.ssa_l2tpv3_cookie", FT_BYTES, BASE_HEX,
2995 NULL, 0x0, "Cookie", HFILL}},
2996 { &hf_bgp_withdrawn_prefix,
2997 { "Withdrawn prefix", "bgp.withdrawn_prefix", FT_IPv4, BASE_NONE,
2998 NULL, 0x0, "", HFILL}},
2999 { &hf_bgp_cluster_list,
3000 { "Cluster List", "bgp.cluster_list", FT_BYTES, BASE_HEX,
3001 NULL, 0x0, "", HFILL}},
3004 static gint *ett[] = {
3010 &ett_bgp_attr_flags,
3012 &ett_bgp_mp_reach_nlri,
3013 &ett_bgp_mp_unreach_nlri,
3018 &ett_bgp_notification,
3019 &ett_bgp_route_refresh,
3020 &ett_bgp_capability,
3022 &ett_bgp_as_path_segments,
3023 &ett_bgp_communities,
3024 &ett_bgp_cluster_list,
3027 &ett_bgp_extended_communities,
3029 &ett_bgp_ssa_subtree,
3033 module_t *bgp_module;
3034 static enum_val_t asn_len[] = {
3035 {"auto-detect", "Auto-detect", 0},
3036 {"2", "2 octet", 2},
3037 {"4", "4 octet", 4},
3041 proto_bgp = proto_register_protocol("Border Gateway Protocol",
3043 proto_register_field_array(proto_bgp, hf, array_length(hf));
3044 proto_register_subtree_array(ett, array_length(ett));
3046 bgp_module = prefs_register_protocol(proto_bgp, NULL);
3047 prefs_register_bool_preference(bgp_module, "desegment",
3048 "Reassemble BGP messages spanning multiple TCP segments",
3049 "Whether the BGP dissector should reassemble messages spanning multiple TCP segments."
3050 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
3052 prefs_register_enum_preference(bgp_module, "asn_len",
3053 "Length of the AS number",
3054 "BGP dissector detect the length of the AS number in AS_PATH attributes automatically or manually (NOTE: Automatic detection is not 100% accurate)",
3055 &bgp_asn_len, asn_len, FALSE);
3059 proto_reg_handoff_bgp(void)
3061 dissector_handle_t bgp_handle;
3063 bgp_handle = create_dissector_handle(dissect_bgp, proto_bgp);
3064 dissector_add("tcp.port", BGP_TCP_PORT, bgp_handle);