2 * This module implements decoding of OpenFlow protocol version 1.0 (wire
3 * protocol 0x01). The decoder implements terse (default), detailed (-v) and
4 * full (-vv) output formats and, as much as each format implies, detects and
5 * tries to work around sizing anomalies inside the messages. The decoder marks
6 * up bogus values of selected message fields and decodes partially captured
7 * messages up to the snapshot end. It is based on the specification below:
9 * [OF10] http://www.openflow.org/documents/openflow-spec-v1.0.0.pdf
11 * Decoding of Ethernet frames nested in OFPT_PACKET_IN and OFPT_PACKET_OUT
12 * messages is done only when the verbosity level set by command-line argument
13 * is "-vvv" or higher. In that case the verbosity level is temporarily
14 * decremented by 3 during the nested frame decoding. For example, running
15 * tcpdump with "-vvvv" will do full decoding of OpenFlow and "-v" decoding of
18 * Partial decoding of Big Switch Networks vendor extensions is done after the
19 * oftest (OpenFlow Testing Framework) source code.
22 * Copyright (c) 2013 The TCPDUMP project
23 * All rights reserved.
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
37 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
38 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
39 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
40 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
41 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
42 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
44 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
45 * POSSIBILITY OF SUCH DAMAGE.
48 #define NETDISSECT_REWORKED
53 #include <tcpdump-stdinc.h>
55 #include "interface.h"
57 #include "addrtoname.h"
59 #include "ethertype.h"
64 static const char tstr
[] = " [|openflow]";
65 static const char cstr
[] = " (corrupt)";
67 #define OFPT_HELLO 0x00
68 #define OFPT_ERROR 0x01
69 #define OFPT_ECHO_REQUEST 0x02
70 #define OFPT_ECHO_REPLY 0x03
71 #define OFPT_VENDOR 0x04
72 #define OFPT_FEATURES_REQUEST 0x05
73 #define OFPT_FEATURES_REPLY 0x06
74 #define OFPT_GET_CONFIG_REQUEST 0x07
75 #define OFPT_GET_CONFIG_REPLY 0x08
76 #define OFPT_SET_CONFIG 0x09
77 #define OFPT_PACKET_IN 0x0a
78 #define OFPT_FLOW_REMOVED 0x0b
79 #define OFPT_PORT_STATUS 0x0c
80 #define OFPT_PACKET_OUT 0x0d
81 #define OFPT_FLOW_MOD 0x0e
82 #define OFPT_PORT_MOD 0x0f
83 #define OFPT_STATS_REQUEST 0x10
84 #define OFPT_STATS_REPLY 0x11
85 #define OFPT_BARRIER_REQUEST 0x12
86 #define OFPT_BARRIER_REPLY 0x13
87 #define OFPT_QUEUE_GET_CONFIG_REQUEST 0x14
88 #define OFPT_QUEUE_GET_CONFIG_REPLY 0x15
89 static const struct tok ofpt_str
[] = {
90 { OFPT_HELLO
, "HELLO" },
91 { OFPT_ERROR
, "ERROR" },
92 { OFPT_ECHO_REQUEST
, "ECHO_REQUEST" },
93 { OFPT_ECHO_REPLY
, "ECHO_REPLY" },
94 { OFPT_VENDOR
, "VENDOR" },
95 { OFPT_FEATURES_REQUEST
, "FEATURES_REQUEST" },
96 { OFPT_FEATURES_REPLY
, "FEATURES_REPLY" },
97 { OFPT_GET_CONFIG_REQUEST
, "GET_CONFIG_REQUEST" },
98 { OFPT_GET_CONFIG_REPLY
, "GET_CONFIG_REPLY" },
99 { OFPT_SET_CONFIG
, "SET_CONFIG" },
100 { OFPT_PACKET_IN
, "PACKET_IN" },
101 { OFPT_FLOW_REMOVED
, "FLOW_REMOVED" },
102 { OFPT_PORT_STATUS
, "PORT_STATUS" },
103 { OFPT_PACKET_OUT
, "PACKET_OUT" },
104 { OFPT_FLOW_MOD
, "FLOW_MOD" },
105 { OFPT_PORT_MOD
, "PORT_MOD" },
106 { OFPT_STATS_REQUEST
, "STATS_REQUEST" },
107 { OFPT_STATS_REPLY
, "STATS_REPLY" },
108 { OFPT_BARRIER_REQUEST
, "BARRIER_REQUEST" },
109 { OFPT_BARRIER_REPLY
, "BARRIER_REPLY" },
110 { OFPT_QUEUE_GET_CONFIG_REQUEST
, "QUEUE_GET_CONFIG_REQUEST" },
111 { OFPT_QUEUE_GET_CONFIG_REPLY
, "QUEUE_GET_CONFIG_REPLY" },
115 #define OFPPC_PORT_DOWN (1 << 0)
116 #define OFPPC_NO_STP (1 << 1)
117 #define OFPPC_NO_RECV (1 << 2)
118 #define OFPPC_NO_RECV_STP (1 << 3)
119 #define OFPPC_NO_FLOOD (1 << 4)
120 #define OFPPC_NO_FWD (1 << 5)
121 #define OFPPC_NO_PACKET_IN (1 << 6)
122 static const struct tok ofppc_bm
[] = {
123 { OFPPC_PORT_DOWN
, "PORT_DOWN" },
124 { OFPPC_NO_STP
, "NO_STP" },
125 { OFPPC_NO_RECV
, "NO_RECV" },
126 { OFPPC_NO_RECV_STP
, "NO_RECV_STP" },
127 { OFPPC_NO_FLOOD
, "NO_FLOOD" },
128 { OFPPC_NO_FWD
, "NO_FWD" },
129 { OFPPC_NO_PACKET_IN
, "NO_PACKET_IN" },
132 #define OFPPC_U (~(OFPPC_PORT_DOWN | OFPPC_NO_STP | OFPPC_NO_RECV | \
133 OFPPC_NO_RECV_STP | OFPPC_NO_FLOOD | OFPPC_NO_FWD | \
136 #define OFPPS_LINK_DOWN (1 << 0)
137 #define OFPPS_STP_LISTEN (0 << 8)
138 #define OFPPS_STP_LEARN (1 << 8)
139 #define OFPPS_STP_FORWARD (2 << 8)
140 #define OFPPS_STP_BLOCK (3 << 8)
141 #define OFPPS_STP_MASK (3 << 8)
142 static const struct tok ofpps_bm
[] = {
143 { OFPPS_LINK_DOWN
, "LINK_DOWN" },
144 { OFPPS_STP_LISTEN
, "STP_LISTEN" },
145 { OFPPS_STP_LEARN
, "STP_LEARN" },
146 { OFPPS_STP_FORWARD
, "STP_FORWARD" },
147 { OFPPS_STP_BLOCK
, "STP_BLOCK" },
150 #define OFPPS_U (~(OFPPS_LINK_DOWN | OFPPS_STP_LISTEN | OFPPS_STP_LEARN | \
151 OFPPS_STP_FORWARD | OFPPS_STP_BLOCK))
153 #define OFPP_MAX 0xff00
154 #define OFPP_IN_PORT 0xfff8
155 #define OFPP_TABLE 0xfff9
156 #define OFPP_NORMAL 0xfffa
157 #define OFPP_FLOOD 0xfffb
158 #define OFPP_ALL 0xfffc
159 #define OFPP_CONTROLLER 0xfffd
160 #define OFPP_LOCAL 0xfffe
161 #define OFPP_NONE 0xffff
162 static const struct tok ofpp_str
[] = {
164 { OFPP_IN_PORT
, "IN_PORT" },
165 { OFPP_TABLE
, "TABLE" },
166 { OFPP_NORMAL
, "NORMAL" },
167 { OFPP_FLOOD
, "FLOOD" },
169 { OFPP_CONTROLLER
, "CONTROLLER" },
170 { OFPP_LOCAL
, "LOCAL" },
171 { OFPP_NONE
, "NONE" },
175 #define OFPPF_10MB_HD (1 << 0)
176 #define OFPPF_10MB_FD (1 << 1)
177 #define OFPPF_100MB_HD (1 << 2)
178 #define OFPPF_100MB_FD (1 << 3)
179 #define OFPPF_1GB_HD (1 << 4)
180 #define OFPPF_1GB_FD (1 << 5)
181 #define OFPPF_10GB_FD (1 << 6)
182 #define OFPPF_COPPER (1 << 7)
183 #define OFPPF_FIBER (1 << 8)
184 #define OFPPF_AUTONEG (1 << 9)
185 #define OFPPF_PAUSE (1 << 10)
186 #define OFPPF_PAUSE_ASYM (1 << 11)
187 static const struct tok ofppf_bm
[] = {
188 { OFPPF_10MB_HD
, "10MB_HD" },
189 { OFPPF_10MB_FD
, "10MB_FD" },
190 { OFPPF_100MB_HD
, "100MB_HD" },
191 { OFPPF_100MB_FD
, "100MB_FD" },
192 { OFPPF_1GB_HD
, "1GB_HD" },
193 { OFPPF_1GB_FD
, "1GB_FD" },
194 { OFPPF_10GB_FD
, "10GB_FD" },
195 { OFPPF_COPPER
, "COPPER" },
196 { OFPPF_FIBER
, "FIBER" },
197 { OFPPF_AUTONEG
, "AUTONEG" },
198 { OFPPF_PAUSE
, "PAUSE" },
199 { OFPPF_PAUSE_ASYM
, "PAUSE_ASYM" },
202 #define OFPPF_U (~(OFPPF_10MB_HD | OFPPF_10MB_FD | OFPPF_100MB_HD | \
203 OFPPF_100MB_FD | OFPPF_1GB_HD | OFPPF_1GB_FD | \
204 OFPPF_10GB_FD | OFPPF_COPPER | OFPPF_FIBER | \
205 OFPPF_AUTONEG | OFPPF_PAUSE | OFPPF_PAUSE_ASYM))
207 #define OFPQT_NONE 0x0000
208 #define OFPQT_MIN_RATE 0x0001
209 static const struct tok ofpqt_str
[] = {
210 { OFPQT_NONE
, "NONE" },
211 { OFPQT_MIN_RATE
, "MIN_RATE" },
215 #define OFPFW_IN_PORT (1 << 0)
216 #define OFPFW_DL_VLAN (1 << 1)
217 #define OFPFW_DL_SRC (1 << 2)
218 #define OFPFW_DL_DST (1 << 3)
219 #define OFPFW_DL_TYPE (1 << 4)
220 #define OFPFW_NW_PROTO (1 << 5)
221 #define OFPFW_TP_SRC (1 << 6)
222 #define OFPFW_TP_DST (1 << 7)
223 #define OFPFW_NW_SRC_SHIFT 8
224 #define OFPFW_NW_SRC_BITS 6
225 #define OFPFW_NW_SRC_MASK (((1 << OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT)
226 #define OFPFW_NW_DST_SHIFT 14
227 #define OFPFW_NW_DST_BITS 6
228 #define OFPFW_NW_DST_MASK (((1 << OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT)
229 #define OFPFW_DL_VLAN_PCP (1 << 20)
230 #define OFPFW_NW_TOS (1 << 21)
231 #define OFPFW_ALL ((1 << 22) - 1)
232 static const struct tok ofpfw_bm
[] = {
233 { OFPFW_IN_PORT
, "IN_PORT" },
234 { OFPFW_DL_VLAN
, "DL_VLAN" },
235 { OFPFW_DL_SRC
, "DL_SRC" },
236 { OFPFW_DL_DST
, "DL_DST" },
237 { OFPFW_DL_TYPE
, "DL_TYPE" },
238 { OFPFW_NW_PROTO
, "NW_PROTO" },
239 { OFPFW_TP_SRC
, "TP_SRC" },
240 { OFPFW_TP_DST
, "TP_DST" },
241 { OFPFW_DL_VLAN_PCP
, "DL_VLAN_PCP" },
242 { OFPFW_NW_TOS
, "NW_TOS" },
245 /* The above array does not include bits 8~13 (OFPFW_NW_SRC_*) and 14~19
246 * (OFPFW_NW_DST_*), which are not a part of the bitmap and require decoding
247 * other than that of tok2str(). The macro below includes these bits such that
248 * they are not reported as bogus in the decoding. */
249 #define OFPFW_U (~(OFPFW_ALL))
251 #define OFPAT_OUTPUT 0x0000
252 #define OFPAT_SET_VLAN_VID 0x0001
253 #define OFPAT_SET_VLAN_PCP 0x0002
254 #define OFPAT_STRIP_VLAN 0x0003
255 #define OFPAT_SET_DL_SRC 0x0004
256 #define OFPAT_SET_DL_DST 0x0005
257 #define OFPAT_SET_NW_SRC 0x0006
258 #define OFPAT_SET_NW_DST 0x0007
259 #define OFPAT_SET_NW_TOS 0x0008
260 #define OFPAT_SET_TP_SRC 0x0009
261 #define OFPAT_SET_TP_DST 0x000a
262 #define OFPAT_ENQUEUE 0x000b
263 #define OFPAT_VENDOR 0xffff
264 static const struct tok ofpat_str
[] = {
265 { OFPAT_OUTPUT
, "OUTPUT" },
266 { OFPAT_SET_VLAN_VID
, "SET_VLAN_VID" },
267 { OFPAT_SET_VLAN_PCP
, "SET_VLAN_PCP" },
268 { OFPAT_STRIP_VLAN
, "STRIP_VLAN" },
269 { OFPAT_SET_DL_SRC
, "SET_DL_SRC" },
270 { OFPAT_SET_DL_DST
, "SET_DL_DST" },
271 { OFPAT_SET_NW_SRC
, "SET_NW_SRC" },
272 { OFPAT_SET_NW_DST
, "SET_NW_DST" },
273 { OFPAT_SET_NW_TOS
, "SET_NW_TOS" },
274 { OFPAT_SET_TP_SRC
, "SET_TP_SRC" },
275 { OFPAT_SET_TP_DST
, "SET_TP_DST" },
276 { OFPAT_ENQUEUE
, "ENQUEUE" },
277 { OFPAT_VENDOR
, "VENDOR" },
281 /* bit-shifted, w/o vendor action */
282 static const struct tok ofpat_bm
[] = {
283 { 1 << OFPAT_OUTPUT
, "OUTPUT" },
284 { 1 << OFPAT_SET_VLAN_VID
, "SET_VLAN_VID" },
285 { 1 << OFPAT_SET_VLAN_PCP
, "SET_VLAN_PCP" },
286 { 1 << OFPAT_STRIP_VLAN
, "STRIP_VLAN" },
287 { 1 << OFPAT_SET_DL_SRC
, "SET_DL_SRC" },
288 { 1 << OFPAT_SET_DL_DST
, "SET_DL_DST" },
289 { 1 << OFPAT_SET_NW_SRC
, "SET_NW_SRC" },
290 { 1 << OFPAT_SET_NW_DST
, "SET_NW_DST" },
291 { 1 << OFPAT_SET_NW_TOS
, "SET_NW_TOS" },
292 { 1 << OFPAT_SET_TP_SRC
, "SET_TP_SRC" },
293 { 1 << OFPAT_SET_TP_DST
, "SET_TP_DST" },
294 { 1 << OFPAT_ENQUEUE
, "ENQUEUE" },
297 #define OFPAT_U (~(1 << OFPAT_OUTPUT | 1 << OFPAT_SET_VLAN_VID | \
298 1 << OFPAT_SET_VLAN_PCP | 1 << OFPAT_STRIP_VLAN | \
299 1 << OFPAT_SET_DL_SRC | 1 << OFPAT_SET_DL_DST | \
300 1 << OFPAT_SET_NW_SRC | 1 << OFPAT_SET_NW_DST | \
301 1 << OFPAT_SET_NW_TOS | 1 << OFPAT_SET_TP_SRC | \
302 1 << OFPAT_SET_TP_DST | 1 << OFPAT_ENQUEUE))
304 #define OFPC_FLOW_STATS (1 << 0)
305 #define OFPC_TABLE_STATS (1 << 1)
306 #define OFPC_PORT_STATS (1 << 2)
307 #define OFPC_STP (1 << 3)
308 #define OFPC_RESERVED (1 << 4)
309 #define OFPC_IP_REASM (1 << 5)
310 #define OFPC_QUEUE_STATS (1 << 6)
311 #define OFPC_ARP_MATCH_IP (1 << 7)
312 static const struct tok ofp_capabilities_bm
[] = {
313 { OFPC_FLOW_STATS
, "FLOW_STATS" },
314 { OFPC_TABLE_STATS
, "TABLE_STATS" },
315 { OFPC_PORT_STATS
, "PORT_STATS" },
317 { OFPC_RESERVED
, "RESERVED" }, /* not in the mask below */
318 { OFPC_IP_REASM
, "IP_REASM" },
319 { OFPC_QUEUE_STATS
, "QUEUE_STATS" },
320 { OFPC_ARP_MATCH_IP
, "ARP_MATCH_IP" },
323 #define OFPCAP_U (~(OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS | \
324 OFPC_STP | OFPC_IP_REASM | OFPC_QUEUE_STATS | \
327 #define OFPC_FRAG_NORMAL 0x0000
328 #define OFPC_FRAG_DROP 0x0001
329 #define OFPC_FRAG_REASM 0x0002
330 #define OFPC_FRAG_MASK 0x0003
331 static const struct tok ofp_config_str
[] = {
332 { OFPC_FRAG_NORMAL
, "FRAG_NORMAL" },
333 { OFPC_FRAG_DROP
, "FRAG_DROP" },
334 { OFPC_FRAG_REASM
, "FRAG_REASM" },
338 #define OFPFC_ADD 0x0000
339 #define OFPFC_MODIFY 0x0001
340 #define OFPFC_MODIFY_STRICT 0x0002
341 #define OFPFC_DELETE 0x0003
342 #define OFPFC_DELETE_STRICT 0x0004
343 static const struct tok ofpfc_str
[] = {
344 { OFPFC_ADD
, "ADD" },
345 { OFPFC_MODIFY
, "MODIFY" },
346 { OFPFC_MODIFY_STRICT
, "MODIFY_STRICT" },
347 { OFPFC_DELETE
, "DELETE" },
348 { OFPFC_DELETE_STRICT
, "DELETE_STRICT" },
352 static const struct tok bufferid_str
[] = {
353 { 0xffffffff, "NONE" },
357 #define OFPFF_SEND_FLOW_REM (1 << 0)
358 #define OFPFF_CHECK_OVERLAP (1 << 1)
359 #define OFPFF_EMERG (1 << 2)
360 static const struct tok ofpff_bm
[] = {
361 { OFPFF_SEND_FLOW_REM
, "SEND_FLOW_REM" },
362 { OFPFF_CHECK_OVERLAP
, "CHECK_OVERLAP" },
363 { OFPFF_EMERG
, "EMERG" },
366 #define OFPFF_U (~(OFPFF_SEND_FLOW_REM | OFPFF_CHECK_OVERLAP | OFPFF_EMERG))
368 #define OFPST_DESC 0x0000
369 #define OFPST_FLOW 0x0001
370 #define OFPST_AGGREGATE 0x0002
371 #define OFPST_TABLE 0x0003
372 #define OFPST_PORT 0x0004
373 #define OFPST_QUEUE 0x0005
374 #define OFPST_VENDOR 0xffff
375 static const struct tok ofpst_str
[] = {
376 { OFPST_DESC
, "DESC" },
377 { OFPST_FLOW
, "FLOW" },
378 { OFPST_AGGREGATE
, "AGGREGATE" },
379 { OFPST_TABLE
, "TABLE" },
380 { OFPST_PORT
, "PORT" },
381 { OFPST_QUEUE
, "QUEUE" },
382 { OFPST_VENDOR
, "VENDOR" },
386 static const struct tok tableid_str
[] = {
392 #define OFPQ_ALL 0xffffffff
393 static const struct tok ofpq_str
[] = {
398 #define OFPSF_REPLY_MORE 0x0001
399 static const struct tok ofpsf_reply_bm
[] = {
400 { OFPSF_REPLY_MORE
, "MORE" },
403 #define OFPSF_REPLY_U (~(OFPSF_REPLY_MORE))
405 #define OFPR_NO_MATCH 0x00
406 #define OFPR_ACTION 0x01
407 static const struct tok ofpr_str
[] = {
408 { OFPR_NO_MATCH
, "NO_MATCH" },
409 { OFPR_ACTION
, "ACTION" },
413 #define OFPRR_IDLE_TIMEOUT 0x00
414 #define OFPRR_HARD_TIMEOUT 0x01
415 #define OFPRR_DELETE 0x02
416 static const struct tok ofprr_str
[] = {
417 { OFPRR_IDLE_TIMEOUT
, "IDLE_TIMEOUT" },
418 { OFPRR_HARD_TIMEOUT
, "HARD_TIMEOUT" },
419 { OFPRR_DELETE
, "DELETE" },
423 #define OFPPR_ADD 0x00
424 #define OFPPR_DELETE 0x01
425 #define OFPPR_MODIFY 0x02
426 static const struct tok ofppr_str
[] = {
427 { OFPPR_ADD
, "ADD" },
428 { OFPPR_DELETE
, "DELETE" },
429 { OFPPR_MODIFY
, "MODIFY" },
433 #define OFPET_HELLO_FAILED 0x0000
434 #define OFPET_BAD_REQUEST 0x0001
435 #define OFPET_BAD_ACTION 0x0002
436 #define OFPET_FLOW_MOD_FAILED 0x0003
437 #define OFPET_PORT_MOD_FAILED 0x0004
438 #define OFPET_QUEUE_OP_FAILED 0x0005
439 static const struct tok ofpet_str
[] = {
440 { OFPET_HELLO_FAILED
, "HELLO_FAILED" },
441 { OFPET_BAD_REQUEST
, "BAD_REQUEST" },
442 { OFPET_BAD_ACTION
, "BAD_ACTION" },
443 { OFPET_FLOW_MOD_FAILED
, "FLOW_MOD_FAILED" },
444 { OFPET_PORT_MOD_FAILED
, "PORT_MOD_FAILED" },
445 { OFPET_QUEUE_OP_FAILED
, "QUEUE_OP_FAILED" },
449 #define OFPHFC_INCOMPATIBLE 0x0000
450 #define OFPHFC_EPERM 0x0001
451 static const struct tok ofphfc_str
[] = {
452 { OFPHFC_INCOMPATIBLE
, "INCOMPATIBLE" },
453 { OFPHFC_EPERM
, "EPERM" },
457 #define OFPBRC_BAD_VERSION 0x0000
458 #define OFPBRC_BAD_TYPE 0x0001
459 #define OFPBRC_BAD_STAT 0x0002
460 #define OFPBRC_BAD_VENDOR 0x0003
461 #define OFPBRC_BAD_SUBTYPE 0x0004
462 #define OFPBRC_EPERM 0x0005
463 #define OFPBRC_BAD_LEN 0x0006
464 #define OFPBRC_BUFFER_EMPTY 0x0007
465 #define OFPBRC_BUFFER_UNKNOWN 0x0008
466 static const struct tok ofpbrc_str
[] = {
467 { OFPBRC_BAD_VERSION
, "BAD_VERSION" },
468 { OFPBRC_BAD_TYPE
, "BAD_TYPE" },
469 { OFPBRC_BAD_STAT
, "BAD_STAT" },
470 { OFPBRC_BAD_VENDOR
, "BAD_VENDOR" },
471 { OFPBRC_BAD_SUBTYPE
, "BAD_SUBTYPE" },
472 { OFPBRC_EPERM
, "EPERM" },
473 { OFPBRC_BAD_LEN
, "BAD_LEN" },
474 { OFPBRC_BUFFER_EMPTY
, "BUFFER_EMPTY" },
475 { OFPBRC_BUFFER_UNKNOWN
, "BUFFER_UNKNOWN" },
479 #define OFPBAC_BAD_TYPE 0x0000
480 #define OFPBAC_BAD_LEN 0x0001
481 #define OFPBAC_BAD_VENDOR 0x0002
482 #define OFPBAC_BAD_VENDOR_TYPE 0x0003
483 #define OFPBAC_BAD_OUT_PORT 0x0004
484 #define OFPBAC_BAD_ARGUMENT 0x0005
485 #define OFPBAC_EPERM 0x0006
486 #define OFPBAC_TOO_MANY 0x0007
487 #define OFPBAC_BAD_QUEUE 0x0008
488 static const struct tok ofpbac_str
[] = {
489 { OFPBAC_BAD_TYPE
, "BAD_TYPE" },
490 { OFPBAC_BAD_LEN
, "BAD_LEN" },
491 { OFPBAC_BAD_VENDOR
, "BAD_VENDOR" },
492 { OFPBAC_BAD_VENDOR_TYPE
, "BAD_VENDOR_TYPE" },
493 { OFPBAC_BAD_OUT_PORT
, "BAD_OUT_PORT" },
494 { OFPBAC_BAD_ARGUMENT
, "BAD_ARGUMENT" },
495 { OFPBAC_EPERM
, "EPERM" },
496 { OFPBAC_TOO_MANY
, "TOO_MANY" },
497 { OFPBAC_BAD_QUEUE
, "BAD_QUEUE" },
501 #define OFPFMFC_ALL_TABLES_FULL 0x0000
502 #define OFPFMFC_OVERLAP 0x0001
503 #define OFPFMFC_EPERM 0x0002
504 #define OFPFMFC_BAD_EMERG_TIMEOUT 0x0003
505 #define OFPFMFC_BAD_COMMAND 0x0004
506 #define OFPFMFC_UNSUPPORTED 0x0005
507 static const struct tok ofpfmfc_str
[] = {
508 { OFPFMFC_ALL_TABLES_FULL
, "ALL_TABLES_FULL" },
509 { OFPFMFC_OVERLAP
, "OVERLAP" },
510 { OFPFMFC_EPERM
, "EPERM" },
511 { OFPFMFC_BAD_EMERG_TIMEOUT
, "BAD_EMERG_TIMEOUT" },
512 { OFPFMFC_BAD_COMMAND
, "BAD_COMMAND" },
513 { OFPFMFC_UNSUPPORTED
, "UNSUPPORTED" },
517 #define OFPPMFC_BAD_PORT 0x0000
518 #define OFPPMFC_BAD_HW_ADDR 0x0001
519 static const struct tok ofppmfc_str
[] = {
520 { OFPPMFC_BAD_PORT
, "BAD_PORT" },
521 { OFPPMFC_BAD_HW_ADDR
, "BAD_HW_ADDR" },
525 #define OFPQOFC_BAD_PORT 0x0000
526 #define OFPQOFC_BAD_QUEUE 0x0001
527 #define OFPQOFC_EPERM 0x0002
528 static const struct tok ofpqofc_str
[] = {
529 { OFPQOFC_BAD_PORT
, "BAD_PORT" },
530 { OFPQOFC_BAD_QUEUE
, "BAD_QUEUE" },
531 { OFPQOFC_EPERM
, "EPERM" },
535 static const struct tok empty_str
[] = {
539 /* lengths (fixed or minimal) of particular protocol structures */
540 #define OF_SWITCH_CONFIG_LEN 12
541 #define OF_PHY_PORT_LEN 48
542 #define OF_SWITCH_FEATURES_LEN 32
543 #define OF_PORT_STATUS_LEN 64
544 #define OF_PORT_MOD_LEN 32
545 #define OF_PACKET_IN_LEN 20
546 #define OF_ACTION_OUTPUT_LEN 8
547 #define OF_ACTION_VLAN_VID_LEN 8
548 #define OF_ACTION_VLAN_PCP_LEN 8
549 #define OF_ACTION_DL_ADDR_LEN 16
550 #define OF_ACTION_NW_ADDR_LEN 8
551 #define OF_ACTION_TP_PORT_LEN 8
552 #define OF_ACTION_NW_TOS_LEN 8
553 #define OF_ACTION_VENDOR_HEADER_LEN 8
554 #define OF_ACTION_HEADER_LEN 8
555 #define OF_PACKET_OUT_LEN 16
556 #define OF_MATCH_LEN 40
557 #define OF_FLOW_MOD_LEN 72
558 #define OF_FLOW_REMOVED_LEN 88
559 #define OF_ERROR_MSG_LEN 12
560 #define OF_STATS_REQUEST_LEN 12
561 #define OF_STATS_REPLY_LEN 12
562 #define OF_DESC_STATS_LEN 1056
563 #define OF_FLOW_STATS_REQUEST_LEN 44
564 #define OF_FLOW_STATS_LEN 88
565 #define OF_AGGREGATE_STATS_REQUEST_LEN 44
566 #define OF_AGGREGATE_STATS_REPLY_LEN 24
567 #define OF_TABLE_STATS_LEN 64
568 #define OF_PORT_STATS_REQUEST_LEN 8
569 #define OF_PORT_STATS_LEN 104
570 #define OF_VENDOR_HEADER_LEN 12
571 #define OF_QUEUE_PROP_HEADER_LEN 8
572 #define OF_QUEUE_PROP_MIN_RATE_LEN 16
573 #define OF_PACKET_QUEUE_LEN 8
574 #define OF_QUEUE_GET_CONFIG_REQUEST_LEN 12
575 #define OF_QUEUE_GET_CONFIG_REPLY_LEN 16
576 #define OF_ACTION_ENQUEUE_LEN 16
577 #define OF_QUEUE_STATS_REQUEST_LEN 8
578 #define OF_QUEUE_STATS_LEN 32
580 /* miscellaneous constants from [OF10] */
581 #define OFP_MAX_TABLE_NAME_LEN 32
582 #define OFP_MAX_PORT_NAME_LEN 16
583 #define DESC_STR_LEN 256
584 #define SERIAL_NUM_LEN 32
585 #define OFP_VLAN_NONE 0xffff
587 /* vendor extensions */
588 #define BSN_SET_IP_MASK 0
589 #define BSN_GET_IP_MASK_REQUEST 1
590 #define BSN_GET_IP_MASK_REPLY 2
591 #define BSN_SET_MIRRORING 3
592 #define BSN_GET_MIRRORING_REQUEST 4
593 #define BSN_GET_MIRRORING_REPLY 5
594 #define BSN_SHELL_COMMAND 6
595 #define BSN_SHELL_OUTPUT 7
596 #define BSN_SHELL_STATUS 8
597 #define BSN_GET_INTERFACES_REQUEST 9
598 #define BSN_GET_INTERFACES_REPLY 10
599 #define BSN_SET_PKTIN_SUPPRESSION_REQUEST 11
600 #define BSN_SET_L2_TABLE_REQUEST 12
601 #define BSN_GET_L2_TABLE_REQUEST 13
602 #define BSN_GET_L2_TABLE_REPLY 14
603 #define BSN_VIRTUAL_PORT_CREATE_REQUEST 15
604 #define BSN_VIRTUAL_PORT_CREATE_REPLY 16
605 #define BSN_VIRTUAL_PORT_REMOVE_REQUEST 17
606 #define BSN_BW_ENABLE_SET_REQUEST 18
607 #define BSN_BW_ENABLE_GET_REQUEST 19
608 #define BSN_BW_ENABLE_GET_REPLY 20
609 #define BSN_BW_CLEAR_DATA_REQUEST 21
610 #define BSN_BW_CLEAR_DATA_REPLY 22
611 #define BSN_BW_ENABLE_SET_REPLY 23
612 #define BSN_SET_L2_TABLE_REPLY 24
613 #define BSN_SET_PKTIN_SUPPRESSION_REPLY 25
614 #define BSN_VIRTUAL_PORT_REMOVE_REPLY 26
615 #define BSN_HYBRID_GET_REQUEST 27
616 #define BSN_HYBRID_GET_REPLY 28
619 #define BSN_PDU_TX_REQUEST 31
620 #define BSN_PDU_TX_REPLY 32
621 #define BSN_PDU_RX_REQUEST 33
622 #define BSN_PDU_RX_REPLY 34
623 #define BSN_PDU_RX_TIMEOUT 35
625 static const struct tok bsn_subtype_str
[] = {
626 { BSN_SET_IP_MASK
, "SET_IP_MASK" },
627 { BSN_GET_IP_MASK_REQUEST
, "GET_IP_MASK_REQUEST" },
628 { BSN_GET_IP_MASK_REPLY
, "GET_IP_MASK_REPLY" },
629 { BSN_SET_MIRRORING
, "SET_MIRRORING" },
630 { BSN_GET_MIRRORING_REQUEST
, "GET_MIRRORING_REQUEST" },
631 { BSN_GET_MIRRORING_REPLY
, "GET_MIRRORING_REPLY" },
632 { BSN_GET_INTERFACES_REQUEST
, "GET_INTERFACES_REQUEST" },
633 { BSN_GET_INTERFACES_REPLY
, "GET_INTERFACES_REPLY" },
634 { BSN_SET_PKTIN_SUPPRESSION_REQUEST
, "SET_PKTIN_SUPPRESSION_REQUEST" },
635 { BSN_SET_L2_TABLE_REQUEST
, "SET_L2_TABLE_REQUEST" },
636 { BSN_GET_L2_TABLE_REQUEST
, "GET_L2_TABLE_REQUEST" },
637 { BSN_GET_L2_TABLE_REPLY
, "GET_L2_TABLE_REPLY" },
638 { BSN_VIRTUAL_PORT_CREATE_REQUEST
, "VIRTUAL_PORT_CREATE_REQUEST" },
639 { BSN_VIRTUAL_PORT_CREATE_REPLY
, "VIRTUAL_PORT_CREATE_REPLY" },
640 { BSN_VIRTUAL_PORT_REMOVE_REQUEST
, "VIRTUAL_PORT_REMOVE_REQUEST" },
641 { BSN_BW_ENABLE_SET_REQUEST
, "BW_ENABLE_SET_REQUEST" },
642 { BSN_BW_ENABLE_GET_REQUEST
, "BW_ENABLE_GET_REQUEST" },
643 { BSN_BW_ENABLE_GET_REPLY
, "BW_ENABLE_GET_REPLY" },
644 { BSN_BW_CLEAR_DATA_REQUEST
, "BW_CLEAR_DATA_REQUEST" },
645 { BSN_BW_CLEAR_DATA_REPLY
, "BW_CLEAR_DATA_REPLY" },
646 { BSN_BW_ENABLE_SET_REPLY
, "BW_ENABLE_SET_REPLY" },
647 { BSN_SET_L2_TABLE_REPLY
, "SET_L2_TABLE_REPLY" },
648 { BSN_SET_PKTIN_SUPPRESSION_REPLY
, "SET_PKTIN_SUPPRESSION_REPLY" },
649 { BSN_VIRTUAL_PORT_REMOVE_REPLY
, "VIRTUAL_PORT_REMOVE_REPLY" },
650 { BSN_HYBRID_GET_REQUEST
, "HYBRID_GET_REQUEST" },
651 { BSN_HYBRID_GET_REPLY
, "HYBRID_GET_REPLY" },
652 { BSN_PDU_TX_REQUEST
, "PDU_TX_REQUEST" },
653 { BSN_PDU_TX_REPLY
, "PDU_TX_REPLY" },
654 { BSN_PDU_RX_REQUEST
, "PDU_RX_REQUEST" },
655 { BSN_PDU_RX_REPLY
, "PDU_RX_REPLY" },
656 { BSN_PDU_RX_TIMEOUT
, "PDU_RX_TIMEOUT" },
662 vlan_str(const uint16_t vid
) {
663 static char buf
[sizeof("65535 (bogus)")];
666 if (vid
== OFP_VLAN_NONE
)
668 fmt
= (vid
> 0 && vid
< 0x0fff) ? "%u" : "%u (bogus)";
669 snprintf(buf
, sizeof(buf
), fmt
, vid
);
674 pcp_str(const uint8_t pcp
) {
675 static char buf
[sizeof("255 (bogus)")];
676 snprintf(buf
, sizeof(buf
), pcp
<= 7 ? "%u" : "%u (bogus)", pcp
);
681 of10_bitmap_print(netdissect_options
*ndo
,
682 const struct tok
*t
, const uint32_t v
, const uint32_t u
) {
683 const char *sep
= " (";
688 for (; t
->s
!= NULL
; t
++)
690 ND_PRINT((ndo
, "%s%s", sep
, t
->s
));
693 /* unassigned bits? */
694 ND_PRINT((ndo
, v
& u
? ") (bogus)" : ")"));
697 static const u_char
*
698 of10_data_print(netdissect_options
*ndo
,
699 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
703 ND_PRINT((ndo
, "\n\t data (%u octets)", len
));
704 ND_TCHECK2(*cp
, len
);
705 if (ndo
->ndo_vflag
>= 2)
706 hex_and_ascii_print(ndo
, "\n\t ", cp
, len
);
710 ND_PRINT((ndo
, "%s", tstr
));
714 static const u_char
*
715 of10_bsn_message_print(netdissect_options
*ndo
,
716 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
717 const u_char
*cp0
= cp
;
724 subtype
= EXTRACT_32BITS(cp
);
726 ND_PRINT((ndo
, "\n\t subtype %s", tok2str(bsn_subtype_str
, "unknown (0x%08x)", subtype
)));
728 case BSN_GET_IP_MASK_REQUEST
:
731 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
732 * +---------------+---------------+---------------+---------------+
734 * +---------------+---------------+---------------+---------------+
736 * +---------------+---------------+---------------+---------------+
738 * +---------------+---------------+---------------+---------------+
745 ND_PRINT((ndo
, ", index %u", *cp
));
751 case BSN_SET_IP_MASK
:
752 case BSN_GET_IP_MASK_REPLY
:
755 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
756 * +---------------+---------------+---------------+---------------+
758 * +---------------+---------------+---------------+---------------+
760 * +---------------+---------------+---------------+---------------+
762 * +---------------+---------------+---------------+---------------+
769 ND_PRINT((ndo
, ", index %u", *cp
));
776 ND_PRINT((ndo
, ", mask %s", ipaddr_string(ndo
, cp
)));
779 case BSN_SET_MIRRORING
:
780 case BSN_GET_MIRRORING_REQUEST
:
781 case BSN_GET_MIRRORING_REPLY
:
784 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
785 * +---------------+---------------+---------------+---------------+
787 * +---------------+---------------+---------------+---------------+
789 * +---------------+---------------+---------------+---------------+
796 ND_PRINT((ndo
, ", ports %u", *cp
));
802 case BSN_GET_INTERFACES_REQUEST
:
803 case BSN_GET_L2_TABLE_REQUEST
:
804 case BSN_BW_ENABLE_GET_REQUEST
:
805 case BSN_BW_CLEAR_DATA_REQUEST
:
806 case BSN_HYBRID_GET_REQUEST
:
809 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
810 * +---------------+---------------+---------------+---------------+
812 * +---------------+---------------+---------------+---------------+
818 case BSN_VIRTUAL_PORT_REMOVE_REQUEST
:
821 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
822 * +---------------+---------------+---------------+---------------+
824 * +---------------+---------------+---------------+---------------+
826 * +---------------+---------------+---------------+---------------+
833 ND_PRINT((ndo
, ", vport_no %u", EXTRACT_32BITS(cp
)));
837 ND_TCHECK2(*cp
, len
- 4);
842 corrupt
: /* skip the undersized data */
843 ND_PRINT((ndo
, "%s", cstr
));
844 ND_TCHECK2(*cp0
, len
);
847 ND_PRINT((ndo
, "%s", tstr
));
851 static const u_char
*
852 of10_vendor_message_print(netdissect_options
*ndo
,
853 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
855 const u_char
*(*decoder
)(netdissect_options
*, const u_char
*, const u_char
*, u_int
);
861 vendor
= EXTRACT_32BITS(cp
);
863 ND_PRINT((ndo
, ", vendor 0x%08x (%s)", vendor
, of_vendor_name(vendor
)));
866 vendor
== OUI_BSN
? of10_bsn_message_print
:
868 return decoder(ndo
, cp
, ep
, len
- 4);
870 corrupt
: /* skip the undersized data */
871 ND_PRINT((ndo
, "%s", cstr
));
872 ND_TCHECK2(*cp
, len
);
875 ND_PRINT((ndo
, "%s", tstr
));
879 /* Vendor ID is mandatory, data is optional. */
880 static const u_char
*
881 of10_vendor_data_print(netdissect_options
*ndo
,
882 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
889 vendor
= EXTRACT_32BITS(cp
);
891 ND_PRINT((ndo
, ", vendor 0x%08x (%s)", vendor
, of_vendor_name(vendor
)));
893 return of10_data_print(ndo
, cp
, ep
, len
- 4);
895 corrupt
: /* skip the undersized data */
896 ND_PRINT((ndo
, "%s", cstr
));
897 ND_TCHECK2(*cp
, len
);
900 ND_PRINT((ndo
, "%s", tstr
));
904 static const u_char
*
905 of10_packet_data_print(netdissect_options
*ndo
,
906 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
910 ND_PRINT((ndo
, "\n\t data (%u octets)", len
));
911 if (ndo
->ndo_vflag
< 3)
913 ND_TCHECK2(*cp
, len
);
915 ND_PRINT((ndo
, ", frame decoding below\n"));
916 ether_print(ndo
, cp
, len
, ndo
->ndo_snapend
- cp
, NULL
, NULL
);
921 ND_PRINT((ndo
, "%s", tstr
));
925 /* [OF10] Section 5.2.1 */
926 static const u_char
*
927 of10_phy_ports_print(netdissect_options
*ndo
,
928 const u_char
*cp
, const u_char
*ep
, u_int len
) {
929 const u_char
*cp0
= cp
;
930 const u_int len0
= len
;
933 if (len
< OF_PHY_PORT_LEN
)
937 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
940 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
941 ND_PRINT((ndo
, ", hw_addr %s", etheraddr_string(ndo
, cp
)));
942 cp
+= ETHER_ADDR_LEN
;
944 ND_TCHECK2(*cp
, OFP_MAX_PORT_NAME_LEN
);
945 ND_PRINT((ndo
, ", name '"));
946 fn_print(ndo
, cp
, cp
+ OFP_MAX_PORT_NAME_LEN
);
947 ND_PRINT((ndo
, "'"));
948 cp
+= OFP_MAX_PORT_NAME_LEN
;
950 if (ndo
->ndo_vflag
< 2) {
957 ND_PRINT((ndo
, "\n\t config 0x%08x", EXTRACT_32BITS(cp
)));
958 of10_bitmap_print(ndo
, ofppc_bm
, EXTRACT_32BITS(cp
), OFPPC_U
);
962 ND_PRINT((ndo
, "\n\t state 0x%08x", EXTRACT_32BITS(cp
)));
963 of10_bitmap_print(ndo
, ofpps_bm
, EXTRACT_32BITS(cp
), OFPPS_U
);
967 ND_PRINT((ndo
, "\n\t curr 0x%08x", EXTRACT_32BITS(cp
)));
968 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
972 ND_PRINT((ndo
, "\n\t advertised 0x%08x", EXTRACT_32BITS(cp
)));
973 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
977 ND_PRINT((ndo
, "\n\t supported 0x%08x", EXTRACT_32BITS(cp
)));
978 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
982 ND_PRINT((ndo
, "\n\t peer 0x%08x", EXTRACT_32BITS(cp
)));
983 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
986 len
-= OF_PHY_PORT_LEN
;
990 corrupt
: /* skip the undersized trailing data */
991 ND_PRINT((ndo
, "%s", cstr
));
992 ND_TCHECK2(*cp0
, len0
);
995 ND_PRINT((ndo
, "%s", tstr
));
999 /* [OF10] Section 5.2.2 */
1000 static const u_char
*
1001 of10_queue_props_print(netdissect_options
*ndo
,
1002 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1003 const u_char
*cp0
= cp
;
1004 const u_int len0
= len
;
1005 uint16_t property
, plen
, rate
;
1008 u_char plen_bogus
= 0, skip
= 0;
1010 if (len
< OF_QUEUE_PROP_HEADER_LEN
)
1014 property
= EXTRACT_16BITS(cp
);
1016 ND_PRINT((ndo
, "\n\t property %s", tok2str(ofpqt_str
, "invalid (0x%04x)", property
)));
1019 plen
= EXTRACT_16BITS(cp
);
1021 ND_PRINT((ndo
, ", len %u", plen
));
1022 if (plen
< OF_QUEUE_PROP_HEADER_LEN
|| plen
> len
)
1027 /* property-specific constraints and decoding */
1030 plen_bogus
= plen
!= OF_QUEUE_PROP_HEADER_LEN
;
1032 case OFPQT_MIN_RATE
:
1033 plen_bogus
= plen
!= OF_QUEUE_PROP_MIN_RATE_LEN
;
1039 ND_PRINT((ndo
, " (bogus)"));
1043 ND_TCHECK2(*cp
, plen
- 4);
1047 if (property
== OFPQT_MIN_RATE
) { /* the only case of property decoding */
1050 rate
= EXTRACT_16BITS(cp
);
1053 ND_PRINT((ndo
, ", rate disabled"));
1055 ND_PRINT((ndo
, ", rate %u.%u%%", rate
/ 10, rate
% 10));
1065 corrupt
: /* skip the rest of queue properties */
1066 ND_PRINT((ndo
, "%s", cstr
));
1067 ND_TCHECK2(*cp0
, len0
);
1070 ND_PRINT((ndo
, "%s", tstr
));
1075 static const u_char
*
1076 of10_queues_print(netdissect_options
*ndo
,
1077 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1078 const u_char
*cp0
= cp
;
1079 const u_int len0
= len
;
1083 if (len
< OF_PACKET_QUEUE_LEN
)
1087 ND_PRINT((ndo
, "\n\t queue_id %u", EXTRACT_32BITS(cp
)));
1091 desclen
= EXTRACT_16BITS(cp
);
1093 ND_PRINT((ndo
, ", len %u", desclen
));
1094 if (desclen
< OF_PACKET_QUEUE_LEN
|| desclen
> len
)
1100 if (ndo
->ndo_vflag
< 2) {
1101 ND_TCHECK2(*cp
, desclen
- OF_PACKET_QUEUE_LEN
);
1102 cp
+= desclen
- OF_PACKET_QUEUE_LEN
;
1105 if (ep
== (cp
= of10_queue_props_print(ndo
, cp
, ep
, desclen
- OF_PACKET_QUEUE_LEN
)))
1106 return ep
; /* end of snapshot */
1112 corrupt
: /* skip the rest of queues */
1113 ND_PRINT((ndo
, "%s", cstr
));
1114 ND_TCHECK2(*cp0
, len0
);
1117 ND_PRINT((ndo
, "%s", tstr
));
1121 /* [OF10] Section 5.2.3 */
1122 static const u_char
*
1123 of10_match_print(netdissect_options
*ndo
,
1124 const char *pfx
, const u_char
*cp
, const u_char
*ep
) {
1129 const char *field_name
;
1133 wildcards
= EXTRACT_32BITS(cp
);
1134 if (wildcards
& OFPFW_U
)
1135 ND_PRINT((ndo
, "%swildcards 0x%08x (bogus)", pfx
, wildcards
));
1139 if (! (wildcards
& OFPFW_IN_PORT
))
1140 ND_PRINT((ndo
, "%smatch in_port %s", pfx
, tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1143 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
1144 if (! (wildcards
& OFPFW_DL_SRC
))
1145 ND_PRINT((ndo
, "%smatch dl_src %s", pfx
, etheraddr_string(ndo
, cp
)));
1146 cp
+= ETHER_ADDR_LEN
;
1148 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
1149 if (! (wildcards
& OFPFW_DL_DST
))
1150 ND_PRINT((ndo
, "%smatch dl_dst %s", pfx
, etheraddr_string(ndo
, cp
)));
1151 cp
+= ETHER_ADDR_LEN
;
1154 if (! (wildcards
& OFPFW_DL_VLAN
))
1155 ND_PRINT((ndo
, "%smatch dl_vlan %s", pfx
, vlan_str(EXTRACT_16BITS(cp
))));
1159 if (! (wildcards
& OFPFW_DL_VLAN_PCP
))
1160 ND_PRINT((ndo
, "%smatch dl_vlan_pcp %s", pfx
, pcp_str(*cp
)));
1167 dl_type
= EXTRACT_16BITS(cp
);
1169 if (! (wildcards
& OFPFW_DL_TYPE
))
1170 ND_PRINT((ndo
, "%smatch dl_type 0x%04x", pfx
, dl_type
));
1173 if (! (wildcards
& OFPFW_NW_TOS
))
1174 ND_PRINT((ndo
, "%smatch nw_tos 0x%02x", pfx
, *cp
));
1180 if (! (wildcards
& OFPFW_NW_PROTO
)) {
1181 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_ARP
1182 ? "arp_opcode" : "nw_proto";
1183 ND_PRINT((ndo
, "%smatch %s %u", pfx
, field_name
, nw_proto
));
1190 nw_bits
= (wildcards
& OFPFW_NW_SRC_MASK
) >> OFPFW_NW_SRC_SHIFT
;
1192 ND_PRINT((ndo
, "%smatch nw_src %s/%u", pfx
, ipaddr_string(ndo
, cp
), 32 - nw_bits
));
1196 nw_bits
= (wildcards
& OFPFW_NW_DST_MASK
) >> OFPFW_NW_DST_SHIFT
;
1198 ND_PRINT((ndo
, "%smatch nw_dst %s/%u", pfx
, ipaddr_string(ndo
, cp
), 32 - nw_bits
));
1202 if (! (wildcards
& OFPFW_TP_SRC
)) {
1203 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_IP
1204 && ! (wildcards
& OFPFW_NW_PROTO
) && nw_proto
== IPPROTO_ICMP
1205 ? "icmp_type" : "tp_src";
1206 ND_PRINT((ndo
, "%smatch %s %u", pfx
, field_name
, EXTRACT_16BITS(cp
)));
1211 if (! (wildcards
& OFPFW_TP_DST
)) {
1212 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_IP
1213 && ! (wildcards
& OFPFW_NW_PROTO
) && nw_proto
== IPPROTO_ICMP
1214 ? "icmp_code" : "tp_dst";
1215 ND_PRINT((ndo
, "%smatch %s %u", pfx
, field_name
, EXTRACT_16BITS(cp
)));
1220 ND_PRINT((ndo
, "%s", tstr
));
1224 /* [OF10] Section 5.2.4 */
1225 static const u_char
*
1226 of10_actions_print(netdissect_options
*ndo
,
1227 const char *pfx
, const u_char
*cp
, const u_char
*ep
,
1229 const u_char
*cp0
= cp
;
1230 const u_int len0
= len
;
1231 uint16_t type
, alen
, output_port
;
1234 u_char alen_bogus
= 0, skip
= 0;
1236 if (len
< OF_ACTION_HEADER_LEN
)
1240 type
= EXTRACT_16BITS(cp
);
1242 ND_PRINT((ndo
, "%saction type %s", pfx
, tok2str(ofpat_str
, "invalid (0x%04x)", type
)));
1245 alen
= EXTRACT_16BITS(cp
);
1247 ND_PRINT((ndo
, ", len %u", alen
));
1248 /* On action size underrun/overrun skip the rest of the action list. */
1249 if (alen
< OF_ACTION_HEADER_LEN
|| alen
> len
)
1251 /* On action size inappropriate for the given type or invalid type just skip
1252 * the current action, as the basic length constraint has been met. */
1255 case OFPAT_SET_VLAN_VID
:
1256 case OFPAT_SET_VLAN_PCP
:
1257 case OFPAT_STRIP_VLAN
:
1258 case OFPAT_SET_NW_SRC
:
1259 case OFPAT_SET_NW_DST
:
1260 case OFPAT_SET_NW_TOS
:
1261 case OFPAT_SET_TP_SRC
:
1262 case OFPAT_SET_TP_DST
:
1263 alen_bogus
= alen
!= 8;
1265 case OFPAT_SET_DL_SRC
:
1266 case OFPAT_SET_DL_DST
:
1268 alen_bogus
= alen
!= 16;
1271 alen_bogus
= alen
% 8 != 0; /* already >= 8 so far */
1277 ND_PRINT((ndo
, " (bogus)"));
1281 ND_TCHECK2(*cp
, alen
- 4);
1285 /* OK to decode the rest of the action structure */
1290 output_port
= EXTRACT_16BITS(cp
);
1292 ND_PRINT((ndo
, ", port %s", tok2str(ofpp_str
, "%u", output_port
)));
1295 if (output_port
== OFPP_CONTROLLER
)
1296 ND_PRINT((ndo
, ", max_len %u", EXTRACT_16BITS(cp
)));
1299 case OFPAT_SET_VLAN_VID
:
1302 ND_PRINT((ndo
, ", vlan_vid %s", vlan_str(EXTRACT_16BITS(cp
))));
1308 case OFPAT_SET_VLAN_PCP
:
1311 ND_PRINT((ndo
, ", vlan_pcp %s", pcp_str(*cp
)));
1317 case OFPAT_SET_DL_SRC
:
1318 case OFPAT_SET_DL_DST
:
1320 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
1321 ND_PRINT((ndo
, ", dl_addr %s", etheraddr_string(ndo
, cp
)));
1322 cp
+= ETHER_ADDR_LEN
;
1327 case OFPAT_SET_NW_SRC
:
1328 case OFPAT_SET_NW_DST
:
1331 ND_PRINT((ndo
, ", nw_addr %s", ipaddr_string(ndo
, cp
)));
1334 case OFPAT_SET_NW_TOS
:
1337 ND_PRINT((ndo
, ", nw_tos 0x%02x", *cp
));
1343 case OFPAT_SET_TP_SRC
:
1344 case OFPAT_SET_TP_DST
:
1347 ND_PRINT((ndo
, ", tp_port %u", EXTRACT_16BITS(cp
)));
1356 ND_PRINT((ndo
, ", port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1363 ND_PRINT((ndo
, ", queue_id %s", tok2str(ofpq_str
, "%u", EXTRACT_32BITS(cp
))));
1367 if (ep
== (cp
= of10_vendor_data_print(ndo
, cp
, ep
, alen
- 4)))
1368 return ep
; /* end of snapshot */
1370 case OFPAT_STRIP_VLAN
:
1381 corrupt
: /* skip the rest of actions */
1382 ND_PRINT((ndo
, "%s", cstr
));
1383 ND_TCHECK2(*cp0
, len0
);
1386 ND_PRINT((ndo
, "%s", tstr
));
1390 /* [OF10] Section 5.3.1 */
1391 static const u_char
*
1392 of10_features_reply_print(netdissect_options
*ndo
,
1393 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1396 ND_PRINT((ndo
, "\n\t dpid 0x%016" PRIx64
, EXTRACT_64BITS(cp
)));
1400 ND_PRINT((ndo
, ", n_buffers %u", EXTRACT_32BITS(cp
)));
1404 ND_PRINT((ndo
, ", n_tables %u", *cp
));
1411 ND_PRINT((ndo
, "\n\t capabilities 0x%08x", EXTRACT_32BITS(cp
)));
1412 of10_bitmap_print(ndo
, ofp_capabilities_bm
, EXTRACT_32BITS(cp
), OFPCAP_U
);
1416 ND_PRINT((ndo
, "\n\t actions 0x%08x", EXTRACT_32BITS(cp
)));
1417 of10_bitmap_print(ndo
, ofpat_bm
, EXTRACT_32BITS(cp
), OFPAT_U
);
1420 return of10_phy_ports_print(ndo
, cp
, ep
, len
- OF_SWITCH_FEATURES_LEN
);
1423 ND_PRINT((ndo
, "%s", tstr
));
1427 /* [OF10] Section 5.3.3 */
1428 static const u_char
*
1429 of10_flow_mod_print(netdissect_options
*ndo
,
1430 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1434 if (ep
== (cp
= of10_match_print(ndo
, "\n\t ", cp
, ep
)))
1435 return ep
; /* end of snapshot */
1438 ND_PRINT((ndo
, "\n\t cookie 0x%016" PRIx64
, EXTRACT_64BITS(cp
)));
1442 command
= EXTRACT_16BITS(cp
);
1443 ND_PRINT((ndo
, ", command %s", tok2str(ofpfc_str
, "invalid (0x%04x)", command
)));
1447 if (EXTRACT_16BITS(cp
))
1448 ND_PRINT((ndo
, ", idle_timeout %u", EXTRACT_16BITS(cp
)));
1452 if (EXTRACT_16BITS(cp
))
1453 ND_PRINT((ndo
, ", hard_timeout %u", EXTRACT_16BITS(cp
)));
1457 if (EXTRACT_16BITS(cp
))
1458 ND_PRINT((ndo
, ", priority %u", EXTRACT_16BITS(cp
)));
1462 if (command
== OFPFC_ADD
|| command
== OFPFC_MODIFY
||
1463 command
== OFPFC_MODIFY_STRICT
)
1464 ND_PRINT((ndo
, ", buffer_id %s", tok2str(bufferid_str
, "0x%08x", EXTRACT_32BITS(cp
))));
1468 if (command
== OFPFC_DELETE
|| command
== OFPFC_DELETE_STRICT
)
1469 ND_PRINT((ndo
, ", out_port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1473 ND_PRINT((ndo
, ", flags 0x%04x", EXTRACT_16BITS(cp
)));
1474 of10_bitmap_print(ndo
, ofpff_bm
, EXTRACT_16BITS(cp
), OFPFF_U
);
1477 return of10_actions_print(ndo
, "\n\t ", cp
, ep
, len
- OF_FLOW_MOD_LEN
);
1480 ND_PRINT((ndo
, "%s", tstr
));
1485 static const u_char
*
1486 of10_port_mod_print(netdissect_options
*ndo
,
1487 const u_char
*cp
, const u_char
*ep
) {
1490 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1493 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
1494 ND_PRINT((ndo
, ", hw_addr %s", etheraddr_string(ndo
, cp
)));
1495 cp
+= ETHER_ADDR_LEN
;
1498 ND_PRINT((ndo
, "\n\t config 0x%08x", EXTRACT_32BITS(cp
)));
1499 of10_bitmap_print(ndo
, ofppc_bm
, EXTRACT_32BITS(cp
), OFPPC_U
);
1503 ND_PRINT((ndo
, "\n\t mask 0x%08x", EXTRACT_32BITS(cp
)));
1504 of10_bitmap_print(ndo
, ofppc_bm
, EXTRACT_32BITS(cp
), OFPPC_U
);
1508 ND_PRINT((ndo
, "\n\t advertise 0x%08x", EXTRACT_32BITS(cp
)));
1509 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
1516 ND_PRINT((ndo
, "%s", tstr
));
1520 /* [OF10] Section 5.3.5 */
1521 static const u_char
*
1522 of10_stats_request_print(netdissect_options
*ndo
,
1523 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1524 const u_char
*cp0
= cp
;
1525 const u_int len0
= len
;
1530 type
= EXTRACT_16BITS(cp
);
1532 ND_PRINT((ndo
, "\n\t type %s", tok2str(ofpst_str
, "invalid (0x%04x)", type
)));
1535 ND_PRINT((ndo
, ", flags 0x%04x", EXTRACT_16BITS(cp
)));
1536 if (EXTRACT_16BITS(cp
))
1537 ND_PRINT((ndo
, " (bogus)"));
1539 /* type-specific body of one of fixed lengths */
1540 len
-= OF_STATS_REQUEST_LEN
;
1548 case OFPST_AGGREGATE
:
1549 if (len
!= OF_FLOW_STATS_REQUEST_LEN
)
1552 if (ep
== (cp
= of10_match_print(ndo
, "\n\t ", cp
, ep
)))
1553 return ep
; /* end of snapshot */
1556 ND_PRINT((ndo
, "\n\t table_id %s", tok2str(tableid_str
, "%u", *cp
)));
1563 ND_PRINT((ndo
, ", out_port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1566 if (len
!= OF_PORT_STATS_REQUEST_LEN
)
1570 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1576 if (len
!= OF_QUEUE_STATS_REQUEST_LEN
)
1580 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1587 ND_PRINT((ndo
, ", queue_id %s", tok2str(ofpq_str
, "%u", EXTRACT_32BITS(cp
))));
1590 return of10_vendor_data_print(ndo
, cp
, ep
, len
);
1594 corrupt
: /* skip the message body */
1595 ND_PRINT((ndo
, "%s", cstr
));
1596 ND_TCHECK2(*cp0
, len0
);
1599 ND_PRINT((ndo
, "%s", tstr
));
1604 static const u_char
*
1605 of10_desc_stats_reply_print(netdissect_options
*ndo
,
1606 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1607 if (len
!= OF_DESC_STATS_LEN
)
1610 ND_TCHECK2(*cp
, DESC_STR_LEN
);
1611 ND_PRINT((ndo
, "\n\t mfr_desc '"));
1612 fn_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1613 ND_PRINT((ndo
, "'"));
1616 ND_TCHECK2(*cp
, DESC_STR_LEN
);
1617 ND_PRINT((ndo
, "\n\t hw_desc '"));
1618 fn_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1619 ND_PRINT((ndo
, "'"));
1622 ND_TCHECK2(*cp
, DESC_STR_LEN
);
1623 ND_PRINT((ndo
, "\n\t sw_desc '"));
1624 fn_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1625 ND_PRINT((ndo
, "'"));
1628 ND_TCHECK2(*cp
, SERIAL_NUM_LEN
);
1629 ND_PRINT((ndo
, "\n\t serial_num '"));
1630 fn_print(ndo
, cp
, cp
+ SERIAL_NUM_LEN
);
1631 ND_PRINT((ndo
, "'"));
1632 cp
+= SERIAL_NUM_LEN
;
1634 ND_TCHECK2(*cp
, DESC_STR_LEN
);
1635 ND_PRINT((ndo
, "\n\t dp_desc '"));
1636 fn_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1637 ND_PRINT((ndo
, "'"));
1638 return cp
+ DESC_STR_LEN
;
1640 corrupt
: /* skip the message body */
1641 ND_PRINT((ndo
, "%s", cstr
));
1642 ND_TCHECK2(*cp
, len
);
1645 ND_PRINT((ndo
, "%s", tstr
));
1650 static const u_char
*
1651 of10_flow_stats_reply_print(netdissect_options
*ndo
,
1652 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1653 const u_char
*cp0
= cp
;
1654 const u_int len0
= len
;
1658 if (len
< OF_FLOW_STATS_LEN
)
1662 entry_len
= EXTRACT_16BITS(cp
);
1663 ND_PRINT((ndo
, "\n\t length %u", entry_len
));
1664 if (entry_len
< OF_FLOW_STATS_LEN
|| entry_len
> len
)
1669 ND_PRINT((ndo
, ", table_id %s", tok2str(tableid_str
, "%u", *cp
)));
1675 if (ep
== (cp
= of10_match_print(ndo
, "\n\t ", cp
, ep
)))
1676 return ep
; /* end of snapshot */
1679 ND_PRINT((ndo
, "\n\t duration_sec %u", EXTRACT_32BITS(cp
)));
1683 ND_PRINT((ndo
, ", duration_nsec %u", EXTRACT_32BITS(cp
)));
1687 ND_PRINT((ndo
, ", priority %u", EXTRACT_16BITS(cp
)));
1691 ND_PRINT((ndo
, ", idle_timeout %u", EXTRACT_16BITS(cp
)));
1695 ND_PRINT((ndo
, ", hard_timeout %u", EXTRACT_16BITS(cp
)));
1702 ND_PRINT((ndo
, ", cookie 0x%016" PRIx64
, EXTRACT_64BITS(cp
)));
1706 ND_PRINT((ndo
, ", packet_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1710 ND_PRINT((ndo
, ", byte_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1713 if (ep
== (cp
= of10_actions_print(ndo
, "\n\t ", cp
, ep
, entry_len
- OF_FLOW_STATS_LEN
)))
1714 return ep
; /* end of snapshot */
1720 corrupt
: /* skip the rest of flow statistics entries */
1721 ND_PRINT((ndo
, "%s", cstr
));
1722 ND_TCHECK2(*cp0
, len0
);
1725 ND_PRINT((ndo
, "%s", tstr
));
1730 static const u_char
*
1731 of10_aggregate_stats_reply_print(netdissect_options
*ndo
,
1732 const u_char
*cp
, const u_char
*ep
,
1734 if (len
!= OF_AGGREGATE_STATS_REPLY_LEN
)
1738 ND_PRINT((ndo
, "\n\t packet_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1742 ND_PRINT((ndo
, ", byte_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1746 ND_PRINT((ndo
, ", flow_count %u", EXTRACT_32BITS(cp
)));
1752 corrupt
: /* skip the message body */
1753 ND_PRINT((ndo
, "%s", cstr
));
1754 ND_TCHECK2(*cp
, len
);
1757 ND_PRINT((ndo
, "%s", tstr
));
1762 static const u_char
*
1763 of10_table_stats_reply_print(netdissect_options
*ndo
,
1764 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1765 const u_char
*cp0
= cp
;
1766 const u_int len0
= len
;
1769 if (len
< OF_TABLE_STATS_LEN
)
1773 ND_PRINT((ndo
, "\n\t table_id %s", tok2str(tableid_str
, "%u", *cp
)));
1779 ND_TCHECK2(*cp
, OFP_MAX_TABLE_NAME_LEN
);
1780 ND_PRINT((ndo
, ", name '"));
1781 fn_print(ndo
, cp
, cp
+ OFP_MAX_TABLE_NAME_LEN
);
1782 ND_PRINT((ndo
, "'"));
1783 cp
+= OFP_MAX_TABLE_NAME_LEN
;
1786 ND_PRINT((ndo
, "\n\t wildcards 0x%08x", EXTRACT_32BITS(cp
)));
1787 of10_bitmap_print(ndo
, ofpfw_bm
, EXTRACT_32BITS(cp
), OFPFW_U
);
1791 ND_PRINT((ndo
, "\n\t max_entries %u", EXTRACT_32BITS(cp
)));
1795 ND_PRINT((ndo
, ", active_count %u", EXTRACT_32BITS(cp
)));
1799 ND_PRINT((ndo
, ", lookup_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1803 ND_PRINT((ndo
, ", matched_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1806 len
-= OF_TABLE_STATS_LEN
;
1810 corrupt
: /* skip the undersized trailing data */
1811 ND_PRINT((ndo
, "%s", cstr
));
1812 ND_TCHECK2(*cp0
, len0
);
1815 ND_PRINT((ndo
, "%s", tstr
));
1820 static const u_char
*
1821 of10_port_stats_reply_print(netdissect_options
*ndo
,
1822 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1823 const u_char
*cp0
= cp
;
1824 const u_int len0
= len
;
1827 if (len
< OF_PORT_STATS_LEN
)
1831 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1833 if (ndo
->ndo_vflag
< 2) {
1834 ND_TCHECK2(*cp
, OF_PORT_STATS_LEN
- 2);
1835 cp
+= OF_PORT_STATS_LEN
- 2;
1843 ND_PRINT((ndo
, ", rx_packets %" PRIu64
, EXTRACT_64BITS(cp
)));
1847 ND_PRINT((ndo
, ", tx_packets %" PRIu64
, EXTRACT_64BITS(cp
)));
1851 ND_PRINT((ndo
, ", rx_bytes %" PRIu64
, EXTRACT_64BITS(cp
)));
1855 ND_PRINT((ndo
, ", tx_bytes %" PRIu64
, EXTRACT_64BITS(cp
)));
1859 ND_PRINT((ndo
, ", rx_dropped %" PRIu64
, EXTRACT_64BITS(cp
)));
1863 ND_PRINT((ndo
, ", tx_dropped %" PRIu64
, EXTRACT_64BITS(cp
)));
1867 ND_PRINT((ndo
, ", rx_errors %" PRIu64
, EXTRACT_64BITS(cp
)));
1871 ND_PRINT((ndo
, ", tx_errors %" PRIu64
, EXTRACT_64BITS(cp
)));
1875 ND_PRINT((ndo
, ", rx_frame_err %" PRIu64
, EXTRACT_64BITS(cp
)));
1879 ND_PRINT((ndo
, ", rx_over_err %" PRIu64
, EXTRACT_64BITS(cp
)));
1883 ND_PRINT((ndo
, ", rx_crc_err %" PRIu64
, EXTRACT_64BITS(cp
)));
1887 ND_PRINT((ndo
, ", collisions %" PRIu64
, EXTRACT_64BITS(cp
)));
1890 len
-= OF_PORT_STATS_LEN
;
1894 corrupt
: /* skip the undersized trailing data */
1895 ND_PRINT((ndo
, "%s", cstr
));
1896 ND_TCHECK2(*cp0
, len0
);
1899 ND_PRINT((ndo
, "%s", tstr
));
1904 static const u_char
*
1905 of10_queue_stats_reply_print(netdissect_options
*ndo
,
1906 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1907 const u_char
*cp0
= cp
;
1908 const u_int len0
= len
;
1911 if (len
< OF_QUEUE_STATS_LEN
)
1915 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1922 ND_PRINT((ndo
, ", queue_id %u", EXTRACT_32BITS(cp
)));
1926 ND_PRINT((ndo
, ", tx_bytes %" PRIu64
, EXTRACT_64BITS(cp
)));
1930 ND_PRINT((ndo
, ", tx_packets %" PRIu64
, EXTRACT_64BITS(cp
)));
1934 ND_PRINT((ndo
, ", tx_errors %" PRIu64
, EXTRACT_64BITS(cp
)));
1937 len
-= OF_QUEUE_STATS_LEN
;
1941 corrupt
: /* skip the undersized trailing data */
1942 ND_PRINT((ndo
, "%s", cstr
));
1943 ND_TCHECK2(*cp0
, len0
);
1946 ND_PRINT((ndo
, "%s", tstr
));
1951 static const u_char
*
1952 of10_stats_reply_print(netdissect_options
*ndo
,
1953 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1954 const u_char
*cp0
= cp
;
1959 type
= EXTRACT_16BITS(cp
);
1960 ND_PRINT((ndo
, "\n\t type %s", tok2str(ofpst_str
, "invalid (0x%04x)", type
)));
1964 ND_PRINT((ndo
, ", flags 0x%04x", EXTRACT_16BITS(cp
)));
1965 of10_bitmap_print(ndo
, ofpsf_reply_bm
, EXTRACT_16BITS(cp
), OFPSF_REPLY_U
);
1968 if (ndo
->ndo_vflag
> 0) {
1969 const u_char
*(*decoder
)(netdissect_options
*, const u_char
*, const u_char
*, u_int
) =
1970 type
== OFPST_DESC
? of10_desc_stats_reply_print
:
1971 type
== OFPST_FLOW
? of10_flow_stats_reply_print
:
1972 type
== OFPST_AGGREGATE
? of10_aggregate_stats_reply_print
:
1973 type
== OFPST_TABLE
? of10_table_stats_reply_print
:
1974 type
== OFPST_PORT
? of10_port_stats_reply_print
:
1975 type
== OFPST_QUEUE
? of10_queue_stats_reply_print
:
1976 type
== OFPST_VENDOR
? of10_vendor_data_print
:
1978 if (decoder
!= NULL
)
1979 return decoder(ndo
, cp
, ep
, len
- OF_STATS_REPLY_LEN
);
1981 ND_TCHECK2(*cp0
, len
);
1985 ND_PRINT((ndo
, "%s", tstr
));
1989 /* [OF10] Section 5.3.6 */
1990 static const u_char
*
1991 of10_packet_out_print(netdissect_options
*ndo
,
1992 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1993 const u_char
*cp0
= cp
;
1994 const u_int len0
= len
;
1995 uint16_t actions_len
;
1999 ND_PRINT((ndo
, "\n\t buffer_id 0x%08x", EXTRACT_32BITS(cp
)));
2003 ND_PRINT((ndo
, ", in_port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
2007 actions_len
= EXTRACT_16BITS(cp
);
2009 if (actions_len
> len
- OF_PACKET_OUT_LEN
)
2012 if (ep
== (cp
= of10_actions_print(ndo
, "\n\t ", cp
, ep
, actions_len
)))
2013 return ep
; /* end of snapshot */
2015 return of10_packet_data_print(ndo
, cp
, ep
, len
- OF_PACKET_OUT_LEN
- actions_len
);
2017 corrupt
: /* skip the rest of the message body */
2018 ND_PRINT((ndo
, "%s", cstr
));
2019 ND_TCHECK2(*cp0
, len0
);
2022 ND_PRINT((ndo
, "%s", tstr
));
2026 /* [OF10] Section 5.4.1 */
2027 static const u_char
*
2028 of10_packet_in_print(netdissect_options
*ndo
,
2029 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
2032 ND_PRINT((ndo
, "\n\t buffer_id %s", tok2str(bufferid_str
, "0x%08x", EXTRACT_32BITS(cp
))));
2036 ND_PRINT((ndo
, ", total_len %u", EXTRACT_16BITS(cp
)));
2040 ND_PRINT((ndo
, ", in_port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
2044 ND_PRINT((ndo
, ", reason %s", tok2str(ofpr_str
, "invalid (0x%02x)", *cp
)));
2050 /* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
2051 return of10_packet_data_print(ndo
, cp
, ep
, len
- (OF_PACKET_IN_LEN
- 2));
2054 ND_PRINT((ndo
, "%s", tstr
));
2058 /* [OF10] Section 5.4.2 */
2059 static const u_char
*
2060 of10_flow_removed_print(netdissect_options
*ndo
,
2061 const u_char
*cp
, const u_char
*ep
) {
2063 if (ep
== (cp
= of10_match_print(ndo
, "\n\t ", cp
, ep
)))
2064 return ep
; /* end of snapshot */
2067 ND_PRINT((ndo
, "\n\t cookie 0x%016" PRIx64
, EXTRACT_64BITS(cp
)));
2071 if (EXTRACT_16BITS(cp
))
2072 ND_PRINT((ndo
, ", priority %u", EXTRACT_16BITS(cp
)));
2076 ND_PRINT((ndo
, ", reason %s", tok2str(ofprr_str
, "unknown (0x%02x)", *cp
)));
2083 ND_PRINT((ndo
, ", duration_sec %u", EXTRACT_32BITS(cp
)));
2087 ND_PRINT((ndo
, ", duration_nsec %u", EXTRACT_32BITS(cp
)));
2091 if (EXTRACT_16BITS(cp
))
2092 ND_PRINT((ndo
, ", idle_timeout %u", EXTRACT_16BITS(cp
)));
2099 ND_PRINT((ndo
, ", packet_count %" PRIu64
, EXTRACT_64BITS(cp
)));
2103 ND_PRINT((ndo
, ", byte_count %" PRIu64
, EXTRACT_64BITS(cp
)));
2107 ND_PRINT((ndo
, "%s", tstr
));
2111 /* [OF10] Section 5.4.4 */
2112 static const u_char
*
2113 of10_error_print(netdissect_options
*ndo
,
2114 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
2116 const struct tok
*code_str
;
2120 type
= EXTRACT_16BITS(cp
);
2122 ND_PRINT((ndo
, "\n\t type %s", tok2str(ofpet_str
, "invalid (0x%04x)", type
)));
2126 type
== OFPET_HELLO_FAILED
? ofphfc_str
:
2127 type
== OFPET_BAD_REQUEST
? ofpbrc_str
:
2128 type
== OFPET_BAD_ACTION
? ofpbac_str
:
2129 type
== OFPET_FLOW_MOD_FAILED
? ofpfmfc_str
:
2130 type
== OFPET_PORT_MOD_FAILED
? ofppmfc_str
:
2131 type
== OFPET_QUEUE_OP_FAILED
? ofpqofc_str
:
2133 ND_PRINT((ndo
, ", code %s", tok2str(code_str
, "invalid (0x%04x)", EXTRACT_16BITS(cp
))));
2136 return of10_data_print(ndo
, cp
, ep
, len
- OF_ERROR_MSG_LEN
);
2139 ND_PRINT((ndo
, "%s", tstr
));
2144 of10_header_body_print(netdissect_options
*ndo
,
2145 const u_char
*cp
, const u_char
*ep
, const uint8_t type
,
2146 const uint16_t len
, const uint32_t xid
) {
2147 const u_char
*cp0
= cp
;
2148 const u_int len0
= len
;
2149 /* Thus far message length is not less than the basic header size, but most
2150 * message types have additional assorted constraints on the length. Wherever
2151 * possible, check that message length meets the constraint, in remaining
2152 * cases check that the length is OK to begin decoding and leave any final
2153 * verification up to a lower-layer function. When the current message is
2154 * corrupt, proceed to the next message. */
2156 /* [OF10] Section 5.1 */
2157 ND_PRINT((ndo
, "\n\tversion 1.0, type %s, length %u, xid 0x%08x",
2158 tok2str(ofpt_str
, "invalid (0x%02x)", type
), len
, xid
));
2160 /* OpenFlow header only. */
2161 case OFPT_FEATURES_REQUEST
: /* [OF10] Section 5.3.1 */
2162 case OFPT_GET_CONFIG_REQUEST
: /* [OF10] Section 5.3.2 */
2163 case OFPT_BARRIER_REQUEST
: /* [OF10] Section 5.3.7 */
2164 case OFPT_BARRIER_REPLY
: /* ibid */
2165 if (len
!= OF_HEADER_LEN
)
2169 /* OpenFlow header and fixed-size message body. */
2170 case OFPT_SET_CONFIG
: /* [OF10] Section 5.3.2 */
2171 case OFPT_GET_CONFIG_REPLY
: /* ibid */
2172 if (len
!= OF_SWITCH_CONFIG_LEN
)
2174 if (ndo
->ndo_vflag
< 1)
2178 ND_PRINT((ndo
, "\n\t flags %s", tok2str(ofp_config_str
, "invalid (0x%04x)", EXTRACT_16BITS(cp
))));
2182 ND_PRINT((ndo
, ", miss_send_len %u", EXTRACT_16BITS(cp
)));
2185 if (len
!= OF_PORT_MOD_LEN
)
2187 if (ndo
->ndo_vflag
< 1)
2189 return of10_port_mod_print(ndo
, cp
, ep
);
2190 case OFPT_QUEUE_GET_CONFIG_REQUEST
: /* [OF10] Section 5.3.4 */
2191 if (len
!= OF_QUEUE_GET_CONFIG_REQUEST_LEN
)
2193 if (ndo
->ndo_vflag
< 1)
2197 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
2202 case OFPT_FLOW_REMOVED
:
2203 if (len
!= OF_FLOW_REMOVED_LEN
)
2205 if (ndo
->ndo_vflag
< 1)
2207 return of10_flow_removed_print(ndo
, cp
, ep
);
2208 case OFPT_PORT_STATUS
: /* [OF10] Section 5.4.3 */
2209 if (len
!= OF_PORT_STATUS_LEN
)
2211 if (ndo
->ndo_vflag
< 1)
2215 ND_PRINT((ndo
, "\n\t reason %s", tok2str(ofppr_str
, "invalid (0x%02x)", *cp
)));
2221 return of10_phy_ports_print(ndo
, cp
, ep
, OF_PHY_PORT_LEN
);
2223 /* OpenFlow header, fixed-size message body and n * fixed-size data units. */
2224 case OFPT_FEATURES_REPLY
:
2225 if (len
< OF_SWITCH_FEATURES_LEN
)
2227 if (ndo
->ndo_vflag
< 1)
2229 return of10_features_reply_print(ndo
, cp
, ep
, len
);
2231 /* OpenFlow header and variable-size data. */
2232 case OFPT_HELLO
: /* [OF10] Section 5.5.1 */
2233 case OFPT_ECHO_REQUEST
: /* [OF10] Section 5.5.2 */
2234 case OFPT_ECHO_REPLY
: /* [OF10] Section 5.5.3 */
2235 if (ndo
->ndo_vflag
< 1)
2237 return of10_data_print(ndo
, cp
, ep
, len
- OF_HEADER_LEN
);
2239 /* OpenFlow header, fixed-size message body and variable-size data. */
2241 if (len
< OF_ERROR_MSG_LEN
)
2243 if (ndo
->ndo_vflag
< 1)
2245 return of10_error_print(ndo
, cp
, ep
, len
);
2247 /* [OF10] Section 5.5.4 */
2248 if (len
< OF_VENDOR_HEADER_LEN
)
2250 if (ndo
->ndo_vflag
< 1)
2252 return of10_vendor_message_print(ndo
, cp
, ep
, len
- OF_HEADER_LEN
);
2253 case OFPT_PACKET_IN
:
2254 /* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
2255 if (len
< OF_PACKET_IN_LEN
- 2)
2257 if (ndo
->ndo_vflag
< 1)
2259 return of10_packet_in_print(ndo
, cp
, ep
, len
);
2261 /* a. OpenFlow header. */
2262 /* b. OpenFlow header and one of the fixed-size message bodies. */
2263 /* c. OpenFlow header, fixed-size message body and variable-size data. */
2264 case OFPT_STATS_REQUEST
:
2265 if (len
< OF_STATS_REQUEST_LEN
)
2267 if (ndo
->ndo_vflag
< 1)
2269 return of10_stats_request_print(ndo
, cp
, ep
, len
);
2271 /* a. OpenFlow header and fixed-size message body. */
2272 /* b. OpenFlow header and n * fixed-size data units. */
2273 /* c. OpenFlow header and n * variable-size data units. */
2274 /* d. OpenFlow header, fixed-size message body and variable-size data. */
2275 case OFPT_STATS_REPLY
:
2276 if (len
< OF_STATS_REPLY_LEN
)
2278 if (ndo
->ndo_vflag
< 1)
2280 return of10_stats_reply_print(ndo
, cp
, ep
, len
);
2282 /* OpenFlow header and n * variable-size data units and variable-size data. */
2283 case OFPT_PACKET_OUT
:
2284 if (len
< OF_PACKET_OUT_LEN
)
2286 if (ndo
->ndo_vflag
< 1)
2288 return of10_packet_out_print(ndo
, cp
, ep
, len
);
2290 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2292 if (len
< OF_FLOW_MOD_LEN
)
2294 if (ndo
->ndo_vflag
< 1)
2296 return of10_flow_mod_print(ndo
, cp
, ep
, len
);
2298 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2299 case OFPT_QUEUE_GET_CONFIG_REPLY
: /* [OF10] Section 5.3.4 */
2300 if (len
< OF_QUEUE_GET_CONFIG_REPLY_LEN
)
2302 if (ndo
->ndo_vflag
< 1)
2306 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
2312 return of10_queues_print(ndo
, cp
, ep
, len
- OF_QUEUE_GET_CONFIG_REPLY_LEN
);
2313 } /* switch (type) */
2316 corrupt
: /* skip the message body */
2317 ND_PRINT((ndo
, "%s", cstr
));
2319 ND_TCHECK2(*cp0
, len0
- OF_HEADER_LEN
);
2320 return cp0
+ len0
- OF_HEADER_LEN
;
2322 ND_PRINT((ndo
, "%s", tstr
));