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
|
|
|
*
|
|
|
|
* 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 <epan/packet.h>
|
2014-08-17 20:11:15 +00:00
|
|
|
#include <epan/expert.h>
|
2013-07-11 21:13:27 +00:00
|
|
|
#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);
|
|
|
|
|
2014-04-02 12:12:01 +00:00
|
|
|
#define OFP_LEGACY_PORT 6633
|
|
|
|
#define OFP_LEGACY2_PORT 6634
|
|
|
|
#define OFP_IANA_PORT 6653
|
|
|
|
static int g_openflow_port = OFP_IANA_PORT;
|
2013-07-11 21:13:27 +00:00
|
|
|
|
2014-04-02 12:12:01 +00:00
|
|
|
static dissector_handle_t openflow_handle;
|
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;
|
|
|
|
|
2014-08-17 20:11:15 +00:00
|
|
|
static expert_field ei_openflow_version = EI_INIT;
|
|
|
|
|
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" },
|
2014-11-24 16:38:43 +00:00
|
|
|
{ 0x05, "1.4" },
|
2013-07-11 21:13:27 +00:00
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2013-11-05 19:36:09 +00:00
|
|
|
static guint
|
2015-01-25 19:30:13 +00:00
|
|
|
get_openflow_pdu_length(packet_info *pinfo _U_, tvbuff_t *tvb,
|
|
|
|
int offset, void *data _U_)
|
2013-11-05 19:36:09 +00:00
|
|
|
{
|
|
|
|
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;
|
2014-08-17 20:11:15 +00:00
|
|
|
proto_item* ti;
|
2013-09-26 21:05:04 +00:00
|
|
|
|
|
|
|
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:
|
2014-08-17 20:11:15 +00:00
|
|
|
ti = proto_tree_add_item(tree, hf_openflow_version, tvb, offset, 1, ENC_BIG_ENDIAN);
|
|
|
|
expert_add_info(pinfo, ti, &ei_openflow_version);
|
2013-09-30 09:02:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-05-04 19:20:54 +00:00
|
|
|
return tvb_reported_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);
|
2014-04-02 12:12:01 +00:00
|
|
|
return tvb_captured_length(tvb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
dissect_openflow_heur(tvbuff_t *tvb, packet_info *pinfo,
|
|
|
|
proto_tree *tree, void *data)
|
|
|
|
{
|
|
|
|
conversation_t *conversation = NULL;
|
|
|
|
|
|
|
|
if ((pinfo->destport != OFP_LEGACY_PORT) &&
|
|
|
|
(pinfo->destport != OFP_LEGACY2_PORT) &&
|
|
|
|
(pinfo->destport != OFP_IANA_PORT) &&
|
|
|
|
(pinfo->destport != (guint32)g_openflow_port)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
conversation = find_or_create_conversation(pinfo);
|
|
|
|
conversation_set_dissector(conversation, openflow_handle);
|
|
|
|
|
|
|
|
dissect_openflow(tvb, pinfo, tree, data);
|
|
|
|
return TRUE;
|
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
|
|
|
};
|
|
|
|
|
2014-08-17 20:11:15 +00:00
|
|
|
static ei_register_info ei[] = {
|
|
|
|
{ &ei_openflow_version, { "openflow.version.unknown", PI_UNDECODED, PI_WARN, "Unsupported version not dissected", EXPFILL }},
|
|
|
|
};
|
|
|
|
|
2013-11-10 10:46:13 +00:00
|
|
|
module_t *openflow_module;
|
2014-08-17 20:11:15 +00:00
|
|
|
expert_module_t* expert_openflow;
|
2013-07-11 21:13:27 +00:00
|
|
|
|
|
|
|
/* Register the protocol name and description */
|
|
|
|
proto_openflow = proto_register_protocol("OpenFlow",
|
2014-12-29 09:17:04 +00:00
|
|
|
"OpenFlow", "openflow");
|
2013-07-11 21:13:27 +00:00
|
|
|
|
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));
|
2014-08-17 20:11:15 +00:00
|
|
|
expert_openflow = expert_register_protocol(proto_openflow);
|
|
|
|
expert_register_field_array(expert_openflow, ei, array_length(ei));
|
2013-07-11 21:13:27 +00:00
|
|
|
|
|
|
|
openflow_module = prefs_register_protocol(proto_openflow, proto_reg_handoff_openflow);
|
|
|
|
|
|
|
|
/* Register port preference */
|
2014-04-02 12:12:01 +00:00
|
|
|
prefs_register_uint_preference(openflow_module, "tcp.port", "OpenFlow TCP port",
|
2014-12-29 09:17:04 +00:00
|
|
|
"OpenFlow TCP port (6653 is the IANA assigned port)",
|
2014-04-02 12:12:01 +00:00
|
|
|
10, &g_openflow_port);
|
|
|
|
|
|
|
|
/* Register heuristic preference */
|
2015-07-13 00:40:31 +00:00
|
|
|
prefs_register_obsolete_preference(openflow_module, "heuristic");
|
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 int currentPort;
|
|
|
|
|
|
|
|
if (!initialized) {
|
|
|
|
openflow_handle = new_create_dissector_handle(dissect_openflow, proto_openflow);
|
2015-07-13 00:40:31 +00:00
|
|
|
heur_dissector_add("tcp", dissect_openflow_heur, "OpenFlow over TCP", "openflow_tcp", proto_openflow, HEURISTIC_ENABLE);
|
2013-07-11 21:13:27 +00:00
|
|
|
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:
|
|
|
|
*/
|