From 307e13d9f2aefaa968f89d0bd065dbae5c992b64 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Fri, 3 Aug 2012 01:58:12 +0000 Subject: [PATCH] Move the list of AX.25 protocol IDs to epan/ax25_pids.h. Use it in packet-ax25.c and packet-arp.c. Add an "ax25.pid" dissector table for those protocol IDs, use it in the AX.25 dissector, and have dissectors register in that table with their protocol IDs. Get rid of some unneeded includes. Clean up some "AX25"s in user-visible strings - say "AX.25" instead. Clean up some indentation. svn path=/trunk/; revision=44235 --- epan/Makefile.common | 1 + epan/ax25_pids.h | 46 +++++++++++++++ epan/dissectors/packet-arp.c | 3 +- epan/dissectors/packet-ax25-nol3.c | 7 +-- epan/dissectors/packet-ax25.c | 95 ++++++------------------------ epan/dissectors/packet-flexnet.c | 7 +-- epan/dissectors/packet-ip.c | 2 + epan/dissectors/packet-netrom.c | 7 +-- epan/dissectors/packet-x25.c | 2 + 9 files changed, 78 insertions(+), 92 deletions(-) create mode 100644 epan/ax25_pids.h diff --git a/epan/Makefile.common b/epan/Makefile.common index af5f075ee1..9eaf49f9ae 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -134,6 +134,7 @@ LIBWIRESHARK_INCLUDES = \ aftypes.h \ arcnet_pids.h \ arptypes.h \ + ax25_pids.h \ asn1.h \ atalk-utils.h \ base64.h \ diff --git a/epan/ax25_pids.h b/epan/ax25_pids.h new file mode 100644 index 0000000000..6fd6413803 --- /dev/null +++ b/epan/ax25_pids.h @@ -0,0 +1,46 @@ +/* ax25_pids.h + * + * Protocol IDs for Amateur Packet Radio protocol dissection + * Copyright 2005,2006,2007,2008,2009,2010,2012 R.W. Stearn + * + * $Id$ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __AX25_PIDS_H__ +#define __AX25_PIDS_H__ + +/* AX.25 Layer 3 Protocol ID's (pid) */ +#define AX25_P_ROSE 0x01 /* ISO 8208 / CCITT X.25 PLP */ +#define AX25_P_RFC1144C 0x06 /* Compressed TCP/IP packet. Van Jacobson RFC1144 */ +#define AX25_P_RFC1144 0x07 /* Uncompressed TCP/IP packet. Van Jacobson RFC1144 */ +#define AX25_P_SEGMENT 0x08 /* segmentation fragment */ +#define AX25_P_TEXNET 0xC3 /* TEXNET datagram */ +#define AX25_P_LCP 0xC4 /* Link Quality Protocol */ +#define AX25_P_ATALK 0xCA /* AppleTalk */ +#define AX25_P_ATALKARP 0xCB /* AppleTalk ARP */ +#define AX25_P_IP 0xCC /* ARPA Internet Protocol */ +#define AX25_P_ARP 0xCD /* ARPA Address Resolution Protocol */ +#define AX25_P_FLEXNET 0xCE /* FlexNet */ +#define AX25_P_NETROM 0xCF /* NET/ROM */ +#define AX25_P_NO_L3 0xF0 /* No layer 3 protocol */ +#define AX25_P_L3_ESC 0xFF /* Escape character. Next octet contains more layer 3 protocol info */ + +#endif /* __AX25_PIDS_H__ */ diff --git a/epan/dissectors/packet-arp.c b/epan/dissectors/packet-arp.c index 41d5624c0f..dc65877afe 100644 --- a/epan/dissectors/packet-arp.c +++ b/epan/dissectors/packet-arp.c @@ -39,6 +39,7 @@ #include "packet-arp.h" #include #include +#include #include #include @@ -345,7 +346,6 @@ static const value_string atmop_vals[] = { */ #define ARP_HW_IS_AX25(ar_hrd, ar_hln) \ ((ar_hrd) == ARPHRD_AX25 && (ar_hln) == 7) -#define AX25_P_IP 0xCC /* ARPA Internet Protocol on AX.25 */ /* * Given the protocol address type and length, check whether an address @@ -2051,4 +2051,5 @@ proto_reg_handoff_arp(void) dissector_add_uint("arcnet.protocol_id", ARCNET_PROTO_ARP_1051, arp_handle); dissector_add_uint("arcnet.protocol_id", ARCNET_PROTO_ARP_1201, arp_handle); dissector_add_uint("arcnet.protocol_id", ARCNET_PROTO_RARP_1201, arp_handle); + dissector_add_uint("ax25.pid", AX25_P_ARP, arp_handle); } diff --git a/epan/dissectors/packet-ax25-nol3.c b/epan/dissectors/packet-ax25-nol3.c index ddaa168093..881afa529f 100644 --- a/epan/dissectors/packet-ax25-nol3.c +++ b/epan/dissectors/packet-ax25-nol3.c @@ -62,6 +62,7 @@ #include #include #include +#include #define STRLEN 80 @@ -265,10 +266,7 @@ proto_register_ax25_nol3(void) }; /* Register the protocol name and description */ - proto_ax25_nol3 = proto_register_protocol("AX25 no Layer 3", "AX25 no L3", "ax25_nol3"); - - /* Register the dissector */ - register_dissector( "ax25_nol3", dissect_ax25_nol3, proto_ax25_nol3 ); + proto_ax25_nol3 = proto_register_protocol("AX.25 no Layer 3", "AX.25 no L3", "ax25_nol3"); /* Required function calls to register the header fields and subtrees used */ proto_register_field_array( proto_ax25_nol3, hf, array_length(hf ) ); @@ -307,6 +305,7 @@ proto_reg_handoff_ax25_nol3(void) static gboolean inited = FALSE; if( !inited ) { + dissector_add_uint( "ax25.pid", AX25_P_NO_L3, create_dissector_handle( dissect_ax25_nol3, proto_ax25_nol3 ) ); /* */ diff --git a/epan/dissectors/packet-ax25.c b/epan/dissectors/packet-ax25.c index 328a0f5133..a335abf0ae 100644 --- a/epan/dissectors/packet-ax25.c +++ b/epan/dissectors/packet-ax25.c @@ -54,7 +54,7 @@ #include #include #include -#include +#include #include #include @@ -67,44 +67,16 @@ #define AX25_HEADER_SIZE 15 /* length of src_addr + dst_addr + cntl */ #define AX25_MAX_DIGIS 8 -/* Layer 3 Protocol ID's (pid) */ -#define AX25_P_ROSE 0x01 /* ISO 8208 / CCITT X.25 PLP */ -#define AX25_P_RFC1144C 0x06 /* Compressed TCP/IP packet. Van Jacobson RFC1144 */ -#define AX25_P_RFC1144 0x07 /* Uncompressed TCP/IP packet. Van Jacobson RFC1144 */ -#define AX25_P_SEGMENT 0x08 /* segmentation fragment */ -#define AX25_P_TEXNET 0xC3 /* TEXNET datagram */ -#define AX25_P_LCP 0xC4 /* Link Quality Protocol */ -#define AX25_P_ATALK 0xCA /* AppleTalk */ -#define AX25_P_ATALKARP 0xCB /* AppleTalk ARP */ -#define AX25_P_IP 0xCC /* ARPA Internet Protocol */ -#define AX25_P_ARP 0xCD /* ARPA Address Resolution Protocol */ -#define AX25_P_FLEXNET 0xCE /* FlexNet */ -#define AX25_P_NETROM 0xCF /* NET/ROM */ -#define AX25_P_NO_L3 0xF0 /* No layer 3 protocol */ -#define AX25_P_L3_ESC 0xFF /* Escape character. Next octet contains more layer 3 protocol info */ - #define I_FRAME( control ) ( ( control & 0x01) == 0 ) #define UI_FRAME( control ) ( ( ( control & 0x03) == 3 ) && ( ( ( ( ( control >> 5 ) & 0x07) << 2) | ( ( control >> 2 ) & 0x03) ) == 0 ) ) /* Forward declaration we need below */ void proto_reg_handoff_ax25(void); -/* Dissector handles - all the possibles are listed */ -static dissector_handle_t x25_handle; -static dissector_handle_t rfc1144c_handle; -static dissector_handle_t rfc1144_handle; -static dissector_handle_t segment_handle; -static dissector_handle_t texnet_handle; -static dissector_handle_t lcp_handle; -static dissector_handle_t atalk_handle; -static dissector_handle_t atalkarp_handle; -static dissector_handle_t ip_handle; -static dissector_handle_t arp_handle; -static dissector_handle_t flexnet_handle; -static dissector_handle_t netrom_handle; -static dissector_handle_t no_l3_handle; -static dissector_handle_t l3_esc_handle; -static dissector_handle_t default_handle; +/* Dissector table */ +static dissector_table_t ax25_dissector_table; + +static dissector_handle_t data_handle; /* Initialize the protocol and registered fields */ static int proto_ax25 = -1; @@ -311,24 +283,11 @@ dissect_ax25( tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree ) next_tvb = tvb_new_subset(tvb, offset, -1, -1); - switch ( pid ) + if (!dissector_try_uint(ax25_dissector_table, pid, next_tvb, pinfo, parent_tree)) { - case AX25_P_ROSE : call_dissector( x25_handle , next_tvb, pinfo, parent_tree ); break; - case AX25_P_RFC1144C : call_dissector( rfc1144c_handle, next_tvb, pinfo, parent_tree ); break; - case AX25_P_RFC1144 : call_dissector( rfc1144_handle , next_tvb, pinfo, parent_tree ); break; - case AX25_P_SEGMENT : call_dissector( segment_handle , next_tvb, pinfo, parent_tree ); break; - case AX25_P_TEXNET : call_dissector( texnet_handle , next_tvb, pinfo, parent_tree ); break; - case AX25_P_LCP : call_dissector( lcp_handle , next_tvb, pinfo, parent_tree ); break; - case AX25_P_ATALK : call_dissector( atalk_handle , next_tvb, pinfo, parent_tree ); break; - case AX25_P_ATALKARP : call_dissector( atalkarp_handle, next_tvb, pinfo, parent_tree ); break; - case AX25_P_IP : call_dissector( ip_handle , next_tvb, pinfo, parent_tree ); break; - case AX25_P_ARP : call_dissector( arp_handle , next_tvb, pinfo, parent_tree ); break; - case AX25_P_FLEXNET : call_dissector( flexnet_handle , next_tvb, pinfo, parent_tree ); break; - case AX25_P_NETROM : call_dissector( netrom_handle , next_tvb, pinfo, parent_tree ); break; - case AX25_P_NO_L3 : call_dissector( no_l3_handle , next_tvb, pinfo, parent_tree ); break; - case AX25_P_L3_ESC : call_dissector( l3_esc_handle , next_tvb, pinfo, parent_tree ); break; - default : call_dissector( default_handle , next_tvb, pinfo, parent_tree ); break; + call_dissector(data_handle, next_tvb, pinfo, parent_tree); } + pinfo->private_data = saved_private_data; } } @@ -459,7 +418,7 @@ proto_register_ax25(void) }; /* Register the protocol name and description */ - proto_ax25 = proto_register_protocol("Amateur Radio AX.25", "AX25", "ax25"); + proto_ax25 = proto_register_protocol("Amateur Radio AX.25", "AX.25", "ax25"); /* Register the dissector */ register_dissector( "ax25", dissect_ax25, proto_ax25 ); @@ -467,6 +426,9 @@ proto_register_ax25(void) /* Required function calls to register the header fields and subtrees used */ proto_register_field_array( proto_ax25, hf, array_length(hf ) ); proto_register_subtree_array(ett, array_length(ett ) ); + + /* Register dissector table for protocol IDs */ + ax25_dissector_table = register_dissector_table("ax25.pid", "AX.25 protocol ID", FT_UINT8, BASE_HEX); } void @@ -476,36 +438,15 @@ proto_reg_handoff_ax25(void) if( !inited ) { - dissector_handle_t ax25_handle; + dissector_handle_t ax25_handle; - ax25_handle = create_dissector_handle( dissect_ax25, proto_ax25 ); - dissector_add_uint("wtap_encap", WTAP_ENCAP_AX25, ax25_handle); - dissector_add_uint("ip.proto", IP_PROTO_AX25, ax25_handle); + ax25_handle = create_dissector_handle( dissect_ax25, proto_ax25 ); + dissector_add_uint("wtap_encap", WTAP_ENCAP_AX25, ax25_handle); + dissector_add_uint("ip.proto", IP_PROTO_AX25, ax25_handle); - /* - I have added the "data" dissector for all the currently known PID's - This is so at least we have an entry in the tree that allows the - payload to be hightlighted. - When a new dissector is available all that needs to be done is to - replace the current dissector name "data" with the new dissector name. - */ - x25_handle = find_dissector( "x.25" ); - rfc1144c_handle = find_dissector( "data" /* "rfc1144c" */ ); - rfc1144_handle = find_dissector( "data" /* "rfc1144" */ ); - segment_handle = find_dissector( "data" /* "segment" */ ); - texnet_handle = find_dissector( "data" /* "texnet" */ ); - lcp_handle = find_dissector( "data" /* "lcp" */ ); - atalk_handle = find_dissector( "data" /* "atalk" */ ); - atalkarp_handle = find_dissector( "data" /* "atalkarp" */ ); - ip_handle = find_dissector( "ip" ); - arp_handle = find_dissector( "arp" ); - flexnet_handle = find_dissector( "flexnet" ); - netrom_handle = find_dissector( "netrom" ); - no_l3_handle = find_dissector( "ax25_nol3" ); - l3_esc_handle = find_dissector( "data" /* "l3_esc" */ ); - default_handle = find_dissector( "data" ); + data_handle = find_dissector( "data" ); - inited = TRUE; + inited = TRUE; } } diff --git a/epan/dissectors/packet-flexnet.c b/epan/dissectors/packet-flexnet.c index fce657bd3f..7b7ec4e07d 100644 --- a/epan/dissectors/packet-flexnet.c +++ b/epan/dissectors/packet-flexnet.c @@ -49,8 +49,7 @@ #include #include #include -#include -#include +#include #define FLEXNET_ADRLEN 15 #define FLEXNET_CTLLEN 15 @@ -147,9 +146,6 @@ proto_register_flexnet(void) /* Register the protocol name and description */ proto_flexnet = proto_register_protocol("FlexNet", "FLEXNET", "flexnet"); - /* Register the dissector */ - register_dissector( "flexnet", dissect_flexnet, proto_flexnet ); - /* Required function calls to register the header fields and subtrees used */ proto_register_field_array( proto_flexnet, hf, array_length( hf ) ); proto_register_subtree_array( ett, array_length( ett ) ); @@ -161,6 +157,7 @@ proto_reg_handoff_flexnet(void) static gboolean inited = FALSE; if( !inited ) { + dissector_add_uint( "ax25.pid", AX25_P_FLEXNET, create_dissector_handle( dissect_flexnet, proto_flexnet ) ); /* */ diff --git a/epan/dissectors/packet-ip.c b/epan/dissectors/packet-ip.c index 14bf19b2a1..ac4f019857 100644 --- a/epan/dissectors/packet-ip.c +++ b/epan/dissectors/packet-ip.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -2929,6 +2930,7 @@ proto_reg_handoff_ip(void) dissector_add_uint("x.25.spi", NLPID_IP, ip_handle); dissector_add_uint("arcnet.protocol_id", ARCNET_PROTO_IP_1051, ip_handle); dissector_add_uint("arcnet.protocol_id", ARCNET_PROTO_IP_1201, ip_handle); + dissector_add_uint("ax25.pid", AX25_P_IP, ip_handle); dissector_add_handle("udp.port", ip_handle); } diff --git a/epan/dissectors/packet-netrom.c b/epan/dissectors/packet-netrom.c index c131cb3e15..6536455861 100644 --- a/epan/dissectors/packet-netrom.c +++ b/epan/dissectors/packet-netrom.c @@ -49,8 +49,7 @@ #include #include #include -#include -#include +#include #include "packet-netrom.h" @@ -656,9 +655,6 @@ proto_register_netrom(void) /* Register the protocol name and description */ proto_netrom = proto_register_protocol( "Amateur Radio Net/ROM", "Net/ROM", "netrom" ); - /* Register the dissector */ - register_dissector( "netrom", dissect_netrom, proto_netrom ); - /* Required function calls to register the header fields and subtrees used */ proto_register_field_array( proto_netrom, hf, array_length(hf ) ); proto_register_subtree_array( ett, array_length( ett ) ); @@ -670,6 +666,7 @@ proto_reg_handoff_netrom(void) static gboolean inited = FALSE; if( !inited ) { + dissector_add_uint( "ax25.pid", AX25_P_NETROM, create_dissector_handle( dissect_netrom, proto_netrom ) ); ip_handle = find_dissector( "ip" ); default_handle = find_dissector( "data" ); diff --git a/epan/dissectors/packet-x25.c b/epan/dissectors/packet-x25.c index e239d225eb..1bc94dc610 100644 --- a/epan/dissectors/packet-x25.c +++ b/epan/dissectors/packet-x25.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -2770,4 +2771,5 @@ proto_reg_handoff_x25(void) x25_handle = find_dissector("x.25"); dissector_add_uint("llc.dsap", SAP_X25, x25_handle); dissector_add_uint("lapd.sapi", LAPD_SAPI_X25, x25_handle); + dissector_add_uint("ax25.pid", AX25_P_ROSE, x25_handle); }