Make GRE use a dissector table for its protocol types, and register

dissectors for protcools that can be encapsulated inside GRE in that
table.

Fix a bug in the handling of WCCPv2 IP encapsulation (it was
constructing the next tvbuff before, rather than after, advancing the
offset past the redirection header).

svn path=/trunk/; revision=2893
This commit is contained in:
Guy Harris 2001-01-13 07:47:49 +00:00
parent 2072d03e78
commit 914d1da71f
8 changed files with 81 additions and 65 deletions

View File

@ -1,7 +1,7 @@
# Makefile.am
# Automake file for Ethereal
#
# $Id: Makefile.am,v 1.275 2001/01/13 03:17:15 gram Exp $
# $Id: Makefile.am,v 1.276 2001/01/13 07:47:48 guy Exp $
#
# Ethereal - Network traffic analyzer
# By Gerald Combs <gerald@zing.org>
@ -279,6 +279,7 @@ ETHEREAL_COMMON_SOURCES = \
etypes.h \
follow.c \
follow.h \
greproto.h \
in_cksum.c \
in_cksum.h \
ipproto.c \

View File

@ -1,7 +1,7 @@
/* etypes.h
* Defines ethernet packet types, similar to tcpdump's ethertype.h
*
* $Id: etypes.h,v 1.14 2000/08/09 22:10:23 deniel Exp $
* $Id: etypes.h,v 1.15 2001/01/13 07:47:48 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -154,6 +154,10 @@
#define ETHERTYPE_MPLS_MULTI 0x8848 /* MPLS multicast packet */
#endif
#ifndef ETHERTYPE_PPP
#define ETHERTYPE_PPP 0x880b /* no, this is not PPPoE */
#endif
#endif /* etypes.h */

36
greproto.h Normal file
View File

@ -0,0 +1,36 @@
/* greproto.h
* Protocol type values for for the Generic Routing Encapsulation (GRE)
* protocol
* Brad Robel-Forrest <brad.robel-forrest@watchguard.com>
*
* The protocol type in GRE is supposed to be an Ethernet type value;
* this file lists protocol type values for which nobody's found an
* official Ethernet type definition and put that in "etypes.h".
* Move these to "etypes.h" if you find an official Ethernet type
* definition for them; when this file is empty, get rid of all includes
* of it, and get rid of it.
*
* $Id: greproto.h,v 1.1 2001/01/13 07:47:48 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
* 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.
*/
#define GRE_WCCP 0x883E
#define GRE_FR 0x6559

View File

@ -3,7 +3,7 @@
*
* Copyright 2001, Paul Ionescu <paul@acorp.ro>
*
* $Id: packet-fr.c,v 1.6 2001/01/10 09:07:35 guy Exp $
* $Id: packet-fr.c,v 1.7 2001/01/13 07:47:48 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -40,6 +40,7 @@
#include "xdlc.h"
#include "oui.h"
#include "nlpid.h"
#include "greproto.h"
static gint proto_fr = -1;
static gint ett_fr = -1;
@ -228,14 +229,12 @@ void proto_register_fr(void)
proto_register_field_array(proto_fr, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
register_dissector("fr", dissect_fr, proto_fr);
fr_subdissector_table = register_dissector_table("fr.ietf");
fr_cisco_subdissector_table = register_dissector_table("fr.cisco");
};
}
void proto_reg_handoff_fr(void)
{
dissector_add("wtap_encap", WTAP_ENCAP_FRELAY, dissect_fr, proto_fr);
dissector_add("gre.proto", GRE_FR, dissect_fr, proto_fr);
}

View File

