MSWSP: fix dissect_mswsp_smb()
[wireshark-wip.git] / epan / dissectors / packet-openflow.c
blob423b069c8c590083990f02f626b6ea2d10589916
1 /* packet-openflow.c
2 * Routines for OpenFlow dissection
3 * Copyright 2013, Anders Broman <anders.broman@ericsson.com>
4 * Copyright 2013, Zoltan Lajos Kis <zoltan.lajos.kis@ericsson.com>
6 * $Id$
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * Ref https://www.opennetworking.org/sdn-resources/onf-specifications/openflow
29 #include "config.h"
31 #include <glib.h>
33 #include <epan/packet.h>
34 #include <epan/prefs.h>
36 #include "packet-tcp.h"
38 void proto_register_openflow(void);
39 void proto_reg_handoff_openflow(void);
41 static int g_openflow_port = 0;
43 static dissector_handle_t openflow_v1_handle;
44 static dissector_handle_t openflow_v4_handle;
46 /* Initialize the protocol and registered fields */
47 static int proto_openflow = -1;
48 static int hf_openflow_version = -1;
50 static gboolean openflow_desegment = TRUE;
52 #define OFP_VERSION_1_0 1
53 #define OFP_VERSION_1_1 2
54 #define OFP_VERSION_1_2 3
55 #define OFP_VERSION_1_3 4
57 static const value_string openflow_version_values[] = {
58 { 0x01, "1.0" },
59 { 0x02, "1.1" },
60 { 0x03, "1.2" },
61 { 0x04, "1.3.1" },
62 { 0, NULL }
66 static guint
67 get_openflow_pdu_length(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
69 return tvb_get_ntohs(tvb, offset + 2);
73 static int
74 dissect_openflow_tcp_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
76 guint offset = 0;
77 guint8 version;
79 version = tvb_get_guint8(tvb, 0);
80 /* Set the Protocol column to the constant string of openflow */
81 col_set_str(pinfo->cinfo, COL_PROTOCOL, "OpenFlow");
82 col_clear(pinfo->cinfo,COL_INFO);
84 switch(version){
85 case OFP_VERSION_1_0:
86 call_dissector(openflow_v1_handle, tvb, pinfo, tree);
87 break;
88 case OFP_VERSION_1_3:
89 call_dissector(openflow_v4_handle, tvb, pinfo, tree);
90 break;
91 default:
92 proto_tree_add_item(tree, hf_openflow_version, tvb, offset, 1, ENC_BIG_ENDIAN);
93 proto_tree_add_text(tree, tvb, offset, -1, "Unsuported version not dissected");
94 break;
96 return tvb_length(tvb);
100 #define OFP_HEADER_LEN 8
101 static int
102 dissect_openflow(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
104 tcp_dissect_pdus(tvb, pinfo, tree, openflow_desegment, OFP_HEADER_LEN,
105 get_openflow_pdu_length, dissect_openflow_tcp_pdu, data);
106 return tvb_length(tvb);
110 * Register the protocol with Wireshark.
112 void
113 proto_register_openflow(void)
115 static hf_register_info hf[] = {
116 { &hf_openflow_version,
117 { "Version", "openflow.version",
118 FT_UINT8, BASE_HEX, VALS(openflow_version_values), 0x7f,
119 NULL, HFILL }
123 module_t *openflow_module;
125 /* Register the protocol name and description */
126 proto_openflow = proto_register_protocol("OpenFlow",
127 "openflow", "openflow");
129 new_register_dissector("openflow", dissect_openflow, proto_openflow);
131 /* Required function calls to register the header fields and subtrees */
132 proto_register_field_array(proto_openflow, hf, array_length(hf));
134 openflow_module = prefs_register_protocol(proto_openflow, proto_reg_handoff_openflow);
136 /* Register port preference */
137 prefs_register_uint_preference(openflow_module, "tcp.port", "openflow TCP Port",
138 " openflow TCP port if other than the default",
139 10, &g_openflow_port);
141 /* Register desegment preference */
142 prefs_register_bool_preference(openflow_module, "desegment",
143 "Reassemble OpenFlow messages spanning multiple TCP segments",
144 "Whether the OpenFlow dissector should reassemble messages spanning multiple TCP segments."
145 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
146 &openflow_desegment);
149 void
150 proto_reg_handoff_openflow(void)
152 static gboolean initialized = FALSE;
153 static dissector_handle_t openflow_handle;
154 static int currentPort;
156 if (!initialized) {
157 openflow_handle = new_create_dissector_handle(dissect_openflow, proto_openflow);
158 initialized = TRUE;
160 } else {
161 dissector_delete_uint("tcp.port", currentPort, openflow_handle);
164 currentPort = g_openflow_port;
166 dissector_add_uint("tcp.port", currentPort, openflow_handle);
168 openflow_v1_handle = find_dissector("openflow_v1");
169 openflow_v4_handle = find_dissector("openflow_v4");
175 * Editor modelines - http://www.wireshark.org/tools/modelines.html
177 * Local variables:
178 * c-basic-offset: 4
179 * tab-width: 8
180 * indent-tabs-mode: nil
181 * End:
183 * vi: set shiftwidth=4 tabstop=8 expandtab:
184 * :indentSize=4:tabSize=8:noTabs=true: