1998-09-16 02:39:15 +00:00
|
|
|
/* packet-udp.c
|
|
|
|
* Routines for UDP packet disassembly
|
|
|
|
*
|
2000-04-20 07:05:58 +00:00
|
|
|
* $Id: packet-udp.c,v 1.69 2000/04/20 07:05:57 guy Exp $
|
1998-09-16 03:22:19 +00:00
|
|
|
*
|
1998-09-16 02:39:15 +00:00
|
|
|
* Ethereal - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@zing.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
1999-02-15 06:36:57 +00:00
|
|
|
* Richard Sharpe, 13-Feb-1999, added dispatch table support and
|
|
|
|
* support for tftp.
|
1998-09-16 02:39:15 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
# include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
1999-03-23 03:14:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
1999-12-09 20:43:38 +00:00
|
|
|
#include "globals.h"
|
1998-09-16 02:39:15 +00:00
|
|
|
#include "resolv.h"
|
|
|
|
|
1999-12-09 20:43:38 +00:00
|
|
|
#include "plugins.h"
|
2000-04-16 22:46:25 +00:00
|
|
|
#include "packet-udp.h"
|
1999-12-09 20:43:38 +00:00
|
|
|
|
2000-04-16 22:46:25 +00:00
|
|
|
#include "packet-ip.h"
|
2000-02-15 21:06:58 +00:00
|
|
|
#include "packet-ncp.h"
|
|
|
|
#include "packet-rpc.h"
|
|
|
|
#include "packet-tftp.h"
|
|
|
|
#include "packet-vines.h"
|
|
|
|
|
1999-11-16 11:44:20 +00:00
|
|
|
static int proto_udp = -1;
|
|
|
|
static int hf_udp_srcport = -1;
|
|
|
|
static int hf_udp_dstport = -1;
|
|
|
|
static int hf_udp_port = -1;
|
|
|
|
static int hf_udp_length = -1;
|
|
|
|
static int hf_udp_checksum = -1;
|
|
|
|
|
|
|
|
static gint ett_udp = -1;
|
1999-07-22 16:41:22 +00:00
|
|
|
|
1999-03-23 03:14:46 +00:00
|
|
|
/* UDP structs and definitions */
|
|
|
|
|
|
|
|
typedef struct _e_udphdr {
|
|
|
|
guint16 uh_sport;
|
|
|
|
guint16 uh_dport;
|
|
|
|
guint16 uh_ulen;
|
|
|
|
guint16 uh_sum;
|
|
|
|
} e_udphdr;
|
|
|
|
|
|
|
|
/* UDP Ports -> should go in packet-udp.h */
|
|
|
|
|
|
|
|
#define UDP_PORT_TFTP 69
|
|
|
|
#define UDP_PORT_VINES 573
|
|
|
|
|
2000-04-03 09:24:12 +00:00
|
|
|
static dissector_table_t udp_dissector_table;
|
1999-02-15 06:36:57 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
/* Determine if there is a sub-dissector and call it. This has been */
|
|
|
|
/* separated into a stand alone routine to other protocol dissectors */
|
|
|
|
/* can call to it, ie. socks */
|
1999-10-02 16:58:41 +00:00
|
|
|
|
2000-04-17 02:39:55 +00:00
|
|
|
void
|
|
|
|
decode_udp_ports( const u_char *pd, int offset, frame_data *fd,
|
|
|
|
proto_tree *tree, int uh_sport, int uh_dport){
|
2000-04-12 22:53:16 +00:00
|
|
|
dissector_t sub_dissector;
|
1999-07-22 16:41:22 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
/* determine if this packet is part of a conversation and call dissector */
|
|
|
|
/* for the conversation if available */
|
1999-07-22 16:41:22 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
sub_dissector = find_conversation_dissector( &pi.src, &pi.dst, PT_UDP,
|
|
|
|
uh_sport, uh_dport);
|
|
|
|
if (sub_dissector){
|
|
|
|
(sub_dissector)(pd, offset, fd, tree);
|
|
|
|
return;
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
|
|
|
|
1999-11-14 20:44:52 +00:00
|
|
|
/* ONC RPC. We can't base this on anything in the UDP header; we have
|
|
|
|
to look at the payload. If "dissect_rpc()" returns TRUE, it was
|
|
|
|
an RPC packet, otherwise it's some other type of packet. */
|
|
|
|
if (dissect_rpc(pd, offset, fd, tree))
|
|
|
|
return;
|
1999-10-29 01:04:44 +00:00
|
|
|
|
1999-12-09 20:43:38 +00:00
|
|
|
/* try to apply the plugins */
|
2000-01-15 00:23:13 +00:00
|
|
|
#ifdef HAVE_PLUGINS
|
1999-12-09 20:43:38 +00:00
|
|
|
{
|
|
|
|
plugin *pt_plug = plugin_list;
|
|
|
|
|
2000-04-04 22:26:36 +00:00
|
|
|
if (enabled_plugins_number > 0) {
|
1999-12-09 20:43:38 +00:00
|
|
|
while (pt_plug) {
|
|
|
|
if (pt_plug->enabled && !strcmp(pt_plug->protocol, "udp") &&
|
2000-04-14 05:39:43 +00:00
|
|
|
tree && dfilter_apply(pt_plug->filter, tree, pd, fd->cap_len)) {
|
1999-12-09 20:43:38 +00:00
|
|
|
pt_plug->dissector(pd, offset, fd, tree);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pt_plug = pt_plug->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-04-17 02:39:55 +00:00
|
|
|
/* do lookup with the subdissector table */
|
|
|
|
if (dissector_try_port(udp_dissector_table, uh_sport, pd, offset, fd, tree) ||
|
|
|
|
dissector_try_port(udp_dissector_table, uh_dport, pd, offset, fd, tree))
|
|
|
|
return;
|
|
|
|
|
2000-04-17 02:47:43 +00:00
|
|
|
/* XXX - we should do these with the subdissector table as well. */
|
1999-06-25 07:15:02 +00:00
|
|
|
#define PORT_IS(port) (uh_sport == port || uh_dport == port)
|
2000-04-18 04:46:07 +00:00
|
|
|
if (PORT_IS(UDP_PORT_VINES)) {
|
2000-04-17 02:39:55 +00:00
|
|
|
/* FIXME: AFAIK, src and dst port must be the same */
|
|
|
|
dissect_vines_frp(pd, offset, fd, tree);
|
Generalize the "ip_src" and "ip_dst" members of the "packet_info"
structure to "dl_src"/"dl_dst", "net_src"/"net_dst", and "src"/"dst"
addresses, where an address is an address type, an address length in
bytes, and a pointer to that many bytes.
"dl_{src,dst}" are the link-layer source/destination; "net_{src,dst}"
are the network-layer source/destination; "{src,dst}" are the
source/destination from the highest of those two layers that we have in
the packet.
Add a port type to "packet_info" as well, specifying whether it's a TCP
or UDP port.
Don't set the address and port columns in the dissector functions; just
set the address and port members of the "packet_info" structure. Set
the columns in "fill_in_columns()"; this means that if we're showing
COL_{DEF,RES,UNRES}_SRC" or "COL_{DEF,RES,UNRES}_DST", we only generate
the string from "src" or "dst", we don't generate a string for the
link-layer address and then overwrite it with a string for the
network-layer address (generating those strings costs CPU).
Add support for "conversations", where a "conversation" is (at present)
a source and destination address and a source and destination port. (In
the future, we may support "conversations" above the transport layer,
e.g. a TFTP conversation, where the first packet goes from the client to
the TFTP server port, but the reply comes back from a different port,
and all subsequent packets go between the client address/port and the
server address/new port, or an NFS conversation, which might include
lock manager, status monitor, and mount packets, as well as NFS
packets.)
Currently, all we support is a call that takes the source and
destination address/port pairs, looks them up in a hash table, and:
if nothing is found, creates a new entry in the hash table, and
assigns it a unique 32-bit conversation ID, and returns that
conversation ID;
if an entry is found, returns its conversation ID.
Use that in the SMB and AFS code to keep track of individual SMB or AFS
conversations. We need to match up requests and replies, as, for
certain replies, the operation code for the request to which it's a
reply doesn't show up in the reply - you have to find the request with a
matching transaction ID. Transaction IDs are per-conversation, so the
hash table for requests should include a conversation ID and transaction
ID as the key.
This allows SMB and AFS decoders to handle IPv4 or IPv6 addresses
transparently (and should allow the SMB decoder to handle NetBIOS atop
other protocols as well, if the source and destination address and port
values in the "packet_info" structure are set appropriately).
In the "Follow TCP Connection" code, check to make sure that the
addresses are IPv4 addressses; ultimately, that code should be changed
to use the conversation code instead, which will let it handle IPv6
transparently.
svn path=/trunk/; revision=909
1999-10-22 07:18:23 +00:00
|
|
|
} else if (PORT_IS(UDP_PORT_TFTP)) {
|
2000-04-17 02:39:55 +00:00
|
|
|
/* This is the first point of call, but it adds a dynamic call */
|
|
|
|
dissector_add("udp.port", MAX(uh_sport, uh_dport), dissect_tftp); /* Add to table */
|
|
|
|
dissect_tftp(pd, offset, fd, tree);
|
|
|
|
} else
|
|
|
|
dissect_data(pd, offset, fd, tree);
|
1998-09-16 02:39:15 +00:00
|
|
|
}
|
1999-07-22 16:41:22 +00:00
|
|
|
|
2000-04-12 22:53:16 +00:00
|
|
|
|
2000-04-20 07:05:58 +00:00
|
|
|
static void
|
2000-04-12 22:53:16 +00:00
|
|
|
dissect_udp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
|
|
|
|
e_udphdr uh;
|
|
|
|
guint16 uh_sport, uh_dport, uh_ulen, uh_sum;
|
|
|
|
proto_tree *udp_tree;
|
|
|
|
proto_item *ti;
|
|
|
|
|
|
|
|
if (!BYTES_ARE_IN_FRAME(offset, sizeof(e_udphdr))) {
|
|
|
|
dissect_data(pd, offset, fd, tree);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Avoids alignment problems on many architectures. */
|
|
|
|
memcpy(&uh, &pd[offset], sizeof(e_udphdr));
|
|
|
|
uh_sport = ntohs(uh.uh_sport);
|
|
|
|
uh_dport = ntohs(uh.uh_dport);
|
|
|
|
uh_ulen = ntohs(uh.uh_ulen);
|
|
|
|
uh_sum = ntohs(uh.uh_sum);
|
|
|
|
|
|
|
|
if (check_col(fd, COL_PROTOCOL))
|
|
|
|
col_add_str(fd, COL_PROTOCOL, "UDP");
|
|
|
|
if (check_col(fd, COL_INFO))
|
|
|
|
col_add_fstr(fd, COL_INFO, "Source port: %s Destination port: %s",
|
|
|
|
get_udp_port(uh_sport), get_udp_port(uh_dport));
|
|
|
|
|
|
|
|
if (tree) {
|
|
|
|
ti = proto_tree_add_item(tree, proto_udp, offset, 8);
|
|
|
|
udp_tree = proto_item_add_subtree(ti, ett_udp);
|
|
|
|
|
|
|
|
proto_tree_add_uint_format(udp_tree, hf_udp_srcport, offset, 2, uh_sport,
|
|
|
|
"Source port: %s (%u)", get_udp_port(uh_sport), uh_sport);
|
|
|
|
proto_tree_add_uint_format(udp_tree, hf_udp_dstport, offset + 2, 2, uh_dport,
|
|
|
|
"Destination port: %s (%u)", get_udp_port(uh_dport), uh_dport);
|
|
|
|
|
|
|
|
proto_tree_add_item_hidden(udp_tree, hf_udp_port, offset, 2, uh_sport);
|
|
|
|
proto_tree_add_item_hidden(udp_tree, hf_udp_port, offset+2, 2, uh_dport);
|
|
|
|
|
|
|
|
proto_tree_add_item(udp_tree, hf_udp_length, offset + 4, 2, uh_ulen);
|
|
|
|
proto_tree_add_uint_format(udp_tree, hf_udp_checksum, offset + 6, 2, uh_sum,
|
|
|
|
"Checksum: 0x%04x", uh_sum);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip over header */
|
|
|
|
offset += 8;
|
|
|
|
|
|
|
|
pi.ptype = PT_UDP;
|
|
|
|
pi.srcport = uh_sport;
|
|
|
|
pi.destport = uh_dport;
|
|
|
|
|
|
|
|
/* call sub-dissectors */
|
|
|
|
decode_udp_ports( pd, offset, fd, tree, uh_sport, uh_dport);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-07-22 16:41:22 +00:00
|
|
|
void
|
|
|
|
proto_register_udp(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_udp_srcport,
|
1999-10-12 06:21:15 +00:00
|
|
|
{ "Source Port", "udp.srcport", FT_UINT16, BASE_DEC, NULL, 0x0,
|
|
|
|
"" }},
|
1999-07-22 16:41:22 +00:00
|
|
|
|
|
|
|
{ &hf_udp_dstport,
|
1999-10-12 06:21:15 +00:00
|
|
|
{ "Destination Port", "udp.dstport", FT_UINT16, BASE_DEC, NULL, 0x0,
|
|
|
|
"" }},
|
1999-07-22 16:41:22 +00:00
|
|
|
|
|
|
|
{ &hf_udp_port,
|
1999-10-12 06:21:15 +00:00
|
|
|
{ "Source or Destination Port", "udp.port", FT_UINT16, BASE_DEC, NULL, 0x0,
|
|
|
|
"" }},
|
1999-07-22 16:41:22 +00:00
|
|
|
|
|
|
|
{ &hf_udp_length,
|
1999-10-12 06:21:15 +00:00
|
|
|
{ "Length", "udp.length", FT_UINT16, BASE_DEC, NULL, 0x0,
|
|
|
|
"" }},
|
1999-07-22 16:41:22 +00:00
|
|
|
|
|
|
|
{ &hf_udp_checksum,
|
1999-10-12 06:21:15 +00:00
|
|
|
{ "Checksum", "udp.checksum", FT_UINT16, BASE_HEX, NULL, 0x0,
|
|
|
|
"" }},
|
1999-07-22 16:41:22 +00:00
|
|
|
};
|
1999-11-16 11:44:20 +00:00
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_udp,
|
|
|
|
};
|
1999-07-22 16:41:22 +00:00
|
|
|
|
|
|
|
proto_udp = proto_register_protocol("User Datagram Protocol", "udp");
|
|
|
|
proto_register_field_array(proto_udp, hf, array_length(hf));
|
1999-11-16 11:44:20 +00:00
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
2000-04-03 09:41:31 +00:00
|
|
|
|
|
|
|
/* subdissector code */
|
Change the sub-dissector handoff registration routines so that the
sub-dissector table is not stored in the header_field_info struct, but
in a separate namespace. Dissector tables are now registered by name
and not by field ID. For example:
udp_dissector_table = register_dissector_table("udp.port");
Because of this different namespace, dissector tables can have names
that are not field names. This is useful for ethertype, since multiple
fields are "ethertypes".
packet-ethertype.c replaces ethertype.c (the name was changed so that it
would be named in the same fashion as all the filenames passed to make-reg-dotc)
Although it registers no protocol or field, it registers one dissector table:
ethertype_dissector_table = register_dissector_table("ethertype");
All protocols that can be called because of an ethertype field now register
that fact with dissector_add() calls.
In this way, one dissector_table services all ethertype fields
(hf_eth_type, hf_llc_type, hf_null_etype, hf_vlan_etype)
Furthermore, the code allows for names of protocols to exist in the
etype_vals, yet a dissector for that protocol doesn't exist. The name
of the dissector is printed in COL_INFO. You're welcome, Richard. :-)
svn path=/trunk/; revision=1848
2000-04-13 18:18:56 +00:00
|
|
|
udp_dissector_table = register_dissector_table("udp.port");
|
1999-07-22 16:41:22 +00:00
|
|
|
}
|
2000-04-16 22:46:25 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_udp(void)
|
|
|
|
{
|
|
|
|
dissector_add("ip.proto", IP_PROTO_UDP, dissect_udp);
|
|
|
|
}
|