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 OFPPS_LINK_DOWN (1U << 0)
166 #define OFPPS_BLOCKED (1U << 1)
167 #define OFPPS_LIVE (1U << 2)
168 static const struct tok ofpps_bm
[] = {
169 { OFPPS_LINK_DOWN
, "LINK_DOWN" },
170 { OFPPS_BLOCKED
, "BLOCKED" },
171 { OFPPS_LIVE
, "LIVE" },
174 #define OFPPS_U (~(OFPPS_LINK_DOWN | OFPPS_BLOCKED | OFPPS_LIVE))
176 #define OFPPF_10MB_HD (1U << 0)
177 #define OFPPF_10MB_FD (1U << 1)
178 #define OFPPF_100MB_HD (1U << 2)
179 #define OFPPF_100MB_FD (1U << 3)
180 #define OFPPF_1GB_HD (1U << 4)
181 #define OFPPF_1GB_FD (1U << 5)
182 #define OFPPF_10GB_FD (1U << 6)
183 #define OFPPF_40GB_FD (1U << 7)
184 #define OFPPF_100GB_FD (1U << 8)
185 #define OFPPF_1TB_FD (1U << 9)
186 #define OFPPF_OTHER (1U << 10)
187 #define OFPPF_COPPER (1U << 11)
188 #define OFPPF_FIBER (1U << 12)
189 #define OFPPF_AUTONEG (1U << 13)
190 #define OFPPF_PAUSE (1U << 14)
191 #define OFPPF_PAUSE_ASYM (1U << 15)
192 static const struct tok ofppf_bm
[] = {
193 { OFPPF_10MB_HD
, "10MB_HD" },
194 { OFPPF_10MB_FD
, "10MB_FD" },
195 { OFPPF_100MB_HD
, "100MB_HD" },
196 { OFPPF_100MB_FD
, "100MB_FD" },
197 { OFPPF_1GB_HD
, "1GB_HD" },
198 { OFPPF_1GB_FD
, "1GB_FD" },
199 { OFPPF_10GB_FD
, "10GB_FD" },
200 { OFPPF_40GB_FD
, "40GB_FD" },
201 { OFPPF_100GB_FD
, "100GB_FD" },
202 { OFPPF_1TB_FD
, "1TB_FD" },
203 { OFPPF_OTHER
, "OTHER" },
204 { OFPPF_COPPER
, "COPPER" },
205 { OFPPF_FIBER
, "FIBER" },
206 { OFPPF_AUTONEG
, "AUTONEG" },
207 { OFPPF_PAUSE
, "PAUSE" },
208 { OFPPF_PAUSE_ASYM
, "PAUSE_ASYM" },
211 #define OFPPF_U (~(OFPPF_10MB_HD | OFPPF_10MB_FD | OFPPF_100MB_HD | \
212 OFPPF_100MB_FD | OFPPF_1GB_HD | OFPPF_1GB_FD | \
213 OFPPF_10GB_FD | OFPPF_40GB_FD | OFPPF_100GB_FD | \
214 OFPPF_1TB_FD | OFPPF_OTHER | OFPPF_COPPER | OFPPF_FIBER | \
215 OFPPF_AUTONEG | OFPPF_PAUSE | OFPPF_PAUSE_ASYM))
217 #define OFPHET_VERSIONBITMAP 1U
218 static const struct tok ofphet_str
[] = {
219 { OFPHET_VERSIONBITMAP
, "VERSIONBITMAP" },
223 #define OFPP_MAX 0xffffff00U
224 #define OFPP_IN_PORT 0xfffffff8U
225 #define OFPP_TABLE 0xfffffff9U
226 #define OFPP_NORMAL 0xfffffffaU
227 #define OFPP_FLOOD 0xfffffffbU
228 #define OFPP_ALL 0xfffffffcU
229 #define OFPP_CONTROLLER 0xfffffffdU
230 #define OFPP_LOCAL 0xfffffffeU
231 #define OFPP_ANY 0xffffffffU
232 static const struct tok ofpp_str
[] = {
234 { OFPP_IN_PORT
, "IN_PORT" },
235 { OFPP_TABLE
, "TABLE" },
236 { OFPP_NORMAL
, "NORMAL" },
237 { OFPP_FLOOD
, "FLOOD" },
239 { OFPP_CONTROLLER
, "CONTROLLER" },
240 { OFPP_LOCAL
, "LOCAL" },
245 #define OFPCR_ROLE_NOCHANGE 0U
246 #define OFPCR_ROLE_EQUAL 1U
247 #define OFPCR_ROLE_MASTER 2U
248 #define OFPCR_ROLE_SLAVE 3U
249 static const struct tok ofpcr_str
[] = {
250 { OFPCR_ROLE_NOCHANGE
, "NOCHANGE" },
251 { OFPCR_ROLE_EQUAL
, "EQUAL" },
252 { OFPCR_ROLE_MASTER
, "MASTER" },
253 { OFPCR_ROLE_SLAVE
, "SLAVE" },
257 #define OF_BIT_VER_1_0 (1U << (OF_VER_1_0 - 1))
258 #define OF_BIT_VER_1_1 (1U << (OF_VER_1_1 - 1))
259 #define OF_BIT_VER_1_2 (1U << (OF_VER_1_2 - 1))
260 #define OF_BIT_VER_1_3 (1U << (OF_VER_1_3 - 1))
261 #define OF_BIT_VER_1_4 (1U << (OF_VER_1_4 - 1))
262 #define OF_BIT_VER_1_5 (1U << (OF_VER_1_5 - 1))
263 static const struct tok ofverbm_str
[] = {
264 { OF_BIT_VER_1_0
, "1.0" },
265 { OF_BIT_VER_1_1
, "1.1" },
266 { OF_BIT_VER_1_2
, "1.2" },
267 { OF_BIT_VER_1_3
, "1.3" },
268 { OF_BIT_VER_1_4
, "1.4" },
269 { OF_BIT_VER_1_5
, "1.5" },
272 #define OF_BIT_VER_U (~(OF_BIT_VER_1_0 | OF_BIT_VER_1_1 | OF_BIT_VER_1_2 | \
273 OF_BIT_VER_1_3 | OF_BIT_VER_1_4 | OF_BIT_VER_1_5))
276 #define OFPPR_DELETE 1U
277 #define OFPPR_MODIFY 2U
278 static const struct tok ofppr_str
[] = {
279 { OFPPR_ADD
, "ADD" },
280 { OFPPR_DELETE
, "DELETE" },
281 { OFPPR_MODIFY
, "MODIFY" },
285 #define OFPET_HELLO_FAILED 0U
286 #define OFPET_BAD_REQUEST 1U
287 #define OFPET_BAD_ACTION 2U
288 #define OFPET_BAD_INSTRUCTION 3U
289 #define OFPET_BAD_MATCH 4U
290 #define OFPET_FLOW_MOD_FAILED 5U
291 #define OFPET_GROUP_MOD_FAILED 6U
292 #define OFPET_PORT_MOD_FAILED 7U
293 #define OFPET_TABLE_MOD_FAILED 8U
294 #define OFPET_QUEUE_OP_FAILED 9U
295 #define OFPET_SWITCH_CONFIG_FAILED 10U
296 #define OFPET_ROLE_REQUEST_FAILED 11U
297 #define OFPET_METER_MOD_FAILED 12U
298 #define OFPET_TABLE_FEATURES_FAILED 13U
299 #define OFPET_EXPERIMENTER 0xffffU /* a special case */
300 static const struct tok ofpet_str
[] = {
301 { OFPET_HELLO_FAILED
, "HELLO_FAILED" },
302 { OFPET_BAD_REQUEST
, "BAD_REQUEST" },
303 { OFPET_BAD_ACTION
, "BAD_ACTION" },
304 { OFPET_BAD_INSTRUCTION
, "BAD_INSTRUCTION" },
305 { OFPET_BAD_MATCH
, "BAD_MATCH" },
306 { OFPET_FLOW_MOD_FAILED
, "FLOW_MOD_FAILED" },
307 { OFPET_GROUP_MOD_FAILED
, "GROUP_MOD_FAILED" },
308 { OFPET_PORT_MOD_FAILED
, "PORT_MOD_FAILED" },
309 { OFPET_TABLE_MOD_FAILED
, "TABLE_MOD_FAILED" },
310 { OFPET_QUEUE_OP_FAILED
, "QUEUE_OP_FAILED" },
311 { OFPET_SWITCH_CONFIG_FAILED
, "SWITCH_CONFIG_FAILED" },
312 { OFPET_ROLE_REQUEST_FAILED
, "ROLE_REQUEST_FAILED" },
313 { OFPET_METER_MOD_FAILED
, "METER_MOD_FAILED" },
314 { OFPET_TABLE_FEATURES_FAILED
, "TABLE_FEATURES_FAILED" },
315 { OFPET_EXPERIMENTER
, "EXPERIMENTER" },
319 #define OFPHFC_INCOMPATIBLE 0U
320 #define OFPHFC_EPERM 1U
321 static const struct tok ofphfc_str
[] = {
322 { OFPHFC_INCOMPATIBLE
, "INCOMPATIBLE" },
323 { OFPHFC_EPERM
, "EPERM" },
327 #define OFPBRC_BAD_VERSION 0U
328 #define OFPBRC_BAD_TYPE 1U
329 #define OFPBRC_BAD_MULTIPART 2U
330 #define OFPBRC_BAD_EXPERIMENTER 3U
331 #define OFPBRC_BAD_EXP_TYPE 4U
332 #define OFPBRC_EPERM 5U
333 #define OFPBRC_BAD_LEN 6U
334 #define OFPBRC_BUFFER_EMPTY 7U
335 #define OFPBRC_BUFFER_UNKNOWN 8U
336 #define OFPBRC_BAD_TABLE_ID 9U
337 #define OFPBRC_IS_SLAVE 10U
338 #define OFPBRC_BAD_PORT 11U
339 #define OFPBRC_BAD_PACKET 12U
340 #define OFPBRC_MULTIPART_BUFFER_OVERFLOW 13U
341 static const struct tok ofpbrc_str
[] = {
342 { OFPBRC_BAD_VERSION
, "BAD_VERSION" },
343 { OFPBRC_BAD_TYPE
, "BAD_TYPE" },
344 { OFPBRC_BAD_MULTIPART
, "BAD_MULTIPART" },
345 { OFPBRC_BAD_EXPERIMENTER
, "BAD_EXPERIMENTER" },
346 { OFPBRC_BAD_EXP_TYPE
, "BAD_EXP_TYPE" },
347 { OFPBRC_EPERM
, "EPERM" },
348 { OFPBRC_BAD_LEN
, "BAD_LEN" },
349 { OFPBRC_BUFFER_EMPTY
, "BUFFER_EMPTY" },
350 { OFPBRC_BUFFER_UNKNOWN
, "BUFFER_UNKNOWN" },
351 { OFPBRC_BAD_TABLE_ID
, "BAD_TABLE_ID" },
352 { OFPBRC_IS_SLAVE
, "IS_SLAVE" },
353 { OFPBRC_BAD_PORT
, "BAD_PORT" },
354 { OFPBRC_BAD_PACKET
, "BAD_PACKET" },
355 { OFPBRC_MULTIPART_BUFFER_OVERFLOW
, "MULTIPART_BUFFER_OVERFLOW" },
359 #define OFPBAC_BAD_TYPE 0U
360 #define OFPBAC_BAD_LEN 1U
361 #define OFPBAC_BAD_EXPERIMENTER 2U
362 #define OFPBAC_BAD_EXP_TYPE 3U
363 #define OFPBAC_BAD_OUT_PORT 4U
364 #define OFPBAC_BAD_ARGUMENT 5U
365 #define OFPBAC_EPERM 6U
366 #define OFPBAC_TOO_MANY 7U
367 #define OFPBAC_BAD_QUEUE 8U
368 #define OFPBAC_BAD_OUT_GROUP 9U
369 #define OFPBAC_MATCH_INCONSISTENT 10U
370 #define OFPBAC_UNSUPPORTED_ORDER 11U
371 #define OFPBAC_BAD_TAG 12U
372 #define OFPBAC_BAD_SET_TYPE 13U
373 #define OFPBAC_BAD_SET_LEN 14U
374 #define OFPBAC_BAD_SET_ARGUMENT 15U
375 static const struct tok ofpbac_str
[] = {
376 { OFPBAC_BAD_TYPE
, "BAD_TYPE" },
377 { OFPBAC_BAD_LEN
, "BAD_LEN" },
378 { OFPBAC_BAD_EXPERIMENTER
, "BAD_EXPERIMENTER" },
379 { OFPBAC_BAD_EXP_TYPE
, "BAD_EXP_TYPE" },
380 { OFPBAC_BAD_OUT_PORT
, "BAD_OUT_PORT" },
381 { OFPBAC_BAD_ARGUMENT
, "BAD_ARGUMENT" },
382 { OFPBAC_EPERM
, "EPERM" },
383 { OFPBAC_TOO_MANY
, "TOO_MANY" },
384 { OFPBAC_BAD_QUEUE
, "BAD_QUEUE" },
385 { OFPBAC_BAD_OUT_GROUP
, "BAD_OUT_GROUP" },
386 { OFPBAC_MATCH_INCONSISTENT
, "MATCH_INCONSISTENT" },
387 { OFPBAC_UNSUPPORTED_ORDER
, "UNSUPPORTED_ORDER" },
388 { OFPBAC_BAD_TAG
, "BAD_TAG" },
389 { OFPBAC_BAD_SET_TYPE
, "BAD_SET_TYPE" },
390 { OFPBAC_BAD_SET_LEN
, "BAD_SET_LEN" },
391 { OFPBAC_BAD_SET_ARGUMENT
, "BAD_SET_ARGUMENT" },
395 #define OFPBIC_UNKNOWN_INST 0U
396 #define OFPBIC_UNSUP_INST 1U
397 #define OFPBIC_BAD_TABLE_ID 2U
398 #define OFPBIC_UNSUP_METADATA 3U
399 #define OFPBIC_UNSUP_METADATA_MASK 4U
400 #define OFPBIC_BAD_EXPERIMENTER 5U
401 #define OFPBIC_BAD_EXP_TYPE 6U
402 #define OFPBIC_BAD_LEN 7U
403 #define OFPBIC_EPERM 8U
404 static const struct tok ofpbic_str
[] = {
405 { OFPBIC_UNKNOWN_INST
, "UNKNOWN_INST" },
406 { OFPBIC_UNSUP_INST
, "UNSUP_INST" },
407 { OFPBIC_BAD_TABLE_ID
, "BAD_TABLE_ID" },
408 { OFPBIC_UNSUP_METADATA
, "UNSUP_METADATA" },
409 { OFPBIC_UNSUP_METADATA_MASK
, "UNSUP_METADATA_MASK" },
410 { OFPBIC_BAD_EXPERIMENTER
, "BAD_EXPERIMENTER" },
411 { OFPBIC_BAD_EXP_TYPE
, "BAD_EXP_TYPE" },
412 { OFPBIC_BAD_LEN
, "BAD_LEN" },
413 { OFPBIC_EPERM
, "EPERM" },
417 #define OFPBMC_BAD_TYPE 0U
418 #define OFPBMC_BAD_LEN 1U
419 #define OFPBMC_BAD_TAG 2U
420 #define OFPBMC_BAD_DL_ADDR_MASK 3U
421 #define OFPBMC_BAD_NW_ADDR_MASK 4U
422 #define OFPBMC_BAD_WILDCARDS 5U
423 #define OFPBMC_BAD_FIELD 6U
424 #define OFPBMC_BAD_VALUE 7U
425 #define OFPBMC_BAD_MASK 8U
426 #define OFPBMC_BAD_PREREQ 9U
427 #define OFPBMC_DUP_FIELD 10U
428 #define OFPBMC_EPERM 11U
429 static const struct tok ofpbmc_str
[] = {
430 { OFPBMC_BAD_TYPE
, "BAD_TYPE" },
431 { OFPBMC_BAD_LEN
, "BAD_LEN" },
432 { OFPBMC_BAD_TAG
, "BAD_TAG" },
433 { OFPBMC_BAD_DL_ADDR_MASK
, "BAD_DL_ADDR_MASK" },
434 { OFPBMC_BAD_NW_ADDR_MASK
, "BAD_NW_ADDR_MASK" },
435 { OFPBMC_BAD_WILDCARDS
, "BAD_WILDCARDS" },
436 { OFPBMC_BAD_FIELD
, "BAD_FIELD" },
437 { OFPBMC_BAD_VALUE
, "BAD_VALUE" },
438 { OFPBMC_BAD_MASK
, "BAD_MASK" },
439 { OFPBMC_BAD_PREREQ
, "BAD_PREREQ" },
440 { OFPBMC_DUP_FIELD
, "DUP_FIELD" },
441 { OFPBMC_EPERM
, "EPERM" },
445 #define OFPFMFC_UNKNOWN 0U
446 #define OFPFMFC_TABLE_FULL 1U
447 #define OFPFMFC_BAD_TABLE_ID 2U
448 #define OFPFMFC_OVERLAP 3U
449 #define OFPFMFC_EPERM 4U
450 #define OFPFMFC_BAD_TIMEOUT 5U
451 #define OFPFMFC_BAD_COMMAND 6U
452 #define OFPFMFC_BAD_FLAGS 7U
453 static const struct tok ofpfmfc_str
[] = {
454 { OFPFMFC_UNKNOWN
, "UNKNOWN" },
455 { OFPFMFC_TABLE_FULL
, "TABLE_FULL" },
456 { OFPFMFC_BAD_TABLE_ID
, "BAD_TABLE_ID" },
457 { OFPFMFC_OVERLAP
, "OVERLAP" },
458 { OFPFMFC_EPERM
, "EPERM" },
459 { OFPFMFC_BAD_TIMEOUT
, "BAD_TIMEOUT" },
460 { OFPFMFC_BAD_COMMAND
, "BAD_COMMAND" },
461 { OFPFMFC_BAD_FLAGS
, "BAD_FLAGS" },
465 #define OFPGMFC_GROUP_EXISTS 0U
466 #define OFPGMFC_INVALID_GROUP 1U
467 #define OFPGMFC_WEIGHT_UNSUPPORTED 2U
468 #define OFPGMFC_OUT_OF_GROUPS 3U
469 #define OFPGMFC_OUT_OF_BUCKETS 4U
470 #define OFPGMFC_CHAINING_UNSUPPORTED 5U
471 #define OFPGMFC_WATCH_UNSUPPORTED 6U
472 #define OFPGMFC_LOOP 7U
473 #define OFPGMFC_UNKNOWN_GROUP 8U
474 #define OFPGMFC_CHAINED_GROUP 9U
475 #define OFPGMFC_BAD_TYPE 10U
476 #define OFPGMFC_BAD_COMMAND 11U
477 #define OFPGMFC_BAD_BUCKET 12U
478 #define OFPGMFC_BAD_MATCH 13U
479 #define OFPGMFC_EPERM 14U
480 static const struct tok ofpgmfc_str
[] = {
481 { OFPGMFC_GROUP_EXISTS
, "GROUP_EXISTS" },
482 { OFPGMFC_INVALID_GROUP
, "INVALID_GROUP" },
483 { OFPGMFC_WEIGHT_UNSUPPORTED
, "WEIGHT_UNSUPPORTED" },
484 { OFPGMFC_OUT_OF_GROUPS
, "OUT_OF_GROUPS" },
485 { OFPGMFC_OUT_OF_BUCKETS
, "OUT_OF_BUCKETS" },
486 { OFPGMFC_CHAINING_UNSUPPORTED
, "CHAINING_UNSUPPORTED" },
487 { OFPGMFC_WATCH_UNSUPPORTED
, "WATCH_UNSUPPORTED" },
488 { OFPGMFC_LOOP
, "LOOP" },
489 { OFPGMFC_UNKNOWN_GROUP
, "UNKNOWN_GROUP" },
490 { OFPGMFC_CHAINED_GROUP
, "CHAINED_GROUP" },
491 { OFPGMFC_BAD_TYPE
, "BAD_TYPE" },
492 { OFPGMFC_BAD_COMMAND
, "BAD_COMMAND" },
493 { OFPGMFC_BAD_BUCKET
, "BAD_BUCKET" },
494 { OFPGMFC_BAD_MATCH
, "BAD_MATCH" },
495 { OFPGMFC_EPERM
, "EPERM" },
499 #define OFPPMFC_BAD_PORT 0U
500 #define OFPPMFC_BAD_HW_ADDR 1U
501 #define OFPPMFC_BAD_CONFIG 2U
502 #define OFPPMFC_BAD_ADVERTISE 3U
503 #define OFPPMFC_EPERM 4U
504 static const struct tok ofppmfc_str
[] = {
505 { OFPPMFC_BAD_PORT
, "BAD_PORT" },
506 { OFPPMFC_BAD_HW_ADDR
, "BAD_HW_ADDR" },
507 { OFPPMFC_BAD_CONFIG
, "BAD_CONFIG" },
508 { OFPPMFC_BAD_ADVERTISE
, "BAD_ADVERTISE" },
509 { OFPPMFC_EPERM
, "EPERM" },
513 #define OFPTMFC_BAD_TABLE 0U
514 #define OFPTMFC_BAD_CONFIG 1U
515 #define OFPTMFC_EPERM 2U
516 static const struct tok ofptmfc_str
[] = {
517 { OFPTMFC_BAD_TABLE
, "BAD_TABLE" },
518 { OFPTMFC_BAD_CONFIG
, "BAD_CONFIG" },
519 { OFPTMFC_EPERM
, "EPERM" },
523 #define OFPQOFC_BAD_PORT 0U
524 #define OFPQOFC_BAD_QUEUE 1U
525 #define OFPQOFC_EPERM 2U
526 static const struct tok ofpqofc_str
[] = {
527 { OFPQOFC_BAD_PORT
, "BAD_PORT" },
528 { OFPQOFC_BAD_QUEUE
, "BAD_QUEUE" },
529 { OFPQOFC_EPERM
, "EPERM" },
533 #define OFPSCFC_BAD_FLAGS 0U
534 #define OFPSCFC_BAD_LEN 1U
535 #define OFPSCFC_EPERM 2U
536 static const struct tok ofpscfc_str
[] = {
537 { OFPSCFC_BAD_FLAGS
, "BAD_FLAGS" },
538 { OFPSCFC_BAD_LEN
, "BAD_LEN" },
539 { OFPSCFC_EPERM
, "EPERM" },
543 #define OFPRRFC_STALE 0U
544 #define OFPRRFC_UNSUP 1U
545 #define OFPRRFC_BAD_ROLE 2U
546 static const struct tok ofprrfc_str
[] = {
547 { OFPRRFC_STALE
, "STALE" },
548 { OFPRRFC_UNSUP
, "UNSUP" },
549 { OFPRRFC_BAD_ROLE
, "BAD_ROLE" },
553 #define OFPMMFC_UNKNOWN 0U
554 #define OFPMMFC_METER_EXISTS 1U
555 #define OFPMMFC_INVALID_METER 2U
556 #define OFPMMFC_UNKNOWN_METER 3U
557 #define OFPMMFC_BAD_COMMAND 4U
558 #define OFPMMFC_BAD_FLAGS 5U
559 #define OFPMMFC_BAD_RATE 6U
560 #define OFPMMFC_BAD_BURST 7U
561 #define OFPMMFC_BAD_BAND 8U
562 #define OFPMMFC_BAD_BAND_VALUE 9U
563 #define OFPMMFC_OUT_OF_METERS 10U
564 #define OFPMMFC_OUT_OF_BANDS 11U
565 static const struct tok ofpmmfc_str
[] = {
566 { OFPMMFC_UNKNOWN
, "UNKNOWN" },
567 { OFPMMFC_METER_EXISTS
, "METER_EXISTS" },
568 { OFPMMFC_INVALID_METER
, "INVALID_METER" },
569 { OFPMMFC_UNKNOWN_METER
, "UNKNOWN_METER" },
570 { OFPMMFC_BAD_COMMAND
, "BAD_COMMAND" },
571 { OFPMMFC_BAD_FLAGS
, "BAD_FLAGS" },
572 { OFPMMFC_BAD_RATE
, "BAD_RATE" },
573 { OFPMMFC_BAD_BURST
, "BAD_BURST" },
574 { OFPMMFC_BAD_BAND
, "BAD_BAND" },
575 { OFPMMFC_BAD_BAND_VALUE
, "BAD_BAND_VALUE" },
576 { OFPMMFC_OUT_OF_METERS
, "OUT_OF_METERS" },
577 { OFPMMFC_OUT_OF_BANDS
, "OUT_OF_BANDS" },
581 #define OFPTFFC_BAD_TABLE 0U
582 #define OFPTFFC_BAD_METADATA 1U
583 #define OFPTFFC_BAD_TYPE 2U
584 #define OFPTFFC_BAD_LEN 3U
585 #define OFPTFFC_BAD_ARGUMENT 4U
586 #define OFPTFFC_EPERM 5U
587 static const struct tok ofptffc_str
[] = {
588 { OFPTFFC_BAD_TABLE
, "BAD_TABLE" },
589 { OFPTFFC_BAD_METADATA
, "BAD_METADATA" },
590 { OFPTFFC_BAD_TYPE
, "BAD_TYPE" },
591 { OFPTFFC_BAD_LEN
, "BAD_LEN" },
592 { OFPTFFC_BAD_ARGUMENT
, "BAD_ARGUMENT" },
593 { OFPTFFC_EPERM
, "EPERM" },
597 static const struct uint_tokary of13_ofpet2tokary
[] = {
598 { OFPET_HELLO_FAILED
, ofphfc_str
},
599 { OFPET_BAD_REQUEST
, ofpbrc_str
},
600 { OFPET_BAD_ACTION
, ofpbac_str
},
601 { OFPET_BAD_INSTRUCTION
, ofpbic_str
},
602 { OFPET_BAD_MATCH
, ofpbmc_str
},
603 { OFPET_FLOW_MOD_FAILED
, ofpfmfc_str
},
604 { OFPET_GROUP_MOD_FAILED
, ofpgmfc_str
},
605 { OFPET_PORT_MOD_FAILED
, ofppmfc_str
},
606 { OFPET_TABLE_MOD_FAILED
, ofptmfc_str
},
607 { OFPET_QUEUE_OP_FAILED
, ofpqofc_str
},
608 { OFPET_SWITCH_CONFIG_FAILED
, ofpscfc_str
},
609 { OFPET_ROLE_REQUEST_FAILED
, ofprrfc_str
},
610 { OFPET_METER_MOD_FAILED
, ofpmmfc_str
},
611 { OFPET_TABLE_FEATURES_FAILED
, ofptffc_str
},
612 { OFPET_EXPERIMENTER
, NULL
}, /* defines no codes */
613 /* uint2tokary() does not use array termination. */
616 /* lengths (fixed or minimal) of particular protocol structures */
617 #define OF_HELLO_ELEM_MINSIZE 4U
618 #define OF_ERROR_MSG_MINLEN 12U
619 #define OF_FEATURES_REPLY_FIXLEN 32U
620 #define OF_PORT_MOD_FIXLEN 40U
621 #define OF_SWITCH_CONFIG_MSG_FIXLEN 12U
622 #define OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN 16U
623 #define OF_ROLE_MSG_FIXLEN 24U
624 #define OF_PORT_STATUS_FIXLEN 80U
625 #define OF_EXPERIMENTER_MSG_MINLEN 16U
627 /* miscellaneous constants from [OF13] */
628 #define OFP_MAX_PORT_NAME_LEN 16U
630 /* [OF13] Section A.1 */
632 of13_msgtype_str(const uint8_t type
)
634 return tok2str(ofpt_str
, "invalid (0x%02x)", type
);
637 /* [OF13] Section 7.2.1 */
639 of13_port_print(netdissect_options
*ndo
,
643 ND_PRINT("\n\t port_no %s",
644 tok2str(ofpp_str
, "%u", GET_BE_U_4(cp
)));
649 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp
));
654 ND_PRINT(", name '");
655 (void)nd_print(ndo
, cp
, cp
+ OFP_MAX_PORT_NAME_LEN
);
657 cp
+= OFP_MAX_PORT_NAME_LEN
;
659 if (ndo
->ndo_vflag
< 2) {
660 ND_TCHECK_LEN(cp
, 32);
665 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp
));
666 of_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
669 ND_PRINT("\n\t state 0x%08x", GET_BE_U_4(cp
));
670 of_bitmap_print(ndo
, ofpps_bm
, GET_BE_U_4(cp
), OFPPS_U
);;
673 ND_PRINT("\n\t curr 0x%08x", GET_BE_U_4(cp
));
674 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
677 ND_PRINT("\n\t advertised 0x%08x", GET_BE_U_4(cp
));
678 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
681 ND_PRINT("\n\t supported 0x%08x", GET_BE_U_4(cp
));
682 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
685 ND_PRINT("\n\t peer 0x%08x", GET_BE_U_4(cp
));
686 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
689 ND_PRINT("\n\t curr_speed %ukbps", GET_BE_U_4(cp
));
692 ND_PRINT("\n\t max_speed %ukbps", GET_BE_U_4(cp
));
695 /* [OF13] Section 7.3.1 */
697 of13_features_reply_print(netdissect_options
*ndo
,
701 ND_PRINT("\n\t dpid 0x%016" PRIx64
, GET_BE_U_8(cp
));
704 ND_PRINT(", n_buffers %u", GET_BE_U_4(cp
));
707 ND_PRINT(", n_tables %u", GET_U_1(cp
));
710 ND_PRINT(", auxiliary_id %u", GET_U_1(cp
));
715 ND_PRINT("\n\t capabilities 0x%08x", GET_BE_U_4(cp
));
716 of_bitmap_print(ndo
, ofp_capabilities_bm
, GET_BE_U_4(cp
), OFPCAP_U
);
722 /* [OF13] Section 7.3.2 */
724 of13_switch_config_msg_print(netdissect_options
*ndo
,
728 ND_PRINT("\n\t flags %s",
729 tok2str(ofp_config_str
, "invalid (0x%04x)", GET_BE_U_2(cp
)));
732 ND_PRINT(", miss_send_len %s",
733 tok2str(ofpcml_str
, "%u", GET_BE_U_2(cp
)));
736 /* [OF13] Section 7.3.9 */
738 of13_role_msg_print(netdissect_options
*ndo
,
742 ND_PRINT("\n\t role %s",
743 tok2str(ofpcr_str
, "invalid (0x%08x)", GET_BE_U_4(cp
)));
748 ND_PRINT(", generation_id 0x%016" PRIx64
, GET_BE_U_8(cp
));
751 /* [OF13] Section 7.3.4.3 */
753 of13_port_mod_print(netdissect_options
*ndo
,
757 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str
, "%u", GET_BE_U_4(cp
)));
762 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp
));
767 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp
));
768 of_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
771 ND_PRINT("\n\t mask 0x%08x", GET_BE_U_4(cp
));
772 of_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
775 ND_PRINT("\n\t advertise 0x%08x", GET_BE_U_4(cp
));
776 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
779 /* Always the last field, check bounds. */
783 /* [OF13] Section 7.4.3 */
785 of13_port_status_print(netdissect_options
*ndo
,
789 ND_PRINT("\n\t reason %s",
790 tok2str(ofppr_str
, "invalid (0x02x)", GET_U_1(cp
)));
795 of13_port_print(ndo
, cp
);
798 /* [OF13] Section 7.5.1 */
800 of13_hello_elements_print(netdissect_options
*ndo
,
801 const u_char
*cp
, u_int len
)
804 uint16_t type
, bmlen
;
806 if (len
< OF_HELLO_ELEM_MINSIZE
)
809 type
= GET_BE_U_2(cp
);
811 ND_PRINT("\n\t type %s",
812 tok2str(ofphet_str
, "unknown (0x%04x)", type
));
814 bmlen
= GET_BE_U_2(cp
);
816 ND_PRINT(", length %u", bmlen
);
817 /* cp is OF_HELLO_ELEM_MINSIZE bytes in */
818 if (bmlen
< OF_HELLO_ELEM_MINSIZE
||
819 bmlen
> OF_HELLO_ELEM_MINSIZE
+ len
)
822 case OFPHET_VERSIONBITMAP
:
824 * The specification obviously overprovisions the space
825 * for version bitmaps in this element ("ofp versions
826 * 32 to 63 are encoded in the second bitmap and so
827 * on"). Keep this code simple for now and recognize
828 * only a single bitmap with no padding.
830 if (bmlen
== OF_HELLO_ELEM_MINSIZE
+ 4) {
831 uint32_t bitmap
= GET_BE_U_4(cp
);
832 ND_PRINT(", bitmap 0x%08x", bitmap
);
833 of_bitmap_print(ndo
, ofverbm_str
, bitmap
,
836 ND_PRINT(" (bogus)");
837 ND_TCHECK_LEN(cp
, bmlen
- OF_HELLO_ELEM_MINSIZE
);
841 ND_TCHECK_LEN(cp
, bmlen
- OF_HELLO_ELEM_MINSIZE
);
843 OF_FWD(bmlen
- OF_HELLO_ELEM_MINSIZE
);
848 nd_print_invalid(ndo
);
849 ND_TCHECK_LEN(cp
, len
);
852 /* [OF13] Section 7.5.4 */
854 of13_experimenter_message_print(netdissect_options
*ndo
,
855 const u_char
*cp
, u_int len
)
857 uint32_t experimenter
;
860 experimenter
= GET_BE_U_4(cp
);
862 ND_PRINT("\n\t experimenter 0x%08x (%s)", experimenter
,
863 of_vendor_name(experimenter
));
865 ND_PRINT(", exp_type 0x%08x", GET_BE_U_4(cp
));
868 of_data_print(ndo
, cp
, len
);
871 /* [OF13] Section A.4.4 */
873 of13_error_print(netdissect_options
*ndo
,
874 const u_char
*cp
, u_int len
)
877 const struct tok
*code_str
;
880 type
= GET_BE_U_2(cp
);
882 ND_PRINT("\n\t type %s", tok2str(ofpet_str
, "invalid (0x%04x)", type
));
884 code
= GET_BE_U_2(cp
);
886 code_str
= uint2tokary(of13_ofpet2tokary
, type
);
887 if (code_str
!= NULL
)
888 ND_PRINT(", code %s",
889 tok2str(code_str
, "invalid (0x%04x)", code
));
891 ND_PRINT(", code invalid (0x%04x)", code
);
893 of_data_print(ndo
, cp
, len
);
897 of13_message_print(netdissect_options
*ndo
,
898 const u_char
*cp
, uint16_t len
, const uint8_t type
)
900 /* See the comment at the beginning of of10_message_print(). */
902 /* OpenFlow header only. */
903 case OFPT_FEATURES_REQUEST
: /* [OF13] Section A.3.1 */
904 case OFPT_GET_CONFIG_REQUEST
: /* [OF13] Section A.3.2 */
905 case OFPT_BARRIER_REQUEST
: /* [OF13] Section A.3.8 */
906 case OFPT_BARRIER_REPLY
: /* ibid */
907 case OFPT_GET_ASYNC_REQUEST
: /* [OF13] Section 7.3.10 */
912 /* OpenFlow header and fixed-size message body. */
913 case OFPT_FEATURES_REPLY
:
914 if (len
!= OF_FEATURES_REPLY_FIXLEN
- OF_HEADER_FIXLEN
)
916 if (ndo
->ndo_vflag
< 1)
918 of13_features_reply_print(ndo
, cp
);
920 case OFPT_QUEUE_GET_CONFIG_REQUEST
: /* [OF13] Section A.3.6 */
921 if (len
!= OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN
- OF_HEADER_FIXLEN
)
923 if (ndo
->ndo_vflag
< 1)
926 ND_PRINT("\n\t port %s",
927 tok2str(ofpp_str
, "%u", GET_BE_U_4(cp
)));
930 /* Always the last field, check bounds. */
933 case OFPT_GET_CONFIG_REPLY
: /* [OF13] Section 7.3.2 */
934 case OFPT_SET_CONFIG
: /* ibid */
935 if (len
!= OF_SWITCH_CONFIG_MSG_FIXLEN
- OF_HEADER_FIXLEN
)
937 if (ndo
->ndo_vflag
< 1)
939 of13_switch_config_msg_print(ndo
, cp
);
941 case OFPT_PORT_MOD
: /* [OF13] Section 7.3.4.3 */
942 if (len
!= OF_PORT_MOD_FIXLEN
- OF_HEADER_FIXLEN
)
944 if (ndo
->ndo_vflag
< 1)
946 of13_port_mod_print(ndo
, cp
);
948 case OFPT_ROLE_REQUEST
: /* [OF13] Section 7.3.9 */
949 case OFPT_ROLE_REPLY
: /* ibid */
950 if (len
!= OF_ROLE_MSG_FIXLEN
- OF_HEADER_FIXLEN
)
952 if (ndo
->ndo_vflag
< 1)
954 of13_role_msg_print(ndo
, cp
);
956 case OFPT_PORT_STATUS
: /* [OF13] Section 7.4.3 */
957 if (len
!= OF_PORT_STATUS_FIXLEN
- OF_HEADER_FIXLEN
)
959 if (ndo
->ndo_vflag
< 1)
961 of13_port_status_print(ndo
, cp
);
964 /* OpenFlow header and variable-size data. */
965 case OFPT_ECHO_REQUEST
: /* [OF13] Section A.5.2 */
966 case OFPT_ECHO_REPLY
: /* [OF13] Section A.5.3 */
967 if (ndo
->ndo_vflag
< 1)
969 of_data_print(ndo
, cp
, len
);
972 /* OpenFlow header and n * variable-size data units. */
973 case OFPT_HELLO
: /* [OF13] Section A.5.1 */
974 if (ndo
->ndo_vflag
< 1)
976 of13_hello_elements_print(ndo
, cp
, len
);
979 /* OpenFlow header, fixed-size message body and variable-size data. */
981 if (len
< OF_ERROR_MSG_MINLEN
- OF_HEADER_FIXLEN
)
983 if (ndo
->ndo_vflag
< 1)
985 of13_error_print(ndo
, cp
, len
);
987 case OFPT_EXPERIMENTER
: /* [OF13] Section 7.5.4 */
988 if (len
< OF_EXPERIMENTER_MSG_MINLEN
- OF_HEADER_FIXLEN
)
990 if (ndo
->ndo_vflag
< 1)
992 of13_experimenter_message_print(ndo
, cp
, len
);
996 * Not a recognised type or did not print the details, fall back to
999 ND_TCHECK_LEN(cp
, len
);
1002 invalid
: /* skip the message body */
1003 nd_print_invalid(ndo
);
1004 ND_TCHECK_LEN(cp
, len
);