2010-04-04 20:30:33 +00:00
|
|
|
/* packet-git.c
|
|
|
|
* Routines for git packet dissection
|
|
|
|
* RFC 1939
|
|
|
|
* Copyright 2010, Jelmer Vernooij <jelmer@samba.org>
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* Copied from packet-pop.c
|
|
|
|
*
|
|
|
|
* 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
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2010-04-04 20:30:33 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
2010-04-04 20:30:33 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
2012-05-15 19:23:35 +00:00
|
|
|
|
2010-04-04 20:30:33 +00:00
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/prefs.h>
|
|
|
|
#include "packet-tcp.h"
|
|
|
|
|
2013-12-14 12:45:57 +00:00
|
|
|
void proto_register_git(void);
|
|
|
|
void proto_reg_handoff_git(void);
|
|
|
|
|
2013-11-16 01:10:05 +00:00
|
|
|
static dissector_handle_t git_handle;
|
|
|
|
|
2010-04-04 20:30:33 +00:00
|
|
|
static int proto_git = -1;
|
|
|
|
|
|
|
|
static gint ett_git = -1;
|
|
|
|
|
|
|
|
static gint hf_git_packet_len = -1;
|
|
|
|
static gint hf_git_packet_data = -1;
|
|
|
|
static gint hf_git_packet_terminator = -1;
|
|
|
|
|
2014-09-30 23:12:26 +00:00
|
|
|
#define TCP_PORT_GIT 9418
|
2010-04-04 20:30:33 +00:00
|
|
|
|
|
|
|
/* desegmentation of Git over TCP */
|
|
|
|
static gboolean git_desegment = TRUE;
|
|
|
|
|
2013-11-09 17:46:28 +00:00
|
|
|
static gboolean get_packet_length(tvbuff_t *tvb, int offset,
|
2014-09-30 23:12:26 +00:00
|
|
|
guint16 *length)
|
2010-04-04 20:30:33 +00:00
|
|
|
{
|
2014-09-30 23:12:26 +00:00
|
|
|
guint8 *lenstr;
|
2010-04-04 20:30:33 +00:00
|
|
|
|
2014-09-30 23:12:26 +00:00
|
|
|
lenstr = tvb_get_string_enc(wmem_packet_scope(), tvb, offset, 4, ENC_ASCII);
|
2010-04-04 20:30:33 +00:00
|
|
|
|
2014-09-30 23:12:26 +00:00
|
|
|
return (sscanf(lenstr, "%hx", length) == 1);
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
get_git_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
|
|
|
|
{
|
2014-09-30 23:12:26 +00:00
|
|
|
guint16 plen;
|
2010-04-04 20:30:33 +00:00
|
|
|
|
2014-09-30 23:12:26 +00:00
|
|
|
if (!get_packet_length(tvb, offset, &plen))
|
|
|
|
return 0; /* No idea what this is */
|
2010-04-04 20:30:33 +00:00
|
|
|
|
2014-09-30 23:12:26 +00:00
|
|
|
if (plen == 0) {
|
|
|
|
/* Terminator packet */
|
|
|
|
return 4;
|
|
|
|
}
|
2013-11-09 17:46:28 +00:00
|
|
|
|
2014-09-30 23:12:26 +00:00
|
|
|
return plen;
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
2013-11-09 17:46:28 +00:00
|
|
|
static int
|
|
|
|
dissect_git_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
|
2010-04-04 20:30:33 +00:00
|
|
|
{
|
|
|
|
proto_tree *git_tree;
|
2010-11-04 11:27:34 +00:00
|
|
|
proto_item *ti;
|
2010-04-04 20:30:33 +00:00
|
|
|
int offset = 0;
|
|
|
|
guint16 plen;
|
|
|
|
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "GIT");
|
|
|
|
|
|
|
|
col_set_str(pinfo->cinfo, COL_INFO, "Git Smart Protocol");
|
|
|
|
|
2011-10-21 02:10:19 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_git, tvb, offset, -1, ENC_NA);
|
2010-04-04 20:30:33 +00:00
|
|
|
git_tree = proto_item_add_subtree(ti, ett_git);
|
|
|
|
|
2013-11-09 17:46:28 +00:00
|
|
|
if (!get_packet_length(tvb, 0, &plen))
|
2014-09-30 23:12:26 +00:00
|
|
|
return 0;
|
2010-04-04 20:30:33 +00:00
|
|
|
|
|
|
|
if (plen == 0) {
|
2014-09-30 23:12:26 +00:00
|
|
|
proto_tree_add_uint(git_tree, hf_git_packet_terminator, tvb, offset,
|
|
|
|
4, plen);
|
|
|
|
return 4;
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (git_tree)
|
|
|
|
{
|
2014-09-30 23:12:26 +00:00
|
|
|
proto_tree_add_uint(git_tree, hf_git_packet_len, tvb, offset,
|
|
|
|
4, plen);
|
2010-04-04 20:30:33 +00:00
|
|
|
|
2014-09-30 23:12:26 +00:00
|
|
|
proto_tree_add_item(git_tree, hf_git_packet_data, tvb, offset+4,
|
|
|
|
plen-4, ENC_NA);
|
2013-11-09 17:46:28 +00:00
|
|
|
}
|
|
|
|
|
2014-06-19 17:18:16 +00:00
|
|
|
return tvb_length(tvb);
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
2013-11-09 17:46:28 +00:00
|
|
|
static int
|
|
|
|
dissect_git(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
|
2010-04-04 20:30:33 +00:00
|
|
|
{
|
2014-09-30 23:12:26 +00:00
|
|
|
tcp_dissect_pdus(tvb, pinfo, tree, git_desegment, 4, get_git_pdu_len,
|
|
|
|
dissect_git_pdu, data);
|
|
|
|
return tvb_length(tvb);
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_git(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
2014-09-30 23:12:26 +00:00
|
|
|
{ &hf_git_packet_len,
|
|
|
|
{ "Packet length", "git.length", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
|
|
|
|
},
|
|
|
|
{ &hf_git_packet_data,
|
|
|
|
{ "Packet data", "git.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL },
|
|
|
|
},
|
|
|
|
{ &hf_git_packet_terminator,
|
|
|
|
{ "Terminator packet", "git.terminator", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL },
|
|
|
|
},
|
2010-04-04 20:30:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_git,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_t *git_module;
|
2013-11-16 01:10:05 +00:00
|
|
|
|
2010-04-04 20:30:33 +00:00
|
|
|
proto_git = proto_register_protocol("Git Smart Protocol", "GIT", "git");
|
|
|
|
proto_register_field_array(proto_git, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
|
2013-11-16 01:10:05 +00:00
|
|
|
git_handle = new_register_dissector("git", dissect_git, proto_git);
|
|
|
|
|
2010-04-04 20:30:33 +00:00
|
|
|
git_module = prefs_register_protocol(proto_git, NULL);
|
|
|
|
|
|
|
|
prefs_register_bool_preference(git_module, "desegment",
|
2014-09-30 23:12:26 +00:00
|
|
|
"Reassemble GIT messages spanning multiple TCP segments",
|
|
|
|
"Whether the GIT dissector should reassemble messages spanning multiple TCP segments."
|
|
|
|
" To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
|
|
|
|
&git_desegment);
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_git(void)
|
|
|
|
{
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_add_uint("tcp.port", TCP_PORT_GIT, git_handle);
|
2010-04-04 20:30:33 +00:00
|
|
|
}
|
2014-09-30 23:12:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 2
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=2 tabstop=8 expandtab:
|
|
|
|
* :indentSize=2:tabSize=8:noTabs=true:
|
|
|
|
*/
|