@ -2,7 +2,7 @@
* Routines for the Generic Routing Encapsulation (GRE) protocol
* Brad Robel-Forrest <brad.robel-forrest@watchguard.com>
*
* $Id: packet-gre.c,v 1.37 2001/01/09 09:59:28 guy Exp $
* $Id: packet-gre.c,v 1.38 2001/01/13 07:47:48 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -36,6 +36,8 @@
#include <netinet/in.h>
#endif
#include <glib.h>
#include "etypes.h"
#include "greproto.h"
#include "packet.h"
#include "packet-ip.h"
#include "packet-ipx.h"
@ -49,6 +51,8 @@ static gint ett_gre = -1;
static gint ett_gre_flags = -1;
static gint ett_gre_wccp2_redirect_header = -1;
static dissector_table_t gre_dissector_table;
/* bit positions for flags in header */
#define GH_B_C 0x8000
#define GH_B_R 0x4000
@ -61,29 +65,18 @@ static gint ett_gre_wccp2_redirect_header = -1;
#define GH_R_FLAGS 0x00F8
#define GH_B_VER 0x0007
#define GRE_PPP 0x880B
#define GRE_IP 0x0800
#define GRE_WCCP 0x883E
#define GRE_IPX 0x8137
#define GRE_FR 0x6559
static void add_flags_and_ver(proto_tree *, guint16, tvbuff_t *, int, int);
static void dissect_gre_wccp2_redirect_header(tvbuff_t *, int, proto_tree *);
static const value_string typevals[] = {
{ GRE_PPP, "PPP" },
{ GRE_IP, "IP" },
{ GRE_WCCP, "WCCP"},
{ GRE_IPX, "IPX"},
{ GRE_FR, "FR"},
{ 0, NULL }
{ ETHERTYPE_PPP, "PPP" },
{ ETHERTYPE_IP, "IP" },
{ GRE_WCCP, "WCCP"},
{ ETHERTYPE_IPX, "IPX"},
{ GRE_FR, "FR"},
{ 0, NULL }
};
static dissector_handle_t ip_handle;
static dissector_handle_t ipx_handle;
static dissector_handle_t ppp_handle;
static dissector_handle_t fr_handle;
static void
dissect_gre(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
@ -122,7 +115,7 @@ dissect_gre(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
len += 4;
switch (type) {
case GRE_PPP:
case ETHERTYPE_PPP:
if (flags_and_ver & GH_P_A)
len += 4;
is_ppp = TRUE;
@ -257,32 +250,16 @@ dissect_gre(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
}
}
next_tvb = tvb_new_subset(tvb, offset, -1, -1);
switch (type) {
case GRE_PPP:
call_dissector(ppp_handle, next_tvb, pinfo, tree);
break;
case GRE_IP:
call_dissector(ip_handle, next_tvb, pinfo, tree);
break;
case GRE_WCCP:
if (is_wccp2) {
if (tree)
dissect_gre_wccp2_redirect_header(tvb, offset, gre_tree);
offset += 4;
}
call_dissector(ip_handle, next_tvb, pinfo, tree);
break;
case GRE_IPX:
call_dissector(ipx_handle, next_tvb, pinfo, tree);
break;
case GRE_FR:
call_dissector(fr_handle, next_tvb, pinfo, tree);
break;
default:
dissect_data(next_tvb, 0, pinfo, gre_tree);
break;
if (type == GRE_WCCP) {
if (is_wccp2) {
if (tree)
dissect_gre_wccp2_redirect_header(tvb, offset, gre_tree);
offset += 4;
}
}
next_tvb = tvb_new_subset(tvb, offset, -1, -1);
if (!dissector_try_port(gre_dissector_table, type, next_tvb, pinfo, tree))
dissect_data(next_tvb, 0, pinfo, gre_tree);
}
static void
@ -380,18 +357,13 @@ proto_register_gre(void)
"GRE", "gre");
proto_register_field_array(proto_gre, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
/* subdissector code */
gre_dissector_table = register_dissector_table("gre.proto");
}
void
proto_reg_handoff_gre(void)
{
dissector_add("ip.proto", IP_PROTO_GRE, dissect_gre, proto_gre);
/*
* Get handles for the IP, IPX, PPP, and Frame Relay dissectors.
*/
ip_handle = find_dissector("ip");
ipx_handle = find_dissector("ipx");
ppp_handle = find_dissector("ppp");
fr_handle = find_dissector("fr");
}

View File

@ -1,7 +1,7 @@
/* packet-ip.c
* Routines for IP and miscellaneous IP protocol packet disassembly
*
* $Id: packet-ip.c,v 1.120 2001/01/10 09:07:35 guy Exp $
* $Id: packet-ip.c,v 1.121 2001/01/13 07:47:48 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -47,6 +47,7 @@
#include "resolv.h"
#include "prefs.h"
#include "etypes.h"
#include "greproto.h"
#include "ppptypes.h"
#include "llcsaps.h"
#include "aftypes.h"
@ -1483,13 +1484,14 @@ proto_reg_handoff_ip(void)
dissector_add("ethertype", ETHERTYPE_IP, dissect_ip, proto_ip);
dissector_add("ppp.protocol", PPP_IP, dissect_ip, proto_ip);
dissector_add("ppp.protocol", ETHERTYPE_IP, dissect_ip, proto_ip);
dissector_add("gre.proto", ETHERTYPE_IP, dissect_ip, proto_ip);
dissector_add("gre.proto", GRE_WCCP, dissect_ip, proto_ip);
dissector_add("llc.dsap", SAP_IP, dissect_ip, proto_ip);
dissector_add("ip.proto", IP_PROTO_IPV4, dissect_ip, proto_ip);
dissector_add("ip.proto", IP_PROTO_IPIP, dissect_ip, proto_ip);
dissector_add("null.type", BSD_AF_INET, dissect_ip, proto_ip);
dissector_add("fr.cisco", ETHERTYPE_IP, dissect_ip, proto_ip);
dissector_add("fr.ietf", NLPID_IP, dissect_ip, proto_ip);
dissector_add("fr.cisco", ETHERTYPE_IP, dissect_ip, proto_ip);
dissector_add("fr.ietf", NLPID_IP, dissect_ip, proto_ip);
}
void

View File

@ -2,7 +2,7 @@
* Routines for NetWare's IPX
* Gilbert Ramirez <gram@xiexie.org>
*
* $Id: packet-ipx.c,v 1.75 2001/01/10 09:07:35 guy Exp $
* $Id: packet-ipx.c,v 1.76 2001/01/13 07:47:48 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -920,6 +920,7 @@ proto_reg_handoff_ipx(void)
dissector_add("ppp.protocol", PPP_IPX, dissect_ipx, proto_ipx);
dissector_add("llc.dsap", SAP_NETWARE, dissect_ipx, proto_ipx);
dissector_add("null.type", BSD_AF_IPX, dissect_ipx, proto_ipx);
dissector_add("gre.proto", ETHERTYPE_IPX, dissect_ipx, proto_ipx);
dissector_add("ipx.packet_type", IPX_PACKET_TYPE_SPX, dissect_spx,
proto_spx);
dissector_add("ipx.socket", IPX_SOCKET_SAP, dissect_ipxsap,

View File

@ -1,7 +1,7 @@
/* packet-ppp.c
* Routines for ppp packet disassembly
*
* $Id: packet-ppp.c,v 1.52 2001/01/10 09:07:35 guy Exp $
* $Id: packet-ppp.c,v 1.53 2001/01/13 07:47:49 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -1473,4 +1473,5 @@ proto_reg_handoff_ppp(void)
dissector_add("wtap_encap", WTAP_ENCAP_PPP, dissect_ppp, proto_ppp);
dissector_add("wtap_encap", WTAP_ENCAP_PPP_WITH_PHDR, dissect_ppp, proto_ppp);
dissector_add("fr.ietf", NLPID_PPP, dissect_ppp, proto_ppp);
dissector_add("gre.proto", ETHERTYPE_PPP, dissect_ppp, proto_ppp);
}