2 * This module implements decoding of OpenFlow protocol version 1.3 (wire
3 * protocol 0x04). It is based on the implementation conventions explained in
4 * print-openflow-1.0.c.
6 * [OF13] https://www.opennetworking.org/wp-content/uploads/2014/10/openflow-switch-v1.3.4.pdf
8 * Copyright (c) 2020 The TCPDUMP project
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 /* \summary: OpenFlow protocol version 1.3 printer */
40 #include "netdissect-stdinc.h"
42 #define ND_LONGJMP_FROM_TCHECK
43 #include "netdissect.h"
45 #include "addrtoname.h"
50 #define OFPT_ECHO_REQUEST 2U
51 #define OFPT_ECHO_REPLY 3U
52 #define OFPT_EXPERIMENTER 4U
53 #define OFPT_FEATURES_REQUEST 5U
54 #define OFPT_FEATURES_REPLY 6U
55 #define OFPT_GET_CONFIG_REQUEST 7U
56 #define OFPT_GET_CONFIG_REPLY 8U
57 #define OFPT_SET_CONFIG 9U
58 #define OFPT_PACKET_IN 10U
59 #define OFPT_FLOW_REMOVED 11U
60 #define OFPT_PORT_STATUS 12U
61 #define OFPT_PACKET_OUT 13U
62 #define OFPT_FLOW_MOD 14U
63 #define OFPT_GROUP_MOD 15U
64 #define OFPT_PORT_MOD 16U
65 #define OFPT_TABLE_MOD 17U
66 #define OFPT_MULTIPART_REQUEST 18U
67 #define OFPT_MULTIPART_REPLY 19U
68 #define OFPT_BARRIER_REQUEST 20U
69 #define OFPT_BARRIER_REPLY 21U
70 #define OFPT_QUEUE_GET_CONFIG_REQUEST 22U
71 #define OFPT_QUEUE_GET_CONFIG_REPLY 23U
72 #define OFPT_ROLE_REQUEST 24U
73 #define OFPT_ROLE_REPLY 25U
74 #define OFPT_GET_ASYNC_REQUEST 26U
75 #define OFPT_GET_ASYNC_REPLY 27U
76 #define OFPT_SET_ASYNC 28U
77 #define OFPT_METER_MOD 29U
78 static const struct tok ofpt_str
[] = {
79 { OFPT_HELLO
, "HELLO" },
80 { OFPT_ERROR
, "ERROR" },
81 { OFPT_ECHO_REQUEST
, "ECHO_REQUEST" },
82 { OFPT_ECHO_REPLY
, "ECHO_REPLY" },
83 { OFPT_EXPERIMENTER
, "EXPERIMENTER" },
84 { OFPT_FEATURES_REQUEST
, "FEATURES_REQUEST" },
85 { OFPT_FEATURES_REPLY
, "FEATURES_REPLY" },
86 { OFPT_GET_CONFIG_REQUEST
, "GET_CONFIG_REQUEST" },
87 { OFPT_GET_CONFIG_REPLY
, "GET_CONFIG_REPLY" },
88 { OFPT_SET_CONFIG
, "SET_CONFIG" },
89 { OFPT_PACKET_IN
, "PACKET_IN" },
90 { OFPT_FLOW_REMOVED
, "FLOW_REMOVED" },
91 { OFPT_PORT_STATUS
, "PORT_STATUS" },
92 { OFPT_PACKET_OUT
, "PACKET_OUT" },
93 { OFPT_FLOW_MOD
, "FLOW_MOD" },
94 { OFPT_GROUP_MOD
, "GROUP_MOD" },
95 { OFPT_PORT_MOD
, "PORT_MOD" },
96 { OFPT_TABLE_MOD
, "TABLE_MOD" },
97 { OFPT_MULTIPART_REQUEST
, "MULTIPART_REQUEST" },
98 { OFPT_MULTIPART_REPLY
, "MULTIPART_REPLY" },
99 { OFPT_BARRIER_REQUEST
, "BARRIER_REQUEST" },
100 { OFPT_BARRIER_REPLY
, "BARRIER_REPLY" },
101 { OFPT_QUEUE_GET_CONFIG_REQUEST
, "QUEUE_GET_CONFIG_REQUEST" },
102 { OFPT_QUEUE_GET_CONFIG_REPLY
, "QUEUE_GET_CONFIG_REPLY" },
103 { OFPT_ROLE_REQUEST
, "ROLE_REQUEST" },
104 { OFPT_ROLE_REPLY
, "ROLE_REPLY" },
105 { OFPT_GET_ASYNC_REQUEST
, "GET_ASYNC_REQUEST" },
106 { OFPT_GET_ASYNC_REPLY
, "GET_ASYNC_REPLY" },
107 { OFPT_SET_ASYNC
, "SET_ASYNC" },
108 { OFPT_METER_MOD
, "METER_MOD" },
112 #define OFPC_FLOW_STATS (1U <<0)
113 #define OFPC_TABLE_STATS (1U <<1)
114 #define OFPC_PORT_STATS (1U <<2)
115 #define OFPC_GROUP_STATS (1U <<3)
116 #define OFPC_IP_REASM (1U <<5)
117 #define OFPC_QUEUE_STATS (1U <<6)
118 #define OFPC_PORT_BLOCKED (1U <<8)
119 static const struct tok ofp_capabilities_bm
[] = {
120 { OFPC_FLOW_STATS
, "FLOW_STATS" },
121 { OFPC_TABLE_STATS
, "TABLE_STATS" },
122 { OFPC_PORT_STATS
, "PORT_STATS" },
123 { OFPC_GROUP_STATS
, "GROUP_STATS" },
124 { OFPC_IP_REASM
, "IP_REASM" },
125 { OFPC_QUEUE_STATS
, "QUEUE_STATS" },
126 { OFPC_PORT_BLOCKED
, "PORT_BLOCKED" },
129 #define OFPCAP_U (~(OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS | \
130 OFPC_GROUP_STATS | OFPC_IP_REASM | OFPC_QUEUE_STATS | \
133 #define OFPC_FRAG_NORMAL 0U
134 #define OFPC_FRAG_DROP 1U
135 #define OFPC_FRAG_REASM 2U
136 static const struct tok ofp_config_str
[] = {
137 { OFPC_FRAG_NORMAL
, "FRAG_NORMAL" },
138 { OFPC_FRAG_DROP
, "FRAG_DROP" },
139 { OFPC_FRAG_REASM
, "FRAG_REASM" },
143 #define OFPCML_MAX 0xffe5U
144 #define OFPCML_NO_BUFFER 0xffffU
145 static const struct tok ofpcml_str
[] = {
146 { OFPCML_MAX
, "MAX" },
147 { OFPCML_NO_BUFFER
, "NO_BUFFER" },
151 #define OFPPC_PORT_DOWN (1U <<0)
152 #define OFPPC_NO_RECV (1U <<2)
153 #define OFPPC_NO_FWD (1U <<5)
154 #define OFPPC_NO_PACKET_IN (1U <<6)
155 static const struct tok ofppc_bm
[] = {
156 { OFPPC_PORT_DOWN
, "PORT_DOWN" },
157 { OFPPC_NO_RECV
, "NO_RECV" },
158 { OFPPC_NO_FWD
, "NO_FWD" },
159 { OFPPC_NO_PACKET_IN
, "NO_PACKET_IN" },
162 #define OFPPC_U (~(OFPPC_PORT_DOWN | OFPPC_NO_RECV | OFPPC_NO_FWD | \
165 #define OFPPF_10MB_HD (1U << 0)
166 #define OFPPF_10MB_FD (1U << 1)
167 #define OFPPF_100MB_HD (1U << 2)
168 #define OFPPF_100MB_FD (1U << 3)
169 #define OFPPF_1GB_HD (1U << 4)
170 #define OFPPF_1GB_FD (1U << 5)
171 #define OFPPF_10GB_FD (1U << 6)
172 #define OFPPF_40GB_FD (1U << 7)
173 #define OFPPF_100GB_FD (1U << 8)
174 #define OFPPF_1TB_FD (1U << 9)
175 #define OFPPF_OTHER (1U << 10)
176 #define OFPPF_COPPER (1U << 11)
177 #define OFPPF_FIBER (1U << 12)
178 #define OFPPF_AUTONEG (1U << 13)
179 #define OFPPF_PAUSE (1U << 14)
180 #define OFPPF_PAUSE_ASYM (1U << 15)
181 static const struct tok ofppf_bm
[] = {
182 { OFPPF_10MB_HD
, "10MB_HD" },
183 { OFPPF_10MB_FD
, "10MB_FD" },
184 { OFPPF_100MB_HD
, "100MB_HD" },
185 { OFPPF_100MB_FD
, "100MB_FD" },
186 { OFPPF_1GB_HD
, "1GB_HD" },
187 { OFPPF_1GB_FD
, "1GB_FD" },
188 { OFPPF_10GB_FD
, "10GB_FD" },
189 { OFPPF_40GB_FD
, "40GB_FD" },
190 { OFPPF_100GB_FD
, "100GB_FD" },
191 { OFPPF_1TB_FD
, "1TB_FD" },
192 { OFPPF_OTHER
, "OTHER" },
193 { OFPPF_COPPER
, "COPPER" },
194 { OFPPF_FIBER
, "FIBER" },
195 { OFPPF_AUTONEG
, "AUTONEG" },
196 { OFPPF_PAUSE
, "PAUSE" },
197 { OFPPF_PAUSE_ASYM
, "PAUSE_ASYM" },
200 #define OFPPF_U (~(OFPPF_10MB_HD | OFPPF_10MB_FD | OFPPF_100MB_HD | \
201 OFPPF_100MB_FD | OFPPF_1GB_HD | OFPPF_1GB_FD | \
202 OFPPF_10GB_FD | OFPPF_40GB_FD | OFPPF_100GB_FD | \
203 OFPPF_1TB_FD | OFPPF_OTHER | OFPPF_COPPER | OFPPF_FIBER | \
204 OFPPF_AUTONEG | OFPPF_PAUSE | OFPPF_PAUSE_ASYM))
206 #define OFPHET_VERSIONBITMAP 1U
207 static const struct tok ofphet_str
[] = {
208 { OFPHET_VERSIONBITMAP
, "VERSIONBITMAP" },
212 #define OFPP_MAX 0xffffff00U
213 #define OFPP_IN_PORT 0xfffffff8U
214 #define OFPP_TABLE 0xfffffff9U
215 #define OFPP_NORMAL 0xfffffffaU
216 #define OFPP_FLOOD 0xfffffffbU
217 #define OFPP_ALL 0xfffffffcU
218 #define OFPP_CONTROLLER 0xfffffffdU
219 #define OFPP_LOCAL 0xfffffffeU
220 #define OFPP_ANY 0xffffffffU
221 static const struct tok ofpp_str
[] = {
223 { OFPP_IN_PORT
, "IN_PORT" },
224 { OFPP_TABLE
, "TABLE" },
225 { OFPP_NORMAL
, "NORMAL" },
226 { OFPP_FLOOD
, "FLOOD" },
228 { OFPP_CONTROLLER
, "CONTROLLER" },
229 { OFPP_LOCAL
, "LOCAL" },
234 #define OF_BIT_VER_1_0 (1U << (OF_VER_1_0 - 1))
235 #define OF_BIT_VER_1_1 (1U << (OF_VER_1_1 - 1))
236 #define OF_BIT_VER_1_2 (1U << (OF_VER_1_2 - 1))
237 #define OF_BIT_VER_1_3 (1U << (OF_VER_1_3 - 1))
238 #define OF_BIT_VER_1_4 (1U << (OF_VER_1_4 - 1))
239 #define OF_BIT_VER_1_5 (1U << (OF_VER_1_5 - 1))
240 static const struct tok ofverbm_str
[] = {
241 { OF_BIT_VER_1_0
, "1.0" },
242 { OF_BIT_VER_1_1
, "1.1" },
243 { OF_BIT_VER_1_2
, "1.2" },
244 { OF_BIT_VER_1_3
, "1.3" },
245 { OF_BIT_VER_1_4
, "1.4" },
246 { OF_BIT_VER_1_5
, "1.5" },
249 #define OF_BIT_VER_U (~(OF_BIT_VER_1_0 | OF_BIT_VER_1_1 | OF_BIT_VER_1_2 | \
250 OF_BIT_VER_1_3 | OF_BIT_VER_1_4 | OF_BIT_VER_1_5))
252 #define OFPET_HELLO_FAILED 0U
253 #define OFPET_BAD_REQUEST 1U
254 #define OFPET_BAD_ACTION 2U
255 #define OFPET_BAD_INSTRUCTION 3U
256 #define OFPET_BAD_MATCH 4U
257 #define OFPET_FLOW_MOD_FAILED 5U
258 #define OFPET_GROUP_MOD_FAILED 6U
259 #define OFPET_PORT_MOD_FAILED 7U
260 #define OFPET_TABLE_MOD_FAILED 8U
261 #define OFPET_QUEUE_OP_FAILED 9U
262 #define OFPET_SWITCH_CONFIG_FAILED 10U
263 #define OFPET_ROLE_REQUEST_FAILED 11U
264 #define OFPET_METER_MOD_FAILED 12U
265 #define OFPET_TABLE_FEATURES_FAILED 13U
266 #define OFPET_EXPERIMENTER 0xffffU /* a special case */
267 static const struct tok ofpet_str
[] = {
268 { OFPET_HELLO_FAILED
, "HELLO_FAILED" },
269 { OFPET_BAD_REQUEST
, "BAD_REQUEST" },
270 { OFPET_BAD_ACTION
, "BAD_ACTION" },
271 { OFPET_BAD_INSTRUCTION
, "BAD_INSTRUCTION" },
272 { OFPET_BAD_MATCH
, "BAD_MATCH" },
273 { OFPET_FLOW_MOD_FAILED
, "FLOW_MOD_FAILED" },
274 { OFPET_GROUP_MOD_FAILED
, "GROUP_MOD_FAILED" },
275 { OFPET_PORT_MOD_FAILED
, "PORT_MOD_FAILED" },
276 { OFPET_TABLE_MOD_FAILED
, "TABLE_MOD_FAILED" },
277 { OFPET_QUEUE_OP_FAILED
, "QUEUE_OP_FAILED" },
278 { OFPET_SWITCH_CONFIG_FAILED
, "SWITCH_CONFIG_FAILED" },
279 { OFPET_ROLE_REQUEST_FAILED
, "ROLE_REQUEST_FAILED" },
280 { OFPET_METER_MOD_FAILED
, "METER_MOD_FAILED" },
281 { OFPET_TABLE_FEATURES_FAILED
, "TABLE_FEATURES_FAILED" },
282 { OFPET_EXPERIMENTER
, "EXPERIMENTER" },
286 #define OFPHFC_INCOMPATIBLE 0U
287 #define OFPHFC_EPERM 1U
288 static const struct tok ofphfc_str
[] = {
289 { OFPHFC_INCOMPATIBLE
, "INCOMPATIBLE" },
290 { OFPHFC_EPERM
, "EPERM" },
294 #define OFPBRC_BAD_VERSION 0U
295 #define OFPBRC_BAD_TYPE 1U
296 #define OFPBRC_BAD_MULTIPART 2U
297 #define OFPBRC_BAD_EXPERIMENTER 3U
298 #define OFPBRC_BAD_EXP_TYPE 4U
299 #define OFPBRC_EPERM 5U
300 #define OFPBRC_BAD_LEN 6U
301 #define OFPBRC_BUFFER_EMPTY 7U
302 #define OFPBRC_BUFFER_UNKNOWN 8U
303 #define OFPBRC_BAD_TABLE_ID 9U
304 #define OFPBRC_IS_SLAVE 10U
305 #define OFPBRC_BAD_PORT 11U
306 #define OFPBRC_BAD_PACKET 12U
307 #define OFPBRC_MULTIPART_BUFFER_OVERFLOW 13U
308 static const struct tok ofpbrc_str
[] = {
309 { OFPBRC_BAD_VERSION
, "BAD_VERSION" },
310 { OFPBRC_BAD_TYPE
, "BAD_TYPE" },
311 { OFPBRC_BAD_MULTIPART
, "BAD_MULTIPART" },
312 { OFPBRC_BAD_EXPERIMENTER
, "BAD_EXPERIMENTER" },
313 { OFPBRC_BAD_EXP_TYPE
, "BAD_EXP_TYPE" },
314 { OFPBRC_EPERM
, "EPERM" },
315 { OFPBRC_BAD_LEN
, "BAD_LEN" },
316 { OFPBRC_BUFFER_EMPTY
, "BUFFER_EMPTY" },
317 { OFPBRC_BUFFER_UNKNOWN
, "BUFFER_UNKNOWN" },
318 { OFPBRC_BAD_TABLE_ID
, "BAD_TABLE_ID" },
319 { OFPBRC_IS_SLAVE
, "IS_SLAVE" },
320 { OFPBRC_BAD_PORT
, "BAD_PORT" },
321 { OFPBRC_BAD_PACKET
, "BAD_PACKET" },
322 { OFPBRC_MULTIPART_BUFFER_OVERFLOW
, "MULTIPART_BUFFER_OVERFLOW" },
326 #define OFPBAC_BAD_TYPE 0U
327 #define OFPBAC_BAD_LEN 1U
328 #define OFPBAC_BAD_EXPERIMENTER 2U
329 #define OFPBAC_BAD_EXP_TYPE 3U
330 #define OFPBAC_BAD_OUT_PORT 4U
331 #define OFPBAC_BAD_ARGUMENT 5U
332 #define OFPBAC_EPERM 6U
333 #define OFPBAC_TOO_MANY 7U
334 #define OFPBAC_BAD_QUEUE 8U
335 #define OFPBAC_BAD_OUT_GROUP 9U
336 #define OFPBAC_MATCH_INCONSISTENT 10U
337 #define OFPBAC_UNSUPPORTED_ORDER 11U
338 #define OFPBAC_BAD_TAG 12U
339 #define OFPBAC_BAD_SET_TYPE 13U
340 #define OFPBAC_BAD_SET_LEN 14U
341 #define OFPBAC_BAD_SET_ARGUMENT 15U
342 static const struct tok ofpbac_str
[] = {
343 { OFPBAC_BAD_TYPE
, "BAD_TYPE" },
344 { OFPBAC_BAD_LEN
, "BAD_LEN" },
345 { OFPBAC_BAD_EXPERIMENTER
, "BAD_EXPERIMENTER" },
346 { OFPBAC_BAD_EXP_TYPE
, "BAD_EXP_TYPE" },
347 { OFPBAC_BAD_OUT_PORT
, "BAD_OUT_PORT" },
348 { OFPBAC_BAD_ARGUMENT
, "BAD_ARGUMENT" },
349 { OFPBAC_EPERM
, "EPERM" },
350 { OFPBAC_TOO_MANY
, "TOO_MANY" },
351 { OFPBAC_BAD_QUEUE
, "BAD_QUEUE" },
352 { OFPBAC_BAD_OUT_GROUP
, "BAD_OUT_GROUP" },
353 { OFPBAC_MATCH_INCONSISTENT
, "MATCH_INCONSISTENT" },
354 { OFPBAC_UNSUPPORTED_ORDER
, "UNSUPPORTED_ORDER" },
355 { OFPBAC_BAD_TAG
, "BAD_TAG" },
356 { OFPBAC_BAD_SET_TYPE
, "BAD_SET_TYPE" },
357 { OFPBAC_BAD_SET_LEN
, "BAD_SET_LEN" },
358 { OFPBAC_BAD_SET_ARGUMENT
, "BAD_SET_ARGUMENT" },
362 #define OFPBIC_UNKNOWN_INST 0U
363 #define OFPBIC_UNSUP_INST 1U
364 #define OFPBIC_BAD_TABLE_ID 2U
365 #define OFPBIC_UNSUP_METADATA 3U
366 #define OFPBIC_UNSUP_METADATA_MASK 4U
367 #define OFPBIC_BAD_EXPERIMENTER 5U
368 #define OFPBIC_BAD_EXP_TYPE 6U
369 #define OFPBIC_BAD_LEN 7U
370 #define OFPBIC_EPERM 8U
371 static const struct tok ofpbic_str
[] = {
372 { OFPBIC_UNKNOWN_INST
, "UNKNOWN_INST" },
373 { OFPBIC_UNSUP_INST
, "UNSUP_INST" },
374 { OFPBIC_BAD_TABLE_ID
, "BAD_TABLE_ID" },
375 { OFPBIC_UNSUP_METADATA
, "UNSUP_METADATA" },
376 { OFPBIC_UNSUP_METADATA_MASK
, "UNSUP_METADATA_MASK" },
377 { OFPBIC_BAD_EXPERIMENTER
, "BAD_EXPERIMENTER" },
378 { OFPBIC_BAD_EXP_TYPE
, "BAD_EXP_TYPE" },
379 { OFPBIC_BAD_LEN
, "BAD_LEN" },
380 { OFPBIC_EPERM
, "EPERM" },
384 #define OFPBMC_BAD_TYPE 0U
385 #define OFPBMC_BAD_LEN 1U
386 #define OFPBMC_BAD_TAG 2U
387 #define OFPBMC_BAD_DL_ADDR_MASK 3U
388 #define OFPBMC_BAD_NW_ADDR_MASK 4U
389 #define OFPBMC_BAD_WILDCARDS 5U
390 #define OFPBMC_BAD_FIELD 6U
391 #define OFPBMC_BAD_VALUE 7U
392 #define OFPBMC_BAD_MASK 8U
393 #define OFPBMC_BAD_PREREQ 9U
394 #define OFPBMC_DUP_FIELD 10U
395 #define OFPBMC_EPERM 11U
396 static const struct tok ofpbmc_str
[] = {
397 { OFPBMC_BAD_TYPE
, "BAD_TYPE" },
398 { OFPBMC_BAD_LEN
, "BAD_LEN" },
399 { OFPBMC_BAD_TAG
, "BAD_TAG" },
400 { OFPBMC_BAD_DL_ADDR_MASK
, "BAD_DL_ADDR_MASK" },
401 { OFPBMC_BAD_NW_ADDR_MASK
, "BAD_NW_ADDR_MASK" },
402 { OFPBMC_BAD_WILDCARDS
, "BAD_WILDCARDS" },
403 { OFPBMC_BAD_FIELD
, "BAD_FIELD" },
404 { OFPBMC_BAD_VALUE
, "BAD_VALUE" },
405 { OFPBMC_BAD_MASK
, "BAD_MASK" },
406 { OFPBMC_BAD_PREREQ
, "BAD_PREREQ" },
407 { OFPBMC_DUP_FIELD
, "DUP_FIELD" },
408 { OFPBMC_EPERM
, "EPERM" },
412 #define OFPFMFC_UNKNOWN 0U
413 #define OFPFMFC_TABLE_FULL 1U
414 #define OFPFMFC_BAD_TABLE_ID 2U
415 #define OFPFMFC_OVERLAP 3U
416 #define OFPFMFC_EPERM 4U
417 #define OFPFMFC_BAD_TIMEOUT 5U
418 #define OFPFMFC_BAD_COMMAND 6U
419 #define OFPFMFC_BAD_FLAGS 7U
420 static const struct tok ofpfmfc_str
[] = {
421 { OFPFMFC_UNKNOWN
, "UNKNOWN" },
422 { OFPFMFC_TABLE_FULL
, "TABLE_FULL" },
423 { OFPFMFC_BAD_TABLE_ID
, "BAD_TABLE_ID" },
424 { OFPFMFC_OVERLAP
, "OVERLAP" },
425 { OFPFMFC_EPERM
, "EPERM" },
426 { OFPFMFC_BAD_TIMEOUT
, "BAD_TIMEOUT" },
427 { OFPFMFC_BAD_COMMAND
, "BAD_COMMAND" },
428 { OFPFMFC_BAD_FLAGS
, "BAD_FLAGS" },
432 #define OFPGMFC_GROUP_EXISTS 0U
433 #define OFPGMFC_INVALID_GROUP 1U
434 #define OFPGMFC_WEIGHT_UNSUPPORTED 2U
435 #define OFPGMFC_OUT_OF_GROUPS 3U
436 #define OFPGMFC_OUT_OF_BUCKETS 4U
437 #define OFPGMFC_CHAINING_UNSUPPORTED 5U
438 #define OFPGMFC_WATCH_UNSUPPORTED 6U
439 #define OFPGMFC_LOOP 7U
440 #define OFPGMFC_UNKNOWN_GROUP 8U
441 #define OFPGMFC_CHAINED_GROUP 9U
442 #define OFPGMFC_BAD_TYPE 10U
443 #define OFPGMFC_BAD_COMMAND 11U
444 #define OFPGMFC_BAD_BUCKET 12U
445 #define OFPGMFC_BAD_MATCH 13U
446 #define OFPGMFC_EPERM 14U
447 static const struct tok ofpgmfc_str
[] = {
448 { OFPGMFC_GROUP_EXISTS
, "GROUP_EXISTS" },
449 { OFPGMFC_INVALID_GROUP
, "INVALID_GROUP" },
450 { OFPGMFC_WEIGHT_UNSUPPORTED
, "WEIGHT_UNSUPPORTED" },
451 { OFPGMFC_OUT_OF_GROUPS
, "OUT_OF_GROUPS" },
452 { OFPGMFC_OUT_OF_BUCKETS
, "OUT_OF_BUCKETS" },
453 { OFPGMFC_CHAINING_UNSUPPORTED
, "CHAINING_UNSUPPORTED" },
454 { OFPGMFC_WATCH_UNSUPPORTED
, "WATCH_UNSUPPORTED" },
455 { OFPGMFC_LOOP
, "LOOP" },
456 { OFPGMFC_UNKNOWN_GROUP
, "UNKNOWN_GROUP" },
457 { OFPGMFC_CHAINED_GROUP
, "CHAINED_GROUP" },
458 { OFPGMFC_BAD_TYPE
, "BAD_TYPE" },
459 { OFPGMFC_BAD_COMMAND
, "BAD_COMMAND" },
460 { OFPGMFC_BAD_BUCKET
, "BAD_BUCKET" },
461 { OFPGMFC_BAD_MATCH
, "BAD_MATCH" },
462 { OFPGMFC_EPERM
, "EPERM" },
466 #define OFPPMFC_BAD_PORT 0U
467 #define OFPPMFC_BAD_HW_ADDR 1U
468 #define OFPPMFC_BAD_CONFIG 2U
469 #define OFPPMFC_BAD_ADVERTISE 3U
470 #define OFPPMFC_EPERM 4U
471 static const struct tok ofppmfc_str
[] = {
472 { OFPPMFC_BAD_PORT
, "BAD_PORT" },
473 { OFPPMFC_BAD_HW_ADDR
, "BAD_HW_ADDR" },
474 { OFPPMFC_BAD_CONFIG
, "BAD_CONFIG" },
475 { OFPPMFC_BAD_ADVERTISE
, "BAD_ADVERTISE" },
476 { OFPPMFC_EPERM
, "EPERM" },
480 #define OFPTMFC_BAD_TABLE 0U
481 #define OFPTMFC_BAD_CONFIG 1U
482 #define OFPTMFC_EPERM 2U
483 static const struct tok ofptmfc_str
[] = {
484 { OFPTMFC_BAD_TABLE
, "BAD_TABLE" },
485 { OFPTMFC_BAD_CONFIG
, "BAD_CONFIG" },
486 { OFPTMFC_EPERM
, "EPERM" },
490 #define OFPQOFC_BAD_PORT 0U
491 #define OFPQOFC_BAD_QUEUE 1U
492 #define OFPQOFC_EPERM 2U
493 static const struct tok ofpqofc_str
[] = {
494 { OFPQOFC_BAD_PORT
, "BAD_PORT" },
495 { OFPQOFC_BAD_QUEUE
, "BAD_QUEUE" },
496 { OFPQOFC_EPERM
, "EPERM" },
500 #define OFPSCFC_BAD_FLAGS 0U
501 #define OFPSCFC_BAD_LEN 1U
502 #define OFPSCFC_EPERM 2U
503 static const struct tok ofpscfc_str
[] = {
504 { OFPSCFC_BAD_FLAGS
, "BAD_FLAGS" },
505 { OFPSCFC_BAD_LEN
, "BAD_LEN" },
506 { OFPSCFC_EPERM
, "EPERM" },
510 #define OFPRRFC_STALE 0U
511 #define OFPRRFC_UNSUP 1U
512 #define OFPRRFC_BAD_ROLE 2U
513 static const struct tok ofprrfc_str
[] = {
514 { OFPRRFC_STALE
, "STALE" },
515 { OFPRRFC_UNSUP
, "UNSUP" },
516 { OFPRRFC_BAD_ROLE
, "BAD_ROLE" },
520 #define OFPMMFC_UNKNOWN 0U
521 #define OFPMMFC_METER_EXISTS 1U
522 #define OFPMMFC_INVALID_METER 2U
523 #define OFPMMFC_UNKNOWN_METER 3U
524 #define OFPMMFC_BAD_COMMAND 4U
525 #define OFPMMFC_BAD_FLAGS 5U
526 #define OFPMMFC_BAD_RATE 6U
527 #define OFPMMFC_BAD_BURST 7U
528 #define OFPMMFC_BAD_BAND 8U
529 #define OFPMMFC_BAD_BAND_VALUE 9U
530 #define OFPMMFC_OUT_OF_METERS 10U
531 #define OFPMMFC_OUT_OF_BANDS 11U
532 static const struct tok ofpmmfc_str
[] = {
533 { OFPMMFC_UNKNOWN
, "UNKNOWN" },
534 { OFPMMFC_METER_EXISTS
, "METER_EXISTS" },
535 { OFPMMFC_INVALID_METER
, "INVALID_METER" },
536 { OFPMMFC_UNKNOWN_METER
, "UNKNOWN_METER" },
537 { OFPMMFC_BAD_COMMAND
, "BAD_COMMAND" },
538 { OFPMMFC_BAD_FLAGS
, "BAD_FLAGS" },
539 { OFPMMFC_BAD_RATE
, "BAD_RATE" },
540 { OFPMMFC_BAD_BURST
, "BAD_BURST" },
541 { OFPMMFC_BAD_BAND
, "BAD_BAND" },
542 { OFPMMFC_BAD_BAND_VALUE
, "BAD_BAND_VALUE" },
543 { OFPMMFC_OUT_OF_METERS
, "OUT_OF_METERS" },
544 { OFPMMFC_OUT_OF_BANDS
, "OUT_OF_BANDS" },
548 #define OFPTFFC_BAD_TABLE 0U
549 #define OFPTFFC_BAD_METADATA 1U
550 #define OFPTFFC_BAD_TYPE 2U
551 #define OFPTFFC_BAD_LEN 3U
552 #define OFPTFFC_BAD_ARGUMENT 4U
553 #define OFPTFFC_EPERM 5U
554 static const struct tok ofptffc_str
[] = {
555 { OFPTFFC_BAD_TABLE
, "BAD_TABLE" },
556 { OFPTFFC_BAD_METADATA
, "BAD_METADATA" },
557 { OFPTFFC_BAD_TYPE
, "BAD_TYPE" },
558 { OFPTFFC_BAD_LEN
, "BAD_LEN" },
559 { OFPTFFC_BAD_ARGUMENT
, "BAD_ARGUMENT" },
560 { OFPTFFC_EPERM
, "EPERM" },
564 static const struct uint_tokary of13_ofpet2tokary
[] = {
565 { OFPET_HELLO_FAILED
, ofphfc_str
},
566 { OFPET_BAD_REQUEST
, ofpbrc_str
},
567 { OFPET_BAD_ACTION
, ofpbac_str
},
568 { OFPET_BAD_INSTRUCTION
, ofpbic_str
},
569 { OFPET_BAD_MATCH
, ofpbmc_str
},
570 { OFPET_FLOW_MOD_FAILED
, ofpfmfc_str
},
571 { OFPET_GROUP_MOD_FAILED
, ofpgmfc_str
},
572 { OFPET_PORT_MOD_FAILED
, ofppmfc_str
},
573 { OFPET_TABLE_MOD_FAILED
, ofptmfc_str
},
574 { OFPET_QUEUE_OP_FAILED
, ofpqofc_str
},
575 { OFPET_SWITCH_CONFIG_FAILED
, ofpscfc_str
},
576 { OFPET_ROLE_REQUEST_FAILED
, ofprrfc_str
},
577 { OFPET_METER_MOD_FAILED
, ofpmmfc_str
},
578 { OFPET_TABLE_FEATURES_FAILED
, ofptffc_str
},
579 { OFPET_EXPERIMENTER
, NULL
}, /* defines no codes */
580 /* uint2tokary() does not use array termination. */
583 /* lengths (fixed or minimal) of particular protocol structures */
584 #define OF_HELLO_ELEM_MINSIZE 4U
585 #define OF_ERROR_MSG_MINLEN 12U
586 #define OF_FEATURES_REPLY_FIXLEN 32U
587 #define OF_PORT_MOD_FIXLEN 40U
588 #define OF_SWITCH_CONFIG_MSG_FIXLEN 12U
589 #define OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN 16U
590 #define OF_EXPERIMENTER_MSG_MINLEN 16U
592 /* [OF13] Section A.1 */
594 of13_msgtype_str(const uint8_t type
)
596 return tok2str(ofpt_str
, "invalid (0x%02x)", type
);
599 /* [OF13] Section 7.3.1 */
601 of13_features_reply_print(netdissect_options
*ndo
,
602 const u_char
*cp
, u_int len
)
605 ND_PRINT("\n\t dpid 0x%016" PRIx64
, GET_BE_U_8(cp
));
608 ND_PRINT(", n_buffers %u", GET_BE_U_4(cp
));
611 ND_PRINT(", n_tables %u", GET_U_1(cp
));
614 ND_PRINT(", auxiliary_id %u", GET_U_1(cp
));
619 ND_PRINT("\n\t capabilities 0x%08x", GET_BE_U_4(cp
));
620 of_bitmap_print(ndo
, ofp_capabilities_bm
, GET_BE_U_4(cp
), OFPCAP_U
);
626 /* [OF13] Section 7.3.2 */
628 of13_switch_config_msg_print(netdissect_options
*ndo
,
629 const u_char
*cp
, u_int len
)
632 ND_PRINT("\n\t flags %s",
633 tok2str(ofp_config_str
, "invalid (0x%04x)", GET_BE_U_2(cp
)));
636 ND_PRINT(", miss_send_len %s",
637 tok2str(ofpcml_str
, "%u", GET_BE_U_2(cp
)));
640 /* [OF13] Section 7.3.4.3 */
642 of13_port_mod_print(netdissect_options
*ndo
,
643 const u_char
*cp
, u_int len
)
646 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str
, "%u", GET_BE_U_4(cp
)));
651 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp
));
652 OF_FWD(MAC_ADDR_LEN
);
656 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp
));
657 of_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
660 ND_PRINT("\n\t mask 0x%08x", GET_BE_U_4(cp
));
661 of_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
664 ND_PRINT("\n\t advertise 0x%08x", GET_BE_U_4(cp
));
665 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
668 /* Always the last field, check bounds. */
672 /* [OF13] Section 7.5.1 */
674 of13_hello_elements_print(netdissect_options
*ndo
,
675 const u_char
*cp
, u_int len
)
678 uint16_t type
, bmlen
;
680 if (len
< OF_HELLO_ELEM_MINSIZE
)
683 type
= GET_BE_U_2(cp
);
685 ND_PRINT("\n\t type %s",
686 tok2str(ofphet_str
, "unknown (0x%04x)", type
));
688 bmlen
= GET_BE_U_2(cp
);
690 ND_PRINT(", length %u", bmlen
);
691 /* cp is OF_HELLO_ELEM_MINSIZE bytes in */
692 if (bmlen
< OF_HELLO_ELEM_MINSIZE
||
693 bmlen
> OF_HELLO_ELEM_MINSIZE
+ len
)
696 case OFPHET_VERSIONBITMAP
:
698 * The specification obviously overprovisions the space
699 * for version bitmaps in this element ("ofp versions
700 * 32 to 63 are encoded in the second bitmap and so
701 * on"). Keep this code simple for now and recognize
702 * only a single bitmap with no padding.
704 if (bmlen
== OF_HELLO_ELEM_MINSIZE
+ 4) {
705 uint32_t bitmap
= GET_BE_U_4(cp
);
706 ND_PRINT(", bitmap 0x%08x", bitmap
);
707 of_bitmap_print(ndo
, ofverbm_str
, bitmap
,
710 ND_PRINT(" (bogus)");
711 ND_TCHECK_LEN(cp
, bmlen
- OF_HELLO_ELEM_MINSIZE
);
715 ND_TCHECK_LEN(cp
, bmlen
- OF_HELLO_ELEM_MINSIZE
);
717 OF_FWD(bmlen
- OF_HELLO_ELEM_MINSIZE
);
722 nd_print_invalid(ndo
);
723 ND_TCHECK_LEN(cp
, len
);
726 /* [OF13] Section 7.5.4 */
728 of13_experimenter_message_print(netdissect_options
*ndo
,
729 const u_char
*cp
, u_int len
)
731 uint32_t experimenter
;
734 experimenter
= GET_BE_U_4(cp
);
736 ND_PRINT("\n\t experimenter 0x%08x (%s)", experimenter
,
737 of_vendor_name(experimenter
));
739 ND_PRINT(", exp_type 0x%08x", GET_BE_U_4(cp
));
742 of_data_print(ndo
, cp
, len
);
745 /* [OF13] Section A.4.4 */
747 of13_error_print(netdissect_options
*ndo
,
748 const u_char
*cp
, u_int len
)
751 const struct tok
*code_str
;
754 type
= GET_BE_U_2(cp
);
756 ND_PRINT("\n\t type %s", tok2str(ofpet_str
, "invalid (0x%04x)", type
));
758 code
= GET_BE_U_2(cp
);
760 code_str
= uint2tokary(of13_ofpet2tokary
, type
);
761 if (code_str
!= NULL
)
762 ND_PRINT(", code %s",
763 tok2str(code_str
, "invalid (0x%04x)", code
));
765 ND_PRINT(", code invalid (0x%04x)", code
);
767 of_data_print(ndo
, cp
, len
);
771 of13_message_print(netdissect_options
*ndo
,
772 const u_char
*cp
, uint16_t len
, const uint8_t type
)
774 /* See the comment at the beginning of of10_message_print(). */
776 /* OpenFlow header only. */
777 case OFPT_FEATURES_REQUEST
: /* [OF13] Section A.3.1 */
778 case OFPT_GET_CONFIG_REQUEST
: /* [OF13] Section A.3.2 */
779 case OFPT_BARRIER_REQUEST
: /* [OF13] Section A.3.8 */
780 case OFPT_BARRIER_REPLY
: /* ibid */
781 case OFPT_GET_ASYNC_REQUEST
: /* [OF13] Section 7.3.10 */
786 /* OpenFlow header and fixed-size message body. */
787 case OFPT_FEATURES_REPLY
:
788 if (len
!= OF_FEATURES_REPLY_FIXLEN
- OF_HEADER_FIXLEN
)
790 if (ndo
->ndo_vflag
< 1)
792 of13_features_reply_print(ndo
, cp
, len
);
794 case OFPT_QUEUE_GET_CONFIG_REQUEST
: /* [OF13] Section A.3.6 */
795 if (len
!= OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN
- OF_HEADER_FIXLEN
)
797 if (ndo
->ndo_vflag
< 1)
800 ND_PRINT("\n\t port %s",
801 tok2str(ofpp_str
, "%u", GET_BE_U_4(cp
)));
804 /* Always the last field, check bounds. */
807 case OFPT_GET_CONFIG_REPLY
: /* [OF13] Section 7.3.2 */
808 case OFPT_SET_CONFIG
: /* ibid */
809 if (len
!= OF_SWITCH_CONFIG_MSG_FIXLEN
- OF_HEADER_FIXLEN
)
811 if (ndo
->ndo_vflag
< 1)
813 of13_switch_config_msg_print(ndo
, cp
, len
);
815 case OFPT_PORT_MOD
: /* [OF13] Section 7.3.4.3 */
816 if (len
!= OF_PORT_MOD_FIXLEN
- OF_HEADER_FIXLEN
)
818 if (ndo
->ndo_vflag
< 1)
820 of13_port_mod_print(ndo
, cp
, len
);
823 /* OpenFlow header and variable-size data. */
824 case OFPT_ECHO_REQUEST
: /* [OF13] Section A.5.2 */
825 case OFPT_ECHO_REPLY
: /* [OF13] Section A.5.3 */
826 if (ndo
->ndo_vflag
< 1)
828 of_data_print(ndo
, cp
, len
);
831 /* OpenFlow header and n * variable-size data units. */
832 case OFPT_HELLO
: /* [OF13] Section A.5.1 */
833 if (ndo
->ndo_vflag
< 1)
835 of13_hello_elements_print(ndo
, cp
, len
);
838 /* OpenFlow header, fixed-size message body and variable-size data. */
840 if (len
< OF_ERROR_MSG_MINLEN
- OF_HEADER_FIXLEN
)
842 if (ndo
->ndo_vflag
< 1)
844 of13_error_print(ndo
, cp
, len
);
846 case OFPT_EXPERIMENTER
: /* [OF13] Section 7.5.4 */
847 if (len
< OF_EXPERIMENTER_MSG_MINLEN
- OF_HEADER_FIXLEN
)
849 if (ndo
->ndo_vflag
< 1)
851 of13_experimenter_message_print(ndo
, cp
, len
);
855 * Not a recognised type or did not print the details, fall back to
858 ND_TCHECK_LEN(cp
, len
);
861 invalid
: /* skip the message body */
862 nd_print_invalid(ndo
);
863 ND_TCHECK_LEN(cp
, len
);