2 * Routines for BGP packet dissection.
3 * Copyright 1999, Jun-ichiro itojun Hagino <itojun@itojun.org>
5 * $Id: packet-bgp.c,v 1.29 2000/12/25 05:28:40 itojun Exp $
8 * RFC1771 A Border Gateway Protocol 4 (BGP-4)
9 * RFC1965 Autonomous System Confederations for BGP
10 * RFC1997 BGP Communities Attribute
11 * RFC2796 BGP Route Reflection An alternative to full mesh IBGP
12 * RFC2842 Capabilities Advertisement with BGP-4
13 * RFC2858 Multiprotocol Extensions for BGP-4
14 * RFC2918 Route Refresh Capability for BGP-4
17 * Destination Preference Attribute for BGP (work in progress)
18 * RFC1863 A BGP/IDRP Route Server alternative to a full mesh routing
20 * Ethereal - Network traffic analyzer
21 * By Gerald Combs <gerald@zing.org>
22 * Copyright 1998 Gerald Combs
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License
26 * as published by the Free Software Foundation; either version 2
27 * of the License, or (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
46 #ifdef HAVE_SYS_TYPES_H
47 # include <sys/types.h>
50 #ifdef HAVE_NETINET_IN_H
51 # include <netinet/in.h>
54 #ifdef HAVE_ARPA_INET_H
55 #include <arpa/inet.h>
61 #ifdef NEED_SNPRINTF_H
62 # include "snprintf.h"
66 #include "packet-bgp.h"
67 #include "packet-ipv6.h"
69 static const value_string bgptypevals[] = {
70 { BGP_OPEN, "OPEN Message" },
71 { BGP_UPDATE, "UPDATE Message" },
72 { BGP_NOTIFICATION, "NOTIFICATION Message" },
73 { BGP_KEEPALIVE, "KEEPALIVE Message" },
74 { BGP_ROUTE_REFRESH, "ROUTE-REFRESH Message" },
78 static const value_string bgpnotify_major[] = {
79 { 1, "Message Header Error" },
80 { 2, "OPEN Message Error" },
81 { 3, "UPDATE Message Error" },
82 { 4, "Hold Timer Expired" },
83 { 5, "Finite State Machine 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" },
105 static const value_string bgpnotify_minor_3[] = {
106 { 1, "Malformed Attribute List" },
107 { 2, "Unrecognized Well-known Attribute" },
108 { 3, "Missing Well-known Attribute" },
109 { 4, "Attribute Flags Error" },
110 { 5, "Attribute Length Error" },
111 { 6, "Invalid ORIGIN Attribute" },
112 { 7, "AS Routing Loop" },
113 { 8, "Invalid NEXT_HOP Attribute" },
114 { 9, "Optional Attribute Error" },
115 { 10, "Invalid Network Field" },
116 { 11, "Malformed AS_PATH" },
120 static const value_string *bgpnotify_minor[] = {
121 NULL, bgpnotify_minor_1, bgpnotify_minor_2, bgpnotify_minor_3,
124 static const value_string bgpattr_origin[] = {
131 static const value_string as_segment_type[] = {
133 { 2, "AS_SEQUENCE" },
134 /* This is wrong according to the RFC... in the Zebra code they say that
135 cisco reversed it. Packet traces seem to agree. */
136 { 4, "AS_CONFED_SET" },
137 { 3, "AS_CONFED_SEQUENCE" },
141 static const value_string bgpattr_type[] = {
142 { BGPTYPE_ORIGIN, "ORIGIN" },
143 { BGPTYPE_AS_PATH, "AS_PATH" },
144 { BGPTYPE_NEXT_HOP, "NEXT_HOP" },
145 { BGPTYPE_MULTI_EXIT_DISC, "MULTI_EXIT_DISC" },
146 { BGPTYPE_LOCAL_PREF, "LOCAL_PREF" },
147 { BGPTYPE_ATOMIC_AGGREGATE, "ATOMIC_AGGREGATE" },
148 { BGPTYPE_AGGREGATOR, "AGGREGATOR" },
149 { BGPTYPE_COMMUNITIES, "COMMUNITIES" },
150 { BGPTYPE_ORIGINATOR_ID, "ORIGINATOR_ID" },
151 { BGPTYPE_CLUSTER_LIST, "CLUSTER_LIST" },
152 { BGPTYPE_MP_REACH_NLRI, "MP_REACH_NLRI" },
153 { BGPTYPE_MP_UNREACH_NLRI, "MP_UNREACH_NLRI" },
157 /* Subsequent address family identifier, RFC2283 section 7 */
158 static const value_string bgpattr_nlri_safi[] = {
162 { 3, "Unicast+Multicast" },
166 static const value_string afnumber[] = {
168 { AFNUM_INET, "IPv4" },
169 { AFNUM_INET6, "IPv6" },
170 { AFNUM_NSAP, "NSAP" },
171 { AFNUM_HDLC, "HDLC" },
172 { AFNUM_BBN1822, "BBN 1822" },
173 { AFNUM_802, "802" },
174 { AFNUM_E163, "E.163" },
175 { AFNUM_E164, "E.164" },
176 { AFNUM_F69, "F.69" },
177 { AFNUM_X121, "X.121" },
178 { AFNUM_IPX, "IPX" },
179 { AFNUM_ATALK, "Appletalk" },
180 { AFNUM_DECNET, "Decnet IV" },
181 { AFNUM_BANYAN, "Banyan Vines" },
182 { AFNUM_E164NSAP, "E.164 with NSAP subaddress" },
183 { 65535, "Reserved" },
187 static int proto_bgp = -1;
188 static int hf_bgp_type = -1;
190 static gint ett_bgp = -1;
191 static gint ett_bgp_unfeas = -1;
192 static gint ett_bgp_attrs = -1;
193 static gint ett_bgp_attr = -1;
194 static gint ett_bgp_attr_flags = -1;
195 static gint ett_bgp_mp_reach_nlri = -1;
196 static gint ett_bgp_mp_unreach_nlri = -1;
197 static gint ett_bgp_nlri = -1;
198 static gint ett_bgp_open = -1;
199 static gint ett_bgp_update = -1;
200 static gint ett_bgp_notification = -1;
201 static gint ett_bgp_route_refresh = -1; /* ROUTE-REFRESH message tree */
202 static gint ett_bgp_as_paths = -1;
203 static gint ett_bgp_communities = -1;
204 static gint ett_bgp_cluster_list = -1; /* cluster list tree */
205 static gint ett_bgp_options = -1; /* optional parameters tree */
206 static gint ett_bgp_option = -1; /* an optional parameter tree */
209 * Decode an IPv4 prefix.
212 decode_prefix4(const u_char *pd, char *buf, int buflen)
214 guint8 addr[4]; /* IP address */
215 int plen; /* prefix length */
216 int length; /* number of octets needed for prefix */
220 if (plen < 0 || 32 < plen)
222 length = (plen + 7) / 8;
225 memset(addr, 0, sizeof(addr));
226 memcpy(addr, &pd[1], length);
228 addr[length - 1] &= ((0xff00 >> (plen % 8)) & 0xff);
230 /* hand back a formatted string */
231 snprintf(buf, buflen, "%s/%d", ip_to_str(addr), plen);
236 * Decode an IPv6 prefix.
239 decode_prefix6(const u_char *pd, char *buf, int buflen)
241 struct e_in6_addr addr; /* IPv6 address */
242 int plen; /* prefix length */
243 int length; /* number of octets needed for prefix */
247 if (plen < 0 || 128 < plen)
249 length = (plen + 7) / 8;
252 memset(&addr, 0, sizeof(addr));
253 memcpy(&addr, &pd[1], length);
255 addr.s6_addr[length - 1] &= ((0xff00 >> (plen % 8)) & 0xff);
257 /* hand back a formatted string */
258 snprintf(buf, buflen, "%s/%d", ip6_to_str(&addr), plen);
263 * Dissect a BGP OPEN message.
266 dissect_bgp_open(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
268 struct bgp_open bgpo; /* BGP OPEN message */
269 int hlen; /* message length */
271 int ptype; /* parameter type */
272 int plen; /* parameter length */
273 int ctype; /* capability type */
274 int clen; /* capability length */
275 int ostart; /* options start */
276 const u_char *oend; /* options end */
277 const u_char *p; /* packet offset pointer */
278 proto_item *ti; /* tree item */
279 proto_tree *subtree; /* subtree for options */
280 proto_tree *subtree2; /* subtree for an option */
281 proto_tree *subtree3; /* subtree for an option */
283 /* snarf OPEN message */
284 memcpy(&bgpo, &pd[offset], sizeof(bgpo));
285 hlen = ntohs(bgpo.bgpo_len);
287 proto_tree_add_text(tree, NullTVB,
288 offset + offsetof(struct bgp_open, bgpo_version), 1,
289 "Version: %u", bgpo.bgpo_version);
290 proto_tree_add_text(tree, NullTVB,
291 offset + offsetof(struct bgp_open, bgpo_myas), 2,
292 "My AS: %u", ntohs(bgpo.bgpo_myas));
293 proto_tree_add_text(tree, NullTVB,
294 offset + offsetof(struct bgp_open, bgpo_holdtime), 2,
295 "Hold time: %u", ntohs(bgpo.bgpo_holdtime));
296 proto_tree_add_text(tree, NullTVB,
297 offset + offsetof(struct bgp_open, bgpo_id), 4,
298 "BGP identifier: %s", ip_to_str((guint8 *)&bgpo.bgpo_id));
299 proto_tree_add_text(tree, NullTVB,
300 offset + offsetof(struct bgp_open, bgpo_optlen), 1,
301 "Optional parameters length: %u %s", bgpo.bgpo_optlen,
302 (bgpo.bgpo_optlen == 1) ? "byte" : "bytes");
304 /* optional parameters */
305 if (bgpo.bgpo_optlen > 0) {
306 /* add a subtree and setup some offsets */
307 ostart = offset + sizeof(bgpo) - 3;
308 ti = proto_tree_add_text(tree, NullTVB, ostart, bgpo.bgpo_optlen,
309 "Optional parameters");
310 subtree = proto_item_add_subtree(ti, ett_bgp_options);
312 oend = p + bgpo.bgpo_optlen;
314 /* step through all of the optional parameters */
317 /* grab the type and length */
323 case BGP_OPTION_AUTHENTICATION:
324 proto_tree_add_text(subtree, NullTVB, p - pd - 2, 2 + plen,
325 "Authentication information (%u %s)", plen,
326 (plen == 1) ? "byte" : "bytes");
328 case BGP_OPTION_CAPABILITY:
329 /* grab the capability code */
333 /* check the capability type */
335 case BGP_CAPABILITY_RESERVED:
336 ti = proto_tree_add_text(subtree, NullTVB, p - pd - 4,
337 2 + plen, "Reserved capability (%u %s)", 2 + plen,
338 (plen == 1) ? "byte" : "bytes");
339 subtree2 = proto_item_add_subtree(ti, ett_bgp_option);
340 proto_tree_add_text(subtree2, NullTVB, p - pd - 4,
341 1, "Parameter type: Capabilities (2)");
342 proto_tree_add_text(subtree2, NullTVB, p - pd - 3,
343 1, "Parameter length: %u %s", plen,
344 (plen == 1) ? "byte" : "bytes");
345 proto_tree_add_text(subtree2, NullTVB, p - pd - 2,
346 1, "Capability code: Reserved (0)");
347 proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
348 1, "Capability length: %u %s", clen,
349 (clen == 1) ? "byte" : "bytes");
351 proto_tree_add_text(subtree2, NullTVB, p - pd,
352 clen, "Capability value: Unknown");
356 case BGP_CAPABILITY_MULTIPROTOCOL:
357 ti = proto_tree_add_text(subtree, NullTVB, p - pd - 4,
359 "Multiprotocol extensions capability (%u %s)",
360 2 + plen, (plen == 1) ? "byte" : "bytes");
361 subtree2 = proto_item_add_subtree(ti, ett_bgp_option);
362 proto_tree_add_text(subtree2, NullTVB, p - pd - 4,
363 1, "Parameter type: Capabilities (2)");
364 proto_tree_add_text(subtree2, NullTVB, p - pd - 3,
365 1, "Parameter length: %u %s", plen,
366 (plen == 1) ? "byte" : "bytes");
367 proto_tree_add_text(subtree2, NullTVB, p - pd - 2,
368 1, "Capability code: Multiprotocol extensions (%d)",
371 proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
372 1, "Capability length: Invalid");
373 proto_tree_add_text(subtree2, NullTVB, p - pd,
374 clen, "Capability value: Unknown");
377 proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
378 1, "Capability length: %u %s", clen,
379 (clen == 1) ? "byte" : "bytes");
380 ti = proto_tree_add_text(subtree2, NullTVB, p - pd,
381 clen, "Capability value");
382 subtree3 = proto_item_add_subtree(ti,
386 proto_tree_add_text(subtree3, NullTVB, p - pd,
387 2, "Address family identifier: %s (%u)",
388 val_to_str(i, afnumber, "Unknown"), i);
391 proto_tree_add_text(subtree3, NullTVB, p - pd,
392 1, "Reserved: 1 byte");
396 proto_tree_add_text(subtree3, NullTVB, p - pd,
397 1, "Subsequent address family identifier: %s (%u)",
398 val_to_str(i, bgpattr_nlri_safi,
399 i >= 128 ? "Vendor specific" : "Unknown"), i);
403 case BGP_CAPABILITY_ROUTE_REFRESH:
404 ti = proto_tree_add_text(subtree, NullTVB, p - pd - 4,
405 2 + plen, "Route refresh capability (%u %s)", 2 + plen,
406 (plen == 1) ? "byte" : "bytes");
407 subtree2 = proto_item_add_subtree(ti, ett_bgp_option);
408 proto_tree_add_text(subtree2, NullTVB, p - pd - 4,
409 1, "Parameter type: Capabilities (2)");
410 proto_tree_add_text(subtree2, NullTVB, p - pd - 3,
411 1, "Parameter length: %u %s", plen,
412 (plen == 1) ? "byte" : "bytes");
413 proto_tree_add_text(subtree2, NullTVB, p - pd - 2,
414 1, "Capability code: Route refresh (%d)", ctype);
416 proto_tree_add_text(subtree2, NullTVB, p - pd,
417 clen, "Capability value: Invalid");
420 proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
421 1, "Capability length: %u %s", clen,
422 (clen == 1) ? "byte" : "bytes");
426 /* unknown capability */
428 ti = proto_tree_add_text(subtree, NullTVB, p - pd - 4,
429 2 + plen, "Unknown capability (%u %s)", 2 + plen,
430 (plen == 1) ? "byte" : "bytes");
431 subtree2 = proto_item_add_subtree(ti, ett_bgp_option);
432 proto_tree_add_text(subtree2, NullTVB, p - pd - 4,
433 1, "Parameter type: Capabilities (2)");
434 proto_tree_add_text(subtree2, NullTVB, p - pd - 3,
435 1, "Parameter length: %u %s", plen,
436 (plen == 1) ? "byte" : "bytes");
437 proto_tree_add_text(subtree2, NullTVB, p - pd - 2,
438 1, "Capability code: %s (%d)",
439 ctype >= 128 ? "Private use" : "Unknown", ctype);
440 proto_tree_add_text(subtree2, NullTVB, p - pd - 1,
441 1, "Capability length: %u %s", clen,
442 (clen == 1) ? "byte" : "bytes");
444 proto_tree_add_text(subtree2, NullTVB, p - pd,
445 clen, "Capability value: Unknown");
452 proto_tree_add_text(subtree, NullTVB, p - pd - 2, 2 + plen,
453 "Unknown optional parameter");
461 * Dissect a BGP UPDATE message.
464 dissect_bgp_update(const u_char *pd, int offset, frame_data *fd,
467 struct bgp bgp; /* BGP header */
468 struct bgp_attr bgpa; /* path attributes */
469 int hlen; /* message length */
470 const u_char *p; /* packet offset pointer */
471 const u_char *q; /* tmp */
472 const u_char *end; /* message end */
474 proto_item *ti; /* tree item */
475 proto_tree *subtree; /* subtree for attibutes */
476 proto_tree *subtree2; /* subtree for attibutes */
477 proto_tree *subtree3; /* subtree for attibutes */
478 proto_tree *as_paths_tree; /* subtree for AS_PATHs */
479 proto_tree *as_path_tree; /* subtree for AS_PATH */
480 proto_tree *communities_tree; /* subtree for COMMUNITIES */
481 proto_tree *community_tree; /* subtree for a community */
482 proto_tree *cluster_list_tree; /* subtree for CLUSTER_LIST */
484 guint8 length; /* AS_PATH length */
485 guint8 type; /* AS_PATH type */
486 char *as_path_str = NULL; /* AS_PATH string */
487 char *communities_str = NULL; /* COMMUNITIES string */
488 char *cluster_list_str = NULL; /* CLUSTER_LIST string */
489 char junk_buf[256]; /* tmp */
492 /* snarf UPDATE message */
493 memcpy(&bgp, &pd[offset], sizeof(bgp));
494 hlen = ntohs(bgp.bgp_len);
495 p = &pd[offset + BGP_HEADER_SIZE]; /*XXX*/
497 /* check for withdrawals */
499 proto_tree_add_text(tree, NullTVB, p - pd, 2,
500 "Unfeasible routes length: %u %s", len, (len == 1) ? "byte" : "bytes");
503 /* parse unfeasible prefixes */
505 ti = proto_tree_add_text(tree, NullTVB, p - pd, len, "Withdrawn routes:");
506 subtree = proto_item_add_subtree(ti, ett_bgp_unfeas);
508 /* parse each prefixes */
511 i = decode_prefix4(p, junk_buf, sizeof(junk_buf));
512 proto_tree_add_text(subtree, NullTVB, p - pd, i, "%s", junk_buf);
520 /* check for advertisements */
522 proto_tree_add_text(tree, NullTVB, p - pd, 2, "Total path attribute length: %u %s",
523 len, (len == 1) ? "byte" : "bytes");
525 /* path attributes */
527 ti = proto_tree_add_text(tree, NullTVB, p - pd + 2, len, "Path attributes");
528 subtree = proto_item_add_subtree(ti, ett_bgp_attrs);
536 memcpy(&bgpa, &p[i], sizeof(bgpa));
537 /* check for the Extended Length bit */
538 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_EXTENDED_LENGTH) {
539 alen = pntohs(&p[i + sizeof(bgpa)]);
540 aoff = sizeof(bgpa) + 2;
542 alen = p[i + sizeof(bgpa)];
543 aoff = sizeof(bgpa) + 1;
546 /* This is kind of ugly - similar code appears twice, but it
547 helps browsing attrs. */
548 /* the first switch prints things in the title of the subtree */
549 switch (bgpa.bgpa_type) {
552 goto default_attribute_top;
553 msg = val_to_str(p[i + aoff], bgpattr_origin, "Unknown");
554 ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
556 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
557 msg, alen + aoff, (alen + aoff == 1) ? "byte" :
560 case BGPTYPE_AS_PATH:
562 (p + current attribute + 3 bytes to first tuple) */
563 end = p + alen + i + 3;
565 /* must be freed by second switch! */
566 /* "alen * 6" (5 digits + space) should be a good estimate
567 of how long the AS path string could be */
568 as_path_str = malloc((alen + 1) * 6);
569 if (as_path_str == NULL) break;
570 as_path_str[0] = '\0';
572 /* snarf each AS path */
575 if (type == AS_SET) {
576 snprintf(as_path_str, 2, "{");
578 else if (type == AS_CONFED_SET) {
579 snprintf(as_path_str, 2, "[");
581 else if (type == AS_CONFED_SEQUENCE) {
582 snprintf(as_path_str, 2, "(");
586 /* snarf each value in path */
587 for (j = 0; j < length; j++) {
588 snprintf(junk_buf, sizeof(junk_buf), "%u%s", pntohs(q),
589 (type == AS_SET || type == AS_CONFED_SET)
591 strncat(as_path_str, junk_buf, sizeof(junk_buf));
595 /* cleanup end of string */
596 if (type == AS_SET) {
597 as_path_str[strlen(as_path_str) - 2] = '}';
599 else if (type == AS_CONFED_SET) {
600 as_path_str[strlen(as_path_str) - 2] = ']';
602 else if (type == AS_CONFED_SEQUENCE) {
603 as_path_str[strlen(as_path_str) - 1] = ')';
606 as_path_str[strlen(as_path_str) - 1] = '\0';
610 /* check for empty AS_PATH */
612 strncpy(as_path_str, "empty", 6);
614 ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
616 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
617 as_path_str, alen + aoff,
618 (alen + aoff == 1) ? "byte" : "bytes");
620 case BGPTYPE_NEXT_HOP:
622 goto default_attribute_top;
623 ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
625 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
626 ip_to_str(&p[i + aoff]), alen + aoff, (alen + aoff == 1)
629 case BGPTYPE_MULTI_EXIT_DISC:
631 goto default_attribute_top;
632 ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
634 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
635 pntohl(&p[i + aoff]), alen + aoff,
636 (alen + aoff == 1) ? "byte" : "bytes");
638 case BGPTYPE_LOCAL_PREF:
640 goto default_attribute_top;
641 ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
643 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
644 pntohl(&p[i + aoff]), alen + aoff,
645 (alen + aoff == 1) ? "byte" : "bytes");
647 case BGPTYPE_ATOMIC_AGGREGATE:
649 goto default_attribute_top;
650 ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
652 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
653 alen + aoff, (alen + aoff == 1) ? "byte" : "bytes");
655 case BGPTYPE_AGGREGATOR:
657 goto default_attribute_top;
658 ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
659 "%s: AS: %u origin: %s (%u %s)",
660 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
661 pntohs(&p[i + aoff]),
662 ip_to_str(&p[i + aoff + 2]), alen + aoff,
663 (alen + aoff == 1) ? "byte" : "bytes");
665 case BGPTYPE_COMMUNITIES:
667 goto default_attribute_top;
670 (p + current attribute + 3 bytes to first tuple) */
671 end = p + alen + i + 3;
673 /* must be freed by second switch! */
674 /* "alen * 12" (5 digits, a :, 5 digits + space ) should be
675 a good estimate of how long the communities string could
677 communities_str = malloc((alen + 1) * 12);
678 if (communities_str == NULL) break;
679 communities_str[0] = '\0';
680 memset(junk_buf, 0, sizeof(junk_buf));
682 /* snarf each community */
684 /* check for well-known communities */
685 if (pntohl(q) == BGP_COMM_NO_EXPORT)
686 strncpy(junk_buf, "NO_EXPORT ", 10);
687 else if (pntohl(q) == BGP_COMM_NO_ADVERTISE)
688 strncpy(junk_buf, "NO_ADVERTISE ", 13);
689 else if (pntohl(q) == BGP_COMM_NO_EXPORT_SUBCONFED)
690 strncpy(junk_buf, "NO_EXPORT_SUBCONFED ", 20);
692 snprintf(junk_buf, sizeof(junk_buf), "%u:%u ",
698 strncat(communities_str, junk_buf, sizeof(junk_buf));
700 /* cleanup end of string */
701 communities_str[strlen(communities_str) - 1] = '\0';
703 ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
705 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
706 communities_str, alen + aoff,
707 (alen + aoff == 1) ? "byte" : "bytes");
709 case BGPTYPE_ORIGINATOR_ID:
711 goto default_attribute_top;
712 ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
714 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
715 ip_to_str(&p[i + aoff]), alen + aoff, (alen + aoff == 1)
718 case BGPTYPE_CLUSTER_LIST:
720 goto default_attribute_top;
723 (p + current attribute + 3 bytes to first tuple) */
724 end = p + alen + i + 3;
726 /* must be freed by second switch! */
727 /* "alen * 16" (12 digits, 3 dots + space ) should be
728 a good estimate of how long the cluster_list string could
730 cluster_list_str = malloc((alen + 1) * 16);
731 if (cluster_list_str == NULL) break;
732 cluster_list_str[0] = '\0';
733 memset(junk_buf, 0, sizeof(junk_buf));
735 /* snarf each cluster list */
737 snprintf(junk_buf, sizeof(junk_buf), "%s ", ip_to_str(q));
738 strncat(cluster_list_str, junk_buf, sizeof(junk_buf));
741 /* cleanup end of string */
742 cluster_list_str[strlen(cluster_list_str) - 1] = '\0';
744 ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
746 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
747 cluster_list_str, alen + aoff,
748 (alen + aoff == 1) ? "byte" : "bytes");
751 default_attribute_top:
752 ti = proto_tree_add_text(subtree, NullTVB, p - pd + i, alen + aoff,
754 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
755 alen + aoff, (alen + aoff == 1) ? "byte" : "bytes");
756 } /* end of first switch */
757 subtree2 = proto_item_add_subtree(ti, ett_bgp_attr);
759 /* figure out flags */
761 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_OPTIONAL) {
762 strncat(junk_buf, "Optional, ", 10);
765 strncat(junk_buf, "Well-known, ", 12);
767 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_TRANSITIVE) {
768 strncat(junk_buf, "Transitive, ", 12);
771 strncat(junk_buf, "Non-transitive, ", 16);
773 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_PARTIAL) {
774 strncat(junk_buf, "Partial, ", 9);
777 strncat(junk_buf, "Complete, ", 10);
779 if (bgpa.bgpa_flags & BGP_ATTR_FLAG_EXTENDED_LENGTH) {
780 strncat(junk_buf, "Extended Length, ", 17);
782 /* stomp last ", " */
783 j = strlen(junk_buf);
784 junk_buf[j - 2] = '\0';
785 ti = proto_tree_add_text(subtree2, NullTVB,
786 p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
787 "Flags: 0x%02x (%s)", bgpa.bgpa_flags, junk_buf);
788 subtree3 = proto_item_add_subtree(ti, ett_bgp_attr_flags);
790 /* add flag bitfield subtrees */
791 proto_tree_add_text(subtree3, NullTVB,
792 p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
793 "%s", decode_boolean_bitfield(bgpa.bgpa_flags,
794 BGP_ATTR_FLAG_OPTIONAL, 8, "Optional", "Well-known"));
795 proto_tree_add_text(subtree3, NullTVB,
796 p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
797 "%s", decode_boolean_bitfield(bgpa.bgpa_flags,
798 BGP_ATTR_FLAG_TRANSITIVE, 8, "Transitive",
800 proto_tree_add_text(subtree3, NullTVB,
801 p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
802 "%s", decode_boolean_bitfield(bgpa.bgpa_flags,
803 BGP_ATTR_FLAG_PARTIAL, 8, "Partial", "Complete"));
804 proto_tree_add_text(subtree3, NullTVB,
805 p - pd + i + offsetof(struct bgp_attr, bgpa_flags), 1,
806 "%s", decode_boolean_bitfield(bgpa.bgpa_flags,
807 BGP_ATTR_FLAG_EXTENDED_LENGTH, 8, "Extended length",
810 proto_tree_add_text(subtree2, NullTVB,
811 p - pd + i + offsetof(struct bgp_attr, bgpa_type), 1,
812 "Type code: %s (%u)",
813 val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
816 proto_tree_add_text(subtree2, NullTVB, p - pd + i + sizeof(bgpa),
817 aoff - sizeof(bgpa), "Length: %d %s", alen,
818 (alen == 1) ? "byte" : "bytes");
820 /* the second switch prints things in the actual subtree of each
822 switch (bgpa.bgpa_type) {
825 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
826 "Origin (invalid): %u %s", alen,
827 (alen == 1) ? "byte" : "bytes");
829 msg = val_to_str(p[i + aoff], bgpattr_origin, "Unknown");
830 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 1,
831 "Origin: %s (%u)", msg, p[i + aoff]);
834 case BGPTYPE_AS_PATH:
835 /* check for empty AS_PATH */
841 ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
842 "AS path: %s", as_path_str);
843 as_paths_tree = proto_item_add_subtree(ti, ett_bgp_as_paths);
846 (p + current attribute + 3 bytes to first tuple) */
847 end = p + alen + i + 3;
850 /* snarf each AS path tuple, we have to step through each one
851 again to make a separate subtree so we can't just reuse
852 as_path_str from above */
854 as_path_str[0] = '\0';
856 if (type == AS_SET) {
857 snprintf(as_path_str, 2, "{");
859 else if (type == AS_CONFED_SET) {
860 snprintf(as_path_str, 2, "[");
862 else if (type == AS_CONFED_SEQUENCE) {
863 snprintf(as_path_str, 2, "(");
867 /* snarf each value in path, we're just going to reuse
868 as_path_str since we already have it malloced */
869 for (j = 0; j < length; j++) {
870 snprintf(junk_buf, sizeof(junk_buf), "%u%s", pntohs(q),
871 (type == AS_SET || type == AS_CONFED_SET)
873 strncat(as_path_str, junk_buf, sizeof(junk_buf));
877 /* cleanup end of string */
878 if (type == AS_SET) {
879 as_path_str[strlen(as_path_str) - 2] = '}';
881 else if (type == AS_CONFED_SET) {
882 as_path_str[strlen(as_path_str) - 2] = ']';
884 else if (type == AS_CONFED_SEQUENCE) {
885 as_path_str[strlen(as_path_str) - 1] = ')';
888 as_path_str[strlen(as_path_str) - 1] = '\0';
891 /* length here means number of ASs, ie length * 2 bytes */
892 ti = proto_tree_add_text(as_paths_tree, NullTVB,
893 q - pd - length * 2 - 2,
894 length * 2 + 2, "AS path segment: %s", as_path_str);
895 as_path_tree = proto_item_add_subtree(ti, ett_bgp_as_paths);
896 proto_tree_add_text(as_path_tree, NullTVB, q - pd - length * 2 - 2,
897 1, "Path segment type: %s (%u)",
898 val_to_str(type, as_segment_type, "Unknown"), type);
899 proto_tree_add_text(as_path_tree, NullTVB, q - pd - length * 2 - 1,
900 1, "Path segment length: %u %s", length,
901 (length == 1) ? "AS" : "ASs");
903 /* backup and reprint path segment value(s) only */
905 as_path_str[0] = '\0';
906 for (j = 0; j < length; j++) {
907 snprintf(junk_buf, sizeof(junk_buf), "%u ", pntohs(q));
908 strncat(as_path_str, junk_buf, sizeof(junk_buf));
911 as_path_str[strlen(as_path_str) - 1] = '\0';
913 proto_tree_add_text(as_path_tree, NullTVB, q - pd - length * 2,
914 length * 2, "Path segment value: %s", as_path_str);
919 case BGPTYPE_NEXT_HOP:
921 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
922 "Next hop (invalid): %u %s", alen,
923 (alen == 1) ? "byte" : "bytes");
925 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
926 "Next hop: %s", ip_to_str(&p[i + aoff]));
929 case BGPTYPE_MULTI_EXIT_DISC:
931 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
932 "Multiple exit discriminator (invalid): %u %s",
933 alen, (alen == 1) ? "byte" : "bytes");
935 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
936 "Multiple exit discriminator: %u",
937 pntohl(&p[i + aoff]));
940 case BGPTYPE_LOCAL_PREF:
942 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
943 "Local preference (invalid): %u %s", alen,
944 (alen == 1) ? "byte" : "bytes");
946 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
947 "Local preference: %u", pntohl(&p[i + aoff]));
950 case BGPTYPE_ATOMIC_AGGREGATE:
952 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
953 "Atomic aggregate (invalid): %u %s", alen,
954 (alen == 1) ? "byte" : "bytes");
957 case BGPTYPE_AGGREGATOR:
959 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
960 "Aggregator (invalid): %u %s", alen,
961 (alen == 1) ? "byte" : "bytes");
963 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 2,
964 "Aggregator AS: %u", pntohs(&p[i + aoff]));
965 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 2, 4,
966 "Aggregator origin: %s",
967 ip_to_str(&p[i + aoff + 2]));
970 case BGPTYPE_COMMUNITIES:
972 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
973 "Communities (invalid): %u %s", alen,
974 (alen == 1) ? "byte" : "bytes");
975 free(communities_str);
979 ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
980 "Communities: %s", communities_str);
981 communities_tree = proto_item_add_subtree(ti,
982 ett_bgp_communities);
985 (p + current attribute + 3 bytes to first tuple) */
986 end = p + alen + i + 3;
989 /* snarf each community */
991 /* check for reserved values */
992 if (pntohs(q) == FOURHEX0 || pntohs(q) == FOURHEXF) {
993 /* check for well-known communities */
994 if (pntohl(q) == BGP_COMM_NO_EXPORT)
995 proto_tree_add_text(communities_tree, NullTVB,
996 q - pd - 3 + aoff, 4,
997 "Community: NO_EXPORT (0x%x)", pntohl(q));
998 else if (pntohl(q) == BGP_COMM_NO_ADVERTISE)
999 proto_tree_add_text(communities_tree, NullTVB,
1000 q - pd - 3 + aoff, 4,
1001 "Community: NO_ADVERTISE (0x%x)", pntohl(q));
1002 else if (pntohl(q) == BGP_COMM_NO_EXPORT_SUBCONFED)
1003 proto_tree_add_text(communities_tree, NullTVB,
1004 q - pd - 3 + aoff, 4,
1005 "Community: NO_EXPORT_SUBCONFED (0x%x)",
1008 proto_tree_add_text(communities_tree, NullTVB,
1009 q - pd - 3 + aoff, 4,
1010 "Community (reserved): 0x%x", pntohl(q));
1014 ti = proto_tree_add_text(communities_tree, NullTVB,
1015 q - pd - 3 + aoff, 4, "Community: %u:%u",
1016 pntohs(q), pntohs(q + 2));
1017 community_tree = proto_item_add_subtree(ti,
1018 ett_bgp_communities);
1019 proto_tree_add_text(community_tree, NullTVB, q - pd - 3 + aoff,
1020 2, "Community AS: %u", pntohs(q));
1021 proto_tree_add_text(community_tree, NullTVB, q - pd - 1 + aoff,
1022 2, "Community value: %u", pntohs(q + 2));
1028 free(communities_str);
1030 case BGPTYPE_ORIGINATOR_ID:
1032 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
1033 "Originator identifier (invalid): %u %s", alen,
1034 (alen == 1) ? "byte" : "bytes");
1036 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
1037 "Originator identifier: %s",
1038 ip_to_str(&p[i + aoff]));
1041 case BGPTYPE_MP_REACH_NLRI:
1042 af = pntohs(&p[i + aoff]);
1043 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 2,
1044 "Address family: %s (%u)",
1045 val_to_str(af, afnumber, "Unknown"), af);
1046 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 2, 1,
1047 "Subsequent address family identifier: %s (%u)",
1048 val_to_str(p[i + aoff + 2], bgpattr_nlri_safi,
1049 p[i + aoff + 2] >= 128 ? "Vendor specific" : "Unknown"),
1051 ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 3, 1,
1052 "Next hop network address (%d %s)",
1053 p[i + aoff + 3], (p[i + aoff + 3] == 1) ? "byte" :
1055 if (af == AFNUM_INET || af == AFNUM_INET6) {
1059 subtree3 = proto_item_add_subtree(ti,
1060 ett_bgp_mp_reach_nlri);
1063 while (j < p[i + aoff + 3]) {
1064 if (af == AFNUM_INET)
1066 else if (af == AFNUM_INET6)
1070 if (j + advance > p[i + aoff + 3])
1073 if (af == AFNUM_INET)
1074 s = ip_to_str(&p[i + aoff + 4 + j]);
1076 s = ip6_to_str((struct e_in6_addr *)
1077 &p[i + aoff + 4 + j]);
1079 proto_tree_add_text(subtree3, NullTVB,
1080 p - pd + i + aoff + 4 + j, advance,
1086 alen -= (p[i + aoff + 3] + 4);
1087 aoff += (p[i + aoff + 3] + 4);
1090 ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 1,
1091 "Subnetwork points of attachment: %u", snpa);
1094 subtree3 = proto_item_add_subtree(ti,
1095 ett_bgp_mp_reach_nlri);
1096 for (/*nothing*/; snpa > 0; snpa--) {
1097 proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff + off, 1,
1098 "SNPA length: %u", p[i + aoff + off]);
1100 proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff + off,
1101 p[i + aoff + off - 1],
1102 "SNPA (%u %s)", p[i + aoff + off - 1],
1103 (p[i + aoff + off - 1] == 1) ? "byte" : "bytes");
1104 off += p[i + aoff + off - 1];
1109 ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
1110 "Network layer reachability information (%u %s)",
1111 alen, (alen == 1) ? "byte" : "bytes");
1113 subtree3 = proto_item_add_subtree(ti,
1114 ett_bgp_mp_unreach_nlri);
1119 if (af == AFNUM_INET) {
1120 advance = decode_prefix4(&p[i + aoff], buf,
1122 } else if (af == AFNUM_INET6) {
1123 advance = decode_prefix6(&p[i + aoff], buf,
1131 proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff, advance,
1132 "Network layer reachability information: %s", buf);
1139 case BGPTYPE_MP_UNREACH_NLRI:
1140 af = pntohs(&p[i + aoff]);
1141 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, 2,
1142 "Address family: %s (%u)",
1143 val_to_str(af, afnumber, "Unknown"), af);
1144 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 2, 1,
1145 "Subsequent address family identifier: %s (%u)",
1146 val_to_str(p[i + aoff + 2], bgpattr_nlri_safi,
1147 p[i + aoff + 2] >= 128 ? "Vendor specific" : "Unknown"),
1149 ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff + 3,
1150 alen - 3, "Withdrawn routes (%u %s)", alen - 3,
1151 (alen - 3 == 1) ? "byte" : "bytes");
1156 subtree3 = proto_item_add_subtree(ti,
1157 ett_bgp_mp_unreach_nlri);
1162 if (af == AFNUM_INET) {
1163 advance = decode_prefix4(&p[i + aoff], buf,
1165 } else if (af == AFNUM_INET6) {
1166 advance = decode_prefix6(&p[i + aoff], buf,
1174 proto_tree_add_text(subtree3, NullTVB, p - pd + i + aoff, advance,
1175 "Withdrawn route: %s", buf);
1182 case BGPTYPE_CLUSTER_LIST:
1183 if (alen % 4 != 0) {
1184 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
1185 "Cluster list (invalid): %u %s", alen,
1186 (alen == 1) ? "byte" : "bytes");
1187 free(cluster_list_str);
1191 ti = proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
1192 "Cluster list: %s", cluster_list_str);
1193 cluster_list_tree = proto_item_add_subtree(ti,
1194 ett_bgp_cluster_list);
1197 (p + current attribute + 3 bytes to first tuple) */
1198 end = p + alen + i + 3;
1201 /* snarf each cluster identifier */
1203 ti = proto_tree_add_text(cluster_list_tree, NullTVB,
1204 q - pd - 3 + aoff, 4, "Cluster identifier: %s",
1210 free(cluster_list_str);
1213 proto_tree_add_text(subtree2, NullTVB, p - pd + i + aoff, alen,
1214 "Unknown (%d %s)", alen, (alen == 1) ? "byte" :
1217 } /* end of second switch */
1224 len = hlen - (p - &pd[offset]);
1226 /* parse prefixes */
1228 ti = proto_tree_add_text(tree, NullTVB, p - pd, len,
1229 "Network layer reachability information: %u %s", len,
1230 (len == 1) ? "byte" : "bytes");
1231 subtree = proto_item_add_subtree(ti, ett_bgp_nlri);
1234 i = decode_prefix4(p, junk_buf, sizeof(junk_buf));
1235 proto_tree_add_text(subtree, NullTVB, p - pd, i, "%s", junk_buf);
1243 * Dissect a BGP NOTIFICATION message.
1246 dissect_bgp_notification(const u_char *pd, int offset, frame_data *fd,
1249 struct bgp_notification bgpn; /* BGP NOTIFICATION message */
1250 int hlen; /* message length */
1251 char *p; /* string pointer */
1254 memcpy(&bgpn, &pd[offset], sizeof(bgpn));
1255 hlen = ntohs(bgpn.bgpn_len);
1257 /* print error code */
1258 proto_tree_add_text(tree, NullTVB,
1259 offset + offsetof(struct bgp_notification, bgpn_major), 1,
1260 "Error code: %s (%u)",
1261 val_to_str(bgpn.bgpn_major, bgpnotify_major, "Unknown"),
1264 /* print error subcode */
1265 if (bgpn.bgpn_major < array_length(bgpnotify_minor)
1266 && bgpnotify_minor[bgpn.bgpn_major] != NULL) {
1267 p = val_to_str(bgpn.bgpn_minor, bgpnotify_minor[bgpn.bgpn_major],
1269 } else if (bgpn.bgpn_minor == 0)
1273 proto_tree_add_text(tree, NullTVB,
1274 offset + offsetof(struct bgp_notification, bgpn_minor), 1,
1275 "Error subcode: %s (%u)", p, bgpn.bgpn_minor);
1277 /* only print if there is optional data */
1278 if (hlen > BGP_MIN_NOTIFICATION_MSG_SIZE) {
1279 proto_tree_add_text(tree, NullTVB, offset + BGP_MIN_NOTIFICATION_MSG_SIZE,
1280 hlen - BGP_MIN_NOTIFICATION_MSG_SIZE, "Data");
1285 * Dissect a BGP ROUTE-REFRESH message.
1288 dissect_bgp_route_refresh(const u_char *pd, int offset, frame_data *fd,
1291 const u_char *p; /* string pointer */
1295 p = &pd[offset + BGP_HEADER_SIZE];
1297 proto_tree_add_text(tree, NullTVB, offset + BGP_HEADER_SIZE, 2,
1298 "Address family identifier: %s (%u)",
1299 val_to_str(i, afnumber, "Unknown"), i);
1302 proto_tree_add_text(tree, NullTVB, offset + BGP_HEADER_SIZE + 2, 1,
1303 "Reserved: 1 byte");
1307 proto_tree_add_text(tree, NullTVB, offset + BGP_HEADER_SIZE + 3, 1,
1308 "Subsequent address family identifier: %s (%u)",
1309 val_to_str(i, bgpattr_nlri_safi,
1310 i >= 128 ? "Vendor specific" : "Unknown"),
1315 * Dissect a BGP packet.
1318 dissect_bgp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
1320 proto_item *ti; /* tree item */
1321 proto_tree *bgp_tree; /* BGP packet tree */
1322 proto_tree *bgp1_tree; /* BGP message tree */
1323 const u_char *p; /* packet offset pointer */
1325 int found; /* number of BGP messages in packet */
1326 static u_char marker[] = { /* BGP message marker */
1327 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1328 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1330 struct bgp bgp; /* BGP header */
1331 int hlen; /* BGP header length */
1332 char *typ; /* BGP message type */
1334 OLD_CHECK_DISPLAY_AS_DATA(proto_bgp, pd, offset, fd, tree);
1336 if (check_col(fd, COL_PROTOCOL))
1337 col_set_str(fd, COL_PROTOCOL, "BGP");
1343 /* run through the TCP packet looking for BGP headers */
1344 /* this is done twice, but this way each message type can be
1345 printed in the COL_INFO field */
1347 /* look for bgp header */
1352 CHECK_SIZE(i, sizeof(marker), l);
1353 if (memcmp(&p[i], marker, sizeof(marker)) != 0) {
1358 memcpy(&bgp, &p[i], sizeof(bgp));
1360 hlen = ntohs(bgp.bgp_len);
1361 typ = val_to_str(bgp.bgp_type, bgptypevals, "Unknown Message");
1363 if (check_col(fd, COL_INFO)) {
1365 col_add_fstr(fd, COL_INFO, "%s", typ);
1367 col_append_fstr(fd, COL_INFO, ", %s", typ);
1374 ti = proto_tree_add_item(tree, proto_bgp, NullTVB, offset,
1375 END_OF_FRAME, FALSE);
1376 bgp_tree = proto_item_add_subtree(ti, ett_bgp);
1381 /* now, run through the TCP packet again, this time dissect */
1382 /* each message that we find */
1384 /* look for bgp header */
1389 CHECK_SIZE(i, sizeof(marker), l);
1390 if (memcmp(&p[i], marker, sizeof(marker)) != 0) {
1395 memcpy(&bgp, &p[i], sizeof(bgp));
1396 hlen = ntohs(bgp.bgp_len);
1397 typ = val_to_str(bgp.bgp_type, bgptypevals, "Unknown Message");
1398 if (END_OF_FRAME < hlen) {
1399 ti = proto_tree_add_text(bgp_tree, NullTVB, offset + i,
1400 END_OF_FRAME, "%s (truncated)", typ);
1402 ti = proto_tree_add_text(bgp_tree, NullTVB, offset + i, hlen,
1405 /* add a different tree for each message type */
1406 switch (bgp.bgp_type) {
1408 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_open);
1411 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_update);
1413 case BGP_NOTIFICATION:
1414 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_notification);
1417 bgp1_tree = proto_item_add_subtree(ti, ett_bgp);
1419 case BGP_ROUTE_REFRESH:
1420 bgp1_tree = proto_item_add_subtree(ti, ett_bgp_route_refresh);
1423 bgp1_tree = proto_item_add_subtree(ti, ett_bgp);
1427 proto_tree_add_text(bgp1_tree, NullTVB, offset + i, BGP_MARKER_SIZE,
1428 "Marker: 16 bytes");
1430 if (hlen < BGP_HEADER_SIZE || hlen > BGP_MAX_PACKET_SIZE) {
1431 proto_tree_add_text(bgp1_tree, NullTVB,
1432 offset + i + offsetof(struct bgp, bgp_len), 2,
1433 "Length (invalid): %u %s", hlen,
1434 (hlen == 1) ? "byte" : "bytes");
1436 proto_tree_add_text(bgp1_tree, NullTVB,
1437 offset + i + offsetof(struct bgp, bgp_len), 2,
1438 "Length: %u %s", hlen,
1439 (hlen == 1) ? "byte" : "bytes");
1442 proto_tree_add_uint_format(bgp1_tree, hf_bgp_type, NullTVB,
1444 offsetof(struct bgp, bgp_type), 1,
1446 "Type: %s (%u)", typ, bgp.bgp_type);
1448 CHECK_SIZE(i, hlen, l);
1450 /* handle each message type */
1451 switch (bgp.bgp_type) {
1453 dissect_bgp_open(pd, offset + i, fd, bgp1_tree);
1456 dissect_bgp_update(pd, offset + i, fd, bgp1_tree);
1458 case BGP_NOTIFICATION:
1459 dissect_bgp_notification(pd, offset + i, fd, bgp1_tree);
1462 /* no data in KEEPALIVE messages */
1464 case BGP_ROUTE_REFRESH:
1465 dissect_bgp_route_refresh(pd, offset + i, fd, bgp1_tree);
1477 * Register ourselves.
1480 proto_register_bgp(void)
1483 static hf_register_info hf[] = {
1485 { "BGP message type", "bgp.type", FT_UINT8, BASE_HEX,
1486 VALS(bgptypevals), 0x0, "BGP message type" }},
1489 static gint *ett[] = {
1494 &ett_bgp_attr_flags,
1495 &ett_bgp_mp_reach_nlri,
1496 &ett_bgp_mp_unreach_nlri,
1500 &ett_bgp_notification,
1501 &ett_bgp_route_refresh,
1503 &ett_bgp_communities,
1504 &ett_bgp_cluster_list,
1509 proto_bgp = proto_register_protocol("Border Gateway Protocol", "bgp");
1510 proto_register_field_array(proto_bgp, hf, array_length(hf));
1511 proto_register_subtree_array(ett, array_length(ett));
1515 proto_reg_handoff_bgp(void)
1517 old_dissector_add("tcp.port", BGP_TCP_PORT, dissect_bgp);