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 * Most functions in this file take 3 arguments into account:
12 * * cp -- the pointer to the first octet to decode
13 * * len -- the length of the current structure as declared on the wire
14 * * ep -- the pointer to the end of the captured frame
15 * They return either the pointer to the next not-yet-decoded part of the frame
16 * or the value of ep, which means the current frame processing is over as it
17 * has been fully decoded or is malformed or truncated. This way it is possible
18 * to chain and nest such functions uniformly to decode an OF1.0 message, which
19 * consists of several layers of nested structures.
21 * Decoding of Ethernet frames nested in OFPT_PACKET_IN and OFPT_PACKET_OUT
22 * messages is done only when the verbosity level set by command-line argument
23 * is "-vvv" or higher. In that case the verbosity level is temporarily
24 * decremented by 3 during the nested frame decoding. For example, running
25 * tcpdump with "-vvvv" will do full decoding of OpenFlow and "-v" decoding of
28 * Partial decoding of Big Switch Networks vendor extensions is done after the
29 * oftest (OpenFlow Testing Framework) source code.
32 * Copyright (c) 2013 The TCPDUMP project
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
44 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
45 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
46 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
47 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
48 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
49 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
50 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
54 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55 * POSSIBILITY OF SUCH DAMAGE.
58 #define NETDISSECT_REWORKED
63 #include <tcpdump-stdinc.h>
65 #include "interface.h"
67 #include "addrtoname.h"
69 #include "ethertype.h"
74 static const char tstr
[] = " [|openflow]";
75 static const char cstr
[] = " (corrupt)";
77 #define OFPT_HELLO 0x00
78 #define OFPT_ERROR 0x01
79 #define OFPT_ECHO_REQUEST 0x02
80 #define OFPT_ECHO_REPLY 0x03
81 #define OFPT_VENDOR 0x04
82 #define OFPT_FEATURES_REQUEST 0x05
83 #define OFPT_FEATURES_REPLY 0x06
84 #define OFPT_GET_CONFIG_REQUEST 0x07
85 #define OFPT_GET_CONFIG_REPLY 0x08
86 #define OFPT_SET_CONFIG 0x09
87 #define OFPT_PACKET_IN 0x0a
88 #define OFPT_FLOW_REMOVED 0x0b
89 #define OFPT_PORT_STATUS 0x0c
90 #define OFPT_PACKET_OUT 0x0d
91 #define OFPT_FLOW_MOD 0x0e
92 #define OFPT_PORT_MOD 0x0f
93 #define OFPT_STATS_REQUEST 0x10
94 #define OFPT_STATS_REPLY 0x11
95 #define OFPT_BARRIER_REQUEST 0x12
96 #define OFPT_BARRIER_REPLY 0x13
97 #define OFPT_QUEUE_GET_CONFIG_REQUEST 0x14
98 #define OFPT_QUEUE_GET_CONFIG_REPLY 0x15
99 static const struct tok ofpt_str
[] = {
100 { OFPT_HELLO
, "HELLO" },
101 { OFPT_ERROR
, "ERROR" },
102 { OFPT_ECHO_REQUEST
, "ECHO_REQUEST" },
103 { OFPT_ECHO_REPLY
, "ECHO_REPLY" },
104 { OFPT_VENDOR
, "VENDOR" },
105 { OFPT_FEATURES_REQUEST
, "FEATURES_REQUEST" },
106 { OFPT_FEATURES_REPLY
, "FEATURES_REPLY" },
107 { OFPT_GET_CONFIG_REQUEST
, "GET_CONFIG_REQUEST" },
108 { OFPT_GET_CONFIG_REPLY
, "GET_CONFIG_REPLY" },
109 { OFPT_SET_CONFIG
, "SET_CONFIG" },
110 { OFPT_PACKET_IN
, "PACKET_IN" },
111 { OFPT_FLOW_REMOVED
, "FLOW_REMOVED" },
112 { OFPT_PORT_STATUS
, "PORT_STATUS" },
113 { OFPT_PACKET_OUT
, "PACKET_OUT" },
114 { OFPT_FLOW_MOD
, "FLOW_MOD" },
115 { OFPT_PORT_MOD
, "PORT_MOD" },
116 { OFPT_STATS_REQUEST
, "STATS_REQUEST" },
117 { OFPT_STATS_REPLY
, "STATS_REPLY" },
118 { OFPT_BARRIER_REQUEST
, "BARRIER_REQUEST" },
119 { OFPT_BARRIER_REPLY
, "BARRIER_REPLY" },
120 { OFPT_QUEUE_GET_CONFIG_REQUEST
, "QUEUE_GET_CONFIG_REQUEST" },
121 { OFPT_QUEUE_GET_CONFIG_REPLY
, "QUEUE_GET_CONFIG_REPLY" },
125 #define OFPPC_PORT_DOWN (1 << 0)
126 #define OFPPC_NO_STP (1 << 1)
127 #define OFPPC_NO_RECV (1 << 2)
128 #define OFPPC_NO_RECV_STP (1 << 3)
129 #define OFPPC_NO_FLOOD (1 << 4)
130 #define OFPPC_NO_FWD (1 << 5)
131 #define OFPPC_NO_PACKET_IN (1 << 6)
132 static const struct tok ofppc_bm
[] = {
133 { OFPPC_PORT_DOWN
, "PORT_DOWN" },
134 { OFPPC_NO_STP
, "NO_STP" },
135 { OFPPC_NO_RECV
, "NO_RECV" },
136 { OFPPC_NO_RECV_STP
, "NO_RECV_STP" },
137 { OFPPC_NO_FLOOD
, "NO_FLOOD" },
138 { OFPPC_NO_FWD
, "NO_FWD" },
139 { OFPPC_NO_PACKET_IN
, "NO_PACKET_IN" },
142 #define OFPPC_U (~(OFPPC_PORT_DOWN | OFPPC_NO_STP | OFPPC_NO_RECV | \
143 OFPPC_NO_RECV_STP | OFPPC_NO_FLOOD | OFPPC_NO_FWD | \
146 #define OFPPS_LINK_DOWN (1 << 0)
147 #define OFPPS_STP_LISTEN (0 << 8)
148 #define OFPPS_STP_LEARN (1 << 8)
149 #define OFPPS_STP_FORWARD (2 << 8)
150 #define OFPPS_STP_BLOCK (3 << 8)
151 #define OFPPS_STP_MASK (3 << 8)
152 static const struct tok ofpps_bm
[] = {
153 { OFPPS_LINK_DOWN
, "LINK_DOWN" },
154 { OFPPS_STP_LISTEN
, "STP_LISTEN" },
155 { OFPPS_STP_LEARN
, "STP_LEARN" },
156 { OFPPS_STP_FORWARD
, "STP_FORWARD" },
157 { OFPPS_STP_BLOCK
, "STP_BLOCK" },
160 #define OFPPS_U (~(OFPPS_LINK_DOWN | OFPPS_STP_LISTEN | OFPPS_STP_LEARN | \
161 OFPPS_STP_FORWARD | OFPPS_STP_BLOCK))
163 #define OFPP_MAX 0xff00
164 #define OFPP_IN_PORT 0xfff8
165 #define OFPP_TABLE 0xfff9
166 #define OFPP_NORMAL 0xfffa
167 #define OFPP_FLOOD 0xfffb
168 #define OFPP_ALL 0xfffc
169 #define OFPP_CONTROLLER 0xfffd
170 #define OFPP_LOCAL 0xfffe
171 #define OFPP_NONE 0xffff
172 static const struct tok ofpp_str
[] = {
174 { OFPP_IN_PORT
, "IN_PORT" },
175 { OFPP_TABLE
, "TABLE" },
176 { OFPP_NORMAL
, "NORMAL" },
177 { OFPP_FLOOD
, "FLOOD" },
179 { OFPP_CONTROLLER
, "CONTROLLER" },
180 { OFPP_LOCAL
, "LOCAL" },
181 { OFPP_NONE
, "NONE" },
185 #define OFPPF_10MB_HD (1 << 0)
186 #define OFPPF_10MB_FD (1 << 1)
187 #define OFPPF_100MB_HD (1 << 2)
188 #define OFPPF_100MB_FD (1 << 3)
189 #define OFPPF_1GB_HD (1 << 4)
190 #define OFPPF_1GB_FD (1 << 5)
191 #define OFPPF_10GB_FD (1 << 6)
192 #define OFPPF_COPPER (1 << 7)
193 #define OFPPF_FIBER (1 << 8)
194 #define OFPPF_AUTONEG (1 << 9)
195 #define OFPPF_PAUSE (1 << 10)
196 #define OFPPF_PAUSE_ASYM (1 << 11)
197 static const struct tok ofppf_bm
[] = {
198 { OFPPF_10MB_HD
, "10MB_HD" },
199 { OFPPF_10MB_FD
, "10MB_FD" },
200 { OFPPF_100MB_HD
, "100MB_HD" },
201 { OFPPF_100MB_FD
, "100MB_FD" },
202 { OFPPF_1GB_HD
, "1GB_HD" },
203 { OFPPF_1GB_FD
, "1GB_FD" },
204 { OFPPF_10GB_FD
, "10GB_FD" },
205 { OFPPF_COPPER
, "COPPER" },
206 { OFPPF_FIBER
, "FIBER" },
207 { OFPPF_AUTONEG
, "AUTONEG" },
208 { OFPPF_PAUSE
, "PAUSE" },
209 { OFPPF_PAUSE_ASYM
, "PAUSE_ASYM" },
212 #define OFPPF_U (~(OFPPF_10MB_HD | OFPPF_10MB_FD | OFPPF_100MB_HD | \
213 OFPPF_100MB_FD | OFPPF_1GB_HD | OFPPF_1GB_FD | \
214 OFPPF_10GB_FD | OFPPF_COPPER | OFPPF_FIBER | \
215 OFPPF_AUTONEG | OFPPF_PAUSE | OFPPF_PAUSE_ASYM))
217 #define OFPQT_NONE 0x0000
218 #define OFPQT_MIN_RATE 0x0001
219 static const struct tok ofpqt_str
[] = {
220 { OFPQT_NONE
, "NONE" },
221 { OFPQT_MIN_RATE
, "MIN_RATE" },
225 #define OFPFW_IN_PORT (1 << 0)
226 #define OFPFW_DL_VLAN (1 << 1)
227 #define OFPFW_DL_SRC (1 << 2)
228 #define OFPFW_DL_DST (1 << 3)
229 #define OFPFW_DL_TYPE (1 << 4)
230 #define OFPFW_NW_PROTO (1 << 5)
231 #define OFPFW_TP_SRC (1 << 6)
232 #define OFPFW_TP_DST (1 << 7)
233 #define OFPFW_NW_SRC_SHIFT 8
234 #define OFPFW_NW_SRC_BITS 6
235 #define OFPFW_NW_SRC_MASK (((1 << OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT)
236 #define OFPFW_NW_DST_SHIFT 14
237 #define OFPFW_NW_DST_BITS 6
238 #define OFPFW_NW_DST_MASK (((1 << OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT)
239 #define OFPFW_DL_VLAN_PCP (1 << 20)
240 #define OFPFW_NW_TOS (1 << 21)
241 #define OFPFW_ALL ((1 << 22) - 1)
242 static const struct tok ofpfw_bm
[] = {
243 { OFPFW_IN_PORT
, "IN_PORT" },
244 { OFPFW_DL_VLAN
, "DL_VLAN" },
245 { OFPFW_DL_SRC
, "DL_SRC" },
246 { OFPFW_DL_DST
, "DL_DST" },
247 { OFPFW_DL_TYPE
, "DL_TYPE" },
248 { OFPFW_NW_PROTO
, "NW_PROTO" },
249 { OFPFW_TP_SRC
, "TP_SRC" },
250 { OFPFW_TP_DST
, "TP_DST" },
251 { OFPFW_DL_VLAN_PCP
, "DL_VLAN_PCP" },
252 { OFPFW_NW_TOS
, "NW_TOS" },
255 /* The above array does not include bits 8~13 (OFPFW_NW_SRC_*) and 14~19
256 * (OFPFW_NW_DST_*), which are not a part of the bitmap and require decoding
257 * other than that of tok2str(). The macro below includes these bits such that
258 * they are not reported as bogus in the decoding. */
259 #define OFPFW_U (~(OFPFW_ALL))
261 #define OFPAT_OUTPUT 0x0000
262 #define OFPAT_SET_VLAN_VID 0x0001
263 #define OFPAT_SET_VLAN_PCP 0x0002
264 #define OFPAT_STRIP_VLAN 0x0003
265 #define OFPAT_SET_DL_SRC 0x0004
266 #define OFPAT_SET_DL_DST 0x0005
267 #define OFPAT_SET_NW_SRC 0x0006
268 #define OFPAT_SET_NW_DST 0x0007
269 #define OFPAT_SET_NW_TOS 0x0008
270 #define OFPAT_SET_TP_SRC 0x0009
271 #define OFPAT_SET_TP_DST 0x000a
272 #define OFPAT_ENQUEUE 0x000b
273 #define OFPAT_VENDOR 0xffff
274 static const struct tok ofpat_str
[] = {
275 { OFPAT_OUTPUT
, "OUTPUT" },
276 { OFPAT_SET_VLAN_VID
, "SET_VLAN_VID" },
277 { OFPAT_SET_VLAN_PCP
, "SET_VLAN_PCP" },
278 { OFPAT_STRIP_VLAN
, "STRIP_VLAN" },
279 { OFPAT_SET_DL_SRC
, "SET_DL_SRC" },
280 { OFPAT_SET_DL_DST
, "SET_DL_DST" },
281 { OFPAT_SET_NW_SRC
, "SET_NW_SRC" },
282 { OFPAT_SET_NW_DST
, "SET_NW_DST" },
283 { OFPAT_SET_NW_TOS
, "SET_NW_TOS" },
284 { OFPAT_SET_TP_SRC
, "SET_TP_SRC" },
285 { OFPAT_SET_TP_DST
, "SET_TP_DST" },
286 { OFPAT_ENQUEUE
, "ENQUEUE" },
287 { OFPAT_VENDOR
, "VENDOR" },
291 /* bit-shifted, w/o vendor action */
292 static const struct tok ofpat_bm
[] = {
293 { 1 << OFPAT_OUTPUT
, "OUTPUT" },
294 { 1 << OFPAT_SET_VLAN_VID
, "SET_VLAN_VID" },
295 { 1 << OFPAT_SET_VLAN_PCP
, "SET_VLAN_PCP" },
296 { 1 << OFPAT_STRIP_VLAN
, "STRIP_VLAN" },
297 { 1 << OFPAT_SET_DL_SRC
, "SET_DL_SRC" },
298 { 1 << OFPAT_SET_DL_DST
, "SET_DL_DST" },
299 { 1 << OFPAT_SET_NW_SRC
, "SET_NW_SRC" },
300 { 1 << OFPAT_SET_NW_DST
, "SET_NW_DST" },
301 { 1 << OFPAT_SET_NW_TOS
, "SET_NW_TOS" },
302 { 1 << OFPAT_SET_TP_SRC
, "SET_TP_SRC" },
303 { 1 << OFPAT_SET_TP_DST
, "SET_TP_DST" },
304 { 1 << OFPAT_ENQUEUE
, "ENQUEUE" },
307 #define OFPAT_U (~(1 << OFPAT_OUTPUT | 1 << OFPAT_SET_VLAN_VID | \
308 1 << OFPAT_SET_VLAN_PCP | 1 << OFPAT_STRIP_VLAN | \
309 1 << OFPAT_SET_DL_SRC | 1 << OFPAT_SET_DL_DST | \
310 1 << OFPAT_SET_NW_SRC | 1 << OFPAT_SET_NW_DST | \
311 1 << OFPAT_SET_NW_TOS | 1 << OFPAT_SET_TP_SRC | \
312 1 << OFPAT_SET_TP_DST | 1 << OFPAT_ENQUEUE))
314 #define OFPC_FLOW_STATS (1 << 0)
315 #define OFPC_TABLE_STATS (1 << 1)
316 #define OFPC_PORT_STATS (1 << 2)
317 #define OFPC_STP (1 << 3)
318 #define OFPC_RESERVED (1 << 4)
319 #define OFPC_IP_REASM (1 << 5)
320 #define OFPC_QUEUE_STATS (1 << 6)
321 #define OFPC_ARP_MATCH_IP (1 << 7)
322 static const struct tok ofp_capabilities_bm
[] = {
323 { OFPC_FLOW_STATS
, "FLOW_STATS" },
324 { OFPC_TABLE_STATS
, "TABLE_STATS" },
325 { OFPC_PORT_STATS
, "PORT_STATS" },
327 { OFPC_RESERVED
, "RESERVED" }, /* not in the mask below */
328 { OFPC_IP_REASM
, "IP_REASM" },
329 { OFPC_QUEUE_STATS
, "QUEUE_STATS" },
330 { OFPC_ARP_MATCH_IP
, "ARP_MATCH_IP" },
333 #define OFPCAP_U (~(OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS | \
334 OFPC_STP | OFPC_IP_REASM | OFPC_QUEUE_STATS | \
337 #define OFPC_FRAG_NORMAL 0x0000
338 #define OFPC_FRAG_DROP 0x0001
339 #define OFPC_FRAG_REASM 0x0002
340 #define OFPC_FRAG_MASK 0x0003
341 static const struct tok ofp_config_str
[] = {
342 { OFPC_FRAG_NORMAL
, "FRAG_NORMAL" },
343 { OFPC_FRAG_DROP
, "FRAG_DROP" },
344 { OFPC_FRAG_REASM
, "FRAG_REASM" },
348 #define OFPFC_ADD 0x0000
349 #define OFPFC_MODIFY 0x0001
350 #define OFPFC_MODIFY_STRICT 0x0002
351 #define OFPFC_DELETE 0x0003
352 #define OFPFC_DELETE_STRICT 0x0004
353 static const struct tok ofpfc_str
[] = {
354 { OFPFC_ADD
, "ADD" },
355 { OFPFC_MODIFY
, "MODIFY" },
356 { OFPFC_MODIFY_STRICT
, "MODIFY_STRICT" },
357 { OFPFC_DELETE
, "DELETE" },
358 { OFPFC_DELETE_STRICT
, "DELETE_STRICT" },
362 static const struct tok bufferid_str
[] = {
363 { 0xffffffff, "NONE" },
367 #define OFPFF_SEND_FLOW_REM (1 << 0)
368 #define OFPFF_CHECK_OVERLAP (1 << 1)
369 #define OFPFF_EMERG (1 << 2)
370 static const struct tok ofpff_bm
[] = {
371 { OFPFF_SEND_FLOW_REM
, "SEND_FLOW_REM" },
372 { OFPFF_CHECK_OVERLAP
, "CHECK_OVERLAP" },
373 { OFPFF_EMERG
, "EMERG" },
376 #define OFPFF_U (~(OFPFF_SEND_FLOW_REM | OFPFF_CHECK_OVERLAP | OFPFF_EMERG))
378 #define OFPST_DESC 0x0000
379 #define OFPST_FLOW 0x0001
380 #define OFPST_AGGREGATE 0x0002
381 #define OFPST_TABLE 0x0003
382 #define OFPST_PORT 0x0004
383 #define OFPST_QUEUE 0x0005
384 #define OFPST_VENDOR 0xffff
385 static const struct tok ofpst_str
[] = {
386 { OFPST_DESC
, "DESC" },
387 { OFPST_FLOW
, "FLOW" },
388 { OFPST_AGGREGATE
, "AGGREGATE" },
389 { OFPST_TABLE
, "TABLE" },
390 { OFPST_PORT
, "PORT" },
391 { OFPST_QUEUE
, "QUEUE" },
392 { OFPST_VENDOR
, "VENDOR" },
396 static const struct tok tableid_str
[] = {
402 #define OFPQ_ALL 0xffffffff
403 static const struct tok ofpq_str
[] = {
408 #define OFPSF_REPLY_MORE 0x0001
409 static const struct tok ofpsf_reply_bm
[] = {
410 { OFPSF_REPLY_MORE
, "MORE" },
413 #define OFPSF_REPLY_U (~(OFPSF_REPLY_MORE))
415 #define OFPR_NO_MATCH 0x00
416 #define OFPR_ACTION 0x01
417 static const struct tok ofpr_str
[] = {
418 { OFPR_NO_MATCH
, "NO_MATCH" },
419 { OFPR_ACTION
, "ACTION" },
423 #define OFPRR_IDLE_TIMEOUT 0x00
424 #define OFPRR_HARD_TIMEOUT 0x01
425 #define OFPRR_DELETE 0x02
426 static const struct tok ofprr_str
[] = {
427 { OFPRR_IDLE_TIMEOUT
, "IDLE_TIMEOUT" },
428 { OFPRR_HARD_TIMEOUT
, "HARD_TIMEOUT" },
429 { OFPRR_DELETE
, "DELETE" },
433 #define OFPPR_ADD 0x00
434 #define OFPPR_DELETE 0x01
435 #define OFPPR_MODIFY 0x02
436 static const struct tok ofppr_str
[] = {
437 { OFPPR_ADD
, "ADD" },
438 { OFPPR_DELETE
, "DELETE" },
439 { OFPPR_MODIFY
, "MODIFY" },
443 #define OFPET_HELLO_FAILED 0x0000
444 #define OFPET_BAD_REQUEST 0x0001
445 #define OFPET_BAD_ACTION 0x0002
446 #define OFPET_FLOW_MOD_FAILED 0x0003
447 #define OFPET_PORT_MOD_FAILED 0x0004
448 #define OFPET_QUEUE_OP_FAILED 0x0005
449 static const struct tok ofpet_str
[] = {
450 { OFPET_HELLO_FAILED
, "HELLO_FAILED" },
451 { OFPET_BAD_REQUEST
, "BAD_REQUEST" },
452 { OFPET_BAD_ACTION
, "BAD_ACTION" },
453 { OFPET_FLOW_MOD_FAILED
, "FLOW_MOD_FAILED" },
454 { OFPET_PORT_MOD_FAILED
, "PORT_MOD_FAILED" },
455 { OFPET_QUEUE_OP_FAILED
, "QUEUE_OP_FAILED" },
459 #define OFPHFC_INCOMPATIBLE 0x0000
460 #define OFPHFC_EPERM 0x0001
461 static const struct tok ofphfc_str
[] = {
462 { OFPHFC_INCOMPATIBLE
, "INCOMPATIBLE" },
463 { OFPHFC_EPERM
, "EPERM" },
467 #define OFPBRC_BAD_VERSION 0x0000
468 #define OFPBRC_BAD_TYPE 0x0001
469 #define OFPBRC_BAD_STAT 0x0002
470 #define OFPBRC_BAD_VENDOR 0x0003
471 #define OFPBRC_BAD_SUBTYPE 0x0004
472 #define OFPBRC_EPERM 0x0005
473 #define OFPBRC_BAD_LEN 0x0006
474 #define OFPBRC_BUFFER_EMPTY 0x0007
475 #define OFPBRC_BUFFER_UNKNOWN 0x0008
476 static const struct tok ofpbrc_str
[] = {
477 { OFPBRC_BAD_VERSION
, "BAD_VERSION" },
478 { OFPBRC_BAD_TYPE
, "BAD_TYPE" },
479 { OFPBRC_BAD_STAT
, "BAD_STAT" },
480 { OFPBRC_BAD_VENDOR
, "BAD_VENDOR" },
481 { OFPBRC_BAD_SUBTYPE
, "BAD_SUBTYPE" },
482 { OFPBRC_EPERM
, "EPERM" },
483 { OFPBRC_BAD_LEN
, "BAD_LEN" },
484 { OFPBRC_BUFFER_EMPTY
, "BUFFER_EMPTY" },
485 { OFPBRC_BUFFER_UNKNOWN
, "BUFFER_UNKNOWN" },
489 #define OFPBAC_BAD_TYPE 0x0000
490 #define OFPBAC_BAD_LEN 0x0001
491 #define OFPBAC_BAD_VENDOR 0x0002
492 #define OFPBAC_BAD_VENDOR_TYPE 0x0003
493 #define OFPBAC_BAD_OUT_PORT 0x0004
494 #define OFPBAC_BAD_ARGUMENT 0x0005
495 #define OFPBAC_EPERM 0x0006
496 #define OFPBAC_TOO_MANY 0x0007
497 #define OFPBAC_BAD_QUEUE 0x0008
498 static const struct tok ofpbac_str
[] = {
499 { OFPBAC_BAD_TYPE
, "BAD_TYPE" },
500 { OFPBAC_BAD_LEN
, "BAD_LEN" },
501 { OFPBAC_BAD_VENDOR
, "BAD_VENDOR" },
502 { OFPBAC_BAD_VENDOR_TYPE
, "BAD_VENDOR_TYPE" },
503 { OFPBAC_BAD_OUT_PORT
, "BAD_OUT_PORT" },
504 { OFPBAC_BAD_ARGUMENT
, "BAD_ARGUMENT" },
505 { OFPBAC_EPERM
, "EPERM" },
506 { OFPBAC_TOO_MANY
, "TOO_MANY" },
507 { OFPBAC_BAD_QUEUE
, "BAD_QUEUE" },
511 #define OFPFMFC_ALL_TABLES_FULL 0x0000
512 #define OFPFMFC_OVERLAP 0x0001
513 #define OFPFMFC_EPERM 0x0002
514 #define OFPFMFC_BAD_EMERG_TIMEOUT 0x0003
515 #define OFPFMFC_BAD_COMMAND 0x0004
516 #define OFPFMFC_UNSUPPORTED 0x0005
517 static const struct tok ofpfmfc_str
[] = {
518 { OFPFMFC_ALL_TABLES_FULL
, "ALL_TABLES_FULL" },
519 { OFPFMFC_OVERLAP
, "OVERLAP" },
520 { OFPFMFC_EPERM
, "EPERM" },
521 { OFPFMFC_BAD_EMERG_TIMEOUT
, "BAD_EMERG_TIMEOUT" },
522 { OFPFMFC_BAD_COMMAND
, "BAD_COMMAND" },
523 { OFPFMFC_UNSUPPORTED
, "UNSUPPORTED" },
527 #define OFPPMFC_BAD_PORT 0x0000
528 #define OFPPMFC_BAD_HW_ADDR 0x0001
529 static const struct tok ofppmfc_str
[] = {
530 { OFPPMFC_BAD_PORT
, "BAD_PORT" },
531 { OFPPMFC_BAD_HW_ADDR
, "BAD_HW_ADDR" },
535 #define OFPQOFC_BAD_PORT 0x0000
536 #define OFPQOFC_BAD_QUEUE 0x0001
537 #define OFPQOFC_EPERM 0x0002
538 static const struct tok ofpqofc_str
[] = {
539 { OFPQOFC_BAD_PORT
, "BAD_PORT" },
540 { OFPQOFC_BAD_QUEUE
, "BAD_QUEUE" },
541 { OFPQOFC_EPERM
, "EPERM" },
545 static const struct tok empty_str
[] = {
549 /* lengths (fixed or minimal) of particular protocol structures */
550 #define OF_SWITCH_CONFIG_LEN 12
551 #define OF_PHY_PORT_LEN 48
552 #define OF_SWITCH_FEATURES_LEN 32
553 #define OF_PORT_STATUS_LEN 64
554 #define OF_PORT_MOD_LEN 32
555 #define OF_PACKET_IN_LEN 20
556 #define OF_ACTION_OUTPUT_LEN 8
557 #define OF_ACTION_VLAN_VID_LEN 8
558 #define OF_ACTION_VLAN_PCP_LEN 8
559 #define OF_ACTION_DL_ADDR_LEN 16
560 #define OF_ACTION_NW_ADDR_LEN 8
561 #define OF_ACTION_TP_PORT_LEN 8
562 #define OF_ACTION_NW_TOS_LEN 8
563 #define OF_ACTION_VENDOR_HEADER_LEN 8
564 #define OF_ACTION_HEADER_LEN 8
565 #define OF_PACKET_OUT_LEN 16
566 #define OF_MATCH_LEN 40
567 #define OF_FLOW_MOD_LEN 72
568 #define OF_FLOW_REMOVED_LEN 88
569 #define OF_ERROR_MSG_LEN 12
570 #define OF_STATS_REQUEST_LEN 12
571 #define OF_STATS_REPLY_LEN 12
572 #define OF_DESC_STATS_LEN 1056
573 #define OF_FLOW_STATS_REQUEST_LEN 44
574 #define OF_FLOW_STATS_LEN 88
575 #define OF_AGGREGATE_STATS_REQUEST_LEN 44
576 #define OF_AGGREGATE_STATS_REPLY_LEN 24
577 #define OF_TABLE_STATS_LEN 64
578 #define OF_PORT_STATS_REQUEST_LEN 8
579 #define OF_PORT_STATS_LEN 104
580 #define OF_VENDOR_HEADER_LEN 12
581 #define OF_QUEUE_PROP_HEADER_LEN 8
582 #define OF_QUEUE_PROP_MIN_RATE_LEN 16
583 #define OF_PACKET_QUEUE_LEN 8
584 #define OF_QUEUE_GET_CONFIG_REQUEST_LEN 12
585 #define OF_QUEUE_GET_CONFIG_REPLY_LEN 16
586 #define OF_ACTION_ENQUEUE_LEN 16
587 #define OF_QUEUE_STATS_REQUEST_LEN 8
588 #define OF_QUEUE_STATS_LEN 32
590 /* miscellaneous constants from [OF10] */
591 #define OFP_MAX_TABLE_NAME_LEN 32
592 #define OFP_MAX_PORT_NAME_LEN 16
593 #define DESC_STR_LEN 256
594 #define SERIAL_NUM_LEN 32
595 #define OFP_VLAN_NONE 0xffff
597 /* vendor extensions */
598 #define BSN_SET_IP_MASK 0
599 #define BSN_GET_IP_MASK_REQUEST 1
600 #define BSN_GET_IP_MASK_REPLY 2
601 #define BSN_SET_MIRRORING 3
602 #define BSN_GET_MIRRORING_REQUEST 4
603 #define BSN_GET_MIRRORING_REPLY 5
604 #define BSN_SHELL_COMMAND 6
605 #define BSN_SHELL_OUTPUT 7
606 #define BSN_SHELL_STATUS 8
607 #define BSN_GET_INTERFACES_REQUEST 9
608 #define BSN_GET_INTERFACES_REPLY 10
609 #define BSN_SET_PKTIN_SUPPRESSION_REQUEST 11
610 #define BSN_SET_L2_TABLE_REQUEST 12
611 #define BSN_GET_L2_TABLE_REQUEST 13
612 #define BSN_GET_L2_TABLE_REPLY 14
613 #define BSN_VIRTUAL_PORT_CREATE_REQUEST 15
614 #define BSN_VIRTUAL_PORT_CREATE_REPLY 16
615 #define BSN_VIRTUAL_PORT_REMOVE_REQUEST 17
616 #define BSN_BW_ENABLE_SET_REQUEST 18
617 #define BSN_BW_ENABLE_GET_REQUEST 19
618 #define BSN_BW_ENABLE_GET_REPLY 20
619 #define BSN_BW_CLEAR_DATA_REQUEST 21
620 #define BSN_BW_CLEAR_DATA_REPLY 22
621 #define BSN_BW_ENABLE_SET_REPLY 23
622 #define BSN_SET_L2_TABLE_REPLY 24
623 #define BSN_SET_PKTIN_SUPPRESSION_REPLY 25
624 #define BSN_VIRTUAL_PORT_REMOVE_REPLY 26
625 #define BSN_HYBRID_GET_REQUEST 27
626 #define BSN_HYBRID_GET_REPLY 28
629 #define BSN_PDU_TX_REQUEST 31
630 #define BSN_PDU_TX_REPLY 32
631 #define BSN_PDU_RX_REQUEST 33
632 #define BSN_PDU_RX_REPLY 34
633 #define BSN_PDU_RX_TIMEOUT 35
635 static const struct tok bsn_subtype_str
[] = {
636 { BSN_SET_IP_MASK
, "SET_IP_MASK" },
637 { BSN_GET_IP_MASK_REQUEST
, "GET_IP_MASK_REQUEST" },
638 { BSN_GET_IP_MASK_REPLY
, "GET_IP_MASK_REPLY" },
639 { BSN_SET_MIRRORING
, "SET_MIRRORING" },
640 { BSN_GET_MIRRORING_REQUEST
, "GET_MIRRORING_REQUEST" },
641 { BSN_GET_MIRRORING_REPLY
, "GET_MIRRORING_REPLY" },
642 { BSN_SHELL_COMMAND
, "SHELL_COMMAND" },
643 { BSN_SHELL_OUTPUT
, "SHELL_OUTPUT" },
644 { BSN_SHELL_STATUS
, "SHELL_STATUS" },
645 { BSN_GET_INTERFACES_REQUEST
, "GET_INTERFACES_REQUEST" },
646 { BSN_GET_INTERFACES_REPLY
, "GET_INTERFACES_REPLY" },
647 { BSN_SET_PKTIN_SUPPRESSION_REQUEST
, "SET_PKTIN_SUPPRESSION_REQUEST" },
648 { BSN_SET_L2_TABLE_REQUEST
, "SET_L2_TABLE_REQUEST" },
649 { BSN_GET_L2_TABLE_REQUEST
, "GET_L2_TABLE_REQUEST" },
650 { BSN_GET_L2_TABLE_REPLY
, "GET_L2_TABLE_REPLY" },
651 { BSN_VIRTUAL_PORT_CREATE_REQUEST
, "VIRTUAL_PORT_CREATE_REQUEST" },
652 { BSN_VIRTUAL_PORT_CREATE_REPLY
, "VIRTUAL_PORT_CREATE_REPLY" },
653 { BSN_VIRTUAL_PORT_REMOVE_REQUEST
, "VIRTUAL_PORT_REMOVE_REQUEST" },
654 { BSN_BW_ENABLE_SET_REQUEST
, "BW_ENABLE_SET_REQUEST" },
655 { BSN_BW_ENABLE_GET_REQUEST
, "BW_ENABLE_GET_REQUEST" },
656 { BSN_BW_ENABLE_GET_REPLY
, "BW_ENABLE_GET_REPLY" },
657 { BSN_BW_CLEAR_DATA_REQUEST
, "BW_CLEAR_DATA_REQUEST" },
658 { BSN_BW_CLEAR_DATA_REPLY
, "BW_CLEAR_DATA_REPLY" },
659 { BSN_BW_ENABLE_SET_REPLY
, "BW_ENABLE_SET_REPLY" },
660 { BSN_SET_L2_TABLE_REPLY
, "SET_L2_TABLE_REPLY" },
661 { BSN_SET_PKTIN_SUPPRESSION_REPLY
, "SET_PKTIN_SUPPRESSION_REPLY" },
662 { BSN_VIRTUAL_PORT_REMOVE_REPLY
, "VIRTUAL_PORT_REMOVE_REPLY" },
663 { BSN_HYBRID_GET_REQUEST
, "HYBRID_GET_REQUEST" },
664 { BSN_HYBRID_GET_REPLY
, "HYBRID_GET_REPLY" },
665 { BSN_PDU_TX_REQUEST
, "PDU_TX_REQUEST" },
666 { BSN_PDU_TX_REPLY
, "PDU_TX_REPLY" },
667 { BSN_PDU_RX_REQUEST
, "PDU_RX_REQUEST" },
668 { BSN_PDU_RX_REPLY
, "PDU_RX_REPLY" },
669 { BSN_PDU_RX_TIMEOUT
, "PDU_RX_TIMEOUT" },
675 vlan_str(const uint16_t vid
) {
676 static char buf
[sizeof("65535 (bogus)")];
679 if (vid
== OFP_VLAN_NONE
)
681 fmt
= (vid
> 0 && vid
< 0x0fff) ? "%u" : "%u (bogus)";
682 snprintf(buf
, sizeof(buf
), fmt
, vid
);
687 pcp_str(const uint8_t pcp
) {
688 static char buf
[sizeof("255 (bogus)")];
689 snprintf(buf
, sizeof(buf
), pcp
<= 7 ? "%u" : "%u (bogus)", pcp
);
694 of10_bitmap_print(netdissect_options
*ndo
,
695 const struct tok
*t
, const uint32_t v
, const uint32_t u
) {
696 const char *sep
= " (";
701 for (; t
->s
!= NULL
; t
++)
703 ND_PRINT((ndo
, "%s%s", sep
, t
->s
));
706 /* unassigned bits? */
707 ND_PRINT((ndo
, v
& u
? ") (bogus)" : ")"));
710 static const u_char
*
711 of10_data_print(netdissect_options
*ndo
,
712 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
716 ND_PRINT((ndo
, "\n\t data (%u octets)", len
));
717 ND_TCHECK2(*cp
, len
);
718 if (ndo
->ndo_vflag
>= 2)
719 hex_and_ascii_print(ndo
, "\n\t ", cp
, len
);
723 ND_PRINT((ndo
, "%s", tstr
));
727 static const u_char
*
728 of10_bsn_message_print(netdissect_options
*ndo
,
729 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
730 const u_char
*cp0
= cp
;
737 subtype
= EXTRACT_32BITS(cp
);
739 ND_PRINT((ndo
, "\n\t subtype %s", tok2str(bsn_subtype_str
, "unknown (0x%08x)", subtype
)));
741 case BSN_GET_IP_MASK_REQUEST
:
744 * 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
745 * +---------------+---------------+---------------+---------------+
747 * +---------------+---------------+---------------+---------------+
749 * +---------------+---------------+---------------+---------------+
751 * +---------------+---------------+---------------+---------------+
758 ND_PRINT((ndo
, ", index %u", *cp
));
764 case BSN_SET_IP_MASK
:
765 case BSN_GET_IP_MASK_REPLY
:
768 * 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
769 * +---------------+---------------+---------------+---------------+
771 * +---------------+---------------+---------------+---------------+
773 * +---------------+---------------+---------------+---------------+
775 * +---------------+---------------+---------------+---------------+
782 ND_PRINT((ndo
, ", index %u", *cp
));
789 ND_PRINT((ndo
, ", mask %s", ipaddr_string(ndo
, cp
)));
792 case BSN_SET_MIRRORING
:
793 case BSN_GET_MIRRORING_REQUEST
:
794 case BSN_GET_MIRRORING_REPLY
:
797 * 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
798 * +---------------+---------------+---------------+---------------+
800 * +---------------+---------------+---------------+---------------+
802 * +---------------+---------------+---------------+---------------+
809 ND_PRINT((ndo
, ", ports %u", *cp
));
815 case BSN_GET_INTERFACES_REQUEST
:
816 case BSN_GET_L2_TABLE_REQUEST
:
817 case BSN_BW_ENABLE_GET_REQUEST
:
818 case BSN_BW_CLEAR_DATA_REQUEST
:
819 case BSN_HYBRID_GET_REQUEST
:
822 * 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
823 * +---------------+---------------+---------------+---------------+
825 * +---------------+---------------+---------------+---------------+
831 case BSN_VIRTUAL_PORT_REMOVE_REQUEST
:
834 * 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
835 * +---------------+---------------+---------------+---------------+
837 * +---------------+---------------+---------------+---------------+
839 * +---------------+---------------+---------------+---------------+
846 ND_PRINT((ndo
, ", vport_no %u", EXTRACT_32BITS(cp
)));
850 ND_TCHECK2(*cp
, len
- 4);
855 corrupt
: /* skip the undersized data */
856 ND_PRINT((ndo
, "%s", cstr
));
857 ND_TCHECK2(*cp0
, len
);
860 ND_PRINT((ndo
, "%s", tstr
));
864 static const u_char
*
865 of10_vendor_message_print(netdissect_options
*ndo
,
866 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
868 const u_char
*(*decoder
)(netdissect_options
*, const u_char
*, const u_char
*, u_int
);
874 vendor
= EXTRACT_32BITS(cp
);
876 ND_PRINT((ndo
, ", vendor 0x%08x (%s)", vendor
, of_vendor_name(vendor
)));
879 vendor
== OUI_BSN
? of10_bsn_message_print
:
881 return decoder(ndo
, cp
, ep
, len
- 4);
883 corrupt
: /* skip the undersized data */
884 ND_PRINT((ndo
, "%s", cstr
));
885 ND_TCHECK2(*cp
, len
);
888 ND_PRINT((ndo
, "%s", tstr
));
892 /* Vendor ID is mandatory, data is optional. */
893 static const u_char
*
894 of10_vendor_data_print(netdissect_options
*ndo
,
895 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
902 vendor
= EXTRACT_32BITS(cp
);
904 ND_PRINT((ndo
, ", vendor 0x%08x (%s)", vendor
, of_vendor_name(vendor
)));
906 return of10_data_print(ndo
, cp
, ep
, len
- 4);
908 corrupt
: /* skip the undersized data */
909 ND_PRINT((ndo
, "%s", cstr
));
910 ND_TCHECK2(*cp
, len
);
913 ND_PRINT((ndo
, "%s", tstr
));
917 static const u_char
*
918 of10_packet_data_print(netdissect_options
*ndo
,
919 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
923 ND_PRINT((ndo
, "\n\t data (%u octets)", len
));
924 if (ndo
->ndo_vflag
< 3)
926 ND_TCHECK2(*cp
, len
);
928 ND_PRINT((ndo
, ", frame decoding below\n"));
929 ether_print(ndo
, cp
, len
, ndo
->ndo_snapend
- cp
, NULL
, NULL
);
934 ND_PRINT((ndo
, "%s", tstr
));
938 /* [OF10] Section 5.2.1 */
939 static const u_char
*
940 of10_phy_ports_print(netdissect_options
*ndo
,
941 const u_char
*cp
, const u_char
*ep
, u_int len
) {
942 const u_char
*cp0
= cp
;
943 const u_int len0
= len
;
946 if (len
< OF_PHY_PORT_LEN
)
950 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
953 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
954 ND_PRINT((ndo
, ", hw_addr %s", etheraddr_string(ndo
, cp
)));
955 cp
+= ETHER_ADDR_LEN
;
957 ND_TCHECK2(*cp
, OFP_MAX_PORT_NAME_LEN
);
958 ND_PRINT((ndo
, ", name '"));
959 fn_print(ndo
, cp
, cp
+ OFP_MAX_PORT_NAME_LEN
);
960 ND_PRINT((ndo
, "'"));
961 cp
+= OFP_MAX_PORT_NAME_LEN
;
963 if (ndo
->ndo_vflag
< 2) {
970 ND_PRINT((ndo
, "\n\t config 0x%08x", EXTRACT_32BITS(cp
)));
971 of10_bitmap_print(ndo
, ofppc_bm
, EXTRACT_32BITS(cp
), OFPPC_U
);
975 ND_PRINT((ndo
, "\n\t state 0x%08x", EXTRACT_32BITS(cp
)));
976 of10_bitmap_print(ndo
, ofpps_bm
, EXTRACT_32BITS(cp
), OFPPS_U
);
980 ND_PRINT((ndo
, "\n\t curr 0x%08x", EXTRACT_32BITS(cp
)));
981 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
985 ND_PRINT((ndo
, "\n\t advertised 0x%08x", EXTRACT_32BITS(cp
)));
986 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
990 ND_PRINT((ndo
, "\n\t supported 0x%08x", EXTRACT_32BITS(cp
)));
991 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
995 ND_PRINT((ndo
, "\n\t peer 0x%08x", EXTRACT_32BITS(cp
)));
996 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
999 len
-= OF_PHY_PORT_LEN
;
1003 corrupt
: /* skip the undersized trailing data */
1004 ND_PRINT((ndo
, "%s", cstr
));
1005 ND_TCHECK2(*cp0
, len0
);
1008 ND_PRINT((ndo
, "%s", tstr
));
1012 /* [OF10] Section 5.2.2 */
1013 static const u_char
*
1014 of10_queue_props_print(netdissect_options
*ndo
,
1015 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1016 const u_char
*cp0
= cp
;
1017 const u_int len0
= len
;
1018 uint16_t property
, plen
, rate
;
1021 u_char plen_bogus
= 0, skip
= 0;
1023 if (len
< OF_QUEUE_PROP_HEADER_LEN
)
1027 property
= EXTRACT_16BITS(cp
);
1029 ND_PRINT((ndo
, "\n\t property %s", tok2str(ofpqt_str
, "invalid (0x%04x)", property
)));
1032 plen
= EXTRACT_16BITS(cp
);
1034 ND_PRINT((ndo
, ", len %u", plen
));
1035 if (plen
< OF_QUEUE_PROP_HEADER_LEN
|| plen
> len
)
1040 /* property-specific constraints and decoding */
1043 plen_bogus
= plen
!= OF_QUEUE_PROP_HEADER_LEN
;
1045 case OFPQT_MIN_RATE
:
1046 plen_bogus
= plen
!= OF_QUEUE_PROP_MIN_RATE_LEN
;
1052 ND_PRINT((ndo
, " (bogus)"));
1056 ND_TCHECK2(*cp
, plen
- 4);
1060 if (property
== OFPQT_MIN_RATE
) { /* the only case of property decoding */
1063 rate
= EXTRACT_16BITS(cp
);
1066 ND_PRINT((ndo
, ", rate disabled"));
1068 ND_PRINT((ndo
, ", rate %u.%u%%", rate
/ 10, rate
% 10));
1078 corrupt
: /* skip the rest of queue properties */
1079 ND_PRINT((ndo
, "%s", cstr
));
1080 ND_TCHECK2(*cp0
, len0
);
1083 ND_PRINT((ndo
, "%s", tstr
));
1088 static const u_char
*
1089 of10_queues_print(netdissect_options
*ndo
,
1090 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1091 const u_char
*cp0
= cp
;
1092 const u_int len0
= len
;
1096 if (len
< OF_PACKET_QUEUE_LEN
)
1100 ND_PRINT((ndo
, "\n\t queue_id %u", EXTRACT_32BITS(cp
)));
1104 desclen
= EXTRACT_16BITS(cp
);
1106 ND_PRINT((ndo
, ", len %u", desclen
));
1107 if (desclen
< OF_PACKET_QUEUE_LEN
|| desclen
> len
)
1113 if (ndo
->ndo_vflag
< 2) {
1114 ND_TCHECK2(*cp
, desclen
- OF_PACKET_QUEUE_LEN
);
1115 cp
+= desclen
- OF_PACKET_QUEUE_LEN
;
1118 if (ep
== (cp
= of10_queue_props_print(ndo
, cp
, ep
, desclen
- OF_PACKET_QUEUE_LEN
)))
1119 return ep
; /* end of snapshot */
1125 corrupt
: /* skip the rest of queues */
1126 ND_PRINT((ndo
, "%s", cstr
));
1127 ND_TCHECK2(*cp0
, len0
);
1130 ND_PRINT((ndo
, "%s", tstr
));
1134 /* [OF10] Section 5.2.3 */
1135 static const u_char
*
1136 of10_match_print(netdissect_options
*ndo
,
1137 const char *pfx
, const u_char
*cp
, const u_char
*ep
) {
1142 const char *field_name
;
1146 wildcards
= EXTRACT_32BITS(cp
);
1147 if (wildcards
& OFPFW_U
)
1148 ND_PRINT((ndo
, "%swildcards 0x%08x (bogus)", pfx
, wildcards
));
1152 if (! (wildcards
& OFPFW_IN_PORT
))
1153 ND_PRINT((ndo
, "%smatch in_port %s", pfx
, tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1156 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
1157 if (! (wildcards
& OFPFW_DL_SRC
))
1158 ND_PRINT((ndo
, "%smatch dl_src %s", pfx
, etheraddr_string(ndo
, cp
)));
1159 cp
+= ETHER_ADDR_LEN
;
1161 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
1162 if (! (wildcards
& OFPFW_DL_DST
))
1163 ND_PRINT((ndo
, "%smatch dl_dst %s", pfx
, etheraddr_string(ndo
, cp
)));
1164 cp
+= ETHER_ADDR_LEN
;
1167 if (! (wildcards
& OFPFW_DL_VLAN
))
1168 ND_PRINT((ndo
, "%smatch dl_vlan %s", pfx
, vlan_str(EXTRACT_16BITS(cp
))));
1172 if (! (wildcards
& OFPFW_DL_VLAN_PCP
))
1173 ND_PRINT((ndo
, "%smatch dl_vlan_pcp %s", pfx
, pcp_str(*cp
)));
1180 dl_type
= EXTRACT_16BITS(cp
);
1182 if (! (wildcards
& OFPFW_DL_TYPE
))
1183 ND_PRINT((ndo
, "%smatch dl_type 0x%04x", pfx
, dl_type
));
1186 if (! (wildcards
& OFPFW_NW_TOS
))
1187 ND_PRINT((ndo
, "%smatch nw_tos 0x%02x", pfx
, *cp
));
1193 if (! (wildcards
& OFPFW_NW_PROTO
)) {
1194 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_ARP
1195 ? "arp_opcode" : "nw_proto";
1196 ND_PRINT((ndo
, "%smatch %s %u", pfx
, field_name
, nw_proto
));
1203 nw_bits
= (wildcards
& OFPFW_NW_SRC_MASK
) >> OFPFW_NW_SRC_SHIFT
;
1205 ND_PRINT((ndo
, "%smatch nw_src %s/%u", pfx
, ipaddr_string(ndo
, cp
), 32 - nw_bits
));
1209 nw_bits
= (wildcards
& OFPFW_NW_DST_MASK
) >> OFPFW_NW_DST_SHIFT
;
1211 ND_PRINT((ndo
, "%smatch nw_dst %s/%u", pfx
, ipaddr_string(ndo
, cp
), 32 - nw_bits
));
1215 if (! (wildcards
& OFPFW_TP_SRC
)) {
1216 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_IP
1217 && ! (wildcards
& OFPFW_NW_PROTO
) && nw_proto
== IPPROTO_ICMP
1218 ? "icmp_type" : "tp_src";
1219 ND_PRINT((ndo
, "%smatch %s %u", pfx
, field_name
, EXTRACT_16BITS(cp
)));
1224 if (! (wildcards
& OFPFW_TP_DST
)) {
1225 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_IP
1226 && ! (wildcards
& OFPFW_NW_PROTO
) && nw_proto
== IPPROTO_ICMP
1227 ? "icmp_code" : "tp_dst";
1228 ND_PRINT((ndo
, "%smatch %s %u", pfx
, field_name
, EXTRACT_16BITS(cp
)));
1233 ND_PRINT((ndo
, "%s", tstr
));
1237 /* [OF10] Section 5.2.4 */
1238 static const u_char
*
1239 of10_actions_print(netdissect_options
*ndo
,
1240 const char *pfx
, const u_char
*cp
, const u_char
*ep
,
1242 const u_char
*cp0
= cp
;
1243 const u_int len0
= len
;
1244 uint16_t type
, alen
, output_port
;
1247 u_char alen_bogus
= 0, skip
= 0;
1249 if (len
< OF_ACTION_HEADER_LEN
)
1253 type
= EXTRACT_16BITS(cp
);
1255 ND_PRINT((ndo
, "%saction type %s", pfx
, tok2str(ofpat_str
, "invalid (0x%04x)", type
)));
1258 alen
= EXTRACT_16BITS(cp
);
1260 ND_PRINT((ndo
, ", len %u", alen
));
1261 /* On action size underrun/overrun skip the rest of the action list. */
1262 if (alen
< OF_ACTION_HEADER_LEN
|| alen
> len
)
1264 /* On action size inappropriate for the given type or invalid type just skip
1265 * the current action, as the basic length constraint has been met. */
1268 case OFPAT_SET_VLAN_VID
:
1269 case OFPAT_SET_VLAN_PCP
:
1270 case OFPAT_STRIP_VLAN
:
1271 case OFPAT_SET_NW_SRC
:
1272 case OFPAT_SET_NW_DST
:
1273 case OFPAT_SET_NW_TOS
:
1274 case OFPAT_SET_TP_SRC
:
1275 case OFPAT_SET_TP_DST
:
1276 alen_bogus
= alen
!= 8;
1278 case OFPAT_SET_DL_SRC
:
1279 case OFPAT_SET_DL_DST
:
1281 alen_bogus
= alen
!= 16;
1284 alen_bogus
= alen
% 8 != 0; /* already >= 8 so far */
1290 ND_PRINT((ndo
, " (bogus)"));
1294 ND_TCHECK2(*cp
, alen
- 4);
1298 /* OK to decode the rest of the action structure */
1303 output_port
= EXTRACT_16BITS(cp
);
1305 ND_PRINT((ndo
, ", port %s", tok2str(ofpp_str
, "%u", output_port
)));
1308 if (output_port
== OFPP_CONTROLLER
)
1309 ND_PRINT((ndo
, ", max_len %u", EXTRACT_16BITS(cp
)));
1312 case OFPAT_SET_VLAN_VID
:
1315 ND_PRINT((ndo
, ", vlan_vid %s", vlan_str(EXTRACT_16BITS(cp
))));
1321 case OFPAT_SET_VLAN_PCP
:
1324 ND_PRINT((ndo
, ", vlan_pcp %s", pcp_str(*cp
)));
1330 case OFPAT_SET_DL_SRC
:
1331 case OFPAT_SET_DL_DST
:
1333 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
1334 ND_PRINT((ndo
, ", dl_addr %s", etheraddr_string(ndo
, cp
)));
1335 cp
+= ETHER_ADDR_LEN
;
1340 case OFPAT_SET_NW_SRC
:
1341 case OFPAT_SET_NW_DST
:
1344 ND_PRINT((ndo
, ", nw_addr %s", ipaddr_string(ndo
, cp
)));
1347 case OFPAT_SET_NW_TOS
:
1350 ND_PRINT((ndo
, ", nw_tos 0x%02x", *cp
));
1356 case OFPAT_SET_TP_SRC
:
1357 case OFPAT_SET_TP_DST
:
1360 ND_PRINT((ndo
, ", tp_port %u", EXTRACT_16BITS(cp
)));
1369 ND_PRINT((ndo
, ", port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1376 ND_PRINT((ndo
, ", queue_id %s", tok2str(ofpq_str
, "%u", EXTRACT_32BITS(cp
))));
1380 if (ep
== (cp
= of10_vendor_data_print(ndo
, cp
, ep
, alen
- 4)))
1381 return ep
; /* end of snapshot */
1383 case OFPAT_STRIP_VLAN
:
1394 corrupt
: /* skip the rest of actions */
1395 ND_PRINT((ndo
, "%s", cstr
));
1396 ND_TCHECK2(*cp0
, len0
);
1399 ND_PRINT((ndo
, "%s", tstr
));
1403 /* [OF10] Section 5.3.1 */
1404 static const u_char
*
1405 of10_features_reply_print(netdissect_options
*ndo
,
1406 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1409 ND_PRINT((ndo
, "\n\t dpid 0x%016" PRIx64
, EXTRACT_64BITS(cp
)));
1413 ND_PRINT((ndo
, ", n_buffers %u", EXTRACT_32BITS(cp
)));
1417 ND_PRINT((ndo
, ", n_tables %u", *cp
));
1424 ND_PRINT((ndo
, "\n\t capabilities 0x%08x", EXTRACT_32BITS(cp
)));
1425 of10_bitmap_print(ndo
, ofp_capabilities_bm
, EXTRACT_32BITS(cp
), OFPCAP_U
);
1429 ND_PRINT((ndo
, "\n\t actions 0x%08x", EXTRACT_32BITS(cp
)));
1430 of10_bitmap_print(ndo
, ofpat_bm
, EXTRACT_32BITS(cp
), OFPAT_U
);
1433 return of10_phy_ports_print(ndo
, cp
, ep
, len
- OF_SWITCH_FEATURES_LEN
);
1436 ND_PRINT((ndo
, "%s", tstr
));
1440 /* [OF10] Section 5.3.3 */
1441 static const u_char
*
1442 of10_flow_mod_print(netdissect_options
*ndo
,
1443 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1447 if (ep
== (cp
= of10_match_print(ndo
, "\n\t ", cp
, ep
)))
1448 return ep
; /* end of snapshot */
1451 ND_PRINT((ndo
, "\n\t cookie 0x%016" PRIx64
, EXTRACT_64BITS(cp
)));
1455 command
= EXTRACT_16BITS(cp
);
1456 ND_PRINT((ndo
, ", command %s", tok2str(ofpfc_str
, "invalid (0x%04x)", command
)));
1460 if (EXTRACT_16BITS(cp
))
1461 ND_PRINT((ndo
, ", idle_timeout %u", EXTRACT_16BITS(cp
)));
1465 if (EXTRACT_16BITS(cp
))
1466 ND_PRINT((ndo
, ", hard_timeout %u", EXTRACT_16BITS(cp
)));
1470 if (EXTRACT_16BITS(cp
))
1471 ND_PRINT((ndo
, ", priority %u", EXTRACT_16BITS(cp
)));
1475 if (command
== OFPFC_ADD
|| command
== OFPFC_MODIFY
||
1476 command
== OFPFC_MODIFY_STRICT
)
1477 ND_PRINT((ndo
, ", buffer_id %s", tok2str(bufferid_str
, "0x%08x", EXTRACT_32BITS(cp
))));
1481 if (command
== OFPFC_DELETE
|| command
== OFPFC_DELETE_STRICT
)
1482 ND_PRINT((ndo
, ", out_port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1486 ND_PRINT((ndo
, ", flags 0x%04x", EXTRACT_16BITS(cp
)));
1487 of10_bitmap_print(ndo
, ofpff_bm
, EXTRACT_16BITS(cp
), OFPFF_U
);
1490 return of10_actions_print(ndo
, "\n\t ", cp
, ep
, len
- OF_FLOW_MOD_LEN
);
1493 ND_PRINT((ndo
, "%s", tstr
));
1498 static const u_char
*
1499 of10_port_mod_print(netdissect_options
*ndo
,
1500 const u_char
*cp
, const u_char
*ep
) {
1503 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1506 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
1507 ND_PRINT((ndo
, ", hw_addr %s", etheraddr_string(ndo
, cp
)));
1508 cp
+= ETHER_ADDR_LEN
;
1511 ND_PRINT((ndo
, "\n\t config 0x%08x", EXTRACT_32BITS(cp
)));
1512 of10_bitmap_print(ndo
, ofppc_bm
, EXTRACT_32BITS(cp
), OFPPC_U
);
1516 ND_PRINT((ndo
, "\n\t mask 0x%08x", EXTRACT_32BITS(cp
)));
1517 of10_bitmap_print(ndo
, ofppc_bm
, EXTRACT_32BITS(cp
), OFPPC_U
);
1521 ND_PRINT((ndo
, "\n\t advertise 0x%08x", EXTRACT_32BITS(cp
)));
1522 of10_bitmap_print(ndo
, ofppf_bm
, EXTRACT_32BITS(cp
), OFPPF_U
);
1529 ND_PRINT((ndo
, "%s", tstr
));
1533 /* [OF10] Section 5.3.5 */
1534 static const u_char
*
1535 of10_stats_request_print(netdissect_options
*ndo
,
1536 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1537 const u_char
*cp0
= cp
;
1538 const u_int len0
= len
;
1543 type
= EXTRACT_16BITS(cp
);
1545 ND_PRINT((ndo
, "\n\t type %s", tok2str(ofpst_str
, "invalid (0x%04x)", type
)));
1548 ND_PRINT((ndo
, ", flags 0x%04x", EXTRACT_16BITS(cp
)));
1549 if (EXTRACT_16BITS(cp
))
1550 ND_PRINT((ndo
, " (bogus)"));
1552 /* type-specific body of one of fixed lengths */
1553 len
-= OF_STATS_REQUEST_LEN
;
1561 case OFPST_AGGREGATE
:
1562 if (len
!= OF_FLOW_STATS_REQUEST_LEN
)
1565 if (ep
== (cp
= of10_match_print(ndo
, "\n\t ", cp
, ep
)))
1566 return ep
; /* end of snapshot */
1569 ND_PRINT((ndo
, "\n\t table_id %s", tok2str(tableid_str
, "%u", *cp
)));
1576 ND_PRINT((ndo
, ", out_port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1579 if (len
!= OF_PORT_STATS_REQUEST_LEN
)
1583 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1589 if (len
!= OF_QUEUE_STATS_REQUEST_LEN
)
1593 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1600 ND_PRINT((ndo
, ", queue_id %s", tok2str(ofpq_str
, "%u", EXTRACT_32BITS(cp
))));
1603 return of10_vendor_data_print(ndo
, cp
, ep
, len
);
1607 corrupt
: /* skip the message body */
1608 ND_PRINT((ndo
, "%s", cstr
));
1609 ND_TCHECK2(*cp0
, len0
);
1612 ND_PRINT((ndo
, "%s", tstr
));
1617 static const u_char
*
1618 of10_desc_stats_reply_print(netdissect_options
*ndo
,
1619 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1620 if (len
!= OF_DESC_STATS_LEN
)
1623 ND_TCHECK2(*cp
, DESC_STR_LEN
);
1624 ND_PRINT((ndo
, "\n\t mfr_desc '"));
1625 fn_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1626 ND_PRINT((ndo
, "'"));
1629 ND_TCHECK2(*cp
, DESC_STR_LEN
);
1630 ND_PRINT((ndo
, "\n\t hw_desc '"));
1631 fn_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1632 ND_PRINT((ndo
, "'"));
1635 ND_TCHECK2(*cp
, DESC_STR_LEN
);
1636 ND_PRINT((ndo
, "\n\t sw_desc '"));
1637 fn_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1638 ND_PRINT((ndo
, "'"));
1641 ND_TCHECK2(*cp
, SERIAL_NUM_LEN
);
1642 ND_PRINT((ndo
, "\n\t serial_num '"));
1643 fn_print(ndo
, cp
, cp
+ SERIAL_NUM_LEN
);
1644 ND_PRINT((ndo
, "'"));
1645 cp
+= SERIAL_NUM_LEN
;
1647 ND_TCHECK2(*cp
, DESC_STR_LEN
);
1648 ND_PRINT((ndo
, "\n\t dp_desc '"));
1649 fn_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1650 ND_PRINT((ndo
, "'"));
1651 return cp
+ DESC_STR_LEN
;
1653 corrupt
: /* skip the message body */
1654 ND_PRINT((ndo
, "%s", cstr
));
1655 ND_TCHECK2(*cp
, len
);
1658 ND_PRINT((ndo
, "%s", tstr
));
1663 static const u_char
*
1664 of10_flow_stats_reply_print(netdissect_options
*ndo
,
1665 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1666 const u_char
*cp0
= cp
;
1667 const u_int len0
= len
;
1671 if (len
< OF_FLOW_STATS_LEN
)
1675 entry_len
= EXTRACT_16BITS(cp
);
1676 ND_PRINT((ndo
, "\n\t length %u", entry_len
));
1677 if (entry_len
< OF_FLOW_STATS_LEN
|| entry_len
> len
)
1682 ND_PRINT((ndo
, ", table_id %s", tok2str(tableid_str
, "%u", *cp
)));
1688 if (ep
== (cp
= of10_match_print(ndo
, "\n\t ", cp
, ep
)))
1689 return ep
; /* end of snapshot */
1692 ND_PRINT((ndo
, "\n\t duration_sec %u", EXTRACT_32BITS(cp
)));
1696 ND_PRINT((ndo
, ", duration_nsec %u", EXTRACT_32BITS(cp
)));
1700 ND_PRINT((ndo
, ", priority %u", EXTRACT_16BITS(cp
)));
1704 ND_PRINT((ndo
, ", idle_timeout %u", EXTRACT_16BITS(cp
)));
1708 ND_PRINT((ndo
, ", hard_timeout %u", EXTRACT_16BITS(cp
)));
1715 ND_PRINT((ndo
, ", cookie 0x%016" PRIx64
, EXTRACT_64BITS(cp
)));
1719 ND_PRINT((ndo
, ", packet_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1723 ND_PRINT((ndo
, ", byte_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1726 if (ep
== (cp
= of10_actions_print(ndo
, "\n\t ", cp
, ep
, entry_len
- OF_FLOW_STATS_LEN
)))
1727 return ep
; /* end of snapshot */
1733 corrupt
: /* skip the rest of flow statistics entries */
1734 ND_PRINT((ndo
, "%s", cstr
));
1735 ND_TCHECK2(*cp0
, len0
);
1738 ND_PRINT((ndo
, "%s", tstr
));
1743 static const u_char
*
1744 of10_aggregate_stats_reply_print(netdissect_options
*ndo
,
1745 const u_char
*cp
, const u_char
*ep
,
1747 if (len
!= OF_AGGREGATE_STATS_REPLY_LEN
)
1751 ND_PRINT((ndo
, "\n\t packet_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1755 ND_PRINT((ndo
, ", byte_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1759 ND_PRINT((ndo
, ", flow_count %u", EXTRACT_32BITS(cp
)));
1765 corrupt
: /* skip the message body */
1766 ND_PRINT((ndo
, "%s", cstr
));
1767 ND_TCHECK2(*cp
, len
);
1770 ND_PRINT((ndo
, "%s", tstr
));
1775 static const u_char
*
1776 of10_table_stats_reply_print(netdissect_options
*ndo
,
1777 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1778 const u_char
*cp0
= cp
;
1779 const u_int len0
= len
;
1782 if (len
< OF_TABLE_STATS_LEN
)
1786 ND_PRINT((ndo
, "\n\t table_id %s", tok2str(tableid_str
, "%u", *cp
)));
1792 ND_TCHECK2(*cp
, OFP_MAX_TABLE_NAME_LEN
);
1793 ND_PRINT((ndo
, ", name '"));
1794 fn_print(ndo
, cp
, cp
+ OFP_MAX_TABLE_NAME_LEN
);
1795 ND_PRINT((ndo
, "'"));
1796 cp
+= OFP_MAX_TABLE_NAME_LEN
;
1799 ND_PRINT((ndo
, "\n\t wildcards 0x%08x", EXTRACT_32BITS(cp
)));
1800 of10_bitmap_print(ndo
, ofpfw_bm
, EXTRACT_32BITS(cp
), OFPFW_U
);
1804 ND_PRINT((ndo
, "\n\t max_entries %u", EXTRACT_32BITS(cp
)));
1808 ND_PRINT((ndo
, ", active_count %u", EXTRACT_32BITS(cp
)));
1812 ND_PRINT((ndo
, ", lookup_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1816 ND_PRINT((ndo
, ", matched_count %" PRIu64
, EXTRACT_64BITS(cp
)));
1819 len
-= OF_TABLE_STATS_LEN
;
1823 corrupt
: /* skip the undersized trailing data */
1824 ND_PRINT((ndo
, "%s", cstr
));
1825 ND_TCHECK2(*cp0
, len0
);
1828 ND_PRINT((ndo
, "%s", tstr
));
1833 static const u_char
*
1834 of10_port_stats_reply_print(netdissect_options
*ndo
,
1835 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1836 const u_char
*cp0
= cp
;
1837 const u_int len0
= len
;
1840 if (len
< OF_PORT_STATS_LEN
)
1844 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1846 if (ndo
->ndo_vflag
< 2) {
1847 ND_TCHECK2(*cp
, OF_PORT_STATS_LEN
- 2);
1848 cp
+= OF_PORT_STATS_LEN
- 2;
1856 ND_PRINT((ndo
, ", rx_packets %" PRIu64
, EXTRACT_64BITS(cp
)));
1860 ND_PRINT((ndo
, ", tx_packets %" PRIu64
, EXTRACT_64BITS(cp
)));
1864 ND_PRINT((ndo
, ", rx_bytes %" PRIu64
, EXTRACT_64BITS(cp
)));
1868 ND_PRINT((ndo
, ", tx_bytes %" PRIu64
, EXTRACT_64BITS(cp
)));
1872 ND_PRINT((ndo
, ", rx_dropped %" PRIu64
, EXTRACT_64BITS(cp
)));
1876 ND_PRINT((ndo
, ", tx_dropped %" PRIu64
, EXTRACT_64BITS(cp
)));
1880 ND_PRINT((ndo
, ", rx_errors %" PRIu64
, EXTRACT_64BITS(cp
)));
1884 ND_PRINT((ndo
, ", tx_errors %" PRIu64
, EXTRACT_64BITS(cp
)));
1888 ND_PRINT((ndo
, ", rx_frame_err %" PRIu64
, EXTRACT_64BITS(cp
)));
1892 ND_PRINT((ndo
, ", rx_over_err %" PRIu64
, EXTRACT_64BITS(cp
)));
1896 ND_PRINT((ndo
, ", rx_crc_err %" PRIu64
, EXTRACT_64BITS(cp
)));
1900 ND_PRINT((ndo
, ", collisions %" PRIu64
, EXTRACT_64BITS(cp
)));
1903 len
-= OF_PORT_STATS_LEN
;
1907 corrupt
: /* skip the undersized trailing data */
1908 ND_PRINT((ndo
, "%s", cstr
));
1909 ND_TCHECK2(*cp0
, len0
);
1912 ND_PRINT((ndo
, "%s", tstr
));
1917 static const u_char
*
1918 of10_queue_stats_reply_print(netdissect_options
*ndo
,
1919 const u_char
*cp
, const u_char
*ep
, u_int len
) {
1920 const u_char
*cp0
= cp
;
1921 const u_int len0
= len
;
1924 if (len
< OF_QUEUE_STATS_LEN
)
1928 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
1935 ND_PRINT((ndo
, ", queue_id %u", EXTRACT_32BITS(cp
)));
1939 ND_PRINT((ndo
, ", tx_bytes %" PRIu64
, EXTRACT_64BITS(cp
)));
1943 ND_PRINT((ndo
, ", tx_packets %" PRIu64
, EXTRACT_64BITS(cp
)));
1947 ND_PRINT((ndo
, ", tx_errors %" PRIu64
, EXTRACT_64BITS(cp
)));
1950 len
-= OF_QUEUE_STATS_LEN
;
1954 corrupt
: /* skip the undersized trailing data */
1955 ND_PRINT((ndo
, "%s", cstr
));
1956 ND_TCHECK2(*cp0
, len0
);
1959 ND_PRINT((ndo
, "%s", tstr
));
1964 static const u_char
*
1965 of10_stats_reply_print(netdissect_options
*ndo
,
1966 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
1967 const u_char
*cp0
= cp
;
1972 type
= EXTRACT_16BITS(cp
);
1973 ND_PRINT((ndo
, "\n\t type %s", tok2str(ofpst_str
, "invalid (0x%04x)", type
)));
1977 ND_PRINT((ndo
, ", flags 0x%04x", EXTRACT_16BITS(cp
)));
1978 of10_bitmap_print(ndo
, ofpsf_reply_bm
, EXTRACT_16BITS(cp
), OFPSF_REPLY_U
);
1981 if (ndo
->ndo_vflag
> 0) {
1982 const u_char
*(*decoder
)(netdissect_options
*, const u_char
*, const u_char
*, u_int
) =
1983 type
== OFPST_DESC
? of10_desc_stats_reply_print
:
1984 type
== OFPST_FLOW
? of10_flow_stats_reply_print
:
1985 type
== OFPST_AGGREGATE
? of10_aggregate_stats_reply_print
:
1986 type
== OFPST_TABLE
? of10_table_stats_reply_print
:
1987 type
== OFPST_PORT
? of10_port_stats_reply_print
:
1988 type
== OFPST_QUEUE
? of10_queue_stats_reply_print
:
1989 type
== OFPST_VENDOR
? of10_vendor_data_print
:
1991 if (decoder
!= NULL
)
1992 return decoder(ndo
, cp
, ep
, len
- OF_STATS_REPLY_LEN
);
1994 ND_TCHECK2(*cp0
, len
);
1998 ND_PRINT((ndo
, "%s", tstr
));
2002 /* [OF10] Section 5.3.6 */
2003 static const u_char
*
2004 of10_packet_out_print(netdissect_options
*ndo
,
2005 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
2006 const u_char
*cp0
= cp
;
2007 const u_int len0
= len
;
2008 uint16_t actions_len
;
2012 ND_PRINT((ndo
, "\n\t buffer_id 0x%08x", EXTRACT_32BITS(cp
)));
2016 ND_PRINT((ndo
, ", in_port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
2020 actions_len
= EXTRACT_16BITS(cp
);
2022 if (actions_len
> len
- OF_PACKET_OUT_LEN
)
2025 if (ep
== (cp
= of10_actions_print(ndo
, "\n\t ", cp
, ep
, actions_len
)))
2026 return ep
; /* end of snapshot */
2028 return of10_packet_data_print(ndo
, cp
, ep
, len
- OF_PACKET_OUT_LEN
- actions_len
);
2030 corrupt
: /* skip the rest of the message body */
2031 ND_PRINT((ndo
, "%s", cstr
));
2032 ND_TCHECK2(*cp0
, len0
);
2035 ND_PRINT((ndo
, "%s", tstr
));
2039 /* [OF10] Section 5.4.1 */
2040 static const u_char
*
2041 of10_packet_in_print(netdissect_options
*ndo
,
2042 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
2045 ND_PRINT((ndo
, "\n\t buffer_id %s", tok2str(bufferid_str
, "0x%08x", EXTRACT_32BITS(cp
))));
2049 ND_PRINT((ndo
, ", total_len %u", EXTRACT_16BITS(cp
)));
2053 ND_PRINT((ndo
, ", in_port %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
2057 ND_PRINT((ndo
, ", reason %s", tok2str(ofpr_str
, "invalid (0x%02x)", *cp
)));
2063 /* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
2064 return of10_packet_data_print(ndo
, cp
, ep
, len
- (OF_PACKET_IN_LEN
- 2));
2067 ND_PRINT((ndo
, "%s", tstr
));
2071 /* [OF10] Section 5.4.2 */
2072 static const u_char
*
2073 of10_flow_removed_print(netdissect_options
*ndo
,
2074 const u_char
*cp
, const u_char
*ep
) {
2076 if (ep
== (cp
= of10_match_print(ndo
, "\n\t ", cp
, ep
)))
2077 return ep
; /* end of snapshot */
2080 ND_PRINT((ndo
, "\n\t cookie 0x%016" PRIx64
, EXTRACT_64BITS(cp
)));
2084 if (EXTRACT_16BITS(cp
))
2085 ND_PRINT((ndo
, ", priority %u", EXTRACT_16BITS(cp
)));
2089 ND_PRINT((ndo
, ", reason %s", tok2str(ofprr_str
, "unknown (0x%02x)", *cp
)));
2096 ND_PRINT((ndo
, ", duration_sec %u", EXTRACT_32BITS(cp
)));
2100 ND_PRINT((ndo
, ", duration_nsec %u", EXTRACT_32BITS(cp
)));
2104 if (EXTRACT_16BITS(cp
))
2105 ND_PRINT((ndo
, ", idle_timeout %u", EXTRACT_16BITS(cp
)));
2112 ND_PRINT((ndo
, ", packet_count %" PRIu64
, EXTRACT_64BITS(cp
)));
2116 ND_PRINT((ndo
, ", byte_count %" PRIu64
, EXTRACT_64BITS(cp
)));
2120 ND_PRINT((ndo
, "%s", tstr
));
2124 /* [OF10] Section 5.4.4 */
2125 static const u_char
*
2126 of10_error_print(netdissect_options
*ndo
,
2127 const u_char
*cp
, const u_char
*ep
, const u_int len
) {
2129 const struct tok
*code_str
;
2133 type
= EXTRACT_16BITS(cp
);
2135 ND_PRINT((ndo
, "\n\t type %s", tok2str(ofpet_str
, "invalid (0x%04x)", type
)));
2139 type
== OFPET_HELLO_FAILED
? ofphfc_str
:
2140 type
== OFPET_BAD_REQUEST
? ofpbrc_str
:
2141 type
== OFPET_BAD_ACTION
? ofpbac_str
:
2142 type
== OFPET_FLOW_MOD_FAILED
? ofpfmfc_str
:
2143 type
== OFPET_PORT_MOD_FAILED
? ofppmfc_str
:
2144 type
== OFPET_QUEUE_OP_FAILED
? ofpqofc_str
:
2146 ND_PRINT((ndo
, ", code %s", tok2str(code_str
, "invalid (0x%04x)", EXTRACT_16BITS(cp
))));
2149 return of10_data_print(ndo
, cp
, ep
, len
- OF_ERROR_MSG_LEN
);
2152 ND_PRINT((ndo
, "%s", tstr
));
2157 of10_header_body_print(netdissect_options
*ndo
,
2158 const u_char
*cp
, const u_char
*ep
, const uint8_t type
,
2159 const uint16_t len
, const uint32_t xid
) {
2160 const u_char
*cp0
= cp
;
2161 const u_int len0
= len
;
2162 /* Thus far message length is not less than the basic header size, but most
2163 * message types have additional assorted constraints on the length. Wherever
2164 * possible, check that message length meets the constraint, in remaining
2165 * cases check that the length is OK to begin decoding and leave any final
2166 * verification up to a lower-layer function. When the current message is
2167 * corrupt, proceed to the next message. */
2169 /* [OF10] Section 5.1 */
2170 ND_PRINT((ndo
, "\n\tversion 1.0, type %s, length %u, xid 0x%08x",
2171 tok2str(ofpt_str
, "invalid (0x%02x)", type
), len
, xid
));
2173 /* OpenFlow header only. */
2174 case OFPT_FEATURES_REQUEST
: /* [OF10] Section 5.3.1 */
2175 case OFPT_GET_CONFIG_REQUEST
: /* [OF10] Section 5.3.2 */
2176 case OFPT_BARRIER_REQUEST
: /* [OF10] Section 5.3.7 */
2177 case OFPT_BARRIER_REPLY
: /* ibid */
2178 if (len
!= OF_HEADER_LEN
)
2182 /* OpenFlow header and fixed-size message body. */
2183 case OFPT_SET_CONFIG
: /* [OF10] Section 5.3.2 */
2184 case OFPT_GET_CONFIG_REPLY
: /* ibid */
2185 if (len
!= OF_SWITCH_CONFIG_LEN
)
2187 if (ndo
->ndo_vflag
< 1)
2191 ND_PRINT((ndo
, "\n\t flags %s", tok2str(ofp_config_str
, "invalid (0x%04x)", EXTRACT_16BITS(cp
))));
2195 ND_PRINT((ndo
, ", miss_send_len %u", EXTRACT_16BITS(cp
)));
2198 if (len
!= OF_PORT_MOD_LEN
)
2200 if (ndo
->ndo_vflag
< 1)
2202 return of10_port_mod_print(ndo
, cp
, ep
);
2203 case OFPT_QUEUE_GET_CONFIG_REQUEST
: /* [OF10] Section 5.3.4 */
2204 if (len
!= OF_QUEUE_GET_CONFIG_REQUEST_LEN
)
2206 if (ndo
->ndo_vflag
< 1)
2210 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
2215 case OFPT_FLOW_REMOVED
:
2216 if (len
!= OF_FLOW_REMOVED_LEN
)
2218 if (ndo
->ndo_vflag
< 1)
2220 return of10_flow_removed_print(ndo
, cp
, ep
);
2221 case OFPT_PORT_STATUS
: /* [OF10] Section 5.4.3 */
2222 if (len
!= OF_PORT_STATUS_LEN
)
2224 if (ndo
->ndo_vflag
< 1)
2228 ND_PRINT((ndo
, "\n\t reason %s", tok2str(ofppr_str
, "invalid (0x%02x)", *cp
)));
2234 return of10_phy_ports_print(ndo
, cp
, ep
, OF_PHY_PORT_LEN
);
2236 /* OpenFlow header, fixed-size message body and n * fixed-size data units. */
2237 case OFPT_FEATURES_REPLY
:
2238 if (len
< OF_SWITCH_FEATURES_LEN
)
2240 if (ndo
->ndo_vflag
< 1)
2242 return of10_features_reply_print(ndo
, cp
, ep
, len
);
2244 /* OpenFlow header and variable-size data. */
2245 case OFPT_HELLO
: /* [OF10] Section 5.5.1 */
2246 case OFPT_ECHO_REQUEST
: /* [OF10] Section 5.5.2 */
2247 case OFPT_ECHO_REPLY
: /* [OF10] Section 5.5.3 */
2248 if (ndo
->ndo_vflag
< 1)
2250 return of10_data_print(ndo
, cp
, ep
, len
- OF_HEADER_LEN
);
2252 /* OpenFlow header, fixed-size message body and variable-size data. */
2254 if (len
< OF_ERROR_MSG_LEN
)
2256 if (ndo
->ndo_vflag
< 1)
2258 return of10_error_print(ndo
, cp
, ep
, len
);
2260 /* [OF10] Section 5.5.4 */
2261 if (len
< OF_VENDOR_HEADER_LEN
)
2263 if (ndo
->ndo_vflag
< 1)
2265 return of10_vendor_message_print(ndo
, cp
, ep
, len
- OF_HEADER_LEN
);
2266 case OFPT_PACKET_IN
:
2267 /* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
2268 if (len
< OF_PACKET_IN_LEN
- 2)
2270 if (ndo
->ndo_vflag
< 1)
2272 return of10_packet_in_print(ndo
, cp
, ep
, len
);
2274 /* a. OpenFlow header. */
2275 /* b. OpenFlow header and one of the fixed-size message bodies. */
2276 /* c. OpenFlow header, fixed-size message body and variable-size data. */
2277 case OFPT_STATS_REQUEST
:
2278 if (len
< OF_STATS_REQUEST_LEN
)
2280 if (ndo
->ndo_vflag
< 1)
2282 return of10_stats_request_print(ndo
, cp
, ep
, len
);
2284 /* a. OpenFlow header and fixed-size message body. */
2285 /* b. OpenFlow header and n * fixed-size data units. */
2286 /* c. OpenFlow header and n * variable-size data units. */
2287 /* d. OpenFlow header, fixed-size message body and variable-size data. */
2288 case OFPT_STATS_REPLY
:
2289 if (len
< OF_STATS_REPLY_LEN
)
2291 if (ndo
->ndo_vflag
< 1)
2293 return of10_stats_reply_print(ndo
, cp
, ep
, len
);
2295 /* OpenFlow header and n * variable-size data units and variable-size data. */
2296 case OFPT_PACKET_OUT
:
2297 if (len
< OF_PACKET_OUT_LEN
)
2299 if (ndo
->ndo_vflag
< 1)
2301 return of10_packet_out_print(ndo
, cp
, ep
, len
);
2303 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2305 if (len
< OF_FLOW_MOD_LEN
)
2307 if (ndo
->ndo_vflag
< 1)
2309 return of10_flow_mod_print(ndo
, cp
, ep
, len
);
2311 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2312 case OFPT_QUEUE_GET_CONFIG_REPLY
: /* [OF10] Section 5.3.4 */
2313 if (len
< OF_QUEUE_GET_CONFIG_REPLY_LEN
)
2315 if (ndo
->ndo_vflag
< 1)
2319 ND_PRINT((ndo
, "\n\t port_no %s", tok2str(ofpp_str
, "%u", EXTRACT_16BITS(cp
))));
2325 return of10_queues_print(ndo
, cp
, ep
, len
- OF_QUEUE_GET_CONFIG_REPLY_LEN
);
2326 } /* switch (type) */
2329 corrupt
: /* skip the message body */
2330 ND_PRINT((ndo
, "%s", cstr
));
2332 ND_TCHECK2(*cp0
, len0
- OF_HEADER_LEN
);
2333 return cp0
+ len0
- OF_HEADER_LEN
;
2335 ND_PRINT((ndo
, "%s", tstr
));