2 * Routines for BGP packet dissection.
3 * Copyright 1999, Jun-ichiro itojun Hagino <itojun@itojun.org>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * RFC1771 A Border Gateway Protocol 4 (BGP-4)
27 * RFC1965 Autonomous System Confederations for BGP
28 * RFC1997 BGP Communities Attribute
29 * RFC2547 BGP/MPLS VPNs
30 * RFC2796 BGP Route Reflection An alternative to full mesh IBGP
31 * RFC2842 Capabilities Advertisement with BGP-4
32 * RFC2858 Multiprotocol Extensions for BGP-4
33 * RFC2918 Route Refresh Capability for BGP-4
34 * RFC3107 Carrying Label Information in BGP-4
35 * draft-ietf-idr-as4bytes-06
36 * draft-ietf-idr-dynamic-cap-03
37 * draft-ietf-idr-bgp-ext-communities-05
38 * draft-knoll-idr-qos-attribute-03
39 * draft-nalawade-kapoor-tunnel-safi-05
42 * Destination Preference Attribute for BGP (work in progress)
43 * RFC1863 A BGP/IDRP Route Server alternative to a full mesh routing
55 #include <epan/packet.h>
56 #include <epan/addr_and_mask.h>
57 #include "packet-bgp.h"
58 #include "packet-ipv6.h"
59 #include "packet-frame.h"
61 #include <epan/prefs.h>
62 #include <epan/emem.h>
64 /* #define MAX_STR_LEN 256 */
66 static const value_string bgptypevals[] = {
67 { BGP_OPEN, "OPEN Message" },
68 { BGP_UPDATE, "UPDATE Message" },
69 { BGP_NOTIFICATION, "NOTIFICATION Message" },
70 { BGP_KEEPALIVE, "KEEPALIVE Message" },
71 { BGP_ROUTE_REFRESH, "ROUTE-REFRESH Message" },
72 { BGP_CAPABILITY, "CAPABILITY Message" },
73 { BGP_ROUTE_REFRESH_CISCO, "Cisco ROUTE-REFRESH Message" },
77 static const value_string bgpnotify_major[] = {
78 { 1, "Message Header Error" },
79 { 2, "OPEN Message Error" },
80 { 3, "UPDATE Message Error" },
81 { 4, "Hold Timer Expired" },
82 { 5, "Finite State Machine Error" },
84 { 7, "CAPABILITY Message Error" },
88 static const value_string bgpnotify_minor_1[] = {
89 { 1, "Connection Not Synchronized" },
90 { 2, "Bad Message Length" },
91 { 3, "Bad Message Type" },
95 static const value_string bgpnotify_minor_2[] = {
96 { 1, "Unsupported Version Number" },
98 { 3, "Bad BGP Identifier" },
99 { 4, "Unsupported Optional Parameter" },
100 { 5, "Authentication Failure" },
101 { 6, "Unacceptable Hold Time" },
102 { 7, "Unsupported Capability" },
106 static const value_string bgpnotify_minor_3[] = {
107 { 1, "Malformed Attribute List" },
108 { 2, "Unrecognized Well-known Attribute" },
109 { 3, "Missing Well-known Attribute" },
110 { 4, "Attribute Flags Error" },
111 { 5, "Attribute Length Error" },
112 { 6, "Invalid ORIGIN Attribute" },
113 { 7, "AS Routing Loop" },
114 { 8, "Invalid NEXT_HOP Attribute" },
115 { 9, "Optional Attribute Error" },
116 { 10, "Invalid Network Field" },
117 { 11, "Malformed AS_PATH" },
121 /* draft-ietf-idr-cease-subcode-02 */
122 static const value_string bgpnotify_minor_6[] = {
123 { 1, "Maximum Number of Prefixes Reached"},
124 { 2, "Administratively Shutdown"},
125 { 3, "Peer Unconfigured"},
126 { 4, "Administratively Reset"},
127 { 5, "Connection Rejected"},
128 { 6, "Other Configuration Change"},
129 { 7, "Connection Collision Resolution"},
133 static const value_string bgpnotify_minor_7[] = {
134 { 1, "Invalid Action Value" },
135 { 2, "Invalid Capability Length" },
136 { 3, "Malformed Capability Value" },
137 { 4, "Unsupported Capability Code" },
141 static const value_string *bgpnotify_minor[] = {
143 bgpnotify_minor_1, /* open */
144 bgpnotify_minor_2, /* update */
145 bgpnotify_minor_3, /* notification */
146 NULL, /* hold-timer expired */
147 NULL, /* FSM error */
148 bgpnotify_minor_6, /* cease */
149 bgpnotify_minor_7 /* capability */
152 static const value_string bgpattr_origin[] = {
159 static const value_string as_segment_type[] = {
161 { 2, "AS_SEQUENCE" },
162 /* RFC1965 has the wrong values, corrected in */
163 /* draft-ietf-idr-bgp-confed-rfc1965bis-01.txt */
164 { 4, "AS_CONFED_SET" },
165 { 3, "AS_CONFED_SEQUENCE" },
169 static const value_string bgpattr_type[] = {
170 { BGPTYPE_ORIGIN, "ORIGIN" },
171 { BGPTYPE_AS_PATH, "AS_PATH" },
172 { BGPTYPE_NEXT_HOP, "NEXT_HOP" },
173 { BGPTYPE_MULTI_EXIT_DISC, "MULTI_EXIT_DISC" },
174 { BGPTYPE_LOCAL_PREF, "LOCAL_PREF" },
175 { BGPTYPE_ATOMIC_AGGREGATE, "ATOMIC_AGGREGATE" },
176 { BGPTYPE_AGGREGATOR, "AGGREGATOR" },
177 { BGPTYPE_COMMUNITIES, "COMMUNITIES" },
178 { BGPTYPE_ORIGINATOR_ID, "ORIGINATOR_ID" },
179 { BGPTYPE_CLUSTER_LIST, "CLUSTER_LIST" },
180 { BGPTYPE_MP_REACH_NLRI, "MP_REACH_NLRI" },
181 { BGPTYPE_MP_UNREACH_NLRI, "MP_UNREACH_NLRI" },
182 { BGPTYPE_EXTENDED_COMMUNITY, "EXTENDED_COMMUNITIES" },
183 { BGPTYPE_NEW_AS_PATH, "NEW_AS_PATH" },
184 { BGPTYPE_NEW_AGGREGATOR, "NEW_AGGREGATOR" },
185 { BGPTYPE_SAFI_SPECIFIC_ATTR, "SAFI_SPECIFIC_ATTRIBUTE" },
189 static const value_string bgpext_com8_type[] = {
190 { BGP_EXT_COM_QOS_MARK_T, "QoS Marking - transitive" },
191 { BGP_EXT_COM_QOS_MARK_NT, "QoS Marking - non-transitive" },
192 { BGP_EXT_COM_COS_CAP_T, "CoS Capability - transitive" },
196 static const value_string bgpext_com_type[] = {
197 { BGP_EXT_COM_RT_0, "Route Target" },
198 { BGP_EXT_COM_RT_1, "Route Target" },
199 { BGP_EXT_COM_RT_2, "Route Target" },
200 { BGP_EXT_COM_RO_0, "Route Origin" },
201 { BGP_EXT_COM_RO_1, "Route Origin" },
202 { BGP_EXT_COM_RO_2, "Route Origin" },
203 { BGP_EXT_COM_LINKBAND, "Link Bandwidth" },
204 { BGP_EXT_COM_VPN_ORIGIN, "OSPF Domain" },
205 { BGP_EXT_COM_OSPF_RTYPE, "OSPF Route Type" },
206 { BGP_EXT_COM_OSPF_RID, "OSPF Router ID" },
207 { BGP_EXT_COM_L2INFO, "Layer 2 Information" },
211 static const value_string qos_tech_type[] = {
212 { QOS_TECH_TYPE_DSCP, "DiffServ enabled IP (DSCP encoding)" },
213 { QOS_TECH_TYPE_802_1q, "Ethernet using 802.1q priority tag" },
214 { QOS_TECH_TYPE_E_LSP, "MPLS using E-LSP" },
215 { QOS_TECH_TYPE_VC, "Virtual Channel (VC) encoding" },
216 { QOS_TECH_TYPE_GMPLS_TIME, "GMPLS - time slot encoding" },
217 { QOS_TECH_TYPE_GMPLS_LAMBDA, "GMPLS - lambda encoding" },
218 { QOS_TECH_TYPE_GMPLS_FIBRE, "GMPLS - fibre encoding" },
222 static const value_string bgp_ssa_type[] = {
223 { BGP_SSA_L2TPv3 , "L2TPv3 Tunnel" },
224 { BGP_SSA_mGRE , "mGRE Tunnel" },
225 { BGP_SSA_IPSec , "IPSec Tunnel" },
226 { BGP_SSA_MPLS , "MPLS Tunnel" },
227 { BGP_SSA_L2TPv3_IN_IPSec , "L2TPv3 in IPSec Tunnel" },
228 { BGP_SSA_mGRE_IN_IPSec , "mGRE in IPSec Tunnel" },
232 static const value_string bgp_l2vpn_encaps[] = {
235 { 2, "ATM AAL5 VCC transport"},
236 { 3, "ATM transparent cell transport"},
237 { 4, "Ethernet VLAN"},
242 { 9, "ATM VCC cell transport"},
243 { 10, "ATM VPC cell transport"},
246 { 64, "IP-interworking"},
250 static const value_string bgpext_ospf_rtype[] = {
251 { BGP_OSPF_RTYPE_RTR, "Router" },
252 { BGP_OSPF_RTYPE_NET, "Network" },
253 { BGP_OSPF_RTYPE_SUM, "Summary" },
254 { BGP_OSPF_RTYPE_EXT, "External" },
255 { BGP_OSPF_RTYPE_NSSA,"NSSA External" },
256 { BGP_OSPF_RTYPE_SHAM,"MPLS-VPN Sham" },
260 /* Subsequent address family identifier, RFC2858 */
261 static const value_string bgpattr_nlri_safi[] = {
263 { SAFNUM_UNICAST, "Unicast" },
264 { SAFNUM_MULCAST, "Multicast" },
265 { SAFNUM_UNIMULC, "Unicast+Multicast" },
266 { SAFNUM_MPLS_LABEL, "Labeled Unicast"},
267 { SAFNUM_TUNNEL, "Tunnel"},
268 { SAFNUM_VPLS, "VPLS"},
269 { SAFNUM_LAB_VPNUNICAST, "Labeled VPN Unicast" }, /* draft-rosen-rfc2547bis-03 */
270 { SAFNUM_LAB_VPNMULCAST, "Labeled VPN Multicast" },
271 { SAFNUM_LAB_VPNUNIMULC, "Labeled VPN Unicast+Multicast" },
275 /* ORF Type, draft-ietf-idr-route-filter-04.txt */
276 static const value_string orf_type_vals[] = {
277 { 2, "Communities ORF-Type" },
278 { 3, "Extended Communities ORF-Type" },
279 { 128, "Cisco PrefixList ORF-Type" },
280 { 129, "Cisco CommunityList ORF-Type" },
281 { 130, "Cisco Extended CommunityList ORF-Type" },
282 { 131, "Cisco AsPathList ORF-Type" },
286 /* ORF Send/Receive, draft-ietf-idr-route-filter-04.txt */
287 static const value_string orf_send_recv_vals[] = {
294 /* ORF Send/Receive, draft-ietf-idr-route-filter-04.txt */
295 static const value_string orf_when_vals[] = {
301 static const value_string orf_entry_action_vals[] = {
304 { 0x80, "RemoveAll" },
308 static const value_string orf_entry_match_vals[] = {
314 static const value_string capability_vals[] = {
315 { BGP_CAPABILITY_RESERVED, "Reserved capability" },
316 { BGP_CAPABILITY_MULTIPROTOCOL, "Multiprotocol extensions capability" },
317 { BGP_CAPABILITY_ROUTE_REFRESH, "Route refresh capability" },
318 { BGP_CAPABILITY_COOPERATIVE_ROUTE_FILTERING, "Cooperative route filtering capability" },
319 { BGP_CAPABILITY_GRACEFUL_RESTART, "Graceful Restart capability" },
320 { BGP_CAPABILITY_4_OCTET_AS_NUMBER, "Support for 4-octet AS number capability" },
321 { BGP_CAPABILITY_DYNAMIC_CAPABILITY, "Support for Dynamic capability" },
322 { BGP_CAPABILITY_ROUTE_REFRESH_CISCO, "Route refresh capability" },
323 { BGP_CAPABILITY_ORF_CISCO, "Cooperative route filtering capability" },
327 /* Capability Message action code */
328 static const value_string bgpcap_action[] = {
329 { 0, "advertising a capability" },
330 { 1, "removing a capability" },
335 /* Maximal size of an IP address string */
336 #define MAX_SIZE_OF_IP_ADDR_STRING 16
338 static int proto_bgp = -1;
339 static int hf_bgp_type = -1;
340 static int hf_bgp_next_hop = -1;
341 static int hf_bgp_as_path = -1;
342 static int hf_bgp_cluster_identifier = -1;
343 static int hf_bgp_community_as = -1;
344 static int hf_bgp_community_value = -1;
345 static int hf_bgp_origin = -1;
346 static int hf_bgp_cluster_list = -1;
347 static int hf_bgp_originator_id = -1;
348 static int hf_bgp_ssa_t = -1;
349 static int hf_bgp_ssa_type = -1;
350 static int hf_bgp_ssa_len = -1;
351 static int hf_bgp_ssa_value = -1;
352 static int hf_bgp_ssa_l2tpv3_pref = -1;
353 static int hf_bgp_ssa_l2tpv3_s = -1;
354 static int hf_bgp_ssa_l2tpv3_unused = -1;
355 static int hf_bgp_ssa_l2tpv3_cookie_len = -1;
356 static int hf_bgp_ssa_l2tpv3_session_id = -1;
357 static int hf_bgp_ssa_l2tpv3_cookie = -1;
358 static int hf_bgp_local_pref = -1;
359 static int hf_bgp_multi_exit_disc = -1;
360 static int hf_bgp_aggregator_as = -1;
361 static int hf_bgp_aggregator_origin = -1;
362 static int hf_bgp_mp_reach_nlri_ipv4_prefix = -1;
363 static int hf_bgp_mp_unreach_nlri_ipv4_prefix = -1;
364 static int hf_bgp_mp_nlri_tnl_id = -1;
365 static int hf_bgp_withdrawn_prefix = -1;
366 static int hf_bgp_nlri_prefix = -1;
368 static gint ett_bgp = -1;
369 static gint ett_bgp_prefix = -1;
370 static gint ett_bgp_unfeas = -1;
371 static gint ett_bgp_attrs = -1;
372 static gint ett_bgp_attr = -1;
373 static gint ett_bgp_attr_flags = -1;
374 static gint ett_bgp_mp_nhna = -1;
375 static gint ett_bgp_mp_reach_nlri = -1;
376 static gint ett_bgp_mp_unreach_nlri = -1;
377 static gint ett_bgp_mp_snpa = -1;
378 static gint ett_bgp_nlri = -1;
379 static gint ett_bgp_open = -1;
380 static gint ett_bgp_update = -1;
381 static gint ett_bgp_notification = -1;
382 static gint ett_bgp_route_refresh = -1; /* ROUTE-REFRESH message tree */
383 static gint ett_bgp_capability = -1;
384 static gint ett_bgp_as_paths = -1;
385 static gint ett_bgp_as_path_segments = -1;
386 static gint ett_bgp_communities = -1;
387 static gint ett_bgp_cluster_list = -1; /* cluster list tree */
388 static gint ett_bgp_options = -1; /* optional parameters tree */
389 static gint ett_bgp_option = -1; /* an optional parameter tree */
390 static gint ett_bgp_extended_communities = -1; /* extended communities list tree */
391 static gint ett_bgp_ext_com_flags = -1; /* extended communities flags tree */
392 static gint ett_bgp_ssa = -1; /* safi specific attribute */
393 static gint ett_bgp_ssa_subtree = -1; /* safi specific attribute Subtrees */
394 static gint ett_bgp_orf = -1; /* orf (outbound route filter) tree */
395 static gint ett_bgp_orf_entry = -1; /* orf entry tree */
398 static gboolean bgp_desegment = TRUE;
400 static gint bgp_asn_len = 0;
403 * Decode an IPv4 prefix.
406 decode_prefix4(proto_tree *tree, int hf_addr, tvbuff_t *tvb, gint offset,
407 guint16 tlen, const char *tag)
410 proto_tree *prefix_tree;
412 guint8 addr_bytes[4];
414 } ip_addr; /* IP address */
415 guint8 plen; /* prefix length */
416 int length; /* number of octets needed for prefix */
418 /* snarf length and prefix */
419 plen = tvb_get_guint8(tvb, offset);
420 length = ipv4_addr_and_mask(tvb, offset + 1, ip_addr.addr_bytes, plen);
422 proto_tree_add_text(tree, tvb, offset, 1, "%s length %u invalid (> 32)",
427 /* put prefix into protocol tree */
428 ti = proto_tree_add_text(tree, tvb, offset,
429 tlen != 0 ? tlen : 1 + length, "%s/%u",
430 ip_to_str(ip_addr.addr_bytes), plen);
431 prefix_tree = proto_item_add_subtree(ti, ett_bgp_prefix);
432 proto_tree_add_text(prefix_tree, tvb, offset, 1, "%s prefix length: %u",
435 proto_tree_add_ipv4(prefix_tree, hf_addr, tvb, offset + 1, length,
438 proto_tree_add_text(prefix_tree, tvb, offset + 1, length,
439 "%s prefix: %s", tag, ip_to_str(ip_addr.addr_bytes));
445 * Decode an IPv6 prefix.
448 decode_prefix6(proto_tree *tree, int hf_addr, tvbuff_t *tvb, gint offset,
449 guint16 tlen, const char *tag)
452 proto_tree *prefix_tree;
453 struct e_in6_addr addr; /* IPv6 address */
454 int plen; /* prefix length */
455 int length; /* number of octets needed for prefix */
457 /* snarf length and prefix */
458 plen = tvb_get_guint8(tvb, offset);
459 length = ipv6_addr_and_mask(tvb, offset + 1, &addr, plen);
461 proto_tree_add_text(tree, tvb, offset, 1, "%s length %u invalid",
466 /* put prefix into protocol tree */
467 ti = proto_tree_add_text(tree, tvb, offset,
468 tlen != 0 ? tlen : 1 + length, "%s/%u",
469 ip6_to_str(&addr), plen);
470 prefix_tree = proto_item_add_subtree(ti, ett_bgp_prefix);
471 proto_tree_add_text(prefix_tree, tvb, offset, 1, "%s prefix length: %u",
474 proto_tree_add_ipv6(prefix_tree, hf_addr, tvb, offset + 1, length,
477 proto_tree_add_text(prefix_tree, tvb, offset + 1, length,
478 "%s prefix: %s", tag, ip6_to_str(&addr));
486 * Decode an MPLS label stack
487 * XXX - We should change *buf to **buf, use ep_alloc() and drop the buflen
491 decode_MPLS_stack(tvbuff_t *tvb, gint offset, emem_strbuf_t *stack_strbuf)
493 guint32 label_entry; /* an MPLS label enrty (label + COS field + stack bit */
494 gint indx; /* index for the label stack */
497 label_entry = 0x000000 ;
499 ep_strbuf_truncate(stack_strbuf, 0);
501 while ((label_entry & 0x000001) == 0) {
503 label_entry = tvb_get_ntoh24(tvb, indx) ;
505 /* withdrawn routes may contain 0 or 0x800000 in the first label */
506 if((indx-offset)==0&&(label_entry==0||label_entry==0x800000)) {
507 ep_strbuf_append(stack_strbuf, "0 (withdrawn)");
511 ep_strbuf_append_printf(stack_strbuf, "%u%s", label_entry >> 4,
512 ((label_entry & 0x000001) == 0) ? "," : " (bottom)");
516 if ((label_entry & 0x000001) == 0) {
517 /* real MPLS multi-label stack in BGP? - maybe later; for now, it must be a bogus packet */
518 ep_strbuf_append(stack_strbuf, " (BOGUS: Bottom of Stack NOT set!)");
523 return((indx - offset) / 3);
527 * Decode a multiprotocol address
531 mp_addr_to_str (guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset, emem_strbuf_t *strbuf)
533 int length; /* length of the address in byte */
534 guint32 ip4addr,ip4addr2; /* IPv4 address */
535 guint16 rd_type; /* Route Distinguisher type */
536 struct e_in6_addr ip6addr; /* IPv6 address */
545 case SAFNUM_MPLS_LABEL:
548 ip4addr = tvb_get_ipv4(tvb, offset);
549 ep_strbuf_append(strbuf, ip_to_str((guint8 *)&ip4addr));
551 case SAFNUM_LAB_VPNUNICAST:
552 case SAFNUM_LAB_VPNMULCAST:
553 case SAFNUM_LAB_VPNUNIMULC:
554 rd_type=tvb_get_ntohs(tvb,offset) ;
557 length = 8 + sizeof(ip4addr);
558 ip4addr = tvb_get_ipv4(tvb, offset + 8); /* Next Hop */
559 ep_strbuf_printf(strbuf, "Empty Label Stack RD=%u:%u IPv4=%s",
560 tvb_get_ntohs(tvb, offset + 2),
561 tvb_get_ntohl(tvb, offset + 4),
562 ip_to_str((guint8 *)&ip4addr));
565 length = 8 + sizeof(ip4addr);
566 ip4addr = tvb_get_ipv4(tvb, offset + 2); /* IP part of the RD */
567 ip4addr2 = tvb_get_ipv4(tvb, offset + 8); /* Next Hop */
568 ep_strbuf_printf(strbuf, "Empty Label Stack RD=%s:%u IPv4=%s",
569 ip_to_str((guint8 *)&ip4addr),
570 tvb_get_ntohs(tvb, offset + 6),
571 ip_to_str((guint8 *)&ip4addr2));
575 ep_strbuf_printf(strbuf, "Unknown (0x%04x) labeled VPN IPv4 address format",rd_type);
577 } /* switch (rd_type) */
581 ep_strbuf_printf(strbuf, "Unknown SAFI (%u) for AFI %u", safi, afi);
583 } /* switch (safi) */
590 case SAFNUM_MPLS_LABEL:
593 tvb_get_ipv6(tvb, offset, &ip6addr);
594 ep_strbuf_printf(strbuf, "%s", ip6_to_str(&ip6addr));
596 case SAFNUM_LAB_VPNUNICAST:
597 case SAFNUM_LAB_VPNMULCAST:
598 case SAFNUM_LAB_VPNUNIMULC:
599 rd_type=tvb_get_ntohs(tvb,offset) ;
603 tvb_get_ipv6(tvb, offset + 8, &ip6addr); /* Next Hop */
604 ep_strbuf_printf(strbuf, "Empty Label Stack RD=%u:%u IPv6=%s",
605 tvb_get_ntohs(tvb, offset + 2),
606 tvb_get_ntohl(tvb, offset + 4),
607 ip6_to_str(&ip6addr));
611 ip4addr = tvb_get_ipv4(tvb, offset + 2); /* IP part of the RD */
612 tvb_get_ipv6(tvb, offset + 8, &ip6addr); /* Next Hop */
613 ep_strbuf_printf(strbuf, "Empty Label Stack RD=%s:%u IPv6=%s",
614 ip_to_str((guint8 *)&ip4addr),
615 tvb_get_ntohs(tvb, offset + 6),
616 ip6_to_str(&ip6addr));
620 ep_strbuf_printf(strbuf, "Unknown (0x%04x) labeled VPN IPv6 address format",rd_type);
622 } /* switch (rd_type) */
626 ep_strbuf_printf(strbuf, "Unknown SAFI (%u) for AFI %u", safi, afi);
628 } /* switch (safi) */
631 case AFNUM_L2VPN_OLD:
633 case SAFNUM_LAB_VPNUNICAST: /* only labeles prefixes do make sense */
634 case SAFNUM_LAB_VPNMULCAST:
635 case SAFNUM_LAB_VPNUNIMULC:
637 length = 4; /* the next-hop is simply an ipv4 addr */
638 ip4addr = tvb_get_ipv4(tvb, offset + 0);
639 ep_strbuf_printf(strbuf, "IPv4=%s",
640 ip_to_str((guint8 *)&ip4addr));
644 ep_strbuf_printf(strbuf, "Unknown SAFI (%u) for AFI %u", safi, afi);
646 } /* switch (safi) */
650 ep_strbuf_printf(strbuf, "Unknown AFI (%u) value", afi);
657 * Decode a multiprotocol prefix
660 decode_prefix_MP(proto_tree *tree, int hf_addr4, int hf_addr6,
661 guint16 afi, guint8 safi, tvbuff_t *tvb, gint offset,
664 int start_offset = offset;
666 proto_tree *prefix_tree;
667 int total_length; /* length of the entire item */
668 int length; /* length of the prefix address, in bytes */
669 guint plen; /* length of the prefix address, in bits */
670 guint labnum; /* number of labels */
671 guint16 tnl_id; /* Tunnel Identifier */
672 int ce_id,labblk_off,labblk_size;
674 guint8 addr_bytes[4];
676 } ip4addr, ip4addr2; /* IPv4 address */
677 struct e_in6_addr ip6addr; /* IPv6 address */
678 guint16 rd_type; /* Route Distinguisher type */
679 emem_strbuf_t *stack_strbuf; /* label stack */
689 total_length = decode_prefix4(tree, hf_addr4, tvb, offset, 0, tag);
690 if (total_length < 0)
694 case SAFNUM_MPLS_LABEL:
695 plen = tvb_get_guint8(tvb, offset);
696 stack_strbuf = ep_strbuf_new_label(NULL);
697 labnum = decode_MPLS_stack(tvb, offset + 1, stack_strbuf);
699 offset += (1 + labnum * 3);
700 if (plen <= (labnum * 3*8)) {
701 proto_tree_add_text(tree, tvb, start_offset, 1,
702 "%s Labeled IPv4 prefix length %u invalid",
706 plen -= (labnum * 3*8);
707 length = ipv4_addr_and_mask(tvb, offset, ip4addr.addr_bytes, plen);
709 proto_tree_add_text(tree, tvb, start_offset, 1,
710 "%s Labeled IPv4 prefix length %u invalid",
711 tag, plen + (labnum * 3*8));
715 ti = proto_tree_add_text(tree, tvb, start_offset,
716 (offset + length) - start_offset,
717 "Label Stack=%s IPv4=%s/%u",
718 stack_strbuf->str, ip_to_str(ip4addr.addr_bytes), plen);
719 prefix_tree = proto_item_add_subtree(ti, ett_bgp_prefix);
720 proto_tree_add_text(prefix_tree, tvb, start_offset, 1, "%s Prefix length: %u",
721 tag, plen + labnum * 3 * 8);
722 proto_tree_add_text(prefix_tree, tvb, start_offset + 1, 3 * labnum, "%s Label Stack: %s",
723 tag, stack_strbuf->str);
724 if (hf_addr4 != -1) {
725 proto_tree_add_ipv4(prefix_tree, hf_addr4, tvb, offset,
726 length, ip4addr.addr);
728 proto_tree_add_text(prefix_tree, tvb, offset, length,
729 "%s IPv4 prefix: %s",
730 tag, ip_to_str(ip4addr.addr_bytes));
732 total_length = (1 + labnum*3) + length;
736 plen = tvb_get_guint8(tvb, offset);
738 proto_tree_add_text(tree, tvb, start_offset, 1,
739 "%s Tunnel IPv4 prefix length %u invalid",
743 tnl_id = tvb_get_ntohs(tvb, offset + 1);
744 offset += 3; /* Length + Tunnel Id */
745 plen -= 16; /* 2-octet Identifier */
746 length = ipv4_addr_and_mask(tvb, offset, ip4addr.addr_bytes, plen);
748 proto_tree_add_text(tree, tvb, start_offset, 1,
749 "%s Tunnel IPv4 prefix length %u invalid",
753 ti = proto_tree_add_text(tree, tvb, start_offset,
754 (offset + length) - start_offset,
755 "Tunnel Identifier=0x%x IPv4=%s/%u",
756 tnl_id, ip_to_str(ip4addr.addr_bytes), plen);
757 prefix_tree = proto_item_add_subtree(ti, ett_bgp_prefix);
759 proto_tree_add_text(prefix_tree, tvb, start_offset, 1, "%s Prefix length: %u",
761 proto_tree_add_item(prefix_tree, hf_bgp_mp_nlri_tnl_id, tvb,
762 start_offset + 1, 2, FALSE);
763 if (hf_addr4 != -1) {
764 proto_tree_add_ipv4(prefix_tree, hf_addr4, tvb, offset,
765 length, ip4addr.addr);
767 proto_tree_add_text(prefix_tree, tvb, offset, length,
768 "%s IPv4 prefix: %s",
769 tag, ip_to_str(ip4addr.addr_bytes));
771 total_length = 1 + 2 + length; /* length field + Tunnel Id + IPv4 len */
774 case SAFNUM_LAB_VPNUNICAST:
775 case SAFNUM_LAB_VPNMULCAST:
776 case SAFNUM_LAB_VPNUNIMULC:
777 plen = tvb_get_guint8(tvb, offset);
778 stack_strbuf = ep_strbuf_new_label(NULL);
779 labnum = decode_MPLS_stack(tvb, offset + 1, stack_strbuf);
781 offset += (1 + labnum * 3);
782 if (plen <= (labnum * 3*8)) {
783 proto_tree_add_text(tree, tvb, start_offset, 1,
784 "%s Labeled VPN IPv4 prefix length %u invalid",
788 plen -= (labnum * 3*8);
790 rd_type = tvb_get_ntohs(tvb, offset);
792 proto_tree_add_text(tree, tvb, start_offset, 1,
793 "%s Labeled VPN IPv4 prefix length %u invalid",
794 tag, plen + (labnum * 3*8));
801 case FORMAT_AS2_LOC: /* Code borrowed from the decode_prefix4 function */
802 length = ipv4_addr_and_mask(tvb, offset + 8, ip4addr.addr_bytes, plen);
804 proto_tree_add_text(tree, tvb, start_offset, 1,
805 "%s Labeled VPN IPv4 prefix length %u invalid",
806 tag, plen + (labnum * 3*8) + 8*8);
810 ti = proto_tree_add_text(tree, tvb, start_offset,
811 (offset + 8 + length) - start_offset,
812 "Label Stack=%s RD=%u:%u, IPv4=%s/%u",
814 tvb_get_ntohs(tvb, offset + 2),
815 tvb_get_ntohl(tvb, offset + 4),
816 ip_to_str(ip4addr.addr_bytes), plen);
817 prefix_tree = proto_item_add_subtree(ti, ett_bgp_prefix);
818 proto_tree_add_text(prefix_tree, tvb, start_offset, 1, "%s Prefix length: %u",
819 tag, plen + labnum * 3 * 8 + 8 * 8);
820 proto_tree_add_text(prefix_tree, tvb, start_offset + 1, 3 * labnum,
821 "%s Label Stack: %s", tag, stack_strbuf->str);
822 proto_tree_add_text(prefix_tree, tvb, start_offset + 1 + 3 * labnum, 8,
823 "%s Route Distinguisher: %u:%u", tag, tvb_get_ntohs(tvb, offset + 2),
824 tvb_get_ntohl(tvb, offset + 4));
825 if (hf_addr4 != -1) {
826 proto_tree_add_ipv4(prefix_tree, hf_addr4, tvb,
827 offset + 8, length, ip4addr.addr);
829 proto_tree_add_text(prefix_tree, tvb, offset + 8,
830 length, "%s IPv4 prefix: %s", tag,
831 ip_to_str(ip4addr.addr_bytes));
833 total_length = (1 + labnum * 3 + 8) + length;
836 case FORMAT_IP_LOC: /* Code borrowed from the decode_prefix4 function */
837 tvb_memcpy(tvb, ip4addr.addr_bytes, offset + 2, 4);
839 length = ipv4_addr_and_mask(tvb, offset + 8, ip4addr2.addr_bytes, plen);
841 proto_tree_add_text(tree, tvb, start_offset, 1,
842 "%s Labeled VPN IPv4 prefix length %u invalid",
843 tag, plen + (labnum * 3*8) + 8*8);
847 ti = proto_tree_add_text(tree, tvb, start_offset,
848 (offset + 8 + length) - start_offset,
849 "Label Stack=%s RD=%s:%u, IPv4=%s/%u",
851 ip_to_str(ip4addr.addr_bytes),
852 tvb_get_ntohs(tvb, offset + 6),
853 ip_to_str(ip4addr2.addr_bytes),
855 prefix_tree = proto_item_add_subtree(ti, ett_bgp_prefix);
856 proto_tree_add_text(prefix_tree, tvb, start_offset, 1, "%s Prefix length: %u",
857 tag, plen + labnum * 3 * 8 + 8 * 8);
858 proto_tree_add_text(prefix_tree, tvb, start_offset + 1, 3 * labnum,
859 "%s Label Stack: %s", tag, stack_strbuf->str);
860 proto_tree_add_text(prefix_tree, tvb, start_offset + 1 + 3 * labnum, 8,
861 "%s Route Distinguisher: %s:%u", tag, ip_to_str(ip4addr.addr_bytes),
862 tvb_get_ntohs(tvb, offset + 6));
863 if (hf_addr4 != -1) {
864 proto_tree_add_ipv4(prefix_tree, hf_addr4, tvb,
865 offset + 8, length, ip4addr2.addr);
867 proto_tree_add_text(prefix_tree, tvb, offset + 8,
868 length, "%s IPv4 prefix: %s", tag,
869 ip_to_str(ip4addr2.addr_bytes));
871 total_length = (1 + labnum * 3 + 8) + length;
875 proto_tree_add_text(tree, tvb, start_offset,
876 (offset - start_offset) + 2,
877 "Unknown labeled VPN IPv4 address format %u", rd_type);
879 } /* switch (rd_type) */
883 proto_tree_add_text(tree, tvb, start_offset, 0,
884 "Unknown SAFI (%u) for AFI %u", safi, afi);
886 } /* switch (safi) */
895 total_length = decode_prefix6(tree, hf_addr6, tvb, offset, 0, tag);
896 if (total_length < 0)
900 case SAFNUM_MPLS_LABEL:
901 plen = tvb_get_guint8(tvb, offset);
902 stack_strbuf = ep_strbuf_new_label(NULL);
903 labnum = decode_MPLS_stack(tvb, offset + 1, stack_strbuf);
905 offset += (1 + labnum * 3);
906 if (plen <= (labnum * 3*8)) {
907 proto_tree_add_text(tree, tvb, start_offset, 1,
908 "%s Labeled IPv6 prefix length %u invalid", tag, plen);
911 plen -= (labnum * 3*8);
913 length = ipv6_addr_and_mask(tvb, offset, &ip6addr, plen);
915 proto_tree_add_text(tree, tvb, start_offset, 1,
916 "%s Labeled IPv6 prefix length %u invalid",
917 tag, plen + (labnum * 3*8));
921 ti = proto_tree_add_text(tree, tvb, start_offset,
922 (offset + length) - start_offset,
923 "Label Stack=%s, IPv6=%s/%u",
925 ip6_to_str(&ip6addr), plen);
926 total_length = (1 + labnum * 3) + length;
930 plen = tvb_get_guint8(tvb, offset);
932 proto_tree_add_text(tree, tvb, start_offset, 1,
933 "%s Tunnel IPv6 prefix length %u invalid",
937 tnl_id = tvb_get_ntohs(tvb, offset + 1);
938 offset += 3; /* Length + Tunnel Id */
939 plen -= 16; /* 2-octet Identifier */
940 length = ipv6_addr_and_mask(tvb, offset, &ip6addr, plen);
942 proto_tree_add_text(tree, tvb, start_offset, 1,
943 "%s Tunnel IPv6 prefix length %u invalid",
947 ti = proto_tree_add_text(tree, tvb, start_offset,
948 (offset + length) - start_offset,
949 "Tunnel Identifier=0x%x IPv6=%s/%u",
950 tnl_id, ip6_to_str(&ip6addr), plen);
951 total_length = (1 + 2) + length; /* length field + Tunnel Id + IPv4 len */
954 case SAFNUM_LAB_VPNUNICAST:
955 case SAFNUM_LAB_VPNMULCAST:
956 case SAFNUM_LAB_VPNUNIMULC:
957 plen = tvb_get_guint8(tvb, offset);
958 stack_strbuf = ep_strbuf_new_label(NULL);
959 labnum = decode_MPLS_stack(tvb, offset + 1, stack_strbuf);
961 offset += (1 + labnum * 3);
962 if (plen <= (labnum * 3*8)) {
963 proto_tree_add_text(tree, tvb, start_offset, 1,
964 "%s Labeled VPN IPv6 prefix length %u invalid", tag, plen);
967 plen -= (labnum * 3*8);
969 rd_type = tvb_get_ntohs(tvb,offset);
971 proto_tree_add_text(tree, tvb, start_offset, 1,
972 "%s Labeled VPN IPv6 prefix length %u invalid",
973 tag, plen + (labnum * 3*8));
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=%u:%u, IPv6=%s/%u",
993 tvb_get_ntohs(tvb, offset + 2),
994 tvb_get_ntohl(tvb, offset + 4),
995 ip6_to_str(&ip6addr), plen);
996 total_length = (1 + labnum * 3 + 8) + length;
1000 tvb_memcpy(tvb, ip4addr.addr_bytes, offset + 2, 4);
1002 length = ipv6_addr_and_mask(tvb, offset + 8, &ip6addr, plen);
1004 proto_tree_add_text(tree, tvb, start_offset, 1,
1005 "%s Labeled VPN IPv6 prefix length %u invalid",
1006 tag, plen + (labnum * 3*8) + 8*8);
1010 ti = proto_tree_add_text(tree, tvb, start_offset,
1011 (offset + 8 + length) - start_offset,
1012 "Label Stack=%s RD=%s:%u, IPv6=%s/%u",
1014 ip_to_str(ip4addr.addr_bytes),
1015 tvb_get_ntohs(tvb, offset + 6),
1016 ip6_to_str(&ip6addr), plen);
1017 total_length = (1 + labnum * 3 + 8) + length;
1021 proto_tree_add_text(tree, tvb, start_offset, 0,
1022 "Unknown labeled VPN IPv6 address format %u", rd_type);
1024 } /* switch (rd_type) */
1028 proto_tree_add_text(tree, tvb, start_offset, 0,
1029 "Unknown SAFI (%u) for AFI %u", safi, afi);
1031 } /* switch (safi) */
1035 case AFNUM_L2VPN_OLD:
1038 case SAFNUM_LAB_VPNUNICAST:
1039 case SAFNUM_LAB_VPNMULCAST:
1040 case SAFNUM_LAB_VPNUNIMULC:
1042 plen = tvb_get_ntohs(tvb,offset);
1043 rd_type=tvb_get_ntohs(tvb,offset+2);
1044 ce_id=tvb_get_ntohs(tvb,offset+10);
1045 labblk_off=tvb_get_ntohs(tvb,offset+12);
1046 labblk_size=tvb_get_ntohs(tvb,offset+14);
1047 stack_strbuf = ep_strbuf_new_label(NULL);
1048 labnum = decode_MPLS_stack(tvb, offset + 16, stack_strbuf);
1052 case FORMAT_AS2_LOC:
1053 tvb_memcpy(tvb, ip4addr.addr_bytes, offset + 6, 4);
1054 proto_tree_add_text(tree, tvb, start_offset,
1055 (offset + plen + 1) - start_offset,
1056 "RD: %u:%s, CE-ID: %u, Label-Block Offset: %u, "
1057 "Label-Block Size: %u Label Base %s",
1058 tvb_get_ntohs(tvb, offset + 4),
1059 ip_to_str(ip4addr.addr_bytes),
1067 tvb_memcpy(tvb, ip4addr.addr_bytes, offset + 4, 4);
1068 proto_tree_add_text(tree, tvb, offset,
1069 (offset + plen + 1) - start_offset,
1070 "RD: %s:%u, CE-ID: %u, Label-Block Offset: %u, "
1071 "Label-Block Size: %u, Label Base %s",
1072 ip_to_str(ip4addr.addr_bytes),
1073 tvb_get_ntohs(tvb, offset + 8),
1081 proto_tree_add_text(tree, tvb, start_offset,
1082 (offset - start_offset) + 2,
1083 "Unknown labeled VPN address format %u", rd_type);
1085 } /* switch (rd_type) */
1086 /* FIXME there are subTLVs left to decode ... for now lets omit them */
1087 total_length = plen+2;
1091 proto_tree_add_text(tree, tvb, start_offset, 0,
1092 "Unknown SAFI (%u) for AFI %u", safi, afi);
1094 } /* switch (safi) */
1098 proto_tree_add_text(tree, tvb, start_offset, 0,
1099 "Unknown AFI (%u) value", afi);
1101 } /* switch (afi) */
1102 return(total_length);
1106 * Dissect a BGP capability.
1109 dissect_bgp_capability_item(tvbuff_t *tvb, int *p, proto_tree *tree, int ctype, int clen)
1111 proto_tree *subtree;
1113 guint8 orfnum; /* number of ORFs */
1114 guint8 orftype; /* ORF Type */
1115 guint8 orfsendrecv; /* ORF Send/Receive */
1116 int tclen; /* capability length */
1119 /* check the capability type */
1121 case BGP_CAPABILITY_RESERVED:
1122 proto_tree_add_text(tree, tvb, *p - 2, 1,
1123 "Capability code: %s (%d)", val_to_str(ctype,
1124 capability_vals, "Unknown capability"), ctype);
1125 proto_tree_add_text(tree, tvb, *p - 1,
1126 1, "Capability length: %u byte%s", clen,
1127 plurality(clen, "", "s"));
1129 proto_tree_add_text(tree, tvb, *p,
1130 clen, "Capability value: Unknown");
1134 case BGP_CAPABILITY_MULTIPROTOCOL:
1135 proto_tree_add_text(tree, tvb, *p - 2, 1,
1136 "Capability code: %s (%d)", val_to_str(ctype,
1137 capability_vals, "Unknown capability"), ctype);
1139 proto_tree_add_text(tree, tvb, *p - 1,
1140 1, "Capability length: Invalid");
1141 proto_tree_add_text(tree, tvb, *p,
1142 clen, "Capability value: Unknown");
1145 proto_tree_add_text(tree, tvb, *p - 1,
1146 1, "Capability length: %u byte%s", clen,
1147 plurality(clen, "", "s"));
1148 ti = proto_tree_add_text(tree, tvb, *p, clen, "Capability value");
1149 subtree = proto_item_add_subtree(ti, ett_bgp_option);
1151 i = tvb_get_ntohs(tvb, *p);
1152 proto_tree_add_text(subtree, tvb, *p,
1153 2, "Address family identifier: %s (%u)",
1154 val_to_str(i, afn_vals, "Unknown"), i);
1157 proto_tree_add_text(subtree, tvb, *p, 1, "Reserved: 1 byte");
1160 i = tvb_get_guint8(tvb, *p);
1161 proto_tree_add_text(subtree, tvb, *p,
1162 1, "Subsequent address family identifier: %s (%u)",
1163 val_to_str(i, bgpattr_nlri_safi,
1164 i >= 128 ? "Vendor specific" : "Unknown"), i);
1168 case BGP_CAPABILITY_GRACEFUL_RESTART:
1169 proto_tree_add_text(tree, tvb, *p - 2, 1,
1170 "Capability code: %s (%d)", val_to_str(ctype,
1171 capability_vals, "Unknown capability"), ctype);
1173 proto_tree_add_text(tree, tvb, *p,
1174 clen, "Capability value: Invalid");
1178 proto_tree_add_text(tree, tvb, *p - 1,
1179 1, "Capability length: %u byte%s", clen,
1180 plurality(clen, "", "s"));
1181 ti = proto_tree_add_text(tree, tvb, *p, clen, "Capability value");
1182 subtree = proto_item_add_subtree(ti, ett_bgp_option);
1184 i = tvb_get_ntohs(tvb, *p);
1185 proto_tree_add_text(subtree, tvb, *p,
1186 2, "Restart Flags: [%s], Restart Time %us",
1187 (i&0x8000) ? "R" : "none", i&0xfff);
1191 * what follows is alist of AFI/SAFI/flag triplets
1192 * read it until the TLV ends
1196 i = tvb_get_ntohs(tvb, *p);
1197 proto_tree_add_text(subtree, tvb, *p,
1198 2, "Address family identifier: %s (%u)",
1199 val_to_str(i, afn_vals, "Unknown"), i);
1202 i = tvb_get_guint8(tvb, *p);
1203 proto_tree_add_text(subtree, tvb, *p,
1204 1, "Subsequent address family identifier: %s (%u)",
1205 val_to_str(i, bgpattr_nlri_safi,
1206 i >= 128 ? "Vendor specific" : "Unknown"), i);
1209 i = tvb_get_guint8(tvb, *p);
1210 proto_tree_add_text(subtree, tvb, *p, 1,
1211 "Preserve forwarding state: %s",
1212 (i&0x80) ? "yes" : "no");
1218 case BGP_CAPABILITY_4_OCTET_AS_NUMBER:
1219 proto_tree_add_text(tree, tvb, *p - 2, 1,
1220 "Capability code: %s (%d)", val_to_str(ctype,
1221 capability_vals, "Unknown capability"), ctype);
1223 proto_tree_add_text(tree, tvb, *p,
1224 clen, "Capability value: Invalid");
1227 proto_tree_add_text(tree, tvb, *p - 1,
1228 1, "Capability length: %u byte%s", clen,
1229 plurality(clen, "", "s"));
1230 ti = proto_tree_add_text(tree, tvb, *p, clen, "Capability value");
1231 subtree = proto_item_add_subtree(ti, ett_bgp_option);
1232 proto_tree_add_text(subtree, tvb, *p, 4,
1233 "AS number: %d", tvb_get_ntohl(tvb, *p));
1237 case BGP_CAPABILITY_DYNAMIC_CAPABILITY:
1238 proto_tree_add_text(tree, tvb, *p - 2, 1,
1239 "Capability code: %s (%d)", val_to_str(ctype,
1240 capability_vals, "Unknown capability"), ctype);
1241 proto_tree_add_text(tree, tvb, *p - 1, 1,
1242 "Capability length: %u byte%s", clen,
1243 plurality(clen, "", "s"));
1245 ti = proto_tree_add_text(tree, tvb, *p, clen, "Capability value");
1246 subtree = proto_item_add_subtree(ti, ett_bgp_option);
1247 for (i = 0; (int)i <= clen; i++) {
1248 proto_tree_add_text(subtree, tvb, *p, 1,
1249 "Capability code: %s (%d)", val_to_str(ctype,
1250 capability_vals, "Unknown capability"),
1251 tvb_get_guint8(tvb, *p));
1256 case BGP_CAPABILITY_ROUTE_REFRESH_CISCO:
1257 case BGP_CAPABILITY_ROUTE_REFRESH:
1258 proto_tree_add_text(tree, tvb, *p - 2, 1,
1259 "Capability code: %s (%d)", val_to_str(ctype,
1260 capability_vals, "Unknown capability"), ctype);
1262 proto_tree_add_text(tree, tvb, *p,
1263 clen, "Capability value: Invalid");
1266 proto_tree_add_text(tree, tvb, *p - 1,
1267 1, "Capability length: %u byte%s", clen,
1268 plurality(clen, "", "s"));
1272 case BGP_CAPABILITY_ORF_CISCO:
1273 case BGP_CAPABILITY_COOPERATIVE_ROUTE_FILTERING:
1274 proto_tree_add_text(tree, tvb, *p - 2, 1,
1275 "Capability code: %s (%d)", val_to_str(ctype,
1276 capability_vals, "Unknown capability"), ctype);
1277 proto_tree_add_text(tree, tvb, *p - 1,
1278 1, "Capability length: %u byte%s", clen,
1279 plurality(clen, "", "s"));
1280 ti = proto_tree_add_text(tree, tvb, *p, clen, "Capability value");
1281 subtree = proto_item_add_subtree(ti, ett_bgp_option);
1283 i = tvb_get_ntohs(tvb, *p);
1284 proto_tree_add_text(subtree, tvb, *p,
1285 2, "Address family identifier: %s (%u)",
1286 val_to_str(i, afn_vals, "Unknown"), i);
1289 proto_tree_add_text(subtree, tvb, *p, 1, "Reserved: 1 byte");
1292 i = tvb_get_guint8(tvb, *p);
1293 proto_tree_add_text(subtree, tvb, *p,
1294 1, "Subsequent address family identifier: %s (%u)",
1295 val_to_str(i, bgpattr_nlri_safi,
1296 i >= 128 ? "Vendor specific" : "Unknown"), i);
1298 /* Number of ORFs */
1299 orfnum = tvb_get_guint8(tvb, *p);
1300 proto_tree_add_text(subtree, tvb, *p, 1, "Number of ORFs: %u", orfnum);
1302 for (i=0; i<orfnum; i++) {
1304 orftype = tvb_get_guint8(tvb, *p);
1305 proto_tree_add_text(subtree, tvb, *p, 1, "ORF Type: %s (%u)",
1306 val_to_str(orftype, orf_type_vals,"Unknown"), orftype);
1309 orfsendrecv = tvb_get_guint8(tvb, *p);
1310 proto_tree_add_text(subtree, tvb, *p,
1311 1, "Send/Receive: %s (%u)",
1312 val_to_str(orfsendrecv, orf_send_recv_vals,
1313 "Uknown"), orfsendrecv);
1317 /* unknown capability */
1319 proto_tree_add_text(tree, tvb, *p - 2, 1,
1320 "Capability code: %s (%d)", val_to_str(ctype,
1321 capability_vals, "Unknown capability"), ctype);
1322 proto_tree_add_text(tree, tvb, *p - 2,
1323 1, "Capability code: %s (%d)",
1324 ctype >= 128 ? "Private use" : "Unknown", ctype);
1325 proto_tree_add_text(tree, tvb, *p - 1,
1326 1, "Capability length: %u byte%s", clen,
1327 plurality(clen, "", "s"));
1329 proto_tree_add_text(tree, tvb, *p,
1330 clen, "Capability value: Unknown");
1334 } /* switch (ctype) */
1339 * Dissect a BGP OPEN message.
1341 static const value_string community_vals[] = {
1342 { BGP_COMM_NO_EXPORT, "NO_EXPORT" },
1343 { BGP_COMM_NO_ADVERTISE, "NO_ADVERTISE" },
1344 { BGP_COMM_NO_EXPORT_SUBCONFED, "NO_EXPORT_SUBCONFED" },
1349 dissect_bgp_open(tvbuff_t *tvb, proto_tree *tree)
1351 struct bgp_open bgpo; /* BGP OPEN message */
1352 int hlen; /* message length */
1353 int ptype; /* parameter type */
1354 int plen; /* parameter length */
1355 int ctype; /* capability type */
1356 int clen; /* capability length */
1357 int cend; /* capabilities end */
1358 int ostart; /* options start */
1359 int oend; /* options end */
1360 int p; /* tvb offset counter */
1361 proto_item *ti; /* tree item */
1362 proto_tree *subtree; /* subtree for options */
1363 proto_tree *subtree1; /* subtree for an option */
1364 proto_tree *subtree2; /* subtree for an option */
1366 /* snarf OPEN message */
1367 tvb_memcpy(tvb, bgpo.bgpo_marker, 0, BGP_MIN_OPEN_MSG_SIZE);
1368 hlen = g_ntohs(bgpo.bgpo_len);
1370 proto_tree_add_text(tree, tvb,
1371 offsetof(struct bgp_open, bgpo_version), 1,
1372 "Version: %u", bgpo.bgpo_version);
1373 proto_tree_add_text(tree, tvb,
1374 offsetof(struct bgp_open, bgpo_myas), 2,
1375 "My AS: %u", g_ntohs(bgpo.bgpo_myas));
1376 proto_tree_add_text(tree, tvb,
1377 offsetof(struct bgp_open, bgpo_holdtime), 2,
1378 "Hold time: %u", g_ntohs(bgpo.bgpo_holdtime));
1379 proto_tree_add_text(tree, tvb,
1380 offsetof(struct bgp_open, bgpo_id), 4,
1381 "BGP identifier: %s", ip_to_str((guint8 *)&bgpo.bgpo_id));
1382 proto_tree_add_text(tree, tvb,
1383 offsetof(struct bgp_open, bgpo_optlen), 1,
1384 "Optional parameters length: %u byte%s", bgpo.bgpo_optlen,
1385 plurality(bgpo.bgpo_optlen, "", "s"));
1387 /* optional parameters */
1388 if (bgpo.bgpo_optlen > 0) {
1389 /* add a subtree and setup some offsets */
1390 ostart = BGP_MIN_OPEN_MSG_SIZE;
1391 ti = proto_tree_add_text(tree, tvb, ostart, bgpo.bgpo_optlen,
1392 "Optional parameters");
1393 subtree = proto_item_add_subtree(ti, ett_bgp_options);
1395 oend = p + bgpo.bgpo_optlen;
1397 /* step through all of the optional parameters */
1400 /* grab the type and length */
1401 ptype = tvb_get_guint8(tvb, p++);
1402 plen = tvb_get_guint8(tvb, p++);
1404 /* check the type */
1406 case BGP_OPTION_AUTHENTICATION:
1407 proto_tree_add_text(subtree, tvb, p - 2, 2 + plen,
1408 "Authentication information (%u byte%s)", plen,
1409 plurality(plen, "", "s"));
1411 case BGP_OPTION_CAPABILITY:
1412 /* grab the capability code */
1413 cend = p - 1 + plen;
1414 ctype = tvb_get_guint8(tvb, p++);
1415 clen = tvb_get_guint8(tvb, p++);
1416 ti = proto_tree_add_text(subtree, tvb, p - 4,
1417 2 + plen, "Capabilities Advertisement (%u bytes)",
1419 subtree1 = proto_item_add_subtree(ti, ett_bgp_option);
1420 proto_tree_add_text(subtree1, tvb, p - 4,
1421 1, "Parameter type: Capabilities (2)");
1422 proto_tree_add_text(subtree1, tvb, p - 3,
1423 1, "Parameter length: %u byte%s", plen,
1424 plurality(plen, "", "s"));
1427 /* step through all of the capabilities */
1429 ctype = tvb_get_guint8(tvb, p++);
1430 clen = tvb_get_guint8(tvb, p++);
1432 ti = proto_tree_add_text(subtree1, tvb, p - 2,
1433 2 + clen, "%s (%u byte%s)", val_to_str(ctype,
1434 capability_vals, "Unknown capability"),
1435 2 + clen, plurality(clen, "", "s"));
1436 subtree2 = proto_item_add_subtree(ti, ett_bgp_option);
1437 dissect_bgp_capability_item(tvb, &p,
1438 subtree2, ctype, clen);
1442 proto_tree_add_text(subtree, tvb, p - 2, 2 + plen,
1443 "Unknown optional parameter");
1445 } /* switch (ptype) */
1451 * Dissect a BGP UPDATE message.
1454 dissect_bgp_update(tvbuff_t *tvb, proto_tree *tree)
1456 struct bgp_attr bgpa; /* path attributes */
1457 guint16 hlen; /* message length */
1458 gint o; /* packet offset */
1460 gint end; /* message end */
1461 guint16 ext_com; /* EXTENDED COMMUNITY extended length type */
1462 guint8 ext_com8; /* EXTENDED COMMUNITY regular type */
1463 gboolean is_regular_type; /* flag for regular types */
1464 gboolean is_extended_type; /* flag for extended types */
1465 guint16 len; /* tmp */
1466 int advance; /* tmp */
1467 proto_item *ti; /* tree item */
1468 proto_tree *subtree; /* subtree for attributes */
1469 proto_tree *subtree2; /* subtree for attributes */
1470 proto_tree *subtree3; /* subtree for attributes */
1471 proto_tree *subtree4; /* subtree for attributes */
1472 proto_tree *subtree5; /* subtree for attributes */
1473 proto_tree *as_paths_tree; /* subtree for AS_PATHs */
1474 proto_tree *as_path_tree; /* subtree for AS_PATH */
1475 proto_tree *as_path_segment_tree; /* subtree for AS_PATH segments */
1476 proto_tree *communities_tree; /* subtree for COMMUNITIES */
1477 proto_tree *community_tree; /* subtree for a community */
1478 proto_tree *cluster_list_tree; /* subtree for CLUSTER_LIST */
1480 guint8 length; /* AS_PATH length */
1481 guint8 type; /* AS_PATH type */
1482 guint32 as_path_item; /* item in AS_PATH segment */
1483 emem_strbuf_t *as_path_emstr = NULL; /* AS_PATH */
1484 emem_strbuf_t *communities_emstr = NULL; /* COMMUNITIES */
1485 emem_strbuf_t *cluster_list_emstr = NULL; /* CLUSTER_LIST */
1486 emem_strbuf_t *junk_emstr; /* tmp */
1487 guint32 ipaddr; /* IPv4 address */
1488 guint32 aggregator_as;
1489 guint16 ssa_type; /* SSA T + Type */
1490 guint16 ssa_len; /* SSA TLV Length */
1491 guint8 ssa_v3_len; /* SSA L2TPv3 Cookie Length */
1492 gfloat linkband; /* Link bandwidth */
1494 hlen = tvb_get_ntohs(tvb, BGP_MARKER_SIZE);
1495 o = BGP_HEADER_SIZE;
1496 junk_emstr = ep_strbuf_new_label(NULL);
1498 /* check for withdrawals */
1499 len = tvb_get_ntohs(tvb, o);
1500 proto_tree_add_text(tree, tvb, o, 2,
1501 "Unfeasible routes length: %u byte%s", len, plurality(len, "", "s"));
1504 /* parse unfeasible prefixes */
1506 ti = proto_tree_add_text(tree, tvb, o, len, "Withdrawn routes:");
1507 subtree = proto_item_add_subtree(ti, ett_bgp_unfeas);
1509 /* parse each prefix */
1512 i = decode_prefix4(subtree, hf_bgp_withdrawn_prefix, tvb, o, len,
1520 /* check for advertisements */
1521 len = tvb_get_ntohs(tvb, o);
1522 proto_tree_add_text(tree, tvb, o, 2, "Total path attribute length: %u byte%s",
1523 len, plurality(len, "", "s"));
1525 /* path attributes */
1527 ti = proto_tree_add_text(tree, tvb, o + 2, len, "Path attributes");
1528 subtree = proto_item_add_subtree(ti, ett_bgp_attrs);
1531 proto_item *hidden_item;
1535 guint16 alen, tlen, aoff, aoff_save;
1541 tvb_memcpy(tvb, (guint8 *)&bgpa, o + i, sizeof(bgpa));
1542 /* check for the Extended Length bit */
1543 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_EXTENDED_LENGTH) {
1544 alen = tvb_get_ntohs(tvb, o + i + sizeof(bgpa));
1545 aoff = sizeof(bgpa) + 2;
1547 alen = tvb_get_guint8(tvb, o + i + sizeof(bgpa));
1548 aoff = sizeof(bgpa) + 1;
1552 /* This is kind of ugly - similar code appears twice, but it
1553 helps browsing attrs. */
1554 /* the first switch prints things in the title of the subtree */
1555 switch (bgpa.bgpa_type) {
1556 case BGPTYPE_ORIGIN:
1558 goto default_attribute_top;
1559 msg = val_to_str(tvb_get_guint8(tvb, o + i + aoff), bgpattr_origin, "Unknown");
1560 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1561 "%s: %s (%u byte%s)",
1562 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1563 msg, tlen + aoff, plurality(tlen + aoff, "", "s"));
1565 case BGPTYPE_AS_PATH:
1566 case BGPTYPE_NEW_AS_PATH:
1568 (o + current attribute + aoff bytes to first tuple) */
1571 /* must be freed by second switch! */
1572 /* "tlen * 11" (10 digits + space) should be a good estimate
1573 of how long the AS path string could be */
1574 if (as_path_emstr == NULL)
1575 as_path_emstr = ep_strbuf_sized_new((tlen + 1) * 11, 0);
1576 ep_strbuf_truncate(as_path_emstr, 0);
1578 /* estimate the length of the AS number */
1579 if (bgpa.bgpa_type == BGPTYPE_NEW_AS_PATH)
1582 if (bgp_asn_len == 0) {
1586 length = tvb_get_guint8(tvb, k++);
1589 asn_len = (k == end) ? 2 : 4;
1592 asn_len = bgp_asn_len;
1596 /* snarf each AS path */
1598 type = tvb_get_guint8(tvb, q++);
1599 if (as_path_emstr->len > 1 &&
1600 as_path_emstr->str[as_path_emstr->len - 1] != ' ')
1601 ep_strbuf_append_c(as_path_emstr, ' ');
1602 if (type == AS_SET) {
1603 ep_strbuf_append_c(as_path_emstr, '{');
1605 else if (type == AS_CONFED_SET) {
1606 ep_strbuf_append_c(as_path_emstr, '[');
1608 else if (type == AS_CONFED_SEQUENCE) {
1609 ep_strbuf_append_c(as_path_emstr, '(');
1611 length = tvb_get_guint8(tvb, q++);
1613 /* snarf each value in path */
1614 for (j = 0; j < length; j++) {
1615 ep_strbuf_append_printf(as_path_emstr, "%u%s",
1617 tvb_get_ntohs(tvb, q) : tvb_get_ntohl(tvb, q),
1618 (type == AS_SET || type == AS_CONFED_SET) ?
1623 /* cleanup end of string */
1624 if (type == AS_SET) {
1625 ep_strbuf_truncate(as_path_emstr, as_path_emstr->len - 2);
1626 ep_strbuf_append_c(as_path_emstr, '}');
1628 else if (type == AS_CONFED_SET) {
1629 ep_strbuf_truncate(as_path_emstr, as_path_emstr->len - 2);
1630 ep_strbuf_append_c(as_path_emstr, ']');
1632 else if (type == AS_CONFED_SEQUENCE) {
1633 ep_strbuf_truncate(as_path_emstr, as_path_emstr->len - 1);
1634 ep_strbuf_append_c(as_path_emstr, ')');
1637 ep_strbuf_truncate(as_path_emstr, as_path_emstr->len - 1);
1641 /* check for empty AS_PATH */
1643 ep_strbuf_printf(as_path_emstr, "empty");
1645 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1646 "%s: %s (%u byte%s)",
1647 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1648 as_path_emstr->str, tlen + aoff,
1649 plurality(tlen + aoff, "", "s"));
1651 case BGPTYPE_NEXT_HOP:
1653 goto default_attribute_top;
1654 ipaddr = tvb_get_ipv4(tvb, o + i + aoff);
1655 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1656 "%s: %s (%u byte%s)",
1657 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1658 ip_to_str((guint8 *)&ipaddr), tlen + aoff,
1659 plurality(tlen + aoff, "", "s"));
1661 case BGPTYPE_MULTI_EXIT_DISC:
1663 goto default_attribute_top;
1664 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1665 "%s: %u (%u byte%s)",
1666 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1667 tvb_get_ntohl(tvb, o + i + aoff), tlen + aoff,
1668 plurality(tlen + aoff, "", "s"));
1670 case BGPTYPE_LOCAL_PREF:
1672 goto default_attribute_top;
1673 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1674 "%s: %u (%u byte%s)",
1675 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1676 tvb_get_ntohl(tvb, o + i + aoff), tlen + aoff,
1677 plurality(tlen + aoff, "", "s"));
1679 case BGPTYPE_ATOMIC_AGGREGATE:
1681 goto default_attribute_top;
1682 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1684 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1685 tlen + aoff, plurality(tlen + aoff, "", "s"));
1687 case BGPTYPE_AGGREGATOR:
1688 if (tlen != 6 && tlen != 8)
1689 goto default_attribute_top;
1690 case BGPTYPE_NEW_AGGREGATOR:
1691 if (bgpa.bgpa_type == BGPTYPE_NEW_AGGREGATOR && tlen != 8)
1692 goto default_attribute_top;
1694 ipaddr = tvb_get_ipv4(tvb, o + i + aoff + asn_len);
1695 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1696 "%s: AS: %u origin: %s (%u byte%s)",
1697 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1698 (asn_len == 2) ? tvb_get_ntohs(tvb, o + i + aoff) :
1699 tvb_get_ntohl(tvb, o + i + aoff),
1700 ip_to_str((guint8 *)&ipaddr),
1701 tlen + aoff, plurality(tlen + aoff, "", "s"));
1703 case BGPTYPE_COMMUNITIES:
1705 goto default_attribute_top;
1708 (o + current attribute + aoff bytes to first tuple) */
1711 /* must be freed by second switch! */
1712 /* "tlen * 12" (5 digits, a :, 5 digits + space ) should be
1713 a good estimate of how long the communities string could
1715 if (communities_emstr == NULL)
1716 communities_emstr = ep_strbuf_sized_new((tlen + 1) * 12, 0);
1717 ep_strbuf_truncate(communities_emstr, 0);
1719 /* snarf each community */
1721 /* check for well-known communities */
1722 if (tvb_get_ntohl(tvb, q) == BGP_COMM_NO_EXPORT)
1723 ep_strbuf_append(communities_emstr, "NO_EXPORT ");
1724 else if (tvb_get_ntohl(tvb, q) == BGP_COMM_NO_ADVERTISE)
1725 ep_strbuf_append(communities_emstr, "NO_ADVERTISE ");
1726 else if (tvb_get_ntohl(tvb, q) == BGP_COMM_NO_EXPORT_SUBCONFED)
1727 ep_strbuf_append(communities_emstr, "NO_EXPORT_SUBCONFED ");
1729 ep_strbuf_append_printf(communities_emstr, "%u:%u ",
1730 tvb_get_ntohs(tvb, q),
1731 tvb_get_ntohs(tvb, q + 2));
1735 /* cleanup end of string */
1736 ep_strbuf_truncate(communities_emstr, communities_emstr->len - 1);
1738 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1739 "%s: %s (%u byte%s)",
1740 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1741 communities_emstr->str, tlen + aoff,
1742 plurality(tlen + aoff, "", "s"));
1744 case BGPTYPE_ORIGINATOR_ID:
1746 goto default_attribute_top;
1747 ipaddr = tvb_get_ipv4(tvb, o + i + aoff);
1748 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1749 "%s: %s (%u byte%s)",
1750 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1751 ip_to_str((guint8 *)&ipaddr),
1752 tlen + aoff, plurality(tlen + aoff, "", "s"));
1754 case BGPTYPE_CLUSTER_LIST:
1756 goto default_attribute_top;
1759 (o + current attribute + aoff bytes to first tuple) */
1762 /* must be freed by second switch! */
1763 /* "tlen * 16" (12 digits, 3 dots + space ) should be
1764 a good estimate of how long the cluster_list string could
1766 if (cluster_list_emstr == NULL)
1767 cluster_list_emstr = ep_strbuf_sized_new((tlen + 1) * 16, 0);
1768 ep_strbuf_truncate(cluster_list_emstr, 0);
1770 /* snarf each cluster list */
1772 ipaddr = tvb_get_ipv4(tvb, q);
1773 ep_strbuf_append_printf(cluster_list_emstr, "%s ", ip_to_str((guint8 *)&ipaddr));
1776 /* cleanup end of string */
1777 ep_strbuf_truncate(cluster_list_emstr, cluster_list_emstr->len - 1);
1779 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1780 "%s: %s (%u byte%s)",
1781 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1782 cluster_list_emstr->str, tlen + aoff,
1783 plurality(tlen + aoff, "", "s"));
1785 case BGPTYPE_EXTENDED_COMMUNITY:
1788 ti = proto_tree_add_text(subtree,tvb,o+i,tlen+aoff,
1790 val_to_str(bgpa.bgpa_type,bgpattr_type,"Unknown"),
1792 plurality(tlen + aoff, "", "s"));
1794 case BGPTYPE_SAFI_SPECIFIC_ATTR:
1795 ti = proto_tree_add_text(subtree,tvb,o+i,tlen+aoff,
1797 val_to_str(bgpa.bgpa_type,bgpattr_type,"Unknown"),
1799 plurality(tlen + aoff, "", "s"));
1803 default_attribute_top:
1804 ti = proto_tree_add_text(subtree, tvb, o + i, tlen + aoff,
1806 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1807 tlen + aoff, plurality(tlen + aoff, "", "s"));
1808 } /* switch (bgpa.bgpa_type) */ /* end of first switch */
1809 subtree2 = proto_item_add_subtree(ti, ett_bgp_attr);
1811 /* figure out flags */
1812 ep_strbuf_truncate(junk_emstr, 0);
1813 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_OPTIONAL) {
1814 ep_strbuf_append(junk_emstr, "Optional, ");
1817 ep_strbuf_append(junk_emstr, "Well-known, ");
1819 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_TRANSITIVE) {
1820 ep_strbuf_append(junk_emstr, "Transitive, ");
1823 ep_strbuf_append(junk_emstr, "Non-transitive, ");
1825 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_PARTIAL) {
1826 ep_strbuf_append(junk_emstr, "Partial");
1829 ep_strbuf_append(junk_emstr, "Complete");
1831 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_EXTENDED_LENGTH) {
1832 ep_strbuf_append(junk_emstr, ", Extended Length");
1834 ti = proto_tree_add_text(subtree2, tvb,
1835 o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
1836 "Flags: 0x%02x (%s)", bgpa.bgpa_flags, junk_emstr->str);
1837 subtree3 = proto_item_add_subtree(ti, ett_bgp_attr_flags);
1839 /* add flag bitfield subtrees */
1840 proto_tree_add_text(subtree3, tvb,
1841 o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
1842 "%s", decode_boolean_bitfield(bgpa.bgpa_flags,
1843 BGP_ATTR_FLAG_OPTIONAL, 8, "Optional", "Well-known"));
1844 proto_tree_add_text(subtree3, tvb,
1845 o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
1846 "%s", decode_boolean_bitfield(bgpa.bgpa_flags,
1847 BGP_ATTR_FLAG_TRANSITIVE, 8, "Transitive",
1849 proto_tree_add_text(subtree3, tvb,
1850 o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
1851 "%s", decode_boolean_bitfield(bgpa.bgpa_flags,
1852 BGP_ATTR_FLAG_PARTIAL, 8, "Partial", "Complete"));
1853 proto_tree_add_text(subtree3, tvb,
1854 o + i + offsetof(struct bgp_attr, bgpa_flags), 1,
1855 "%s", decode_boolean_bitfield(bgpa.bgpa_flags,
1856 BGP_ATTR_FLAG_EXTENDED_LENGTH, 8, "Extended length",
1859 proto_tree_add_text(subtree2, tvb,
1860 o + i + offsetof(struct bgp_attr, bgpa_type), 1,
1861 "Type code: %s (%u)",
1862 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
1865 proto_tree_add_text(subtree2, tvb, o + i + sizeof(bgpa),
1866 aoff - sizeof(bgpa), "Length: %d byte%s", tlen,
1867 plurality(tlen, "", "s"));
1869 /* the second switch prints things in the actual subtree of each
1871 switch (bgpa.bgpa_type) {
1872 case BGPTYPE_ORIGIN:
1874 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
1875 "Origin (invalid): %u byte%s", tlen,
1876 plurality(tlen, "", "s"));
1878 proto_tree_add_item(subtree2, hf_bgp_origin, tvb,
1879 o + i + aoff, 1, FALSE);
1882 case BGPTYPE_AS_PATH:
1883 case BGPTYPE_NEW_AS_PATH:
1884 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
1885 "AS path: %s", as_path_emstr->str);
1886 as_paths_tree = proto_item_add_subtree(ti, ett_bgp_as_paths);
1889 (o + current attribute + aoff bytes to first tuple) */
1893 /* snarf each AS path tuple, we have to step through each one
1894 again to make a separate subtree so we can't just reuse
1895 as_path_gstr from above */
1896 /* XXX - Can we use some g_string*() trickery instead, e.g.
1897 g_string_erase()? */
1899 ep_strbuf_truncate(as_path_emstr, 0);
1900 type = tvb_get_guint8(tvb, q++);
1901 if (type == AS_SET) {
1902 ep_strbuf_append_c(as_path_emstr, '{');
1904 else if (type == AS_CONFED_SET) {
1905 ep_strbuf_append_c(as_path_emstr, '[');
1907 else if (type == AS_CONFED_SEQUENCE) {
1908 ep_strbuf_append_c(as_path_emstr, '(');
1910 length = tvb_get_guint8(tvb, q++);
1912 /* snarf each value in path */
1913 for (j = 0; j < length; j++) {
1914 ep_strbuf_append_printf(as_path_emstr, "%u%s",
1916 tvb_get_ntohs(tvb, q) : tvb_get_ntohl(tvb, q),
1917 (type == AS_SET || type == AS_CONFED_SET) ? ", " : " ");
1921 /* cleanup end of string */
1922 if (type == AS_SET) {
1923 ep_strbuf_truncate(as_path_emstr, as_path_emstr->len - 2);
1924 ep_strbuf_append_c(as_path_emstr, '}');
1926 else if (type == AS_CONFED_SET) {
1927 ep_strbuf_truncate(as_path_emstr, as_path_emstr->len - 2);
1928 ep_strbuf_append_c(as_path_emstr, ']');
1930 else if (type == AS_CONFED_SEQUENCE) {
1931 ep_strbuf_truncate(as_path_emstr, as_path_emstr->len - 1);
1932 ep_strbuf_append_c(as_path_emstr, ')');
1935 ep_strbuf_truncate(as_path_emstr, as_path_emstr->len - 1);
1938 /* length here means number of ASs, ie length * 2 bytes */
1939 ti = proto_tree_add_text(as_paths_tree, tvb,
1940 q - length * asn_len - 2,
1941 length * asn_len + 2, "AS path segment: %s", as_path_emstr->str);
1942 as_path_tree = proto_item_add_subtree(ti, ett_bgp_as_paths);
1943 proto_tree_add_text(as_path_tree, tvb, q - length * asn_len - 2,
1944 1, "Path segment type: %s (%u)",
1945 val_to_str(type, as_segment_type, "Unknown"), type);
1946 proto_tree_add_text(as_path_tree, tvb, q - length * asn_len - 1,
1947 1, "Path segment length: %u AS%s", length,
1948 plurality(length, "", "s"));
1950 /* backup and reprint path segment value(s) only */
1951 q -= asn_len * length;
1952 ti = proto_tree_add_text(as_path_tree, tvb, q,
1953 length * asn_len, "Path segment value:");
1954 as_path_segment_tree = proto_item_add_subtree(ti,
1955 ett_bgp_as_path_segments);
1956 for (j = 0; j < length; j++) {
1957 as_path_item = (asn_len == 2) ?
1958 tvb_get_ntohs(tvb, q) : tvb_get_ntohl(tvb, q);
1959 proto_item_append_text(ti, " %u", as_path_item);
1960 hidden_item = proto_tree_add_uint(as_path_tree, hf_bgp_as_path, tvb,
1961 q, asn_len, as_path_item);
1962 PROTO_ITEM_SET_HIDDEN(hidden_item);
1968 case BGPTYPE_NEXT_HOP:
1970 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
1971 "Next hop (invalid): %u byte%s", tlen,
1972 plurality(tlen, "", "s"));
1974 proto_tree_add_item(subtree2, hf_bgp_next_hop, tvb,
1975 o + i + aoff, tlen, FALSE);
1978 case BGPTYPE_MULTI_EXIT_DISC:
1980 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
1981 "Multiple exit discriminator (invalid): %u byte%s",
1982 tlen, plurality(tlen, "", "s"));
1984 proto_tree_add_item(subtree2, hf_bgp_multi_exit_disc, tvb,
1985 o + i + aoff, tlen, FALSE);
1988 case BGPTYPE_LOCAL_PREF:
1990 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
1991 "Local preference (invalid): %u byte%s", tlen,
1992 plurality(tlen, "", "s"));
1994 proto_tree_add_item(subtree2, hf_bgp_local_pref, tvb,
1995 o + i + aoff, tlen, FALSE);
1998 case BGPTYPE_ATOMIC_AGGREGATE:
2000 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2001 "Atomic aggregate (invalid): %u byte%s", tlen,
2002 plurality(tlen, "", "s"));
2005 case BGPTYPE_AGGREGATOR:
2006 if (tlen != 6 && tlen != 8) {
2007 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2008 "Aggregator (invalid): %u byte%s", tlen,
2009 plurality(tlen, "", "s"));
2012 case BGPTYPE_NEW_AGGREGATOR:
2013 if (bgpa.bgpa_type == BGPTYPE_NEW_AGGREGATOR && tlen != 8)
2014 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2015 "Aggregator (invalid): %u byte%s", tlen,
2016 plurality(tlen, "", "s"));
2019 aggregator_as = (asn_len == 2) ?
2020 tvb_get_ntohs(tvb, o + i + aoff) :
2021 tvb_get_ntohl(tvb, o + i + aoff);
2022 proto_tree_add_uint(subtree2, hf_bgp_aggregator_as, tvb,
2023 o + i + aoff, asn_len, aggregator_as);
2024 proto_tree_add_item(subtree2, hf_bgp_aggregator_origin, tvb,
2025 o + i + aoff + asn_len, 4, FALSE);
2028 case BGPTYPE_COMMUNITIES:
2029 if (tlen % 4 != 0) {
2030 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2031 "Communities (invalid): %u byte%s", tlen,
2032 plurality(tlen, "", "s"));
2036 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2037 "Communities: %s", communities_emstr ? communities_emstr->str : "<none>");
2038 communities_tree = proto_item_add_subtree(ti,
2039 ett_bgp_communities);
2042 (o + current attribute + aoff bytes to first tuple) */
2046 /* snarf each community */
2048 /* check for reserved values */
2049 guint32 community = tvb_get_ntohl(tvb, q);
2050 if ((community & 0xFFFF0000) == FOURHEX0 ||
2051 (community & 0xFFFF0000) == FOURHEXF) {
2052 proto_tree_add_text(communities_tree, tvb,
2054 "Community: %s (0x%08x)",
2055 val_to_str(community, community_vals, "(reserved)"),
2059 ti = proto_tree_add_text(communities_tree, tvb,
2060 q - 3 + aoff, 4, "Community: %u:%u",
2061 tvb_get_ntohs(tvb, q), tvb_get_ntohs(tvb, q + 2));
2062 community_tree = proto_item_add_subtree(ti,
2063 ett_bgp_communities);
2064 proto_tree_add_item(community_tree, hf_bgp_community_as,
2065 tvb, q - 3 + aoff, 2, FALSE);
2066 proto_tree_add_item(community_tree, hf_bgp_community_value,
2067 tvb, q - 1 + aoff, 2, FALSE);
2074 case BGPTYPE_ORIGINATOR_ID:
2076 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2077 "Originator identifier (invalid): %u byte%s", tlen,
2078 plurality(tlen, "", "s"));
2080 proto_tree_add_item(subtree2, hf_bgp_originator_id, tvb,
2081 o + i + aoff, tlen, FALSE);
2084 case BGPTYPE_MP_REACH_NLRI:
2086 * RFC 2545 specifies that there may be more than one
2087 * address in the MP_REACH_NLRI attribute in section
2088 * 3, "Constructing the Next Hop field".
2090 * Yes, RFC 2858 says you can't do that, and, yes, RFC
2091 * 2858 obsoletes RFC 2283, which says you can do that,
2092 * but that doesn't mean we shouldn't dissect packets
2093 * that conform to RFC 2283 but not RFC 2858, as some
2094 * device on the network might implement the 2283-style
2095 * BGP extensions rather than RFC 2858-style extensions.
2097 af = tvb_get_ntohs(tvb, o + i + aoff);
2098 proto_tree_add_text(subtree2, tvb, o + i + aoff, 2,
2099 "Address family: %s (%u)",
2100 val_to_str(af, afn_vals, "Unknown"), af);
2101 saf = tvb_get_guint8(tvb, o + i + aoff + 2) ;
2102 proto_tree_add_text(subtree2, tvb, o + i + aoff + 2, 1,
2103 "Subsequent address family identifier: %s (%u)",
2104 val_to_str(saf, bgpattr_nlri_safi, saf >= 128 ? "Vendor specific" : "Unknown"),
2106 nexthop_len = tvb_get_guint8(tvb, o + i + aoff + 3);
2107 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff + 3,
2109 "Next hop network address (%d byte%s)",
2110 nexthop_len, plurality(nexthop_len, "", "s"));
2111 subtree3 = proto_item_add_subtree(ti, ett_bgp_mp_nhna);
2114 * The addresses don't contain lengths, so if we
2115 * don't understand the address family type, we
2116 * cannot parse the subsequent addresses as we
2117 * don't know how long they are.
2121 proto_tree_add_text(subtree3, tvb, o + i + aoff + 4,
2122 nexthop_len, "Unknown Address Family");
2128 case AFNUM_L2VPN_OLD:
2131 while (j < nexthop_len) {
2132 advance = mp_addr_to_str(af, saf, tvb, o + i + aoff + 4 + j,
2134 if (advance == 0) /* catch if this is a unknown AFI type*/
2136 if (j + advance > nexthop_len)
2138 proto_tree_add_text(subtree3, tvb,o + i + aoff + 4 + j,
2139 advance, "Next hop: %s (%u)", junk_emstr->str, advance);
2146 tlen -= nexthop_len + 4;
2147 aoff += nexthop_len + 4 ;
2150 snpa = tvb_get_guint8(tvb, o + i + aoff);
2151 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, 1,
2152 "Subnetwork points of attachment: %u", snpa);
2155 subtree3 = proto_item_add_subtree(ti, ett_bgp_mp_snpa);
2156 for (/*nothing*/; snpa > 0; snpa--) {
2157 proto_tree_add_text(subtree3, tvb, o + i + aoff + off, 1,
2158 "SNPA length: %u", tvb_get_guint8(tvb, o + i + aoff + off));
2160 proto_tree_add_text(subtree3, tvb, o + i + aoff + off,
2161 tvb_get_guint8(tvb, o + i + aoff + off - 1),
2162 "SNPA (%u byte%s)", tvb_get_guint8(tvb, o + i + aoff + off - 1),
2163 plurality(tvb_get_guint8(tvb, o + i + aoff + off - 1), "", "s"));
2164 off += tvb_get_guint8(tvb, o + i + aoff + off - 1);
2170 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2171 "Network layer reachability information (%u byte%s)",
2172 tlen, plurality(tlen, "", "s"));
2174 subtree3 = proto_item_add_subtree(ti,ett_bgp_mp_reach_nlri);
2175 if (af != AFNUM_INET && af != AFNUM_INET6 && af != AFNUM_L2VPN) {
2176 proto_tree_add_text(subtree3, tvb, o + i + aoff,
2177 tlen, "Unknown Address Family");
2180 advance = decode_prefix_MP(subtree3,
2181 hf_bgp_mp_reach_nlri_ipv4_prefix,
2184 tvb, o + i + aoff, "MP Reach NLRI");
2194 case BGPTYPE_MP_UNREACH_NLRI:
2195 af = tvb_get_ntohs(tvb, o + i + aoff);
2196 proto_tree_add_text(subtree2, tvb, o + i + aoff, 2,
2197 "Address family: %s (%u)",
2198 val_to_str(af, afn_vals, "Unknown"), af);
2199 saf = tvb_get_guint8(tvb, o + i + aoff + 2) ;
2200 proto_tree_add_text(subtree2, tvb, o + i + aoff + 2, 1,
2201 "Subsequent address family identifier: %s (%u)",
2202 val_to_str(saf, bgpattr_nlri_safi, saf >= 128 ? "Vendor specific" : "Unknown"),
2204 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff + 3,
2205 tlen - 3, "Withdrawn routes (%u byte%s)", tlen - 3,
2206 plurality(tlen - 3, "", "s"));
2212 subtree3 = proto_item_add_subtree(ti,ett_bgp_mp_unreach_nlri);
2215 advance = decode_prefix_MP(subtree3,
2216 hf_bgp_mp_unreach_nlri_ipv4_prefix,
2219 tvb, o + i + aoff, "MP Unreach NLRI");
2228 case BGPTYPE_CLUSTER_LIST:
2229 if (tlen % 4 != 0) {
2230 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2231 "Cluster list (invalid): %u byte%s", tlen,
2232 plurality(tlen, "", "s"));
2236 ti = proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2237 "Cluster list: %s", cluster_list_emstr ? cluster_list_emstr->str : "<none>");
2238 cluster_list_tree = proto_item_add_subtree(ti,
2239 ett_bgp_cluster_list);
2242 (o + current attribute + aoff bytes to first tuple) */
2246 /* snarf each cluster identifier */
2248 proto_tree_add_item(cluster_list_tree, hf_bgp_cluster_list,
2249 tvb, q - 3 + aoff, 4, FALSE);
2254 case BGPTYPE_EXTENDED_COMMUNITY:
2256 proto_tree_add_text(subtree3, tvb, o + i + aoff, tlen, "Extended community (invalid) : %u byte%s", tlen,
2257 plurality(tlen, "", "s"));
2260 end = o + i + aoff + tlen ;
2261 ti = proto_tree_add_text(subtree2,tvb,q,tlen, "Carried Extended communities");
2262 subtree3 = proto_item_add_subtree(ti,ett_bgp_extended_communities);
2265 ext_com8 = tvb_get_guint8(tvb,q); /* handle regular types (8 bit) */
2266 ext_com = tvb_get_ntohs(tvb,q); /* handle extended length types (16 bit) */
2267 ep_strbuf_printf(junk_emstr, "%s", val_to_str(ext_com8,bgpext_com8_type,"Unknown"));
2268 is_regular_type = FALSE;
2269 is_extended_type = FALSE;
2270 /* handle regular types (8 bit) */
2272 case BGP_EXT_COM_QOS_MARK_T:
2273 case BGP_EXT_COM_QOS_MARK_NT:
2274 is_regular_type = TRUE;
2275 ti = proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_emstr->str);
2277 subtree4 = proto_item_add_subtree(ti,ett_bgp_extended_communities);
2278 ti = proto_tree_add_text(subtree4, tvb, q, 1,
2279 "Type: 0x%02x", tvb_get_guint8(tvb,q));
2280 ti = proto_tree_add_text(subtree4, tvb, q+1, 1,
2281 "Flags: 0x%02x", tvb_get_guint8(tvb,q+1));
2282 subtree5 = proto_item_add_subtree(ti,ett_bgp_ext_com_flags);
2283 /* add flag bitfield */
2284 ti = proto_tree_add_text(subtree5, tvb, q+1, 1, "%s", decode_boolean_bitfield(tvb_get_guint8(tvb,q+1),
2285 0x10, 8, "Remarking", "No Remarking"));
2286 ti = proto_tree_add_text(subtree5, tvb, q+1, 1, "%s", decode_boolean_bitfield(tvb_get_guint8(tvb,q+1),
2287 0x08, 8, "Ignored marking", "No Ignored marking"));
2288 ti = proto_tree_add_text(subtree5, tvb, q+1, 1, "%s", decode_boolean_bitfield(tvb_get_guint8(tvb,q+1),
2289 0x04, 8, "Aggregation of markings", "No Aggregation of markings"));
2291 ti = proto_tree_add_text(subtree4, tvb, q+2, 1,
2292 "QoS Set Number: 0x%02x", tvb_get_guint8(tvb,q+2));
2293 ti = proto_tree_add_text(subtree4, tvb, q+3, 1,
2294 "Technology Type: 0x%02x (%s)", tvb_get_guint8(tvb,q+3),
2295 val_to_str(tvb_get_guint8(tvb,q+3),qos_tech_type,"Unknown"));
2296 ti = proto_tree_add_text(subtree4, tvb, q+4, 2,
2297 "QoS Marking O (16 bit): %s", decode_numeric_bitfield(tvb_get_ntohs(tvb,q+4),
2298 0xffff, 16, "0x%04x"));
2299 ti = proto_tree_add_text(subtree4, tvb, q+6, 1,
2300 "QoS Marking A (8 bit): %s (decimal %d)", decode_numeric_bitfield(tvb_get_guint8(tvb,q+6),
2301 0xff, 8, "0x%02x"), tvb_get_guint8(tvb,q+6));
2302 ti = proto_tree_add_text(subtree4, tvb, q+7, 1,
2303 "Defaults to zero: 0x%02x", tvb_get_guint8(tvb,q+7));
2305 case BGP_EXT_COM_COS_CAP_T:
2306 is_regular_type = TRUE;
2307 ti = proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_emstr->str);
2309 subtree4 = proto_item_add_subtree(ti,ett_bgp_extended_communities);
2310 ti = proto_tree_add_text(subtree4, tvb, q, 1,
2311 "Type: 0x%02x", tvb_get_guint8(tvb,q));
2312 ti = proto_tree_add_text(subtree4, tvb, q+1, 1,
2313 "Flags byte 1 : 0x%02x", tvb_get_guint8(tvb,q+1));
2314 subtree5 = proto_item_add_subtree(ti,ett_bgp_ext_com_flags);
2315 /* add flag bitfield */
2316 ti = proto_tree_add_text(subtree5, tvb, q+1, 1, "%s", decode_boolean_bitfield(tvb_get_guint8(tvb,q+1),
2317 0x80, 8, "BE class supported", "BE class NOT supported"));
2318 ti = proto_tree_add_text(subtree5, tvb, q+1, 1, "%s", decode_boolean_bitfield(tvb_get_guint8(tvb,q+1),
2319 0x40, 8, "EF class supported", "EF class NOT supported"));
2320 ti = proto_tree_add_text(subtree5, tvb, q+1, 1, "%s", decode_boolean_bitfield(tvb_get_guint8(tvb,q+1),
2321 0x20, 8, "AF class supported", "AF class NOT supported"));
2322 ti = proto_tree_add_text(subtree5, tvb, q+1, 1, "%s", decode_boolean_bitfield(tvb_get_guint8(tvb,q+1),
2323 0x10, 8, "LE class supported", "LE class NOT supported"));
2324 ti = proto_tree_add_text(subtree4, tvb, q+2, 1,
2325 "Flags byte 2..7 : 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x",
2326 tvb_get_guint8(tvb,q+2),tvb_get_guint8(tvb,q+3),tvb_get_guint8(tvb,q+4),
2327 tvb_get_guint8(tvb,q+5),tvb_get_guint8(tvb,q+6),tvb_get_guint8(tvb,q+7));
2329 } /* switch (ext_com8) */
2331 if (!is_regular_type) {
2332 ep_strbuf_append(junk_emstr, val_to_str(ext_com,bgpext_com_type,"Unknown"));
2334 /* handle extended length types (16 bit) */
2336 case BGP_EXT_COM_RT_0:
2337 case BGP_EXT_COM_RT_2:
2338 case BGP_EXT_COM_RO_0:
2339 case BGP_EXT_COM_RO_2:
2340 is_extended_type = TRUE;
2341 ep_strbuf_append_printf(junk_emstr, ": %u%s%d",
2342 tvb_get_ntohs(tvb,q+2),":",tvb_get_ntohl(tvb,q+4));
2343 proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_emstr->str);
2345 case BGP_EXT_COM_RT_1:
2346 case BGP_EXT_COM_RO_1:
2347 is_extended_type = TRUE;
2348 ipaddr = tvb_get_ipv4(tvb,q+2);
2349 ep_strbuf_append_printf(junk_emstr, ": %s%s%u",
2350 ip_to_str((guint8 *)&ipaddr),":",tvb_get_ntohs(tvb,q+6));
2351 proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_emstr->str);
2353 case BGP_EXT_COM_VPN_ORIGIN:
2354 case BGP_EXT_COM_OSPF_RID:
2355 is_extended_type = TRUE;
2356 ipaddr = tvb_get_ipv4(tvb,q+2);
2357 ep_strbuf_append_printf(junk_emstr, ": %s", ip_to_str((guint8 *)&ipaddr));
2358 proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_emstr->str);
2360 case BGP_EXT_COM_OSPF_RTYPE:
2361 is_extended_type = TRUE;
2362 ipaddr = tvb_get_ipv4(tvb,q+2);
2363 ep_strbuf_append_printf(junk_emstr, ": Area: %s, Type: %s", ip_to_str((guint8 *)&ipaddr),
2364 val_to_str(tvb_get_guint8(tvb,q+6),bgpext_ospf_rtype,"Unknown"));
2365 /* print OSPF Metric type if selected */
2366 /* always print E2 even if not external route -- receiving router should ignore */
2367 if ( (tvb_get_guint8(tvb,q+7)) & BGP_OSPF_RTYPE_METRIC_TYPE ) {
2368 ep_strbuf_append(junk_emstr, " E2");
2369 } else if ((tvb_get_guint8(tvb,q+6)==BGP_OSPF_RTYPE_EXT) || (tvb_get_guint8(tvb,q+6)==BGP_OSPF_RTYPE_NSSA)) {
2370 ep_strbuf_append(junk_emstr, " E1");
2372 ep_strbuf_append(junk_emstr, ", no options");
2374 proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_emstr->str);
2376 case BGP_EXT_COM_LINKBAND:
2377 is_extended_type = TRUE;
2378 linkband = tvb_get_ntohieee_float(tvb,q+2);
2379 ep_strbuf_append_printf(junk_emstr, ": %.3f Mbps", linkband*8/1000000);
2380 proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_emstr->str);
2382 case BGP_EXT_COM_L2INFO:
2383 is_extended_type = TRUE;
2384 ep_strbuf_append_printf(junk_emstr,
2385 ": %s, Control Flags: %s%s%s%s%s, MTU: %u byte%s",
2386 val_to_str(tvb_get_guint8(tvb,q+2),bgp_l2vpn_encaps,"Unknown"),
2387 tvb_get_guint8(tvb,q+3) ? "" : "none",
2388 tvb_get_ntohs(tvb,q+3)&0x08 ? "Q" : "",
2389 tvb_get_ntohs(tvb,q+3)&0x04 ? "F" : "",
2390 tvb_get_ntohs(tvb,q+3)&0x02 ? "C" : "",
2391 tvb_get_ntohs(tvb,q+3)&0x01 ? "S" : "",
2392 tvb_get_ntohs(tvb,q+4),
2393 plurality(tvb_get_ntohs(tvb,q+4), "", "s"));
2394 ti = proto_tree_add_text(subtree3,tvb,q,8, "%s",junk_emstr->str);
2396 subtree4 = proto_item_add_subtree(ti,ett_bgp_extended_communities);
2397 proto_tree_add_text(subtree4,tvb,q+2,1, "Encapsulation: %s",
2398 val_to_str(tvb_get_guint8(tvb,q+2),bgp_l2vpn_encaps,"Unknown"));
2399 proto_tree_add_text(subtree4,tvb,q+3,1, "Control Flags: %s%sControl Word %s required, Sequenced delivery %s required",
2400 tvb_get_ntohs(tvb,q+3)&0x08 ? "Q flag (Reserved) set" : "",
2401 tvb_get_ntohs(tvb,q+3)&0x04 ? "F flag (reserved) set" : "",
2402 tvb_get_ntohs(tvb,q+3)&0x02 ? "is" : "not",
2403 tvb_get_ntohs(tvb,q+3)&0x01 ? "is" : "not");
2404 proto_tree_add_text(subtree4,tvb,q+4,2, "MTU: %u byte%s",
2405 tvb_get_ntohs(tvb,q+4),
2406 plurality(tvb_get_ntohs(tvb,q+4), "", "s"));
2408 } /* switch (ext_com) */
2410 if (!is_regular_type && !is_extended_type)
2411 proto_tree_add_text(subtree3,tvb,q,8, "%s","Unknown");
2416 case BGPTYPE_SAFI_SPECIFIC_ATTR:
2418 end = o + i + aoff + tlen ;
2421 ssa_type = tvb_get_ntohs(tvb, q) & BGP_SSA_TYPE;
2422 ssa_len = tvb_get_ntohs(tvb, q + 2);
2424 ti = proto_tree_add_text(subtree2, tvb, q, MIN(ssa_len + 4, end - q),
2426 val_to_str(ssa_type, bgp_ssa_type, "Unknown SSA"));
2427 subtree3 = proto_item_add_subtree(ti, ett_bgp_ssa);
2429 proto_tree_add_item(subtree3, hf_bgp_ssa_t, tvb,
2431 hidden_item = proto_tree_add_item(subtree3, hf_bgp_ssa_type, tvb,
2433 PROTO_ITEM_SET_HIDDEN(hidden_item);
2434 proto_tree_add_text(subtree3, tvb, q, 2,
2435 "Type: %s", val_to_str(ssa_type, bgp_ssa_type, "Unknown"));
2436 if ((ssa_len == 0) || (q + ssa_len > end)) {
2437 proto_tree_add_text(subtree3, tvb, q + 2, end - q - 2,
2438 "Invalid Length of %u", ssa_len);
2441 proto_tree_add_item(subtree3, hf_bgp_ssa_len, tvb,
2445 case BGP_SSA_L2TPv3:
2446 proto_tree_add_item(subtree3, hf_bgp_ssa_l2tpv3_pref, tvb,
2449 ti = proto_tree_add_text(subtree3, tvb, q + 6, 1, "Flags");
2450 subtree4 = proto_item_add_subtree(ti, ett_bgp_ssa_subtree) ;
2451 proto_tree_add_item(subtree4, hf_bgp_ssa_l2tpv3_s, tvb,
2453 proto_tree_add_item(subtree4, hf_bgp_ssa_l2tpv3_unused, tvb,
2456 ssa_v3_len = tvb_get_guint8(tvb, q + 7);
2457 if (ssa_v3_len + 8 == ssa_len){
2458 proto_tree_add_item(subtree3, hf_bgp_ssa_l2tpv3_cookie_len, tvb,
2461 proto_tree_add_text(subtree3, tvb, q + 7, 1,
2462 "Invalid Cookie Length of %u", ssa_v3_len);
2463 q += ssa_len + 4; /* 4 from type and length */
2466 proto_tree_add_item(subtree3, hf_bgp_ssa_l2tpv3_session_id, tvb,
2469 proto_tree_add_item(subtree3, hf_bgp_ssa_l2tpv3_cookie, tvb,
2470 q + 12, ssa_v3_len, FALSE);
2471 q += ssa_len + 4; /* 4 from type and length */
2477 proto_tree_add_item(subtree3, hf_bgp_ssa_value, tvb,
2478 q + 4, ssa_len, FALSE);
2479 q += ssa_len + 4; /* 4 from type and length */
2481 case BGP_SSA_L2TPv3_IN_IPSec:
2482 case BGP_SSA_mGRE_IN_IPSec:
2483 /* These contain BGP_SSA_IPSec and BGP_SSA_L2TPv3/BGP_SSA_mGRE */
2484 q += 4; /* 4 from type and length */
2486 } /* switch (bgpa.bgpa_type) */
2491 proto_tree_add_text(subtree2, tvb, o + i + aoff, tlen,
2492 "Unknown (%u byte%s)", tlen, plurality(tlen, "", "s"));
2494 } /* switch (bgpa.bgpa_type) */ /* end of second switch */
2504 /* parse prefixes */
2506 ti = proto_tree_add_text(tree, tvb, o, len,
2507 "Network layer reachability information: %u byte%s", len,
2508 plurality(len, "", "s"));
2509 subtree = proto_item_add_subtree(ti, ett_bgp_nlri);
2512 i = decode_prefix4(subtree, hf_bgp_nlri_prefix, tvb, o, 0,
2523 * Dissect a BGP NOTIFICATION message.
2526 dissect_bgp_notification(tvbuff_t *tvb, proto_tree *tree)
2528 struct bgp_notification bgpn; /* BGP NOTIFICATION message */
2529 int hlen; /* message length */
2530 const char *p; /* string pointer */
2533 tvb_memcpy(tvb, bgpn.bgpn_marker, 0, BGP_MIN_NOTIFICATION_MSG_SIZE);
2534 hlen = g_ntohs(bgpn.bgpn_len);
2536 /* print error code */
2537 proto_tree_add_text(tree, tvb,
2538 offsetof(struct bgp_notification, bgpn_major), 1,
2539 "Error code: %s (%u)",
2540 val_to_str(bgpn.bgpn_major, bgpnotify_major, "Unknown"),
2543 /* print error subcode */
2544 if (bgpn.bgpn_major < array_length(bgpnotify_minor)
2545 && bgpnotify_minor[bgpn.bgpn_major] != NULL) {
2546 p = val_to_str(bgpn.bgpn_minor, bgpnotify_minor[bgpn.bgpn_major],
2548 } else if (bgpn.bgpn_minor == 0)
2552 proto_tree_add_text(tree, tvb,
2553 offsetof(struct bgp_notification, bgpn_minor), 1,
2554 "Error subcode: %s (%u)", p, bgpn.bgpn_minor);
2556 /* only print if there is optional data */
2557 if (hlen > BGP_MIN_NOTIFICATION_MSG_SIZE) {
2558 proto_tree_add_text(tree, tvb, BGP_MIN_NOTIFICATION_MSG_SIZE,
2559 hlen - BGP_MIN_NOTIFICATION_MSG_SIZE, "Data");
2564 * Dissect a BGP ROUTE-REFRESH message.
2567 dissect_bgp_route_refresh(tvbuff_t *tvb, proto_tree *tree)
2569 guint16 i; /* tmp */
2570 int p; /* tvb offset counter */
2571 int pend; /* end of list of entries for one orf type */
2572 guint16 hlen; /* tvb RR msg length */
2573 proto_item *ti; /* tree item */
2574 proto_item *ti1; /* tree item */
2575 proto_tree *subtree; /* tree for orf */
2576 proto_tree *subtree1; /* tree for orf entry */
2577 guint8 orftype; /* ORF Type */
2578 guint8 orfwhen; /* ORF flag: immediate, defer */
2579 guint16 orflen; /* ORF len */
2580 guint8 entryflag; /* ORF Entry flag: action(add,del,delall) match(permit,deny) */
2581 guint32 entryseq; /* ORF Entry sequence number */
2582 int entrylen; /* ORF Entry length */
2583 guint8 pfx_ge; /* ORF PrefixList mask lower bound */
2584 guint8 pfx_le; /* ORF PrefixList mask upper bound */
2585 int advance; /* tmp */
2591 00 01 00 01 afi,safi= ipv4-unicast
2592 02 80 00 01 defer, prefix-orf, len=1
2596 00 01 00 01 afi,saif= ipv4-unicast
2597 01 80 00 0a immediate, prefix-orf, len=10
2599 00 00 00 05 seqno = 5
2602 10 07 02 prefix = 7.2.0.0/16
2604 hlen = tvb_get_ntohs(tvb, BGP_MARKER_SIZE);
2605 p = BGP_HEADER_SIZE;
2607 i = tvb_get_ntohs(tvb, p);
2608 proto_tree_add_text(tree, tvb, p, 2,
2609 "Address family identifier: %s (%u)",
2610 val_to_str(i, afn_vals, "Unknown"), i);
2613 proto_tree_add_text(tree, tvb, p, 1,
2614 "Reserved: 1 byte");
2617 i = tvb_get_guint8(tvb, p);
2618 proto_tree_add_text(tree, tvb, p, 1,
2619 "Subsequent address family identifier: %s (%u)",
2620 val_to_str(i, bgpattr_nlri_safi,
2621 i >= 128 ? "Vendor specific" : "Unknown"),
2624 if ( hlen == BGP_HEADER_SIZE + 4 )
2628 orfwhen = tvb_get_guint8(tvb, p);
2629 orftype = tvb_get_guint8(tvb, p+1);
2630 orflen = tvb_get_ntohs(tvb, p+2);
2631 ti = proto_tree_add_text(tree, tvb, p , orflen + 4 , "ORF information (%u bytes)", orflen + 4);
2632 subtree = proto_item_add_subtree(ti, ett_bgp_orf);
2633 proto_tree_add_text(subtree, tvb, p , 1, "ORF flag: %s", val_to_str(orfwhen, orf_when_vals,"UNKNOWN"));
2634 proto_tree_add_text(subtree, tvb, p+1 , 1, "ORF type: %s", val_to_str(orftype, orf_type_vals,"UNKNOWN"));
2635 proto_tree_add_text(subtree, tvb, p+2 , 2, "ORF len: %u byte%s", orflen, plurality(orflen, "", "s"));
2638 if (orftype != BGP_ORF_PREFIX_CISCO) {
2639 proto_tree_add_text(subtree, tvb, p, orflen,
2640 "ORFEntry-Unknown (%u bytes)", orflen);
2646 entryflag = tvb_get_guint8(tvb, p);
2647 if ((entryflag & BGP_ORF_ACTION) == BGP_ORF_REMOVEALL) {
2648 ti1 = proto_tree_add_text(subtree, tvb, p, 1,
2649 "ORFEntry-PrefixList (1 byte)");
2650 subtree1 = proto_item_add_subtree(ti1, ett_bgp_orf_entry);
2651 proto_tree_add_text(subtree1, tvb, p , 1, "RemoveAll");
2654 ti1 = proto_tree_add_text(subtree, tvb, p, -1,
2655 "ORFEntry-PrefixList");
2656 subtree1 = proto_item_add_subtree(ti1, ett_bgp_orf_entry);
2657 proto_tree_add_text(subtree1, tvb, p, 1,
2658 "ACTION: %s MATCH: %s",
2659 val_to_str(entryflag&BGP_ORF_ACTION,
2660 orf_entry_action_vals, "UNKNOWN"),
2661 val_to_str(entryflag&BGP_ORF_MATCH,
2662 orf_entry_match_vals, "UNKNOWN"));
2664 entryseq = tvb_get_ntohl(tvb, p);
2665 proto_tree_add_text(subtree1, tvb, p, 4,
2666 "Entry Sequence No: %u", entryseq);
2668 pfx_ge = tvb_get_guint8(tvb, p);
2669 proto_tree_add_text(subtree1, tvb, p, 1,
2670 "PrefixMask length lower bound: %u", pfx_ge);
2672 pfx_le = tvb_get_guint8(tvb, p);
2673 proto_tree_add_text(subtree1, tvb, p, 1,
2674 "PrefixMask length upper bound: %u", pfx_le);
2677 advance = decode_prefix4(subtree1, -1, tvb, p, 0, "ORF");
2680 entrylen = 7 + 1 + advance;
2682 proto_item_append_text(ti1, " (%u bytes)", entrylen);
2683 proto_item_set_len(ti1, entrylen);
2691 * Dissect a BGP CAPABILITY message.
2694 dissect_bgp_capability(tvbuff_t *tvb, proto_tree *tree)
2698 proto_tree *subtree;
2704 mend = offset + tvb_get_ntohs(tvb, offset + BGP_MARKER_SIZE);
2705 offset += BGP_HEADER_SIZE;
2706 /* step through all of the capabilities */
2707 while (offset < mend) {
2708 action = tvb_get_guint8(tvb, offset++);
2709 ctype = tvb_get_guint8(tvb, offset++);
2710 clen = tvb_get_guint8(tvb, offset++);
2712 ti = proto_tree_add_text(tree, tvb, offset - 2, 2 + clen,
2713 "%s (%u byte%s)", val_to_str(ctype, capability_vals,
2714 "Unknown capability"), 2 + clen, plurality(clen, "", "s"));
2715 subtree = proto_item_add_subtree(ti, ett_bgp_option);
2716 proto_tree_add_text(subtree, tvb, offset-2, 1, "Action: %d (%s)",
2717 action, val_to_str(action, bgpcap_action, "Invalid action value"));
2718 dissect_bgp_capability_item(tvb, &offset, subtree, ctype, clen);
2723 dissect_bgp_pdu(tvbuff_t *volatile tvb, packet_info *pinfo, proto_tree *tree,
2726 guint16 bgp_len; /* Message length */
2727 guint8 bgp_type; /* Message type */
2728 const char *typ; /* Message type (string) */
2729 proto_item *ti; /* tree item */
2730 proto_tree *bgp_tree; /* BGP packet tree */
2731 proto_tree *bgp1_tree; /* BGP message tree */
2733 bgp_len = tvb_get_ntohs(tvb, BGP_MARKER_SIZE);
2734 bgp_type = tvb_get_guint8(tvb, BGP_MARKER_SIZE + 2);
2735 typ = val_to_str(bgp_type, bgptypevals, "Unknown message type (0x%02x)");
2738 col_add_str(pinfo->cinfo, COL_INFO, typ);
2740 col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", typ);
2743 ti = proto_tree_add_item(tree, proto_bgp, tvb, 0, -1, FALSE);
2744 bgp_tree = proto_item_add_subtree(ti, ett_bgp);
2746 ti = proto_tree_add_text(bgp_tree, tvb, 0, -1, "%s", typ);
2748 /* add a different tree for each message type */
2751 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_open);
2754 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_update);
2756 case BGP_NOTIFICATION:
2757 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_notification);
2760 bgp1_tree = proto_item_add_subtree(ti, ett_bgp);
2762 case BGP_ROUTE_REFRESH_CISCO:
2763 case BGP_ROUTE_REFRESH:
2764 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_route_refresh);
2766 case BGP_CAPABILITY:
2767 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_capability);
2770 bgp1_tree = proto_item_add_subtree(ti, ett_bgp);
2774 proto_tree_add_text(bgp1_tree, tvb, 0, BGP_MARKER_SIZE,
2775 "Marker: 16 bytes");
2777 if (bgp_len < BGP_HEADER_SIZE || bgp_len > BGP_MAX_PACKET_SIZE) {
2778 proto_tree_add_text(bgp1_tree, tvb, BGP_MARKER_SIZE, 2,
2779 "Length (invalid): %u byte%s", bgp_len,
2780 plurality(bgp_len, "", "s"));
2783 proto_tree_add_text(bgp1_tree, tvb, BGP_MARKER_SIZE, 2,
2784 "Length: %u byte%s", bgp_len,
2785 plurality(bgp_len, "", "s"));
2788 proto_tree_add_uint(bgp1_tree, hf_bgp_type, tvb,
2789 BGP_MARKER_SIZE + 2, 1,
2794 dissect_bgp_open(tvb, bgp1_tree);
2797 dissect_bgp_update(tvb, bgp1_tree);
2799 case BGP_NOTIFICATION:
2800 dissect_bgp_notification(tvb, bgp1_tree);
2803 /* no data in KEEPALIVE messages */
2805 case BGP_ROUTE_REFRESH_CISCO:
2806 case BGP_ROUTE_REFRESH:
2807 dissect_bgp_route_refresh(tvb, bgp1_tree);
2809 case BGP_CAPABILITY:
2810 dissect_bgp_capability(tvb, bgp1_tree);
2819 * Dissect a BGP packet.
2822 dissect_bgp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2824 volatile int offset = 0; /* offset into the tvbuff */
2825 gint reported_length_remaining;
2826 guint8 bgp_marker[BGP_MARKER_SIZE]; /* Marker (should be all ones */
2827 static guchar marker[] = { /* BGP message marker */
2828 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2829 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
2831 proto_item *ti; /* tree item */
2832 proto_tree *bgp_tree; /* BGP packet tree */
2833 guint16 bgp_len; /* Message length */
2835 guint length_remaining;
2837 volatile gboolean first = TRUE; /* TRUE for the first BGP message in packet */
2838 tvbuff_t *volatile next_tvb;
2841 col_set_str(pinfo->cinfo, COL_PROTOCOL, "BGP");
2842 col_clear(pinfo->cinfo, COL_INFO);
2845 * Scan through the TCP payload looking for a BGP marker.
2847 while ((reported_length_remaining = tvb_reported_length_remaining(tvb, offset))
2850 * "reported_length_remaining" is the number of bytes of TCP payload
2851 * remaining. If it's more than the length of a BGP marker,
2852 * we check only the number of bytes in a BGP marker.
2854 if (reported_length_remaining > BGP_MARKER_SIZE)
2855 reported_length_remaining = BGP_MARKER_SIZE;
2858 * OK, is there a BGP marker starting at the specified offset -
2859 * or, at least, the beginning of a BGP marker running to the end
2860 * of the TCP payload?
2862 * This will throw an exception if the frame is short; that's what
2865 tvb_memcpy(tvb, bgp_marker, offset, reported_length_remaining);
2866 if (memcmp(bgp_marker, marker, reported_length_remaining) == 0) {
2868 * Yes - stop scanning and start processing BGP packets.
2874 * No - keep scanning through the tvbuff to try to find a marker.
2880 * If we skipped any bytes, mark it as a BGP continuation.
2883 ti = proto_tree_add_item(tree, proto_bgp, tvb, 0, -1, FALSE);
2884 bgp_tree = proto_item_add_subtree(ti, ett_bgp);
2886 proto_tree_add_text(bgp_tree, tvb, 0, offset, "Continuation");
2890 * Now process the BGP packets in the TCP payload.
2892 * XXX - perhaps "tcp_dissect_pdus()" should take a starting
2893 * offset, in which case we can replace the loop below with
2894 * a call to "tcp_dissect_pdus()".
2896 while (tvb_reported_length_remaining(tvb, offset) > 0) {
2898 * This will throw an exception if we don't have any data left.
2899 * That's what we want. (See "tcp_dissect_pdus()", which is
2902 length_remaining = tvb_ensure_length_remaining(tvb, offset);
2905 * Can we do reassembly?
2907 if (bgp_desegment && pinfo->can_desegment) {
2909 * Yes - would a BGP header starting at this offset be split
2910 * across segment boundaries?
2912 if (length_remaining < BGP_HEADER_SIZE) {
2914 * Yes. Tell the TCP dissector where the data for this
2915 * message starts in the data it handed us, and how many
2916 * more bytes we need, and return.
2918 pinfo->desegment_offset = offset;
2919 pinfo->desegment_len = BGP_HEADER_SIZE - length_remaining;
2925 * Get the length and type from the BGP header.
2927 bgp_len = tvb_get_ntohs(tvb, offset + BGP_MARKER_SIZE);
2928 if (bgp_len < BGP_HEADER_SIZE) {
2930 * The BGP length doesn't include the BGP header; report that
2933 show_reported_bounds_error(tvb, pinfo, tree);
2938 * Can we do reassembly?
2940 if (bgp_desegment && pinfo->can_desegment) {
2942 * Yes - is the PDU split across segment boundaries?
2944 if (length_remaining < bgp_len) {
2946 * Yes. Tell the TCP dissector where the data for this
2947 * message starts in the data it handed us, and how many
2948 * more bytes we need, and return.
2950 pinfo->desegment_offset = offset;
2951 pinfo->desegment_len = bgp_len - length_remaining;
2957 * Construct a tvbuff containing the amount of the payload we have
2958 * available. Make its reported length the amount of data in the PDU.
2960 * XXX - if reassembly isn't enabled. the subdissector will throw a
2961 * BoundsError exception, rather than a ReportedBoundsError exception.
2962 * We really want a tvbuff where the length is "length", the reported
2963 * length is "plen", and the "if the snapshot length were infinite"
2964 * length is the minimum of the reported length of the tvbuff handed
2965 * to us and "plen", with a new type of exception thrown if the offset
2966 * is within the reported length but beyond that third length, with
2967 * that exception getting the "Unreassembled Packet" error.
2969 length = length_remaining;
2970 if (length > bgp_len)
2972 next_tvb = tvb_new_subset(tvb, offset, length, bgp_len);
2977 * Catch the ReportedBoundsError exception; if this particular message
2978 * happens to get a ReportedBoundsError exception, that doesn't mean
2979 * that we should stop dissecting PDUs within this frame or chunk of
2982 * If it gets a BoundsError, we can stop, as there's nothing more to
2983 * see, so we just re-throw it.
2985 pd_save = pinfo->private_data;
2987 dissect_bgp_pdu(next_tvb, pinfo, tree, first);
2989 CATCH(BoundsError) {
2992 CATCH(ReportedBoundsError) {
2993 /* Restore the private_data structure in case one of the
2994 * called dissectors modified it (and, due to the exception,
2995 * was unable to restore it).
2997 pinfo->private_data = pd_save;
2999 show_reported_bounds_error(tvb, pinfo, tree);
3006 * Step to the next PDU.
3007 * Make sure we don't overflow.
3009 offset_before = offset;
3011 if (offset <= offset_before)
3017 * Register ourselves.
3020 proto_register_bgp(void)
3023 static hf_register_info hf[] = {
3025 { "Type", "bgp.type", FT_UINT8, BASE_DEC,
3026 VALS(bgptypevals), 0x0, "BGP message type", HFILL }},
3027 { &hf_bgp_aggregator_as,
3028 { "Aggregator AS", "bgp.aggregator_as", FT_UINT16, BASE_DEC,
3029 NULL, 0x0, NULL, HFILL}},
3030 { &hf_bgp_aggregator_origin,
3031 { "Aggregator origin", "bgp.aggregator_origin", FT_IPv4, BASE_NONE,
3032 NULL, 0x0, NULL, HFILL}},
3034 { "AS Path", "bgp.as_path", FT_UINT16, BASE_DEC,
3035 NULL, 0x0, NULL, HFILL}},
3036 { &hf_bgp_cluster_identifier,
3037 { "Cluster identifier", "bgp.cluster_identifier", FT_IPv4, BASE_NONE,
3038 NULL, 0x0, NULL, HFILL}},
3039 { &hf_bgp_community_as,
3040 { "Community AS", "bgp.community_as", FT_UINT16, BASE_DEC,
3041 NULL, 0x0, NULL, HFILL}},
3042 { &hf_bgp_community_value,
3043 { "Community value", "bgp.community_value", FT_UINT16, BASE_DEC,
3044 NULL, 0x0, NULL, HFILL}},
3045 { &hf_bgp_local_pref,
3046 { "Local preference", "bgp.local_pref", FT_UINT32, BASE_DEC,
3047 NULL, 0x0, NULL, HFILL}},
3048 { &hf_bgp_mp_reach_nlri_ipv4_prefix,
3049 { "MP Reach NLRI IPv4 prefix", "bgp.mp_reach_nlri_ipv4_prefix", FT_IPv4, BASE_NONE,
3050 NULL, 0x0, NULL, HFILL}},
3051 { &hf_bgp_mp_unreach_nlri_ipv4_prefix,
3052 { "MP Unreach NLRI IPv4 prefix", "bgp.mp_unreach_nlri_ipv4_prefix", FT_IPv4, BASE_NONE,
3053 NULL, 0x0, NULL, HFILL}},
3054 { &hf_bgp_mp_nlri_tnl_id,
3055 { "MP Reach NLRI Tunnel Identifier", "bgp.mp_nlri_tnl_id", FT_UINT16, BASE_HEX,
3056 NULL, 0x0, NULL, HFILL}},
3057 { &hf_bgp_multi_exit_disc,
3058 { "Multiple exit discriminator", "bgp.multi_exit_disc", FT_UINT32, BASE_DEC,
3059 NULL, 0x0, NULL, HFILL}},
3061 { "Next hop", "bgp.next_hop", FT_IPv4, BASE_NONE,
3062 NULL, 0x0, NULL, HFILL}},
3063 { &hf_bgp_nlri_prefix,
3064 { "NLRI prefix", "bgp.nlri_prefix", FT_IPv4, BASE_NONE,
3065 NULL, 0x0, NULL, HFILL}},
3067 { "Origin", "bgp.origin", FT_UINT8, BASE_DEC,
3068 VALS(bgpattr_origin), 0x0, NULL, HFILL}},
3069 { &hf_bgp_originator_id,
3070 { "Originator identifier", "bgp.originator_id", FT_IPv4, BASE_NONE,
3071 NULL, 0x0, NULL, HFILL}},
3073 { "Transitive bit", "bgp.ssa_t", FT_BOOLEAN, 8,
3074 NULL, 0x80, "SSA Transitive bit", HFILL}},
3076 { "SSA Type", "bgp.ssa_type", FT_UINT16, BASE_DEC,
3077 VALS(bgp_ssa_type), 0x7FFF, NULL, HFILL}},
3079 { "Length", "bgp.ssa_len", FT_UINT16, BASE_DEC,
3080 NULL, 0x0, "SSA Length", HFILL}},
3081 { &hf_bgp_ssa_value,
3082 { "Value", "bgp.ssa_value", FT_BYTES, BASE_NONE,
3083 NULL, 0x0, "SSA Value", HFILL}},
3084 { &hf_bgp_ssa_l2tpv3_pref,
3085 { "Preference", "bgp.ssa_l2tpv3_pref", FT_UINT16, BASE_DEC,
3086 NULL, 0x0, NULL, HFILL}},
3087 { &hf_bgp_ssa_l2tpv3_s,
3088 { "Sequencing bit", "bgp.ssa_l2tpv3_s", FT_BOOLEAN, 8,
3089 NULL, 0x80, "Sequencing S-bit", HFILL}},
3090 { &hf_bgp_ssa_l2tpv3_unused,
3091 { "Unused", "bgp.ssa_l2tpv3_Unused", FT_BOOLEAN, 8,
3092 NULL, 0x7F, "Unused Flags", HFILL}},
3093 { &hf_bgp_ssa_l2tpv3_cookie_len,
3094 { "Cookie Length", "bgp.ssa_l2tpv3_cookie_len", FT_UINT8, BASE_DEC,
3095 NULL, 0x0, NULL, HFILL}},
3096 { &hf_bgp_ssa_l2tpv3_session_id,
3097 { "Session ID", "bgp.ssa_l2tpv3_session_id", FT_UINT32, BASE_DEC,
3098 NULL, 0x0, NULL, HFILL}},
3099 { &hf_bgp_ssa_l2tpv3_cookie,
3100 { "Cookie", "bgp.ssa_l2tpv3_cookie", FT_BYTES, BASE_NONE,
3101 NULL, 0x0, NULL, HFILL}},
3102 { &hf_bgp_withdrawn_prefix,
3103 { "Withdrawn prefix", "bgp.withdrawn_prefix", FT_IPv4, BASE_NONE,
3104 NULL, 0x0, NULL, HFILL}},
3105 { &hf_bgp_cluster_list,
3106 { "Cluster List", "bgp.cluster_list", FT_BYTES, BASE_NONE,
3107 NULL, 0x0, NULL, HFILL}}
3110 static gint *ett[] = {
3116 &ett_bgp_attr_flags,
3118 &ett_bgp_mp_reach_nlri,
3119 &ett_bgp_mp_unreach_nlri,
3124 &ett_bgp_notification,
3125 &ett_bgp_route_refresh,
3126 &ett_bgp_capability,
3128 &ett_bgp_as_path_segments,
3129 &ett_bgp_communities,
3130 &ett_bgp_cluster_list,
3133 &ett_bgp_extended_communities,
3134 &ett_bgp_ext_com_flags,
3136 &ett_bgp_ssa_subtree,
3140 module_t *bgp_module;
3141 static enum_val_t asn_len[] = {
3142 {"auto-detect", "Auto-detect", 0},
3143 {"2", "2 octet", 2},
3144 {"4", "4 octet", 4},
3148 proto_bgp = proto_register_protocol("Border Gateway Protocol",
3150 proto_register_field_array(proto_bgp, hf, array_length(hf));
3151 proto_register_subtree_array(ett, array_length(ett));
3153 bgp_module = prefs_register_protocol(proto_bgp, NULL);
3154 prefs_register_bool_preference(bgp_module, "desegment",
3155 "Reassemble BGP messages spanning multiple TCP segments",
3156 "Whether the BGP dissector should reassemble messages spanning multiple TCP segments."
3157 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
3159 prefs_register_enum_preference(bgp_module, "asn_len",
3160 "Length of the AS number",
3161 "BGP dissector detect the length of the AS number in AS_PATH attributes automatically or manually (NOTE: Automatic detection is not 100% accurate)",
3162 &bgp_asn_len, asn_len, FALSE);
3166 proto_reg_handoff_bgp(void)
3168 dissector_handle_t bgp_handle;
3170 bgp_handle = create_dissector_handle(dissect_bgp, proto_bgp);
3171 dissector_add("tcp.port", BGP_TCP_PORT, bgp_handle);