2013-07-11 21:13:27 +00:00
|
|
|
/* packet-openflow.c
|
|
|
|
* Routines for OpenFlow dissection
|
|
|
|
* Copyright 2013, Anders Broman <anders.broman@ericsson.com>
|
2013-11-06 22:07:04 +00:00
|
|
|
* Copyright 2013, Zoltan Lajos Kis <zoltan.lajos.kis@ericsson.com>
|
2013-07-11 21:13:27 +00:00
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2013-09-27 08:06:44 +00:00
|
|
|
* Ref https://www.opennetworking.org/sdn-resources/onf-specifications/openflow
|
2013-07-11 21:13:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/prefs.h>
|
|
|
|
|
2013-11-05 19:36:09 +00:00
|
|
|
#include "packet-tcp.h"
|
|
|
|
|
2013-10-23 20:54:17 +00:00
|
|
|
void proto_register_openflow(void);
|
2013-07-11 21:13:27 +00:00
|
|
|
void proto_reg_handoff_openflow(void);
|
|
|
|
|
|
|
|
static int g_openflow_port = 0;
|
|
|
|
|
2013-11-10 10:46:13 +00:00
|
|
|
static dissector_handle_t openflow_v1_handle;
|
2013-10-13 21:25:19 +00:00
|
|
|
static dissector_handle_t openflow_v4_handle;
|
2013-11-18 06:24:27 +00:00
|
|
|
static dissector_handle_t openflow_v5_handle;
|
2013-09-01 19:59:48 +00:00
|
|
|
|
2013-07-11 21:13:27 +00:00
|
|
|
/* Initialize the protocol and registered fields */
|
|
|
|
static int proto_openflow = -1;
|
|
|
|
static int hf_openflow_version = -1;
|
|
|
|
|
2013-11-05 19:36:09 +00:00
|
|
|
static gboolean openflow_desegment = TRUE;
|
|
|
|
|
2013-09-01 19:59:48 +00:00
|
|
|
#define OFP_VERSION_1_0 1
|
|
|
|
#define OFP_VERSION_1_1 2
|
|
|
|
#define OFP_VERSION_1_2 3
|
|
|
|
#define OFP_VERSION_1_3 4
|
2013-11-18 06:24:27 +00:00
|
|
|
#define OFP_VERSION_1_4 5
|
2013-07-11 21:13:27 +00:00
|
|
|
|
|
|
|
static const value_string openflow_version_values[] = {
|
|
|
|
{ 0x01, "1.0" },
|
|
|
|
{ 0x02, "1.1" },
|
|
|
|
{ 0x03, "1.2" },
|
2013-11-18 06:24:27 +00:00
|
|
|
{ 0x04, "1.3" },
|
|
|
|
{ 0x04, "1.4" },
|
2013-07-11 21:13:27 +00:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2013-09-26 21:05:04 +00:00
|
|
|
|
2013-11-05 19:36:09 +00:00
|
|
|
static guint
|
|
|
|
get_openflow_pdu_length(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
|
|
|
|
{
|
|
|
|
return tvb_get_ntohs(tvb, offset + 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-09 17:46:28 +00:00
|
|
|
static int
|
|
|
|
dissect_openflow_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
|
2013-09-26 21:05:04 +00:00
|
|
|
{
|
|
|
|
guint offset = 0;
|
|
|
|
guint8 version;
|
|
|
|
|
|
|
|
version = tvb_get_guint8(tvb, 0);
|
|
|
|
/* Set the Protocol column to the constant string of openflow */
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "OpenFlow");
|
|
|
|
col_clear(pinfo->cinfo,COL_INFO);
|
|
|
|
|
2013-09-30 09:02:56 +00:00
|
|
|
switch(version){
|
|
|
|
case OFP_VERSION_1_0:
|
2013-11-10 10:46:13 +00:00
|
|
|
call_dissector(openflow_v1_handle, tvb, pinfo, tree);
|
2013-09-30 09:02:56 +00:00
|
|
|
break;
|
|
|
|
case OFP_VERSION_1_3:
|
2013-10-16 20:35:08 +00:00
|
|
|
call_dissector(openflow_v4_handle, tvb, pinfo, tree);
|
2013-09-30 09:02:56 +00:00
|
|
|
break;
|
2013-11-18 06:24:27 +00:00
|
|
|
case OFP_VERSION_1_4:
|
|
|
|
call_dissector(openflow_v5_handle, tvb, pinfo, tree);
|
|
|
|
break;
|
2013-09-30 09:02:56 +00:00
|
|
|
default:
|
|
|
|
proto_tree_add_item(tree, hf_openflow_version, tvb, offset, 1, ENC_BIG_ENDIAN);
|
|
|
|
proto_tree_add_text(tree, tvb, offset, -1, "Unsuported version not dissected");
|
|
|
|
break;
|
|
|
|
}
|
2013-11-09 17:46:28 +00:00
|
|
|
return tvb_length(tvb);
|
2013-11-05 19:36:09 +00:00
|
|
|
}
|
2013-09-30 09:02:56 +00:00
|
|
|
|
2013-11-05 19:36:09 +00:00
|
|
|
|
|
|
|
#define OFP_HEADER_LEN 8
|
|
|
|
static int
|
2013-11-09 17:46:28 +00:00
|
|
|
dissect_openflow(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
|
2013-11-05 19:36:09 +00:00
|
|
|
{
|
|
|
|
tcp_dissect_pdus(tvb, pinfo, tree, openflow_desegment, OFP_HEADER_LEN,
|
2013-11-09 17:46:28 +00:00
|
|
|
get_openflow_pdu_length, dissect_openflow_tcp_pdu, data);
|
2013-11-05 19:36:09 +00:00
|
|
|
return tvb_length(tvb);
|
2013-07-11 21:13:27 +00:00
|
|
|
}
|
|
|
|
|
2013-10-16 20:35:08 +00:00
|
|
|
/*
|
2013-10-13 21:25:19 +00:00
|
|
|
* Register the protocol with Wireshark.
|
2013-07-11 21:13:27 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
proto_register_openflow(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_openflow_version,
|
|
|
|
{ "Version", "openflow.version",
|
|
|
|
FT_UINT8, BASE_HEX, VALS(openflow_version_values), 0x7f,
|
|
|
|
NULL, HFILL }
|
2013-11-10 10:46:13 +00:00
|
|
|
}
|
2013-07-11 21:13:27 +00:00
|
|
|
};
|
|
|
|
|
2013-11-10 10:46:13 +00:00
|
|
|
module_t *openflow_module;
|
2013-07-11 21:13:27 +00:00
|
|
|
|
|
|
|
/* Register the protocol name and description */
|
|
|
|
proto_openflow = proto_register_protocol("OpenFlow",
|
|
|
|
"openflow", "openflow");
|
|
|
|
|
2013-10-16 20:35:08 +00:00
|
|
|
new_register_dissector("openflow", dissect_openflow, proto_openflow);
|
2013-10-13 21:25:19 +00:00
|
|
|
|
2013-07-11 21:13:27 +00:00
|
|
|
/* Required function calls to register the header fields and subtrees */
|
|
|
|
proto_register_field_array(proto_openflow, hf, array_length(hf));
|
|
|
|
|
|
|
|
openflow_module = prefs_register_protocol(proto_openflow, proto_reg_handoff_openflow);
|
|
|
|
|
|
|
|
/* Register port preference */
|
|
|
|
prefs_register_uint_preference(openflow_module, "tcp.port", "openflow TCP Port",
|
|
|
|
" openflow TCP port if other than the default",
|
|
|
|
10, &g_openflow_port);
|
2013-11-05 19:36:09 +00:00
|
|
|
|
|
|
|
/* Register desegment preference */
|
|
|
|
prefs_register_bool_preference(openflow_module, "desegment",
|
|
|
|
"Reassemble OpenFlow messages spanning multiple TCP segments",
|
|
|
|
"Whether the OpenFlow 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.",
|
|
|
|
&openflow_desegment);
|
2013-07-11 21:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_openflow(void)
|
|
|
|
{
|
|
|
|
static gboolean initialized = FALSE;
|
|
|
|
static dissector_handle_t openflow_handle;
|
|
|
|
static int currentPort;
|
|
|
|
|
|
|
|
if (!initialized) {
|
|
|
|
openflow_handle = new_create_dissector_handle(dissect_openflow, proto_openflow);
|
|
|
|
initialized = TRUE;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
dissector_delete_uint("tcp.port", currentPort, openflow_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
currentPort = g_openflow_port;
|
|
|
|
|
|
|
|
dissector_add_uint("tcp.port", currentPort, openflow_handle);
|
2013-11-10 10:46:13 +00:00
|
|
|
|
|
|
|
openflow_v1_handle = find_dissector("openflow_v1");
|
2013-10-16 20:35:08 +00:00
|
|
|
openflow_v4_handle = find_dissector("openflow_v4");
|
2013-11-18 06:24:27 +00:00
|
|
|
openflow_v5_handle = find_dissector("openflow_v5");
|
2013-07-11 21:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|