Ethereal-dev: [Ethereal-dev] Changes to Ethereal on pcacket-bgp.c
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: Marcio Franco <franco.marcio@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 22 Apr 2003 18:14:18 +0000
I send my modification of file "packet-bgp.c" for BGP protocol. The modification are filter for different values. On close : packet-bgp.c.diff My email : franco.marcio@xxxxxxxxxxxxxxxxxxxx
Index: packet-bgp.c
===================================================================
RCS file: /cvsroot/ethereal/packet-bgp.c,v
retrieving revision 1.75
diff -u -r1.75 packet-bgp.c
--- packet-bgp.c 5 Apr 2003 11:20:53 -0000 1.75
+++ packet-bgp.c 22 Apr 2003 15:50:11 -0000
@@ -288,6 +288,21 @@
static int proto_bgp = -1;
static int hf_bgp_type = -1;
+static int hf_bgp_next_hop = -1;
+static int hf_bgp_as_path = -1;
+static int hf_bgp_community_as = -1;
+static int hf_bgp_community_value = -1;
+static int hf_bgp_origin = -1;
+static int hf_bgp_cluster_list = -1;
+static int hf_bgp_originator_id = -1;
+static int hf_bgp_local_pref = -1;
+static int hf_bgp_multi_exit_disc = -1;
+static int hf_bgp_aggregator_as = -1;
+static int hf_bgp_aggregator_origin = -1;
+static int hf_bgp_mp_reach_nlri = -1;
+static int hf_bgp_mp_unreach_nlri = -1;
+static int hf_bgp_nlri = -1;
+static int hf_bgp_withdrawn = -1;
static gint ett_bgp = -1;
static gint ett_bgp_unfeas = -1;
@@ -1148,6 +1163,7 @@
guint16 len; /* tmp */
int advance; /* tmp */
proto_item *ti; /* tree item */
+ proto_tree *bgp_tree; /* subtree for attributes */
proto_tree *subtree; /* subtree for attributes */
proto_tree *subtree2; /* subtree for attributes */
proto_tree *subtree3; /* subtree for attributes */
@@ -1166,6 +1182,7 @@
char junk_buf[256]; /* tmp */
int junk_buf_len; /* tmp len */
guint8 ipaddr[4]; /* IPv4 address */
+ guint8 mask; /* tmp */
hlen = tvb_get_ntohs(tvb, BGP_MARKER_SIZE);
o = BGP_HEADER_SIZE;
@@ -1184,7 +1201,24 @@
/* parse each prefixes */
end = o + len;
while (o < end) {
- i = decode_prefix4(tvb, o, junk_buf, sizeof(junk_buf));
+ /* filter for withdrawn routes */
+ mask = tvb_get_guint8(tvb, o);
+ memset(ipaddr, 0, sizeof(ipaddr));
+ if (mask > 24) {
+ tvb_memcpy(tvb, ipaddr, o+1, 4);
+ }
+ else if (mask > 16) {
+ tvb_memcpy(tvb, ipaddr, o+1, 3);
+ }
+ else if (mask > 8) {
+ tvb_memcpy(tvb, ipaddr, o+1, 2);
+ }
+ else {
+ ipaddr[0] = tvb_get_guint8(tvb, o+1);
+ }
+ proto_tree_add_ipv4_hidden(subtree, hf_bgp_withdrawn, tvb, o, len, *((guint32*)ipaddr));
+
+ i = decode_prefix4(tvb, o, junk_buf, sizeof(junk_buf));
if (i < 0 || 32 < i) {
proto_tree_add_text (tree, tvb, o, len,
"Invalid withdrawn route prefix length: %u",
@@ -1241,6 +1275,9 @@
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
msg, tlen + aoff, (tlen + aoff == 1) ? "byte" :
"bytes");
+ /* filter for origin */
+ bgp_tree = proto_item_add_subtree(ti, ett_bgp);
+ proto_tree_add_uint_hidden (bgp_tree, hf_bgp_origin, tvb, o+i+3, 1, tvb_get_guint8(tvb,o+i+3));
break;
case BGPTYPE_AS_PATH:
case BGPTYPE_NEW_AS_PATH:
@@ -1327,6 +1364,15 @@
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
as_path_str, tlen + aoff,
(tlen + aoff == 1) ? "byte" : "bytes");
+
+ /* filter for as_path */
+ bgp_tree = proto_item_add_subtree(ti, ett_bgp);
+ q = o+i+5;
+ end = q + tlen-2;
+ while( q < end) {
+ proto_tree_add_uint_hidden (bgp_tree, hf_bgp_as_path, tvb, q, 2, tvb_get_ntohs(tvb,q));
+ q = q + 2;
+ }
break;
case BGPTYPE_NEXT_HOP:
if (tlen != 4)
@@ -1337,6 +1383,8 @@
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
ip_to_str(ipaddr), tlen + aoff, (tlen + aoff == 1)
? "byte" : "bytes");
+ /* filter for next_hop */
+ proto_tree_add_ipv4_hidden(subtree, hf_bgp_next_hop, tvb, o+i+2, tlen, *((guint32*)ipaddr));
break;
case BGPTYPE_MULTI_EXIT_DISC:
if (tlen != 4)
@@ -1346,6 +1394,9 @@
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
tvb_get_ntohl(tvb, o + i + aoff), tlen + aoff,
(tlen + aoff == 1) ? "byte" : "bytes");
+ /* filter for multi_exit_disc */
+ bgp_tree = proto_item_add_subtree(ti, ett_bgp);
+ proto_tree_add_uint_hidden (bgp_tree, hf_bgp_multi_exit_disc, tvb, o+i+3, 4, tvb_get_ntohl(tvb,o+i+3));
break;
case BGPTYPE_LOCAL_PREF:
if (tlen != 4)
@@ -1355,6 +1406,9 @@
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
tvb_get_ntohl(tvb, o + i + aoff), tlen + aoff,
(tlen + aoff == 1) ? "byte" : "bytes");
+ /* filter for local_pref */
+ bgp_tree = proto_item_add_subtree(ti, ett_bgp);
+ proto_tree_add_uint_hidden (bgp_tree, hf_bgp_local_pref, tvb, o+i+3, 4, tvb_get_ntohl(tvb,o+i+3));
break;
case BGPTYPE_ATOMIC_AGGREGATE:
if (tlen != 0)
@@ -1379,6 +1433,10 @@
tvb_get_ntohl(tvb, o + i + aoff),
ip_to_str(ipaddr), tlen + aoff,
(tlen + aoff == 1) ? "byte" : "bytes");
+ /* filter for aggregator_as & aggregator_origin */
+ bgp_tree = proto_item_add_subtree(ti, ett_bgp);
+ proto_tree_add_uint_hidden (bgp_tree, hf_bgp_aggregator_as, tvb, o+i+3, 2, tvb_get_ntohs(tvb,o+i+3));
+ proto_tree_add_ipv4_hidden (subtree, hf_bgp_aggregator_origin, tvb, o+i+5, 4, *((guint32*)ipaddr));
break;
case BGPTYPE_COMMUNITIES:
if (tlen % 4 != 0)
@@ -1423,7 +1481,16 @@
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
communities_str, tlen + aoff,
(tlen + aoff == 1) ? "byte" : "bytes");
- break;
+ /* filter coomunity_as & community_value */
+ bgp_tree = proto_item_add_subtree(ti, ett_bgp);
+ q = o+i+3;
+ end = q + tlen;
+ while( q < end) {
+ proto_tree_add_uint_hidden (bgp_tree, hf_bgp_community_as, tvb, q, 2, tvb_get_ntohs(tvb,q));
+ proto_tree_add_uint_hidden (bgp_tree, hf_bgp_community_value, tvb, q+2, 2, tvb_get_ntohs(tvb,q+2));
+ q += 4;
+ }
+ break;
case BGPTYPE_ORIGINATOR_ID:
if (tlen != 4)
goto default_attribute_top;
@@ -1433,6 +1500,8 @@
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
ip_to_str(ipaddr), tlen + aoff, (tlen + aoff == 1)
? "byte" : "bytes");
+ /* filter for originator_id */
+ proto_tree_add_ipv4_hidden (subtree, hf_bgp_originator_id, tvb, o+i+3, tlen, *((guint32*)ipaddr));
break;
case BGPTYPE_CLUSTER_LIST:
if (tlen % 4 != 0)
@@ -1466,6 +1535,8 @@
val_to_str(bgpa.bgpa_type, bgpattr_type, "Unknown"),
cluster_list_str, tlen + aoff,
(tlen + aoff == 1) ? "byte" : "bytes");
+ /* filter for cluster_list */
+ proto_tree_add_ipv4_hidden (subtree, hf_bgp_cluster_list, tvb, o+i+3, tlen, *((guint32*)ipaddr));
break;
case BGPTYPE_EXTENDED_COMMUNITY:
if (tlen %8 != 0)
@@ -1854,7 +1925,24 @@
subtree3 = proto_item_add_subtree(ti,ett_bgp_mp_reach_nlri);
while (tlen > 0) {
- advance = decode_prefix_MP(af, saf, tvb, o + i + aoff , junk_buf, sizeof(junk_buf)) ;
+ /* filter for mp_reach_nlri */
+ mask = tvb_get_guint8(tvb, o+i+aoff);
+ memset(ipaddr, 0, sizeof(ipaddr));
+ if (mask > 24) {
+ tvb_memcpy(tvb, ipaddr, o+i+aoff+1, 4);
+ }
+ else if (mask > 16) {
+ tvb_memcpy(tvb, ipaddr, o+i+aoff+1, 3);
+ }
+ else if (mask > 8) {
+ tvb_memcpy(tvb, ipaddr, o+i+aoff+1, 2);
+ }
+ else {
+ ipaddr[0] = tvb_get_guint8(tvb, o+i+aoff+1);
+ }
+ proto_tree_add_ipv4_hidden(subtree, hf_bgp_mp_reach_nlri, tvb, o+i+12, tlen, *((guint32*)ipaddr));
+
+ advance = decode_prefix_MP(af, saf, tvb, o + i + aoff , junk_buf, sizeof(junk_buf)) ;
proto_tree_add_text(subtree3, tvb, o + i + aoff, advance, "%s", junk_buf) ;
tlen -= advance;
aoff += advance;
@@ -1881,7 +1969,24 @@
subtree3 = proto_item_add_subtree(ti,ett_bgp_mp_unreach_nlri);
while (tlen > 0) {
- advance = decode_prefix_MP(af, saf, tvb, o + i + aoff , junk_buf, sizeof(junk_buf)) ;
+ /* filter for mp_unreach_nlri */
+ mask = tvb_get_guint8(tvb, o+i+aoff);
+ memset(ipaddr, 0, sizeof(ipaddr));
+ if (mask > 24) {
+ tvb_memcpy(tvb, ipaddr, o+i+aoff+1, 4);
+ }
+ else if (mask > 16) {
+ tvb_memcpy(tvb, ipaddr, o+i+aoff+1, 3);
+ }
+ else if (mask > 8) {
+ tvb_memcpy(tvb, ipaddr, o+i+aoff+1, 2);
+ }
+ else {
+ ipaddr[0] = tvb_get_guint8(tvb, o+i+aoff+1);
+ }
+ proto_tree_add_ipv4_hidden(subtree, hf_bgp_mp_unreach_nlri, tvb, o+i+6, tlen, *((guint32*)ipaddr));
+
+ advance = decode_prefix_MP(af, saf, tvb, o + i + aoff , junk_buf, sizeof(junk_buf)) ;
proto_tree_add_text(subtree3, tvb, o + i + aoff, advance, "%s", junk_buf) ;
tlen -= advance;
aoff += advance;
@@ -2041,7 +2146,24 @@
subtree = proto_item_add_subtree(ti, ett_bgp_nlri);
end = o + len;
while (o < end) {
- i = decode_prefix4(tvb, o, junk_buf, sizeof(junk_buf));
+ /* filter for nlri */
+ mask = tvb_get_guint8(tvb, o);
+ memset(ipaddr, 0, sizeof(ipaddr));
+ if (mask > 24) {
+ tvb_memcpy(tvb, ipaddr, o+1, 4);
+ }
+ else if (mask > 16) {
+ tvb_memcpy(tvb, ipaddr, o+1, 3);
+ }
+ else if (mask > 8) {
+ tvb_memcpy(tvb, ipaddr, o+1, 2);
+ }
+ else {
+ ipaddr[0] = tvb_get_guint8(tvb, o+1);
+ }
+ proto_tree_add_ipv4_hidden(subtree, hf_bgp_nlri, tvb, o, len, *((guint32*)ipaddr));
+
+ i = decode_prefix4(tvb, o, junk_buf, sizeof(junk_buf));
if (i < 0 || 32 < i) {
proto_tree_add_text (tree, tvb, o, len,
"Invalid NLRI prefix length: %u",
@@ -2546,8 +2668,53 @@
static hf_register_info hf[] = {
{ &hf_bgp_type,
- { "BGP message type", "bgp.type", FT_UINT8, BASE_HEX,
+ { "BGP Message Type", "bgp.type", FT_UINT8, BASE_HEX,
VALS(bgptypevals), 0x0, "BGP message type", HFILL }},
+ { &hf_bgp_aggregator_as,
+ { "BGP Aggregator AS", "bgp.aggregator_as", FT_UINT16, BASE_DEC,
+ NULL, 0x0, "", HFILL}},
+ { &hf_bgp_aggregator_origin,
+ { "BGP Aggregator Origin", "bgp.aggregator_origin", FT_IPv4, BASE_NONE,
+ NULL, 0x0, "", HFILL}},
+ { &hf_bgp_as_path,
+ { "BGP AS Path", "bgp.as_path", FT_UINT16, BASE_DEC,
+ NULL, 0x0, "", HFILL}},
+ { &hf_bgp_cluster_list,
+ { "BGP Cluster List", "bgp.cluster_list", FT_IPv4, BASE_NONE,
+ NULL, 0x0, "", HFILL}},
+ { &hf_bgp_community_as,
+ { "BGP Community AS", "bgp.community_as", FT_UINT16, BASE_DEC,
+ NULL, 0x0, "", HFILL}},
+ { &hf_bgp_community_value,
+ { "BGP Community Value", "bgp.community_value", FT_UINT16, BASE_DEC,
+ NULL, 0x0, "", HFILL}},
+ { &hf_bgp_local_pref,
+ { "BGP Local Pref", "bgp.local_pref", FT_UINT32, BASE_DEC,
+ NULL, 0x0, "", HFILL}},
+ { &hf_bgp_mp_reach_nlri,
+ { "BGP MP Reach NLRI", "bgp.mp_reach_nlri", FT_IPv4, BASE_NONE,
+ NULL, 0x0, "", HFILL}},
+ { &hf_bgp_mp_unreach_nlri,
+ { "BGP MP Unreach NLRI", "bgp.mp_unreach_nlri", FT_IPv4, BASE_NONE,
+ NULL, 0x0, "", HFILL}},
+ { &hf_bgp_multi_exit_disc,
+ { "BGP Multi Exit Disc", "bgp.multi_exit_disc", FT_UINT32, BASE_DEC,
+ NULL, 0x0, "", HFILL}},
+ { &hf_bgp_next_hop,
+ { "BGP Next Hop", "bgp.next_hop", FT_IPv4, BASE_NONE,
+ NULL, 0x0, "", HFILL}},
+ { &hf_bgp_nlri,
+ { "BGP NLRI", "bgp.nlri", FT_IPv4, BASE_NONE,
+ NULL, 0x0, "", HFILL}},
+ { &hf_bgp_origin,
+ { "BGP Origin", "bgp.origin", FT_UINT8, BASE_DEC,
+ VALS(bgpattr_origin), 0x0, "", HFILL}},
+ { &hf_bgp_originator_id,
+ { "BGP Originator ID", "bgp.originator_id", FT_IPv4, BASE_NONE,
+ NULL, 0x0, "", HFILL}},
+ { &hf_bgp_withdrawn,
+ { "BGP Withdrawn", "bgp.withdrawn", FT_IPv4, BASE_NONE,
+ NULL, 0x0, "", HFILL}},
};
static gint *ett[] = {
- Follow-Ups:
- Re: [Ethereal-dev] Changes to Ethereal on pcacket-bgp.c
- From: Guy Harris
- Re: [Ethereal-dev] Changes to Ethereal on pcacket-bgp.c
- Prev by Date: Re: [Ethereal-dev] RSVP patch
- Next by Date: [Ethereal-dev] [patch] Added additional NFSv4 status codes
- Previous by thread: Re: [Ethereal-dev] RSVP patch
- Next by thread: Re: [Ethereal-dev] Changes to Ethereal on pcacket-bgp.c
- Index(es):





