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
:
805 * 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
806 * +---------------+---------------+---------------+---------------+
808 * +---------------+---------------+---------------+---------------+
815 ND_TCHECK2(*cp
, len
- 4);
820 corrupt
: /* skip the undersized data */
821 ND_PRINT((ndo
, "%s", cstr
));
822 ND_TCHECK2(*cp0
, len
);
825 ND_PRINT((ndo
, "%s", tstr
));
829 static const u_char
*
830 of10_vendor_message_print(netdissect_options
*ndo
,
831 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
833 const u_char
*(*decoder
)(netdissect_options
*, const u_char
*, const u_char
*, u_int
);
839 vendor
= EXTRACT_32BITS(cp
);
841 ND_PRINT((ndo
, ", vendor 0x%08x (%s)", vendor
, of_vendor_name(vendor
)));
844 vendor
== OUI_BSN
? of10_bsn_message_print
:
846 return decoder(ndo
, cp
, ep
, len
- 4);
848 corrupt
: /* skip the undersized data */
849 ND_PRINT((ndo
, "%s", cstr
));
850 ND_TCHECK2(*cp
, len
);
853 ND_PRINT((ndo
, "%s", tstr
));
857 /* Vendor ID is mandatory, data is optional. */
858 static const u_char
*
859 of10_vendor_data_print(netdissect_options
*ndo
,
860 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
867 vendor
= EXTRACT_32BITS(cp
);
869 ND_PRINT((ndo
, ", vendor 0x%08x (%s)", vendor
, of_vendor_name(vendor
)));
871 return of10_data_print(ndo
, cp
, ep
, len
- 4);
873 corrupt
: /* skip the undersized data */
874 ND_PRINT((ndo
, "%s", cstr
));
875 ND_TCHECK2(*cp
, len
);
878 ND_PRINT((ndo
, "%s", tstr
));
882 static const u_char
*
883 of10_packet_data_print(netdissect_options
*ndo
,
884 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
888 ND_PRINT((ndo
, "\n\t data (%u octets)", len
));
889 if (ndo
->ndo_vflag
< 3)
891 ND_TCHECK2(*cp
, len
);
893 ND_PRINT((ndo
, ", frame decoding below\n"));
894 ether_print(ndo
, cp
, len
, ndo
->ndo_snapend
- cp
, NULL
, NULL
);
899 ND_PRINT((ndo
, "%s", tstr
));
903 /* [OF10] Section 5.2.1 */
904 static const u_char
*
905 of10_phy_ports_print(netdissect_options
*ndo
,
906 const u_char
*cp
, const u_char
*ep
, u_int len
) {
907 const u_char
*cp0
= cp
;
908 const u_int len0
= len
;
911 if (len
< OF_PHY_PORT_LEN
)
915 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
918 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
919 ND_PRINT((ndo
, ", hw_addr %s", etheraddr_string(ndo
, cp
)));
920 cp
+= ETHER_ADDR_LEN
;
922 ND_TCHECK2(*cp
, OFP_MAX_PORT_NAME_LEN
);
923 ND_PRINT((ndo
, ", name '"));
924 fn_print(ndo
, cp
, cp
+ OFP_MAX_PORT_NAME_LEN
);
925 ND_PRINT((ndo
, "'"));
926 cp
+= OFP_MAX_PORT_NAME_LEN
;
928 if (ndo
->ndo_vflag
< 2) {
935 ND_PRINT((ndo
, "\n\t config 0x%08x", EXTRACT_32BITS(cp
)));
936 of10_bitmap_print(ndo
, ofppc_bm
, EXTRACT_32BITS(cp
), OFPPC_U
);
940 ND_PRINT((ndo
, "\n\t state 0x%08x", EXTRACT_32BITS(cp
)));
941 of10_bitmap_print(ndo
, ofpps_bm
, EXTRACT_32BITS(cp
), OFPPS_U
);
945 ND_PRINT((ndo
, "\n\t curr 0x%08x", EXTRACT_32BITS(cp
)));
946 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
950 ND_PRINT((ndo
, "\n\t advertised 0x%08x", EXTRACT_32BITS(cp
)));
951 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
955 ND_PRINT((ndo
, "\n\t supported 0x%08x", EXTRACT_32BITS(cp
)));
956 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
960 ND_PRINT((ndo
, "\n\t peer 0x%08x", EXTRACT_32BITS(cp
)));
961 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
964 len
-= OF_PHY_PORT_LEN
;
968 corrupt
: /* skip the undersized trailing data */
969 ND_PRINT((ndo
, "%s", cstr
));
970 ND_TCHECK2(*cp0
, len0
);
973 ND_PRINT((ndo
, "%s", tstr
));
977 /* [OF10] Section 5.2.2 */
978 static const u_char
*
979 of10_queue_props_print(netdissect_options
*ndo
,
980 const u_char
*cp
, const u_char
*ep
, u_int len
) {
981 const u_char
*cp0
= cp
;
982 const u_int len0
= len
;
983 uint16_t property
, plen
, rate
;
986 u_char plen_bogus
= 0, skip
= 0;
988 if (len
< OF_QUEUE_PROP_HEADER_LEN
)
992 property
= EXTRACT_16BITS(cp
);
994 ND_PRINT((ndo
, "\n\t property %s", tok2str(ofpqt_str
, "invalid (0x%04x)", property
)));
997 plen
= EXTRACT_16BITS(cp
);
999 ND_PRINT((ndo
, ", len %u", plen
));
1000 if (plen
< OF_QUEUE_PROP_HEADER_LEN
|| plen
> len
)
1005 /* property-specific constraints and decoding */
1008 plen_bogus
= plen
!= OF_QUEUE_PROP_HEADER_LEN
;
1010 case OFPQT_MIN_RATE
:
1011 plen_bogus
= plen
!= OF_QUEUE_PROP_MIN_RATE_LEN
;
1017 ND_PRINT((ndo
, " (bogus)"));
1021 ND_TCHECK2(*cp
, plen
- 4);
1025 if (property
== OFPQT_MIN_RATE
) { /* the only case of property decoding */
1028 rate
= EXTRACT_16BITS(cp
);
1031 ND_PRINT((ndo
, ", rate disabled"));
1033 ND_PRINT((ndo
, ", rate %u.%u%%", rate
/ 10, rate
% 10));
1043 corrupt
: /* skip the rest of queue properties */
1044 ND_PRINT((ndo
, "%s", cstr
));
1045 ND_TCHECK2(*cp0
, len0
);
1048 ND_PRINT((ndo
, "%s", tstr
));
1053 static const u_char
*
1054 of10_queues_print(netdissect_options
*ndo
,
1055 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1056 const u_char
*cp0
= cp
;
1057 const u_int len0
= len
;
1061 if (len
< OF_PACKET_QUEUE_LEN
)
1065 ND_PRINT((ndo
, "\n\t queue_id %u", EXTRACT_32BITS(cp
)));
1069 desclen
= EXTRACT_16BITS(cp
);
1071 ND_PRINT((ndo
, ", len %u", desclen
));
1072 if (desclen
< OF_PACKET_QUEUE_LEN
|| desclen
> len
)
1078 if (ndo
->ndo_vflag
< 2) {
1079 ND_TCHECK2(*cp
, desclen
- OF_PACKET_QUEUE_LEN
);
1080 cp
+= desclen
- OF_PACKET_QUEUE_LEN
;
1083 if (ep
== (cp
= of10_queue_props_print(ndo
, cp
, ep
, desclen
- OF_PACKET_QUEUE_LEN
)))
1084 return ep
; /* end of snapshot */
1090 corrupt
: /* skip the rest of queues */
1091 ND_PRINT((ndo
, "%s", cstr
));
1092 ND_TCHECK2(*cp0
, len0
);
1095 ND_PRINT((ndo
, "%s", tstr
));
1099 /* [OF10] Section 5.2.3 */
1100 static const u_char
*
1101 of10_match_print(netdissect_options
*ndo
,
1102 const char *pfx
, const u_char
*cp
, const u_char
*ep
) {
1107 const char *field_name
;
1111 wildcards
= EXTRACT_32BITS(cp
);
1112 if (wildcards
& OFPFW_U
)
1113 ND_PRINT((ndo
, "%swildcards 0x%08x (bogus)", pfx
, wildcards
));
1117 if (! (wildcards
& OFPFW_IN_PORT
))
1118 ND_PRINT((ndo
, "%smatch in_port %s", pfx
, tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1121 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
1122 if (! (wildcards
& OFPFW_DL_SRC
))
1123 ND_PRINT((ndo
, "%smatch dl_src %s", pfx
, etheraddr_string(ndo
, cp
)));
1124 cp
+= ETHER_ADDR_LEN
;
1126 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
1127 if (! (wildcards
& OFPFW_DL_DST
))
1128 ND_PRINT((ndo
, "%smatch dl_dst %s", pfx
, etheraddr_string(ndo
, cp
)));
1129 cp
+= ETHER_ADDR_LEN
;
1132 if (! (wildcards
& OFPFW_DL_VLAN
))
1133 ND_PRINT((ndo
, "%smatch dl_vlan %s", pfx
, vlan_str(EXTRACT_16BITS(cp
))));
1137 if (! (wildcards
& OFPFW_DL_VLAN_PCP
))
1138 ND_PRINT((ndo
, "%smatch dl_vlan_pcp %s", pfx
, pcp_str(*cp
)));
1145 dl_type
= EXTRACT_16BITS(cp
);
1147 if (! (wildcards
& OFPFW_DL_TYPE
))
1148 ND_PRINT((ndo
, "%smatch dl_type 0x%04x", pfx
, dl_type
));
1151 if (! (wildcards
& OFPFW_NW_TOS
))
1152 ND_PRINT((ndo
, "%smatch nw_tos 0x%02x", pfx
, *cp
));
1158 if (! (wildcards
& OFPFW_NW_PROTO
)) {
1159 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_ARP
1160 ? "arp_opcode" : "nw_proto";
1161 ND_PRINT((ndo
, "%smatch %s %u", pfx
, field_name
, nw_proto
));
1168 nw_bits
= (wildcards
& OFPFW_NW_SRC_MASK
) >> OFPFW_NW_SRC_SHIFT
;
1170 ND_PRINT((ndo
, "%smatch nw_src %s/%u", pfx
, ipaddr_string(ndo
, cp
), 32 - nw_bits
));
1174 nw_bits
= (wildcards
& OFPFW_NW_DST_MASK
) >> OFPFW_NW_DST_SHIFT
;
1176 ND_PRINT((ndo
, "%smatch nw_dst %s/%u", pfx
, ipaddr_string(ndo
, cp
), 32 - nw_bits
));
1180 if (! (wildcards
& OFPFW_TP_SRC
)) {
1181 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_IP
1182 && ! (wildcards
& OFPFW_NW_PROTO
) && nw_proto
== IPPROTO_ICMP
1183 ? "icmp_type" : "tp_src";
1184 ND_PRINT((ndo
, "%smatch %s %u", pfx
, field_name
, EXTRACT_16BITS(cp
)));
1189 if (! (wildcards
& OFPFW_TP_DST
)) {
1190 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_IP
1191 && ! (wildcards
& OFPFW_NW_PROTO
) && nw_proto
== IPPROTO_ICMP
1192 ? "icmp_code" : "tp_dst";
1193 ND_PRINT((ndo
, "%smatch %s %u", pfx
, field_name
, EXTRACT_16BITS(cp
)));
1198 ND_PRINT((ndo
, "%s", tstr
));
1202 /* [OF10] Section 5.2.4 */
1203 static const u_char
*
1204 of10_actions_print(netdissect_options
*ndo
,
1205 const char *pfx
, const u_char
*cp
, const u_char
*ep
,
1207 const u_char
*cp0
= cp
;
1208 const u_int len0
= len
;
1209 uint16_t type
, alen
, output_port
;
1212 u_char alen_bogus
= 0, skip
= 0;
1214 if (len
< OF_ACTION_HEADER_LEN
)
1218 type
= EXTRACT_16BITS(cp
);
1220 ND_PRINT((ndo
, "%saction type %s", pfx
, tok2str(ofpat_str
, "invalid (0x%04x)", type
)));
1223 alen
= EXTRACT_16BITS(cp
);
1225 ND_PRINT((ndo
, ", len %u", alen
));
1226 /* On action size underrun/overrun skip the rest of the action list. */
1227 if (alen
< OF_ACTION_HEADER_LEN
|| alen
> len
)
1229 /* On action size inappropriate for the given type or invalid type just skip
1230 * the current action, as the basic length constraint has been met. */
1233 case OFPAT_SET_VLAN_VID
:
1234 case OFPAT_SET_VLAN_PCP
:
1235 case OFPAT_STRIP_VLAN
:
1236 case OFPAT_SET_NW_SRC
:
1237 case OFPAT_SET_NW_DST
:
1238 case OFPAT_SET_NW_TOS
:
1239 case OFPAT_SET_TP_SRC
:
1240 case OFPAT_SET_TP_DST
:
1241 alen_bogus
= alen
!= 8;
1243 case OFPAT_SET_DL_SRC
:
1244 case OFPAT_SET_DL_DST
:
1246 alen_bogus
= alen
!= 16;
1249 alen_bogus
= alen
% 8 != 0; /* already >= 8 so far */
1255 ND_PRINT((ndo
, " (bogus)"));
1259 ND_TCHECK2(*cp
, alen
- 4);
1263 /* OK to decode the rest of the action structure */
1268 output_port
= EXTRACT_16BITS(cp
);
1270 ND_PRINT((ndo
, ", port %s", tok2str(ofpp_str
, "%u", output_port
)));
1273 if (output_port
== OFPP_CONTROLLER
)
1274 ND_PRINT((ndo
, ", max_len %u", EXTRACT_16BITS(cp
)));
1277 case OFPAT_SET_VLAN_VID
:
1280 ND_PRINT((ndo
, ", vlan_vid %s", vlan_str(EXTRACT_16BITS(cp
))));
1286 case OFPAT_SET_VLAN_PCP
:
1289 ND_PRINT((ndo
, ", vlan_pcp %s", pcp_str(*cp
)));
1295 case OFPAT_SET_DL_SRC
:
1296 case OFPAT_SET_DL_DST
:
1298 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
1299 ND_PRINT((ndo
, ", dl_addr %s", etheraddr_string(ndo
, cp
)));
1300 cp
+= ETHER_ADDR_LEN
;
1305 case OFPAT_SET_NW_SRC
:
1306 case OFPAT_SET_NW_DST
:
1309 ND_PRINT((ndo
, ", nw_addr %s", ipaddr_string(ndo
, cp
)));
1312 case OFPAT_SET_NW_TOS
:
1315 ND_PRINT((ndo
, ", nw_tos 0x%02x", *cp
));
1321 case OFPAT_SET_TP_SRC
:
1322 case OFPAT_SET_TP_DST
:
1325 ND_PRINT((ndo
, ", tp_port %u", EXTRACT_16BITS(cp
)));
1334 ND_PRINT((ndo
, ", port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1341 ND_PRINT((ndo
, ", queue_id %s", tok2str(ofpq_str
, "%u", EXTRACT_32BITS(cp
))));
1345 if (ep
== (cp
= of10_vendor_data_print(ndo
, cp
, ep
, alen
- 4)))
1346 return ep
; /* end of snapshot */
1348 case OFPAT_STRIP_VLAN
:
1359 corrupt
: /* skip the rest of actions */
1360 ND_PRINT((ndo
, "%s", cstr
));
1361 ND_TCHECK2(*cp0
, len0
);
1364 ND_PRINT((ndo
, "%s", tstr
));
1368 /* [OF10] Section 5.3.1 */
1369 static const u_char
*
1370 of10_features_reply_print(netdissect_options
*ndo
,
1371 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1374 ND_PRINT((ndo
, "\n\t dpid 0x%016" PRIx64
, EXTRACT_64BITS(cp
)));
1378 ND_PRINT((ndo
, ", n_buffers %u", EXTRACT_32BITS(cp
)));
1382 ND_PRINT((ndo
, ", n_tables %u", *cp
));
1389 ND_PRINT((ndo
, "\n\t capabilities 0x%08x", EXTRACT_32BITS(cp
)));
1390 of10_bitmap_print(ndo
, ofp_capabilities_bm
, EXTRACT_32BITS(cp
), OFPCAP_U
);
1394 ND_PRINT((ndo
, "\n\t actions 0x%08x", EXTRACT_32BITS(cp
)));
1395 of10_bitmap_print(ndo
, ofpat_bm
, EXTRACT_32BITS(cp
), OFPAT_U
);
1398 return of10_phy_ports_print(ndo
, cp
, ep
, len
- OF_SWITCH_FEATURES_LEN
);
1401 ND_PRINT((ndo
, "%s", tstr
));
1405 /* [OF10] Section 5.3.3 */
1406 static const u_char
*
1407 of10_flow_mod_print(netdissect_options
*ndo
,
1408 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1412 if (ep
== (cp
= of10_match_print(ndo
, "\n\t ", cp
, ep
)))
1413 return ep
; /* end of snapshot */
1416 ND_PRINT((ndo
, "\n\t cookie 0x%016" PRIx64
, EXTRACT_64BITS(cp
)));
1420 command
= EXTRACT_16BITS(cp
);
1421 ND_PRINT((ndo
, ", command %s", tok2str(ofpfc_str
, "invalid (0x%04x)", command
)));
1425 if (EXTRACT_16BITS(cp
))
1426 ND_PRINT((ndo
, ", idle_timeout %u", EXTRACT_16BITS(cp
)));
1430 if (EXTRACT_16BITS(cp
))
1431 ND_PRINT((ndo
, ", hard_timeout %u", EXTRACT_16BITS(cp
)));
1435 if (EXTRACT_16BITS(cp
))
1436 ND_PRINT((ndo
, ", priority %u", EXTRACT_16BITS(cp
)));
1440 if (command
== OFPFC_ADD
|| command
== OFPFC_MODIFY
||
1441 command
== OFPFC_MODIFY_STRICT
)
1442 ND_PRINT((ndo
, ", buffer_id %s", tok2str(bufferid_str
, "0x%08x", EXTRACT_32BITS(cp
))));
1446 if (command
== OFPFC_DELETE
|| command
== OFPFC_DELETE_STRICT
)
1447 ND_PRINT((ndo
, ", out_port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1451 ND_PRINT((ndo
, ", flags 0x%04x", EXTRACT_16BITS(cp
)));
1452 of10_bitmap_print(ndo
, ofpff_bm
, EXTRACT_16BITS(cp
), OFPFF_U
);
1455 return of10_actions_print(ndo
, "\n\t ", cp
, ep
, len
- OF_FLOW_MOD_LEN
);
1458 ND_PRINT((ndo
, "%s", tstr
));
1463 static const u_char
*
1464 of10_port_mod_print(netdissect_options
*ndo
,
1465 const u_char
*cp
, const u_char
*ep
) {
1468 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1471 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
1472 ND_PRINT((ndo
, ", hw_addr %s", etheraddr_string(ndo
, cp
)));
1473 cp
+= ETHER_ADDR_LEN
;
1476 ND_PRINT((ndo
, "\n\t config 0x%08x", EXTRACT_32BITS(cp
)));
1477 of10_bitmap_print(ndo
, ofppc_bm
, EXTRACT_32BITS(cp
), OFPPC_U
);
1481 ND_PRINT((ndo
, "\n\t mask 0x%08x", EXTRACT_32BITS(cp
)));
1482 of10_bitmap_print(ndo
, ofppc_bm
, EXTRACT_32BITS(cp
), OFPPC_U
);
1486 ND_PRINT((ndo
, "\n\t advertise 0x%08x", EXTRACT_32BITS(cp
)));
1487 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
1494 ND_PRINT((ndo
, "%s", tstr
));
1498 /* [OF10] Section 5.3.5 */
1499 static const u_char
*
1500 of10_stats_request_print(netdissect_options
*ndo
,
1501 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1502 const u_char
*cp0
= cp
;
1503 const u_int len0
= len
;
1508 type
= EXTRACT_16BITS(cp
);
1510 ND_PRINT((ndo
, "\n\t type %s", tok2str(ofpst_str
, "invalid (0x%04x)", type
)));
1513 ND_PRINT((ndo
, ", flags 0x%04x", EXTRACT_16BITS(cp
)));
1514 if (EXTRACT_16BITS(cp
))
1515 ND_PRINT((ndo
, " (bogus)"));
1517 /* type-specific body of one of fixed lengths */
1518 len
-= OF_STATS_REQUEST_LEN
;
1526 case OFPST_AGGREGATE
:
1527 if (len
!= OF_FLOW_STATS_REQUEST_LEN
)
1530 if (ep
== (cp
= of10_match_print(ndo
, "\n\t ", cp
, ep
)))
1531 return ep
; /* end of snapshot */
1534 ND_PRINT((ndo
, "\n\t table_id %s", tok2str(tableid_str
, "%u", *cp
)));
1541 ND_PRINT((ndo
, ", out_port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1544 if (len
!= OF_PORT_STATS_REQUEST_LEN
)
1548 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1554 if (len
!= OF_QUEUE_STATS_REQUEST_LEN
)
1558 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1565 ND_PRINT((ndo
, ", queue_id %s", tok2str(ofpq_str
, "%u", EXTRACT_32BITS(cp
))));
1568 return of10_vendor_data_print(ndo
, cp
, ep
, len
);
1572 corrupt
: /* skip the message body */
1573 ND_PRINT((ndo
, "%s", cstr
));
1574 ND_TCHECK2(*cp0
, len0
);
1577 ND_PRINT((ndo
, "%s", tstr
));
1582 static const u_char
*
1583 of10_desc_stats_reply_print(netdissect_options
*ndo
,
1584 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1585 if (len
!= OF_DESC_STATS_LEN
)
1588 ND_TCHECK2(*cp
, DESC_STR_LEN
);
1589 ND_PRINT((ndo
, "\n\t mfr_desc '"));
1590 fn_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1591 ND_PRINT((ndo
, "'"));
1594 ND_TCHECK2(*cp
, DESC_STR_LEN
);
1595 ND_PRINT((ndo
, "\n\t hw_desc '"));
1596 fn_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1597 ND_PRINT((ndo
, "'"));
1600 ND_TCHECK2(*cp
, DESC_STR_LEN
);
1601 ND_PRINT((ndo
, "\n\t sw_desc '"));
1602 fn_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1603 ND_PRINT((ndo
, "'"));
1606 ND_TCHECK2(*cp
, SERIAL_NUM_LEN
);
1607 ND_PRINT((ndo
, "\n\t serial_num '"));
1608 fn_print(ndo
, cp
, cp
+ SERIAL_NUM_LEN
);
1609 ND_PRINT((ndo
, "'"));
1610 cp
+= SERIAL_NUM_LEN
;
1612 ND_TCHECK2(*cp
, DESC_STR_LEN
);
1613 ND_PRINT((ndo
, "\n\t dp_desc '"));
1614 fn_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1615 ND_PRINT((ndo
, "'"));
1616 return cp
+ DESC_STR_LEN
;
1618 corrupt
: /* skip the message body */
1619 ND_PRINT((ndo
, "%s", cstr
));
1620 ND_TCHECK2(*cp
, len
);
1623 ND_PRINT((ndo
, "%s", tstr
));
1628 static const u_char
*
1629 of10_flow_stats_reply_print(netdissect_options
*ndo
,
1630 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1631 const u_char
*cp0
= cp
;
1632 const u_int len0
= len
;
1636 if (len
< OF_FLOW_STATS_LEN
)
1640 entry_len
= EXTRACT_16BITS(cp
);
1641 ND_PRINT((ndo
, "\n\t length %u", entry_len
));
1642 if (entry_len
< OF_FLOW_STATS_LEN
|| entry_len
> len
)
1647 ND_PRINT((ndo
, ", table_id %s", tok2str(tableid_str
, "%u", *cp
)));
1653 if (ep
== (cp
= of10_match_print(ndo
, "\n\t ", cp
, ep
)))
1654 return ep
; /* end of snapshot */
1657 ND_PRINT((ndo
, "\n\t duration_sec %u", EXTRACT_32BITS(cp
)));
1661 ND_PRINT((ndo
, ", duration_nsec %u", EXTRACT_32BITS(cp
)));
1665 ND_PRINT((ndo
, ", priority %u", EXTRACT_16BITS(cp
)));
1669 ND_PRINT((ndo
, ", idle_timeout %u", EXTRACT_16BITS(cp
)));
1673 ND_PRINT((ndo
, ", hard_timeout %u", EXTRACT_16BITS(cp
)));
1680 ND_PRINT((ndo
, ", cookie 0x%016" PRIx64
, EXTRACT_64BITS(cp
)));
1684 ND_PRINT((ndo
, ", packet_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1688 ND_PRINT((ndo
, ", byte_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1691 if (ep
== (cp
= of10_actions_print(ndo
, "\n\t ", cp
, ep
, entry_len
- OF_FLOW_STATS_LEN
)))
1692 return ep
; /* end of snapshot */
1698 corrupt
: /* skip the rest of flow statistics entries */
1699 ND_PRINT((ndo
, "%s", cstr
));
1700 ND_TCHECK2(*cp0
, len0
);
1703 ND_PRINT((ndo
, "%s", tstr
));
1708 static const u_char
*
1709 of10_aggregate_stats_reply_print(netdissect_options
*ndo
,
1710 const u_char
*cp
, const u_char
*ep
,
1712 if (len
!= OF_AGGREGATE_STATS_REPLY_LEN
)
1716 ND_PRINT((ndo
, "\n\t packet_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1720 ND_PRINT((ndo
, ", byte_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1724 ND_PRINT((ndo
, ", flow_count %u", EXTRACT_32BITS(cp
)));
1730 corrupt
: /* skip the message body */
1731 ND_PRINT((ndo
, "%s", cstr
));
1732 ND_TCHECK2(*cp
, len
);
1735 ND_PRINT((ndo
, "%s", tstr
));
1740 static const u_char
*
1741 of10_table_stats_reply_print(netdissect_options
*ndo
,
1742 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1743 const u_char
*cp0
= cp
;
1744 const u_int len0
= len
;
1747 if (len
< OF_TABLE_STATS_LEN
)
1751 ND_PRINT((ndo
, "\n\t table_id %s", tok2str(tableid_str
, "%u", *cp
)));
1757 ND_TCHECK2(*cp
, OFP_MAX_TABLE_NAME_LEN
);
1758 ND_PRINT((ndo
, ", name '"));
1759 fn_print(ndo
, cp
, cp
+ OFP_MAX_TABLE_NAME_LEN
);
1760 ND_PRINT((ndo
, "'"));
1761 cp
+= OFP_MAX_TABLE_NAME_LEN
;
1764 ND_PRINT((ndo
, "\n\t wildcards 0x%08x", EXTRACT_32BITS(cp
)));
1765 of10_bitmap_print(ndo
, ofpfw_bm
, EXTRACT_32BITS(cp
), OFPFW_U
);
1769 ND_PRINT((ndo
, "\n\t max_entries %u", EXTRACT_32BITS(cp
)));
1773 ND_PRINT((ndo
, ", active_count %u", EXTRACT_32BITS(cp
)));
1777 ND_PRINT((ndo
, ", lookup_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1781 ND_PRINT((ndo
, ", matched_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1784 len
-= OF_TABLE_STATS_LEN
;
1788 corrupt
: /* skip the undersized trailing data */
1789 ND_PRINT((ndo
, "%s", cstr
));
1790 ND_TCHECK2(*cp0
, len0
);
1793 ND_PRINT((ndo
, "%s", tstr
));
1798 static const u_char
*
1799 of10_port_stats_reply_print(netdissect_options
*ndo
,
1800 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1801 const u_char
*cp0
= cp
;
1802 const u_int len0
= len
;
1805 if (len
< OF_PORT_STATS_LEN
)
1809 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1811 if (ndo
->ndo_vflag
< 2) {
1812 ND_TCHECK2(*cp
, OF_PORT_STATS_LEN
- 2);
1813 cp
+= OF_PORT_STATS_LEN
- 2;
1821 ND_PRINT((ndo
, ", rx_packets %" PRIu64
, EXTRACT_64BITS(cp
)));
1825 ND_PRINT((ndo
, ", tx_packets %" PRIu64
, EXTRACT_64BITS(cp
)));
1829 ND_PRINT((ndo
, ", rx_bytes %" PRIu64
, EXTRACT_64BITS(cp
)));
1833 ND_PRINT((ndo
, ", tx_bytes %" PRIu64
, EXTRACT_64BITS(cp
)));
1837 ND_PRINT((ndo
, ", rx_dropped %" PRIu64
, EXTRACT_64BITS(cp
)));
1841 ND_PRINT((ndo
, ", tx_dropped %" PRIu64
, EXTRACT_64BITS(cp
)));
1845 ND_PRINT((ndo
, ", rx_errors %" PRIu64
, EXTRACT_64BITS(cp
)));
1849 ND_PRINT((ndo
, ", tx_errors %" PRIu64
, EXTRACT_64BITS(cp
)));
1853 ND_PRINT((ndo
, ", rx_frame_err %" PRIu64
, EXTRACT_64BITS(cp
)));
1857 ND_PRINT((ndo
, ", rx_over_err %" PRIu64
, EXTRACT_64BITS(cp
)));
1861 ND_PRINT((ndo
, ", rx_crc_err %" PRIu64
, EXTRACT_64BITS(cp
)));
1865 ND_PRINT((ndo
, ", collisions %" PRIu64
, EXTRACT_64BITS(cp
)));
1868 len
-= OF_PORT_STATS_LEN
;
1872 corrupt
: /* skip the undersized trailing data */
1873 ND_PRINT((ndo
, "%s", cstr
));
1874 ND_TCHECK2(*cp0
, len0
);
1877 ND_PRINT((ndo
, "%s", tstr
));
1882 static const u_char
*
1883 of10_queue_stats_reply_print(netdissect_options
*ndo
,
1884 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1885 const u_char
*cp0
= cp
;
1886 const u_int len0
= len
;
1889 if (len
< OF_QUEUE_STATS_LEN
)
1893 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1900 ND_PRINT((ndo
, ", queue_id %u", EXTRACT_32BITS(cp
)));
1904 ND_PRINT((ndo
, ", tx_bytes %" PRIu64
, EXTRACT_64BITS(cp
)));
1908 ND_PRINT((ndo
, ", tx_packets %" PRIu64
, EXTRACT_64BITS(cp
)));
1912 ND_PRINT((ndo
, ", tx_errors %" PRIu64
, EXTRACT_64BITS(cp
)));
1915 len
-= OF_QUEUE_STATS_LEN
;
1919 corrupt
: /* skip the undersized trailing data */
1920 ND_PRINT((ndo
, "%s", cstr
));
1921 ND_TCHECK2(*cp0
, len0
);
1924 ND_PRINT((ndo
, "%s", tstr
));
1929 static const u_char
*
1930 of10_stats_reply_print(netdissect_options
*ndo
,
1931 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1932 const u_char
*cp0
= cp
;
1937 type
= EXTRACT_16BITS(cp
);
1938 ND_PRINT((ndo
, "\n\t type %s", tok2str(ofpst_str
, "invalid (0x%04x)", type
)));
1942 ND_PRINT((ndo
, ", flags 0x%04x", EXTRACT_16BITS(cp
)));
1943 of10_bitmap_print(ndo
, ofpsf_reply_bm
, EXTRACT_16BITS(cp
), OFPSF_REPLY_U
);
1946 if (ndo
->ndo_vflag
> 0) {
1947 const u_char
*(*decoder
)(netdissect_options
*, const u_char
*, const u_char
*, u_int
) =
1948 type
== OFPST_DESC
? of10_desc_stats_reply_print
:
1949 type
== OFPST_FLOW
? of10_flow_stats_reply_print
:
1950 type
== OFPST_AGGREGATE
? of10_aggregate_stats_reply_print
:
1951 type
== OFPST_TABLE
? of10_table_stats_reply_print
:
1952 type
== OFPST_PORT
? of10_port_stats_reply_print
:
1953 type
== OFPST_QUEUE
? of10_queue_stats_reply_print
:
1954 type
== OFPST_VENDOR
? of10_vendor_data_print
:
1956 if (decoder
!= NULL
)
1957 return decoder(ndo
, cp
, ep
, len
- OF_STATS_REPLY_LEN
);
1959 ND_TCHECK2(*cp0
, len
);
1963 ND_PRINT((ndo
, "%s", tstr
));
1967 /* [OF10] Section 5.3.6 */
1968 static const u_char
*
1969 of10_packet_out_print(netdissect_options
*ndo
,
1970 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1971 const u_char
*cp0
= cp
;
1972 const u_int len0
= len
;
1973 uint16_t actions_len
;
1977 ND_PRINT((ndo
, "\n\t buffer_id 0x%08x", EXTRACT_32BITS(cp
)));
1981 ND_PRINT((ndo
, ", in_port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1985 actions_len
= EXTRACT_16BITS(cp
);
1987 if (actions_len
> len
- OF_PACKET_OUT_LEN
)
1990 if (ep
== (cp
= of10_actions_print(ndo
, "\n\t ", cp
, ep
, actions_len
)))
1991 return ep
; /* end of snapshot */
1993 return of10_packet_data_print(ndo
, cp
, ep
, len
- OF_PACKET_OUT_LEN
- actions_len
);
1995 corrupt
: /* skip the rest of the message body */
1996 ND_PRINT((ndo
, "%s", cstr
));
1997 ND_TCHECK2(*cp0
, len0
);
2000 ND_PRINT((ndo
, "%s", tstr
));
2004 /* [OF10] Section 5.4.1 */
2005 static const u_char
*
2006 of10_packet_in_print(netdissect_options
*ndo
,
2007 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
2010 ND_PRINT((ndo
, "\n\t buffer_id %s", tok2str(bufferid_str
, "0x%08x", EXTRACT_32BITS(cp
))));
2014 ND_PRINT((ndo
, ", total_len %u", EXTRACT_16BITS(cp
)));
2018 ND_PRINT((ndo
, ", in_port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
2022 ND_PRINT((ndo
, ", reason %s", tok2str(ofpr_str
, "invalid (0x%02x)", *cp
)));
2028 /* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
2029 return of10_packet_data_print(ndo
, cp
, ep
, len
- (OF_PACKET_IN_LEN
- 2));
2032 ND_PRINT((ndo
, "%s", tstr
));
2036 /* [OF10] Section 5.4.2 */
2037 static const u_char
*
2038 of10_flow_removed_print(netdissect_options
*ndo
,
2039 const u_char
*cp
, const u_char
*ep
) {
2041 if (ep
== (cp
= of10_match_print(ndo
, "\n\t ", cp
, ep
)))
2042 return ep
; /* end of snapshot */
2045 ND_PRINT((ndo
, "\n\t cookie 0x%016" PRIx64
, EXTRACT_64BITS(cp
)));
2049 if (EXTRACT_16BITS(cp
))
2050 ND_PRINT((ndo
, ", priority %u", EXTRACT_16BITS(cp
)));
2054 ND_PRINT((ndo
, ", reason %s", tok2str(ofprr_str
, "unknown (0x%02x)", *cp
)));
2061 ND_PRINT((ndo
, ", duration_sec %u", EXTRACT_32BITS(cp
)));
2065 ND_PRINT((ndo
, ", duration_nsec %u", EXTRACT_32BITS(cp
)));
2069 if (EXTRACT_16BITS(cp
))
2070 ND_PRINT((ndo
, ", idle_timeout %u", EXTRACT_16BITS(cp
)));
2077 ND_PRINT((ndo
, ", packet_count %" PRIu64
, EXTRACT_64BITS(cp
)));
2081 ND_PRINT((ndo
, ", byte_count %" PRIu64
, EXTRACT_64BITS(cp
)));
2085 ND_PRINT((ndo
, "%s", tstr
));
2089 /* [OF10] Section 5.4.4 */
2090 static const u_char
*
2091 of10_error_print(netdissect_options
*ndo
,
2092 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
2094 const struct tok
*code_str
;
2098 type
= EXTRACT_16BITS(cp
);
2100 ND_PRINT((ndo
, "\n\t type %s", tok2str(ofpet_str
, "invalid (0x%04x)", type
)));
2104 type
== OFPET_HELLO_FAILED
? ofphfc_str
:
2105 type
== OFPET_BAD_REQUEST
? ofpbrc_str
:
2106 type
== OFPET_BAD_ACTION
? ofpbac_str
:
2107 type
== OFPET_FLOW_MOD_FAILED
? ofpfmfc_str
:
2108 type
== OFPET_PORT_MOD_FAILED
? ofppmfc_str
:
2109 type
== OFPET_QUEUE_OP_FAILED
? ofpqofc_str
:
2111 ND_PRINT((ndo
, ", code %s", tok2str(code_str
, "invalid (0x%04x)", EXTRACT_16BITS(cp
))));
2114 return of10_data_print(ndo
, cp
, ep
, len
- OF_ERROR_MSG_LEN
);
2117 ND_PRINT((ndo
, "%s", tstr
));
2122 of10_header_body_print(netdissect_options
*ndo
,
2123 const u_char
*cp
, const u_char
*ep
, const uint8_t type
,
2124 const uint16_t len
, const uint32_t xid
) {
2125 const u_char
*cp0
= cp
;
2126 const u_int len0
= len
;
2127 /* Thus far message length is not less than the basic header size, but most
2128 * message types have additional assorted constraints on the length. Wherever
2129 * possible, check that message length meets the constraint, in remaining
2130 * cases check that the length is OK to begin decoding and leave any final
2131 * verification up to a lower-layer function. When the current message is
2132 * corrupt, proceed to the next message. */
2134 /* [OF10] Section 5.1 */
2135 ND_PRINT((ndo
, "\n\tversion 1.0, type %s, length %u, xid 0x%08x",
2136 tok2str(ofpt_str
, "invalid (0x%02x)", type
), len
, xid
));
2138 /* OpenFlow header only. */
2139 case OFPT_FEATURES_REQUEST
: /* [OF10] Section 5.3.1 */
2140 case OFPT_GET_CONFIG_REQUEST
: /* [OF10] Section 5.3.2 */
2141 case OFPT_BARRIER_REQUEST
: /* [OF10] Section 5.3.7 */
2142 case OFPT_BARRIER_REPLY
: /* ibid */
2143 if (len
!= OF_HEADER_LEN
)
2147 /* OpenFlow header and fixed-size message body. */
2148 case OFPT_SET_CONFIG
: /* [OF10] Section 5.3.2 */
2149 case OFPT_GET_CONFIG_REPLY
: /* ibid */
2150 if (len
!= OF_SWITCH_CONFIG_LEN
)
2152 if (ndo
->ndo_vflag
< 1)
2156 ND_PRINT((ndo
, "\n\t flags %s", tok2str(ofp_config_str
, "invalid (0x%04x)", EXTRACT_16BITS(cp
))));
2160 ND_PRINT((ndo
, ", miss_send_len %u", EXTRACT_16BITS(cp
)));
2163 if (len
!= OF_PORT_MOD_LEN
)
2165 if (ndo
->ndo_vflag
< 1)
2167 return of10_port_mod_print(ndo
, cp
, ep
);
2168 case OFPT_QUEUE_GET_CONFIG_REQUEST
: /* [OF10] Section 5.3.4 */
2169 if (len
!= OF_QUEUE_GET_CONFIG_REQUEST_LEN
)
2171 if (ndo
->ndo_vflag
< 1)
2175 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
2180 case OFPT_FLOW_REMOVED
:
2181 if (len
!= OF_FLOW_REMOVED_LEN
)
2183 if (ndo
->ndo_vflag
< 1)
2185 return of10_flow_removed_print(ndo
, cp
, ep
);
2186 case OFPT_PORT_STATUS
: /* [OF10] Section 5.4.3 */
2187 if (len
!= OF_PORT_STATUS_LEN
)
2189 if (ndo
->ndo_vflag
< 1)
2193 ND_PRINT((ndo
, "\n\t reason %s", tok2str(ofppr_str
, "invalid (0x%02x)", *cp
)));
2199 return of10_phy_ports_print(ndo
, cp
, ep
, OF_PHY_PORT_LEN
);
2201 /* OpenFlow header, fixed-size message body and n * fixed-size data units. */
2202 case OFPT_FEATURES_REPLY
:
2203 if (len
< OF_SWITCH_FEATURES_LEN
)
2205 if (ndo
->ndo_vflag
< 1)
2207 return of10_features_reply_print(ndo
, cp
, ep
, len
);
2209 /* OpenFlow header and variable-size data. */
2210 case OFPT_HELLO
: /* [OF10] Section 5.5.1 */
2211 case OFPT_ECHO_REQUEST
: /* [OF10] Section 5.5.2 */
2212 case OFPT_ECHO_REPLY
: /* [OF10] Section 5.5.3 */
2213 if (ndo
->ndo_vflag
< 1)
2215 return of10_data_print(ndo
, cp
, ep
, len
- OF_HEADER_LEN
);
2217 /* OpenFlow header, fixed-size message body and variable-size data. */
2219 if (len
< OF_ERROR_MSG_LEN
)
2221 if (ndo
->ndo_vflag
< 1)
2223 return of10_error_print(ndo
, cp
, ep
, len
);
2225 /* [OF10] Section 5.5.4 */
2226 if (len
< OF_VENDOR_HEADER_LEN
)
2228 if (ndo
->ndo_vflag
< 1)
2230 return of10_vendor_message_print(ndo
, cp
, ep
, len
- OF_HEADER_LEN
);
2231 case OFPT_PACKET_IN
:
2232 /* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
2233 if (len
< OF_PACKET_IN_LEN
- 2)
2235 if (ndo
->ndo_vflag
< 1)
2237 return of10_packet_in_print(ndo
, cp
, ep
, len
);
2239 /* a. OpenFlow header. */
2240 /* b. OpenFlow header and one of the fixed-size message bodies. */
2241 /* c. OpenFlow header, fixed-size message body and variable-size data. */
2242 case OFPT_STATS_REQUEST
:
2243 if (len
< OF_STATS_REQUEST_LEN
)
2245 if (ndo
->ndo_vflag
< 1)
2247 return of10_stats_request_print(ndo
, cp
, ep
, len
);
2249 /* a. OpenFlow header and fixed-size message body. */
2250 /* b. OpenFlow header and n * fixed-size data units. */
2251 /* c. OpenFlow header and n * variable-size data units. */
2252 /* d. OpenFlow header, fixed-size message body and variable-size data. */
2253 case OFPT_STATS_REPLY
:
2254 if (len
< OF_STATS_REPLY_LEN
)
2256 if (ndo
->ndo_vflag
< 1)
2258 return of10_stats_reply_print(ndo
, cp
, ep
, len
);
2260 /* OpenFlow header and n * variable-size data units and variable-size data. */
2261 case OFPT_PACKET_OUT
:
2262 if (len
< OF_PACKET_OUT_LEN
)
2264 if (ndo
->ndo_vflag
< 1)
2266 return of10_packet_out_print(ndo
, cp
, ep
, len
);
2268 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2270 if (len
< OF_FLOW_MOD_LEN
)
2272 if (ndo
->ndo_vflag
< 1)
2274 return of10_flow_mod_print(ndo
, cp
, ep
, len
);
2276 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2277 case OFPT_QUEUE_GET_CONFIG_REPLY
: /* [OF10] Section 5.3.4 */
2278 if (len
< OF_QUEUE_GET_CONFIG_REPLY_LEN
)
2280 if (ndo
->ndo_vflag
< 1)
2284 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
2290 return of10_queues_print(ndo
, cp
, ep
, len
- OF_QUEUE_GET_CONFIG_REPLY_LEN
);
2291 } /* switch (type) */
2294 corrupt
: /* skip the message body */
2295 ND_PRINT((ndo
, "%s", cstr
));
2297 ND_TCHECK2(*cp0
, len0
- OF_HEADER_LEN
);
2298 return cp0
+ len0
- OF_HEADER_LEN
;
2300 ND_PRINT((ndo
, "%s", tstr
));