diff options
author | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2013-11-08 21:38:32 +0000 |
---|---|---|
committer | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2013-11-08 21:38:32 +0000 |
commit | 7e312c9bbc83f9241c85d439b9c3dd47fac0763f (patch) | |
tree | 4cfc43bc37ece810cd6d44a556a42036b5ea6650 | |
parent | b3a4b56ae94f554adc04c13c13712d4a476f0bbc (diff) |
Convert: vlan, sll, rip to NEW_PROTO_TREE_API
svn path=/trunk/; revision=53175
-rw-r--r-- | epan/dissectors/packet-rip.c | 168 | ||||
-rw-r--r-- | epan/dissectors/packet-sll.c | 163 | ||||
-rw-r--r-- | epan/dissectors/packet-vlan.c | 94 |
3 files changed, 237 insertions, 188 deletions
diff --git a/epan/dissectors/packet-rip.c b/epan/dissectors/packet-rip.c index 2ab94ceef7..b44d09373b 100644 --- a/epan/dissectors/packet-rip.c +++ b/epan/dissectors/packet-rip.c @@ -27,6 +27,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define NEW_PROTO_TREE_API + #include "config.h" #include <glib.h> @@ -82,18 +84,56 @@ static gboolean pref_display_routing_domain = FALSE; void proto_reg_handoff_rip(void); -static int proto_rip = -1; -static int hf_rip_command = -1; -static int hf_rip_version = -1; -static int hf_rip_routing_domain = -1; -static int hf_rip_ip = -1; -static int hf_rip_netmask = -1; -static int hf_rip_next_hop = -1; -static int hf_rip_metric = -1; -static int hf_rip_auth = -1; -static int hf_rip_auth_passwd = -1; -static int hf_rip_family = -1; -static int hf_rip_route_tag = -1; + +static dissector_handle_t rip_handle; + +static header_field_info *hfi_rip = NULL; + +#define RIP_HFI_INIT HFI_INIT(proto_rip) + +static header_field_info hfi_rip_command RIP_HFI_INIT = + { "Command", "rip.command", FT_UINT8, BASE_DEC, + VALS(command_vals), 0, "What type of RIP Command is this", HFILL }; + +static header_field_info hfi_rip_version RIP_HFI_INIT = + { "Version", "rip.version", FT_UINT8, BASE_DEC, + VALS(version_vals), 0, "Version of the RIP protocol", HFILL }; + +static header_field_info hfi_rip_routing_domain RIP_HFI_INIT = + { "Routing Domain", "rip.routing_domain", FT_UINT16, BASE_DEC, + NULL, 0, "RIPv2 Routing Domain", HFILL }; + +static header_field_info hfi_rip_ip RIP_HFI_INIT = + { "IP Address", "rip.ip", FT_IPv4, BASE_NONE, + NULL, 0, NULL, HFILL}; + +static header_field_info hfi_rip_netmask RIP_HFI_INIT = + { "Netmask", "rip.netmask", FT_IPv4, BASE_NONE, + NULL, 0, NULL, HFILL}; + +static header_field_info hfi_rip_next_hop RIP_HFI_INIT = + { "Next Hop", "rip.next_hop", FT_IPv4, BASE_NONE, + NULL, 0, "Next Hop router for this route", HFILL}; + +static header_field_info hfi_rip_metric RIP_HFI_INIT = + { "Metric", "rip.metric", FT_UINT16, BASE_DEC, + NULL, 0, "Metric for this route", HFILL }; + +static header_field_info hfi_rip_auth RIP_HFI_INIT = + { "Authentication type", "rip.auth.type", FT_UINT16, BASE_DEC, + VALS(rip_auth_type), 0, "Type of authentication", HFILL }; + +static header_field_info hfi_rip_auth_passwd RIP_HFI_INIT = + { "Password", "rip.auth.passwd", FT_STRING, BASE_NONE, + NULL, 0, "Authentication password", HFILL }; + +static header_field_info hfi_rip_family RIP_HFI_INIT = + { "Address Family", "rip.family", FT_UINT16, BASE_DEC, + VALS(family_vals), 0, NULL, HFILL }; + +static header_field_info hfi_rip_route_tag RIP_HFI_INIT = + { "Route Tag", "rip.route_tag", FT_UINT16, BASE_DEC, + NULL, 0, NULL, HFILL }; static gint ett_rip = -1; static gint ett_rip_vec = -1; @@ -130,13 +170,13 @@ dissect_rip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) val_to_str(command, command_vals, "Unknown command (%u)")); if (tree) { - ti = proto_tree_add_item(tree, proto_rip, tvb, 0, -1, ENC_NA); + ti = proto_tree_add_item(tree, hfi_rip, tvb, 0, -1, ENC_NA); rip_tree = proto_item_add_subtree(ti, ett_rip); - proto_tree_add_uint(rip_tree, hf_rip_command, tvb, 0, 1, command); - proto_tree_add_uint(rip_tree, hf_rip_version, tvb, 1, 1, version); + proto_tree_add_uint(rip_tree, &hfi_rip_command, tvb, 0, 1, command); + proto_tree_add_uint(rip_tree, &hfi_rip_version, tvb, 1, 1, version); if (version == RIPv2 && pref_display_routing_domain == TRUE) - proto_tree_add_uint(rip_tree, hf_rip_routing_domain, tvb, 2, 2, + proto_tree_add_uint(rip_tree, &hfi_rip_routing_domain, tvb, 2, 2, tvb_get_ntohs(tvb, 2)); /* skip header */ @@ -191,16 +231,16 @@ dissect_unspec_rip_vektor(tvbuff_t *tvb, int offset, guint8 version, metric); rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec); - proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, ENC_BIG_ENDIAN); + proto_tree_add_item(rip_vektor_tree, &hfi_rip_family, tvb, offset, 2, ENC_BIG_ENDIAN); if (version == RIPv2) { - proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2, + proto_tree_add_item(rip_vektor_tree, &hfi_rip_route_tag, tvb, offset+2, 2, ENC_BIG_ENDIAN); - proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4, + proto_tree_add_item(rip_vektor_tree, &hfi_rip_netmask, tvb, offset+8, 4, ENC_BIG_ENDIAN); - proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4, + proto_tree_add_item(rip_vektor_tree, &hfi_rip_next_hop, tvb, offset+12, 4, ENC_BIG_ENDIAN); } - proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb, + proto_tree_add_uint(rip_vektor_tree, &hfi_rip_metric, tvb, offset+16, 4, metric); } @@ -218,21 +258,21 @@ dissect_ip_rip_vektor(tvbuff_t *tvb, int offset, guint8 version, tvb_ip_to_str(tvb, offset+4), metric); rip_vektor_tree = proto_item_add_subtree(ti, ett_rip_vec); - proto_tree_add_item(rip_vektor_tree, hf_rip_family, tvb, offset, 2, ENC_BIG_ENDIAN); + proto_tree_add_item(rip_vektor_tree, &hfi_rip_family, tvb, offset, 2, ENC_BIG_ENDIAN); if (version == RIPv2) { - proto_tree_add_item(rip_vektor_tree, hf_rip_route_tag, tvb, offset+2, 2, + proto_tree_add_item(rip_vektor_tree, &hfi_rip_route_tag, tvb, offset+2, 2, ENC_BIG_ENDIAN); } - proto_tree_add_item(rip_vektor_tree, hf_rip_ip, tvb, offset+4, 4, ENC_BIG_ENDIAN); + proto_tree_add_item(rip_vektor_tree, &hfi_rip_ip, tvb, offset+4, 4, ENC_BIG_ENDIAN); if (version == RIPv2) { - proto_tree_add_item(rip_vektor_tree, hf_rip_netmask, tvb, offset+8, 4, + proto_tree_add_item(rip_vektor_tree, &hfi_rip_netmask, tvb, offset+8, 4, ENC_BIG_ENDIAN); - proto_tree_add_item(rip_vektor_tree, hf_rip_next_hop, tvb, offset+12, 4, + proto_tree_add_item(rip_vektor_tree, &hfi_rip_next_hop, tvb, offset+12, 4, ENC_BIG_ENDIAN); } - proto_tree_add_uint(rip_vektor_tree, hf_rip_metric, tvb, + proto_tree_add_uint(rip_vektor_tree, &hfi_rip_metric, tvb, offset+16, 4, metric); } @@ -251,13 +291,13 @@ dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree) "Authentication: %s", val_to_str( authtype, rip_auth_type, "Unknown (%u)" ) ); rip_authentication_tree = proto_item_add_subtree(ti, ett_rip_vec); - proto_tree_add_uint(rip_authentication_tree, hf_rip_auth, tvb, offset+2, 2, + proto_tree_add_uint(rip_authentication_tree, &hfi_rip_auth, tvb, offset+2, 2, authtype); switch ( authtype ) { case AUTH_PASSWORD: /* Plain text password */ - proto_tree_add_item(rip_authentication_tree, hf_rip_auth_passwd, + proto_tree_add_item(rip_authentication_tree, &hfi_rip_auth_passwd, tvb, offset+4, 16, ENC_ASCII|ENC_NA); break; @@ -291,52 +331,22 @@ dissect_rip_authentication(tvbuff_t *tvb, int offset, proto_tree *tree) void proto_register_rip(void) { - static hf_register_info hf[] = { - { &hf_rip_command, - { "Command", "rip.command", FT_UINT8, BASE_DEC, - VALS(command_vals), 0, "What type of RIP Command is this", HFILL }}, - - { &hf_rip_version, - { "Version", "rip.version", FT_UINT8, BASE_DEC, - VALS(version_vals), 0, "Version of the RIP protocol", HFILL }}, - - { &hf_rip_family, - { "Address Family", "rip.family", FT_UINT16, BASE_DEC, - VALS(family_vals), 0, NULL, HFILL }}, - - { &hf_rip_routing_domain, - { "Routing Domain", "rip.routing_domain", FT_UINT16, BASE_DEC, - NULL, 0, "RIPv2 Routing Domain", HFILL }}, - - { &hf_rip_ip, - { "IP Address", "rip.ip", FT_IPv4, BASE_NONE, - NULL, 0, NULL, HFILL}}, - - { &hf_rip_netmask, - { "Netmask", "rip.netmask", FT_IPv4, BASE_NONE, - NULL, 0, NULL, HFILL}}, - - { &hf_rip_next_hop, - { "Next Hop", "rip.next_hop", FT_IPv4, BASE_NONE, - NULL, 0, "Next Hop router for this route", HFILL}}, - - { &hf_rip_metric, - { "Metric", "rip.metric", FT_UINT16, BASE_DEC, - NULL, 0, "Metric for this route", HFILL }}, - - { &hf_rip_auth, - { "Authentication type", "rip.auth.type", FT_UINT16, BASE_DEC, - VALS(rip_auth_type), 0, "Type of authentication", HFILL }}, - - { &hf_rip_auth_passwd, - { "Password", "rip.auth.passwd", FT_STRING, BASE_NONE, - NULL, 0, "Authentication password", HFILL }}, - - { &hf_rip_route_tag, - { "Route Tag", "rip.route_tag", FT_UINT16, BASE_DEC, - NULL, 0, NULL, HFILL }}, - +#ifndef HAVE_HFI_SECTION_INIT + static header_field_info *hfi[] = { + &hfi_rip_command, + &hfi_rip_version, + &hfi_rip_family, + &hfi_rip_routing_domain, + &hfi_rip_ip, + &hfi_rip_netmask, + &hfi_rip_next_hop, + &hfi_rip_metric, + &hfi_rip_auth, + &hfi_rip_auth_passwd, + &hfi_rip_route_tag, }; +#endif /* HAVE_HFI_SECTION_INIT */ + static gint *ett[] = { &ett_rip, &ett_rip_vec, @@ -344,22 +354,24 @@ proto_register_rip(void) }; module_t *rip_module; + int proto_rip; proto_rip = proto_register_protocol("Routing Information Protocol", "RIP", "rip"); - proto_register_field_array(proto_rip, hf, array_length(hf)); + hfi_rip = proto_registrar_get_nth(proto_rip); + + proto_register_fields(proto_rip, hfi, array_length(hfi)); proto_register_subtree_array(ett, array_length(ett)); rip_module = prefs_register_protocol(proto_rip, proto_reg_handoff_rip); prefs_register_bool_preference(rip_module, "display_routing_domain", "Display Routing Domain field", "Display the third and forth bytes of the RIPv2 header as the Routing Domain field (introduced in RFC 1388 [January 1993] and obsolete as of RFC 1723 [November 1994])", &pref_display_routing_domain); + + rip_handle = create_dissector_handle(dissect_rip, proto_rip); } void proto_reg_handoff_rip(void) { - dissector_handle_t rip_handle; - - rip_handle = create_dissector_handle(dissect_rip, proto_rip); dissector_add_uint("udp.port", UDP_PORT_RIP, rip_handle); } diff --git a/epan/dissectors/packet-sll.c b/epan/dissectors/packet-sll.c index 85a7414114..e41023c46f 100644 --- a/epan/dissectors/packet-sll.c +++ b/epan/dissectors/packet-sll.c @@ -22,6 +22,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define NEW_PROTO_TREE_API + #include "config.h" #include <glib.h> @@ -37,20 +39,6 @@ #include <epan/addr_resolv.h> #include <epan/etypes.h> -static int proto_sll = -1; -static int hf_sll_pkttype = -1; -static int hf_sll_hatype = -1; -static int hf_sll_halen = -1; -static int hf_sll_src_eth = -1; -static int hf_sll_src_ipv4 = -1; -static int hf_sll_src_other = -1; -static int hf_sll_ltype = -1; -static int hf_sll_gretype = -1; -static int hf_sll_etype = -1; -static int hf_sll_trailer = -1; - -static gint ett_sll = -1; - /* * A DLT_LINUX_SLL fake link-layer header. */ @@ -86,6 +74,63 @@ static const value_string ltype_vals[] = { { 0, NULL } }; + +static dissector_handle_t sll_handle; + +static header_field_info *hfi_sll = NULL; + +#define SLL_HFI_INIT HFI_INIT(proto_sll) + +static header_field_info hfi_sll_pkttype SLL_HFI_INIT = + { "Packet type", "sll.pkttype", FT_UINT16, BASE_DEC, + VALS(packet_type_vals), 0x0, NULL, HFILL }; + +/* ARP hardware type? With Linux extensions? */ +static header_field_info hfi_sll_hatype SLL_HFI_INIT = + { "Link-layer address type", "sll.hatype", FT_UINT16, BASE_DEC, + NULL, 0x0, NULL, HFILL }; + +static header_field_info hfi_sll_halen SLL_HFI_INIT = + { "Link-layer address length", "sll.halen", FT_UINT16, BASE_DEC, + NULL, 0x0, NULL, HFILL }; + +/* Source address if it's an Ethernet-type address */ +static header_field_info hfi_sll_src_eth SLL_HFI_INIT = + { "Source", "sll.src.eth", FT_ETHER, BASE_NONE, + NULL, 0x0, "Source link-layer address", HFILL }; + +/* Source address if it's an IPv4 address */ +static header_field_info hfi_sll_src_ipv4 SLL_HFI_INIT = + { "Source", "sll.src.ipv4", FT_IPv4, BASE_NONE, + NULL, 0x0, "Source link-layer address", HFILL }; + +/* Source address if it's not an Ethernet-type address */ +static header_field_info hfi_sll_src_other SLL_HFI_INIT = + { "Source", "sll.src.other", FT_BYTES, BASE_NONE, + NULL, 0x0, "Source link-layer address", HFILL }; + +/* if the protocol field is an internal Linux protocol type */ +static header_field_info hfi_sll_ltype SLL_HFI_INIT = + { "Protocol", "sll.ltype", FT_UINT16, BASE_HEX, + VALS(ltype_vals), 0x0, "Linux protocol type", HFILL }; + +/* if the protocol field is a GRE protocol type */ +static header_field_info hfi_sll_gretype SLL_HFI_INIT = + { "Protocol", "sll.gretype", FT_UINT16, BASE_HEX, + VALS(gre_typevals), 0x0, "GRE protocol type", HFILL }; + +/* registered here but handled in ethertype.c */ +static header_field_info hfi_sll_etype SLL_HFI_INIT = + { "Protocol", "sll.etype", FT_UINT16, BASE_HEX, + VALS(etype_vals), 0x0, "Ethernet protocol type", HFILL }; + +static header_field_info hfi_sll_trailer SLL_HFI_INIT = + { "Trailer", "sll.trailer", FT_BYTES, BASE_NONE, + NULL, 0x0, NULL, HFILL }; + + +static gint ett_sll = -1; + static dissector_table_t sll_linux_dissector_table; static dissector_table_t gre_dissector_table; static dissector_handle_t data_handle; @@ -181,10 +226,10 @@ dissect_sll(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) val_to_str(pkttype, packet_type_vals, "Unknown (%u)")); if (tree) { - ti = proto_tree_add_protocol_format(tree, proto_sll, tvb, 0, + ti = proto_tree_add_protocol_format(tree, hfi_sll->id, tvb, 0, SLL_HEADER_SIZE, "Linux cooked capture"); fh_tree = proto_item_add_subtree(ti, ett_sll); - proto_tree_add_item(fh_tree, hf_sll_pkttype, tvb, 0, 2, ENC_BIG_ENDIAN); + proto_tree_add_item(fh_tree, &hfi_sll_pkttype, tvb, 0, 2, ENC_BIG_ENDIAN); } /* @@ -194,8 +239,8 @@ dissect_sll(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) hatype = tvb_get_ntohs(tvb, 2); halen = tvb_get_ntohs(tvb, 4); if (tree) { - proto_tree_add_uint(fh_tree, hf_sll_hatype, tvb, 2, 2, hatype); - proto_tree_add_uint(fh_tree, hf_sll_halen, tvb, 4, 2, halen); + proto_tree_add_uint(fh_tree, &hfi_sll_hatype, tvb, 2, 2, hatype); + proto_tree_add_uint(fh_tree, &hfi_sll_halen, tvb, 4, 2, halen); } switch (halen) { case 4: @@ -203,7 +248,7 @@ dissect_sll(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) SET_ADDRESS(&pinfo->dl_src, AT_IPv4, 4, src); SET_ADDRESS(&pinfo->src, AT_IPv4, 4, src); if (tree) { - proto_tree_add_item(fh_tree, hf_sll_src_ipv4, tvb, + proto_tree_add_item(fh_tree, &hfi_sll_src_ipv4, tvb, 6, 4, ENC_BIG_ENDIAN); } break; @@ -212,7 +257,7 @@ dissect_sll(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, src); SET_ADDRESS(&pinfo->src, AT_ETHER, 6, src); if (tree) { - proto_tree_add_ether(fh_tree, hf_sll_src_eth, tvb, + proto_tree_add_ether(fh_tree, hfi_sll_src_eth.id, tvb, 6, 6, src); } break; @@ -220,7 +265,7 @@ dissect_sll(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) break; default: if (tree) { - proto_tree_add_item(fh_tree, hf_sll_src_other, tvb, + proto_tree_add_item(fh_tree, &hfi_sll_src_other, tvb, 6, halen > 8 ? 8 : halen, ENC_NA); } break; @@ -236,7 +281,7 @@ dissect_sll(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * be trailer data. * XXX - do the same thing we do for packets with Ethertypes? */ - proto_tree_add_uint(fh_tree, hf_sll_ltype, tvb, 14, 2, + proto_tree_add_uint(fh_tree, &hfi_sll_ltype, tvb, 14, 2, protocol); if(!dissector_try_uint(sll_linux_dissector_table, protocol, @@ -246,14 +291,14 @@ dissect_sll(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } else { switch (hatype) { case ARPHRD_IPGRE: - proto_tree_add_uint(fh_tree, hf_sll_gretype, tvb, 14, 2, + proto_tree_add_uint(fh_tree, &hfi_sll_gretype, tvb, 14, 2, protocol); dissector_try_uint(gre_dissector_table, protocol, next_tvb, pinfo, tree); break; default: ethertype(protocol, tvb, SLL_HEADER_SIZE, pinfo, tree, - fh_tree, hf_sll_etype, hf_sll_trailer, 0); + fh_tree, hfi_sll_etype.id, hfi_sll_trailer.id, 0); break; } } @@ -262,63 +307,38 @@ dissect_sll(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) void proto_register_sll(void) { - static hf_register_info hf[] = { - { &hf_sll_pkttype, - { "Packet type", "sll.pkttype", FT_UINT16, BASE_DEC, - VALS(packet_type_vals), 0x0, NULL, HFILL }}, - +#ifndef HAVE_HFI_SECTION_INIT + static header_field_info *hfi[] = { + &hfi_sll_pkttype, /* ARP hardware type? With Linux extensions? */ - { &hf_sll_hatype, - { "Link-layer address type", "sll.hatype", FT_UINT16, BASE_DEC, - NULL, 0x0, NULL, HFILL }}, - - { &hf_sll_halen, - { "Link-layer address length", "sll.halen", FT_UINT16, BASE_DEC, - NULL, 0x0, NULL, HFILL }}, - - /* Source address if it's an Ethernet-type address */ - { &hf_sll_src_eth, - { "Source", "sll.src.eth", FT_ETHER, BASE_NONE, NULL, 0x0, - "Source link-layer address", HFILL }}, - - /* Source address if it's an IPv4 address */ - { &hf_sll_src_ipv4, - { "Source", "sll.src.ipv4", FT_IPv4, BASE_NONE, NULL, 0x0, - "Source link-layer address", HFILL }}, - - /* Source address if it's not an Ethernet-type address */ - { &hf_sll_src_other, - { "Source", "sll.src.other", FT_BYTES, BASE_NONE, NULL, 0x0, - "Source link-layer address", HFILL }}, - - /* if the protocol field is an internal Linux protocol type */ - { &hf_sll_ltype, - { "Protocol", "sll.ltype", FT_UINT16, BASE_HEX, - VALS(ltype_vals), 0x0, "Linux protocol type", HFILL }}, - - /* if the protocol field is a GRE protocol type */ - { &hf_sll_gretype, - { "Protocol", "sll.gretype", FT_UINT16, BASE_HEX, - VALS(gre_typevals), 0x0, "GRE protocol type", HFILL }}, - + &hfi_sll_hatype, + &hfi_sll_halen, + &hfi_sll_src_eth, + &hfi_sll_src_ipv4, + &hfi_sll_src_other, + &hfi_sll_ltype, + &hfi_sll_gretype, /* registered here but handled in ethertype.c */ - { &hf_sll_etype, - { "Protocol", "sll.etype", FT_UINT16, BASE_HEX, - VALS(etype_vals), 0x0, "Ethernet protocol type", HFILL }}, - - { &hf_sll_trailer, - { "Trailer", "sll.trailer", FT_BYTES, BASE_NONE, NULL, 0x0, - NULL, HFILL }} + &hfi_sll_etype, + &hfi_sll_trailer, }; +#endif + static gint *ett[] = { &ett_sll }; + int proto_sll; + proto_sll = proto_register_protocol("Linux cooked-mode capture", "SLL", "sll" ); - proto_register_field_array(proto_sll, hf, array_length(hf)); + hfi_sll = proto_registrar_get_nth(proto_sll); + + proto_register_fields(proto_sll, hfi, array_length(hfi)); proto_register_subtree_array(ett, array_length(ett)); + sll_handle = create_dissector_handle(dissect_sll, proto_sll); + sll_linux_dissector_table = register_dissector_table ( "sll.ltype", "Linux SLL protocol type", @@ -330,14 +350,11 @@ proto_register_sll(void) void proto_reg_handoff_sll(void) { - dissector_handle_t sll_handle; - /* * Get handles for the IPX and LLC dissectors. */ gre_dissector_table = find_dissector_table("gre.proto"); data_handle = find_dissector("data"); - sll_handle = create_dissector_handle(dissect_sll, proto_sll); dissector_add_uint("wtap_encap", WTAP_ENCAP_SLL, sll_handle); } diff --git a/epan/dissectors/packet-vlan.c b/epan/dissectors/packet-vlan.c index 340baf969d..74458d72ae 100644 --- a/epan/dissectors/packet-vlan.c +++ b/epan/dissectors/packet-vlan.c @@ -22,6 +22,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define NEW_PROTO_TREE_API + #include "config.h" #include <glib.h> @@ -40,17 +42,12 @@ static unsigned int q_in_q_ethertype = 0x9100; static gboolean vlan_summary_in_tree = TRUE; -static int proto_vlan = -1; -static int hf_vlan_priority = -1; -static int hf_vlan_cfi = -1; -static int hf_vlan_id = -1; -static int hf_vlan_etype = -1; -static int hf_vlan_len = -1; -static int hf_vlan_trailer = -1; -static gint ett_vlan = -1; +static dissector_handle_t vlan_handle; -static expert_field ei_vlan_len = EI_INIT; +static header_field_info *hfi_vlan = NULL; + +#define VLAN_HFI_INIT HFI_INIT(proto_vlan) /* From Table G-2 of IEEE standard 802.1D-2004 */ static const value_string pri_vals[] = { @@ -65,12 +62,40 @@ static const value_string pri_vals[] = { { 0, NULL } }; +static header_field_info hfi_vlan_priority VLAN_HFI_INIT = { + "Priority", "vlan.priority", FT_UINT16, BASE_DEC, + VALS(pri_vals), 0xE000, "Descriptions are recommendations from IEEE standard 802.1D-2004", HFILL }; + static const value_string cfi_vals[] = { { 0, "Canonical" }, { 1, "Non-canonical" }, { 0, NULL } }; +static header_field_info hfi_vlan_cfi VLAN_HFI_INIT = { + "CFI", "vlan.cfi", FT_UINT16, BASE_DEC, + VALS(cfi_vals), 0x1000, "Canonical Format Identifier", HFILL }; + +static header_field_info hfi_vlan_id VLAN_HFI_INIT = { + "ID", "vlan.id", FT_UINT16, BASE_DEC, + NULL, 0x0FFF, "VLAN ID", HFILL }; + +static header_field_info hfi_vlan_etype VLAN_HFI_INIT = { + "Type", "vlan.etype", FT_UINT16, BASE_HEX, + VALS(etype_vals), 0x0, "Ethertype", HFILL }; + +static header_field_info hfi_vlan_len VLAN_HFI_INIT = { + "Length", "vlan.len", FT_UINT16, BASE_DEC, + NULL, 0x0, NULL, HFILL }; + +static header_field_info hfi_vlan_trailer VLAN_HFI_INIT = { + "Trailer", "vlan.trailer", FT_BYTES, BASE_NONE, + NULL, 0x0, "VLAN Trailer", HFILL }; + + +static gint ett_vlan = -1; + +static expert_field ei_vlan_len = EI_INIT; void capture_vlan(const guchar *pd, int offset, int len, packet_counts *ld ) { @@ -112,7 +137,7 @@ dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) vlan_tree = NULL; if (tree) { - ti = proto_tree_add_item(tree, proto_vlan, tvb, 0, 4, ENC_NA); + ti = proto_tree_add_item(tree, hfi_vlan, tvb, 0, 4, ENC_NA); if (vlan_summary_in_tree) { proto_item_append_text(ti, ", PRI: %u, CFI: %u, ID: %u", @@ -121,9 +146,9 @@ dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) vlan_tree = proto_item_add_subtree(ti, ett_vlan); - proto_tree_add_item(vlan_tree, hf_vlan_priority, tvb, 0, 2, ENC_BIG_ENDIAN); - proto_tree_add_item(vlan_tree, hf_vlan_cfi, tvb, 0, 2, ENC_BIG_ENDIAN); - proto_tree_add_item(vlan_tree, hf_vlan_id, tvb, 0, 2, ENC_BIG_ENDIAN); + proto_tree_add_item(vlan_tree, &hfi_vlan_priority, tvb, 0, 2, ENC_BIG_ENDIAN); + proto_tree_add_item(vlan_tree, &hfi_vlan_cfi, tvb, 0, 2, ENC_BIG_ENDIAN); + proto_tree_add_item(vlan_tree, &hfi_vlan_id, tvb, 0, 2, ENC_BIG_ENDIAN); } encap_proto = tvb_get_ntohs(tvb, 2); @@ -145,47 +170,43 @@ dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } dissect_802_3(encap_proto, is_802_2, tvb, 4, pinfo, tree, vlan_tree, - hf_vlan_len, hf_vlan_trailer, &ei_vlan_len, 0); + hfi_vlan_len.id, hfi_vlan_trailer.id, &ei_vlan_len, 0); } else { ethertype(encap_proto, tvb, 4, pinfo, tree, vlan_tree, - hf_vlan_etype, hf_vlan_trailer, 0); + hfi_vlan_etype.id, hfi_vlan_trailer.id, 0); } } void proto_register_vlan(void) { - static hf_register_info hf[] = { - { &hf_vlan_priority, { - "Priority", "vlan.priority", FT_UINT16, BASE_DEC, - VALS(pri_vals), 0xE000, "Descriptions are recommendations from IEEE standard 802.1D-2004", HFILL }}, - { &hf_vlan_cfi, { - "CFI", "vlan.cfi", FT_UINT16, BASE_DEC, - VALS(cfi_vals), 0x1000, "Canonical Format Identifier", HFILL }}, - { &hf_vlan_id, { - "ID", "vlan.id", FT_UINT16, BASE_DEC, - NULL, 0x0FFF, "VLAN ID", HFILL }}, - { &hf_vlan_etype, { - "Type", "vlan.etype", FT_UINT16, BASE_HEX, - VALS(etype_vals), 0x0, "Ethertype", HFILL }}, - { &hf_vlan_len, { - "Length", "vlan.len", FT_UINT16, BASE_DEC, - NULL, 0x0, NULL, HFILL }}, - { &hf_vlan_trailer, { - "Trailer", "vlan.trailer", FT_BYTES, BASE_NONE, - NULL, 0x0, "VLAN Trailer", HFILL }} +#ifndef HAVE_HFI_SECTION_INIT + static header_field_info *hfi[] = { + &hfi_vlan_priority, + &hfi_vlan_cfi, + &hfi_vlan_id, + &hfi_vlan_etype, + &hfi_vlan_len, + &hfi_vlan_trailer, }; +#endif /* HAVE_HFI_SECTION_INIT */ + static gint *ett[] = { &ett_vlan }; + static ei_register_info ei[] = { { &ei_vlan_len, { "vlan.len.past_end", PI_MALFORMED, PI_ERROR, "Length field value goes past the end of the payload", EXPFILL }}, }; + module_t *vlan_module; expert_module_t* expert_vlan; + int proto_vlan; proto_vlan = proto_register_protocol("802.1Q Virtual LAN", "VLAN", "vlan"); - proto_register_field_array(proto_vlan, hf, array_length(hf)); + hfi_vlan = proto_registrar_get_nth(proto_vlan); + + proto_register_fields(proto_vlan, hfi, array_length(hfi)); proto_register_subtree_array(ett, array_length(ett)); expert_vlan = expert_register_protocol(proto_vlan); expert_register_field_array(expert_vlan, ei, array_length(ei)); @@ -200,18 +221,17 @@ proto_register_vlan(void) "The (hexadecimal) Ethertype used to indicate 802.1QinQ VLAN in VLAN tunneling.", 16, &q_in_q_ethertype); + vlan_handle = create_dissector_handle(dissect_vlan, proto_vlan); } void proto_reg_handoff_vlan(void) { static gboolean prefs_initialized = FALSE; - static dissector_handle_t vlan_handle; static unsigned int old_q_in_q_ethertype; if (!prefs_initialized) { - vlan_handle = create_dissector_handle(dissect_vlan, proto_vlan); dissector_add_uint("ethertype", ETHERTYPE_VLAN, vlan_handle); prefs_initialized = TRUE; } |