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] https://www.opennetworking.org/wp-content/uploads/2013/04/openflow-spec-v1.0.0.pdf
11 * Most functions in this file take the following arguments:
12 * * cp -- the pointer to the first octet to decode
13 * * len -- the declared length of the structure to decode
14 * The convention is that a printer function returns iff the given structure is
15 * completely within the packet buffer; otherwise it processes the part that is
16 * within the buffer, sooner of later takes the "truncated packet" shortcut via
17 * longjmp() and never returns. With that in mind, the function may return
18 * without printing the structure completely if it is invalid or the ndo_vflag
19 * value is not high enough. This way the calling function can try to decode
22 * Decoding of Ethernet frames nested in OFPT_PACKET_IN and OFPT_PACKET_OUT
23 * messages is done only when the verbosity level set by command-line argument
24 * is "-vvv" or higher. In that case the verbosity level is temporarily
25 * decremented by 3 during the nested frame decoding. For example, running
26 * tcpdump with "-vvvv" will do full decoding of OpenFlow and "-v" decoding of
29 * Partial decoding of Big Switch Networks vendor extensions is done after the
30 * oftest (OpenFlow Testing Framework) and Loxigen (library generator) source
34 * Copyright (c) 2013 The TCPDUMP project
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
46 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
47 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
48 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
49 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
50 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
52 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
53 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
54 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
56 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57 * POSSIBILITY OF SUCH DAMAGE.
60 /* \summary: OpenFlow protocol version 1.0 printer */
66 #include "netdissect-stdinc.h"
68 #define ND_LONGJMP_FROM_TCHECK
69 #include "netdissect.h"
71 #include "addrtoname.h"
72 #include "ethertype.h"
78 #define OFPT_HELLO 0x00
79 #define OFPT_ERROR 0x01
80 #define OFPT_ECHO_REQUEST 0x02
81 #define OFPT_ECHO_REPLY 0x03
82 #define OFPT_VENDOR 0x04
83 #define OFPT_FEATURES_REQUEST 0x05
84 #define OFPT_FEATURES_REPLY 0x06
85 #define OFPT_GET_CONFIG_REQUEST 0x07
86 #define OFPT_GET_CONFIG_REPLY 0x08
87 #define OFPT_SET_CONFIG 0x09
88 #define OFPT_PACKET_IN 0x0a
89 #define OFPT_FLOW_REMOVED 0x0b
90 #define OFPT_PORT_STATUS 0x0c
91 #define OFPT_PACKET_OUT 0x0d
92 #define OFPT_FLOW_MOD 0x0e
93 #define OFPT_PORT_MOD 0x0f
94 #define OFPT_STATS_REQUEST 0x10
95 #define OFPT_STATS_REPLY 0x11
96 #define OFPT_BARRIER_REQUEST 0x12
97 #define OFPT_BARRIER_REPLY 0x13
98 #define OFPT_QUEUE_GET_CONFIG_REQUEST 0x14
99 #define OFPT_QUEUE_GET_CONFIG_REPLY 0x15
100 static const struct tok ofpt_str
[] = {
101 { OFPT_HELLO
, "HELLO" },
102 { OFPT_ERROR
, "ERROR" },
103 { OFPT_ECHO_REQUEST
, "ECHO_REQUEST" },
104 { OFPT_ECHO_REPLY
, "ECHO_REPLY" },
105 { OFPT_VENDOR
, "VENDOR" },
106 { OFPT_FEATURES_REQUEST
, "FEATURES_REQUEST" },
107 { OFPT_FEATURES_REPLY
, "FEATURES_REPLY" },
108 { OFPT_GET_CONFIG_REQUEST
, "GET_CONFIG_REQUEST" },
109 { OFPT_GET_CONFIG_REPLY
, "GET_CONFIG_REPLY" },
110 { OFPT_SET_CONFIG
, "SET_CONFIG" },
111 { OFPT_PACKET_IN
, "PACKET_IN" },
112 { OFPT_FLOW_REMOVED
, "FLOW_REMOVED" },
113 { OFPT_PORT_STATUS
, "PORT_STATUS" },
114 { OFPT_PACKET_OUT
, "PACKET_OUT" },
115 { OFPT_FLOW_MOD
, "FLOW_MOD" },
116 { OFPT_PORT_MOD
, "PORT_MOD" },
117 { OFPT_STATS_REQUEST
, "STATS_REQUEST" },
118 { OFPT_STATS_REPLY
, "STATS_REPLY" },
119 { OFPT_BARRIER_REQUEST
, "BARRIER_REQUEST" },
120 { OFPT_BARRIER_REPLY
, "BARRIER_REPLY" },
121 { OFPT_QUEUE_GET_CONFIG_REQUEST
, "QUEUE_GET_CONFIG_REQUEST" },
122 { OFPT_QUEUE_GET_CONFIG_REPLY
, "QUEUE_GET_CONFIG_REPLY" },
126 #define OFPPC_PORT_DOWN (1U <<0)
127 #define OFPPC_NO_STP (1U <<1)
128 #define OFPPC_NO_RECV (1U <<2)
129 #define OFPPC_NO_RECV_STP (1U <<3)
130 #define OFPPC_NO_FLOOD (1U <<4)
131 #define OFPPC_NO_FWD (1U <<5)
132 #define OFPPC_NO_PACKET_IN (1U <<6)
133 static const struct tok ofppc_bm
[] = {
134 { OFPPC_PORT_DOWN
, "PORT_DOWN" },
135 { OFPPC_NO_STP
, "NO_STP" },
136 { OFPPC_NO_RECV
, "NO_RECV" },
137 { OFPPC_NO_RECV_STP
, "NO_RECV_STP" },
138 { OFPPC_NO_FLOOD
, "NO_FLOOD" },
139 { OFPPC_NO_FWD
, "NO_FWD" },
140 { OFPPC_NO_PACKET_IN
, "NO_PACKET_IN" },
143 #define OFPPC_U (~(OFPPC_PORT_DOWN | OFPPC_NO_STP | OFPPC_NO_RECV | \
144 OFPPC_NO_RECV_STP | OFPPC_NO_FLOOD | OFPPC_NO_FWD | \
147 #define OFPPS_LINK_DOWN (1U << 0)
148 #define OFPPS_STP_LISTEN (0U << 8)
149 #define OFPPS_STP_LEARN (1U << 8)
150 #define OFPPS_STP_FORWARD (2U << 8)
151 #define OFPPS_STP_BLOCK (3U << 8)
152 #define OFPPS_STP_MASK (3U << 8)
153 static const struct tok ofpps_bm
[] = {
154 { OFPPS_LINK_DOWN
, "LINK_DOWN" },
155 { OFPPS_STP_LISTEN
, "STP_LISTEN" },
156 { OFPPS_STP_LEARN
, "STP_LEARN" },
157 { OFPPS_STP_FORWARD
, "STP_FORWARD" },
158 { OFPPS_STP_BLOCK
, "STP_BLOCK" },
161 #define OFPPS_U (~(OFPPS_LINK_DOWN | OFPPS_STP_LISTEN | OFPPS_STP_LEARN | \
162 OFPPS_STP_FORWARD | OFPPS_STP_BLOCK))
164 #define OFPP_MAX 0xff00U
165 #define OFPP_IN_PORT 0xfff8U
166 #define OFPP_TABLE 0xfff9U
167 #define OFPP_NORMAL 0xfffaU
168 #define OFPP_FLOOD 0xfffbU
169 #define OFPP_ALL 0xfffcU
170 #define OFPP_CONTROLLER 0xfffdU
171 #define OFPP_LOCAL 0xfffeU
172 #define OFPP_NONE 0xffffU
173 static const struct tok ofpp_str
[] = {
175 { OFPP_IN_PORT
, "IN_PORT" },
176 { OFPP_TABLE
, "TABLE" },
177 { OFPP_NORMAL
, "NORMAL" },
178 { OFPP_FLOOD
, "FLOOD" },
180 { OFPP_CONTROLLER
, "CONTROLLER" },
181 { OFPP_LOCAL
, "LOCAL" },
182 { OFPP_NONE
, "NONE" },
186 #define OFPPF_10MB_HD (1U << 0)
187 #define OFPPF_10MB_FD (1U << 1)
188 #define OFPPF_100MB_HD (1U << 2)
189 #define OFPPF_100MB_FD (1U << 3)
190 #define OFPPF_1GB_HD (1U << 4)
191 #define OFPPF_1GB_FD (1U << 5)
192 #define OFPPF_10GB_FD (1U << 6)
193 #define OFPPF_COPPER (1U << 7)
194 #define OFPPF_FIBER (1U << 8)
195 #define OFPPF_AUTONEG (1U << 9)
196 #define OFPPF_PAUSE (1U <<10)
197 #define OFPPF_PAUSE_ASYM (1U <<11)
198 static const struct tok ofppf_bm
[] = {
199 { OFPPF_10MB_HD
, "10MB_HD" },
200 { OFPPF_10MB_FD
, "10MB_FD" },
201 { OFPPF_100MB_HD
, "100MB_HD" },
202 { OFPPF_100MB_FD
, "100MB_FD" },
203 { OFPPF_1GB_HD
, "1GB_HD" },
204 { OFPPF_1GB_FD
, "1GB_FD" },
205 { OFPPF_10GB_FD
, "10GB_FD" },
206 { OFPPF_COPPER
, "COPPER" },
207 { OFPPF_FIBER
, "FIBER" },
208 { OFPPF_AUTONEG
, "AUTONEG" },
209 { OFPPF_PAUSE
, "PAUSE" },
210 { OFPPF_PAUSE_ASYM
, "PAUSE_ASYM" },
213 #define OFPPF_U (~(OFPPF_10MB_HD | OFPPF_10MB_FD | OFPPF_100MB_HD | \
214 OFPPF_100MB_FD | OFPPF_1GB_HD | OFPPF_1GB_FD | \
215 OFPPF_10GB_FD | OFPPF_COPPER | OFPPF_FIBER | \
216 OFPPF_AUTONEG | OFPPF_PAUSE | OFPPF_PAUSE_ASYM))
218 #define OFPQT_NONE 0x0000
219 #define OFPQT_MIN_RATE 0x0001
220 static const struct tok ofpqt_str
[] = {
221 { OFPQT_NONE
, "NONE" },
222 { OFPQT_MIN_RATE
, "MIN_RATE" },
226 #define OFPFW_IN_PORT (1U <<0)
227 #define OFPFW_DL_VLAN (1U <<1)
228 #define OFPFW_DL_SRC (1U <<2)
229 #define OFPFW_DL_DST (1U <<3)
230 #define OFPFW_DL_TYPE (1U <<4)
231 #define OFPFW_NW_PROTO (1U <<5)
232 #define OFPFW_TP_SRC (1U <<6)
233 #define OFPFW_TP_DST (1U <<7)
234 #define OFPFW_NW_SRC_SHIFT 8
235 #define OFPFW_NW_SRC_BITS 6
236 #define OFPFW_NW_SRC_MASK (((1U <<OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT)
237 #define OFPFW_NW_DST_SHIFT 14
238 #define OFPFW_NW_DST_BITS 6
239 #define OFPFW_NW_DST_MASK (((1U <<OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT)
240 #define OFPFW_DL_VLAN_PCP (1U <<20)
241 #define OFPFW_NW_TOS (1U <<21)
242 #define OFPFW_ALL ((1U <<22) - 1)
243 static const struct tok ofpfw_bm
[] = {
244 { OFPFW_IN_PORT
, "IN_PORT" },
245 { OFPFW_DL_VLAN
, "DL_VLAN" },
246 { OFPFW_DL_SRC
, "DL_SRC" },
247 { OFPFW_DL_DST
, "DL_DST" },
248 { OFPFW_DL_TYPE
, "DL_TYPE" },
249 { OFPFW_NW_PROTO
, "NW_PROTO" },
250 { OFPFW_TP_SRC
, "TP_SRC" },
251 { OFPFW_TP_DST
, "TP_DST" },
252 { OFPFW_DL_VLAN_PCP
, "DL_VLAN_PCP" },
253 { OFPFW_NW_TOS
, "NW_TOS" },
256 /* The above array does not include bits 8~13 (OFPFW_NW_SRC_*) and 14~19
257 * (OFPFW_NW_DST_*), which are not a part of the bitmap and require decoding
258 * other than that of tok2str(). The macro below includes these bits such that
259 * they are not reported as bogus in the decoding. */
260 #define OFPFW_U (~(OFPFW_ALL))
262 #define OFPAT_OUTPUT 0x0000U
263 #define OFPAT_SET_VLAN_VID 0x0001U
264 #define OFPAT_SET_VLAN_PCP 0x0002U
265 #define OFPAT_STRIP_VLAN 0x0003U
266 #define OFPAT_SET_DL_SRC 0x0004U
267 #define OFPAT_SET_DL_DST 0x0005U
268 #define OFPAT_SET_NW_SRC 0x0006U
269 #define OFPAT_SET_NW_DST 0x0007U
270 #define OFPAT_SET_NW_TOS 0x0008U
271 #define OFPAT_SET_TP_SRC 0x0009U
272 #define OFPAT_SET_TP_DST 0x000aU
273 #define OFPAT_ENQUEUE 0x000bU
274 #define OFPAT_VENDOR 0xffffU
275 static const struct tok ofpat_str
[] = {
276 { OFPAT_OUTPUT
, "OUTPUT" },
277 { OFPAT_SET_VLAN_VID
, "SET_VLAN_VID" },
278 { OFPAT_SET_VLAN_PCP
, "SET_VLAN_PCP" },
279 { OFPAT_STRIP_VLAN
, "STRIP_VLAN" },
280 { OFPAT_SET_DL_SRC
, "SET_DL_SRC" },
281 { OFPAT_SET_DL_DST
, "SET_DL_DST" },
282 { OFPAT_SET_NW_SRC
, "SET_NW_SRC" },
283 { OFPAT_SET_NW_DST
, "SET_NW_DST" },
284 { OFPAT_SET_NW_TOS
, "SET_NW_TOS" },
285 { OFPAT_SET_TP_SRC
, "SET_TP_SRC" },
286 { OFPAT_SET_TP_DST
, "SET_TP_DST" },
287 { OFPAT_ENQUEUE
, "ENQUEUE" },
288 { OFPAT_VENDOR
, "VENDOR" },
292 /* bit-shifted, w/o vendor action */
293 static const struct tok ofpat_bm
[] = {
294 { 1U <<OFPAT_OUTPUT
, "OUTPUT" },
295 { 1U <<OFPAT_SET_VLAN_VID
, "SET_VLAN_VID" },
296 { 1U <<OFPAT_SET_VLAN_PCP
, "SET_VLAN_PCP" },
297 { 1U <<OFPAT_STRIP_VLAN
, "STRIP_VLAN" },
298 { 1U <<OFPAT_SET_DL_SRC
, "SET_DL_SRC" },
299 { 1U <<OFPAT_SET_DL_DST
, "SET_DL_DST" },
300 { 1U <<OFPAT_SET_NW_SRC
, "SET_NW_SRC" },
301 { 1U <<OFPAT_SET_NW_DST
, "SET_NW_DST" },
302 { 1U <<OFPAT_SET_NW_TOS
, "SET_NW_TOS" },
303 { 1U <<OFPAT_SET_TP_SRC
, "SET_TP_SRC" },
304 { 1U <<OFPAT_SET_TP_DST
, "SET_TP_DST" },
305 { 1U <<OFPAT_ENQUEUE
, "ENQUEUE" },
308 #define OFPAT_U (~(1U <<OFPAT_OUTPUT | 1U <<OFPAT_SET_VLAN_VID | \
309 1U <<OFPAT_SET_VLAN_PCP | 1U <<OFPAT_STRIP_VLAN | \
310 1U <<OFPAT_SET_DL_SRC | 1U <<OFPAT_SET_DL_DST | \
311 1U <<OFPAT_SET_NW_SRC | 1U <<OFPAT_SET_NW_DST | \
312 1U <<OFPAT_SET_NW_TOS | 1U <<OFPAT_SET_TP_SRC | \
313 1U <<OFPAT_SET_TP_DST | 1U <<OFPAT_ENQUEUE))
315 #define OFPC_FLOW_STATS (1U <<0)
316 #define OFPC_TABLE_STATS (1U <<1)
317 #define OFPC_PORT_STATS (1U <<2)
318 #define OFPC_STP (1U <<3)
319 #define OFPC_RESERVED (1U <<4)
320 #define OFPC_IP_REASM (1U <<5)
321 #define OFPC_QUEUE_STATS (1U <<6)
322 #define OFPC_ARP_MATCH_IP (1U <<7)
323 static const struct tok ofp_capabilities_bm
[] = {
324 { OFPC_FLOW_STATS
, "FLOW_STATS" },
325 { OFPC_TABLE_STATS
, "TABLE_STATS" },
326 { OFPC_PORT_STATS
, "PORT_STATS" },
328 { OFPC_RESERVED
, "RESERVED" }, /* not in the mask below */
329 { OFPC_IP_REASM
, "IP_REASM" },
330 { OFPC_QUEUE_STATS
, "QUEUE_STATS" },
331 { OFPC_ARP_MATCH_IP
, "ARP_MATCH_IP" },
334 #define OFPCAP_U (~(OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS | \
335 OFPC_STP | OFPC_IP_REASM | OFPC_QUEUE_STATS | \
338 #define OFPC_FRAG_NORMAL 0x0000U
339 #define OFPC_FRAG_DROP 0x0001U
340 #define OFPC_FRAG_REASM 0x0002U
341 #define OFPC_FRAG_MASK 0x0003U
342 static const struct tok ofp_config_str
[] = {
343 { OFPC_FRAG_NORMAL
, "FRAG_NORMAL" },
344 { OFPC_FRAG_DROP
, "FRAG_DROP" },
345 { OFPC_FRAG_REASM
, "FRAG_REASM" },
349 #define OFPFC_ADD 0x0000U
350 #define OFPFC_MODIFY 0x0001U
351 #define OFPFC_MODIFY_STRICT 0x0002U
352 #define OFPFC_DELETE 0x0003U
353 #define OFPFC_DELETE_STRICT 0x0004U
354 static const struct tok ofpfc_str
[] = {
355 { OFPFC_ADD
, "ADD" },
356 { OFPFC_MODIFY
, "MODIFY" },
357 { OFPFC_MODIFY_STRICT
, "MODIFY_STRICT" },
358 { OFPFC_DELETE
, "DELETE" },
359 { OFPFC_DELETE_STRICT
, "DELETE_STRICT" },
363 static const struct tok bufferid_str
[] = {
364 { 0xffffffff, "NONE" },
368 #define OFPFF_SEND_FLOW_REM (1U <<0)
369 #define OFPFF_CHECK_OVERLAP (1U <<1)
370 #define OFPFF_EMERG (1U <<2)
371 static const struct tok ofpff_bm
[] = {
372 { OFPFF_SEND_FLOW_REM
, "SEND_FLOW_REM" },
373 { OFPFF_CHECK_OVERLAP
, "CHECK_OVERLAP" },
374 { OFPFF_EMERG
, "EMERG" },
377 #define OFPFF_U (~(OFPFF_SEND_FLOW_REM | OFPFF_CHECK_OVERLAP | OFPFF_EMERG))
379 #define OFPST_DESC 0x0000U
380 #define OFPST_FLOW 0x0001U
381 #define OFPST_AGGREGATE 0x0002U
382 #define OFPST_TABLE 0x0003U
383 #define OFPST_PORT 0x0004U
384 #define OFPST_QUEUE 0x0005U
385 #define OFPST_VENDOR 0xffffU
386 static const struct tok ofpst_str
[] = {
387 { OFPST_DESC
, "DESC" },
388 { OFPST_FLOW
, "FLOW" },
389 { OFPST_AGGREGATE
, "AGGREGATE" },
390 { OFPST_TABLE
, "TABLE" },
391 { OFPST_PORT
, "PORT" },
392 { OFPST_QUEUE
, "QUEUE" },
393 { OFPST_VENDOR
, "VENDOR" },
397 static const struct tok tableid_str
[] = {
403 #define OFPQ_ALL 0xffffffffU
404 static const struct tok ofpq_str
[] = {
409 #define OFPSF_REPLY_MORE 0x0001U
410 static const struct tok ofpsf_reply_bm
[] = {
411 { OFPSF_REPLY_MORE
, "MORE" },
414 #define OFPSF_REPLY_U (~(OFPSF_REPLY_MORE))
416 #define OFPR_NO_MATCH 0x00U
417 #define OFPR_ACTION 0x01U
418 static const struct tok ofpr_str
[] = {
419 { OFPR_NO_MATCH
, "NO_MATCH" },
420 { OFPR_ACTION
, "ACTION" },
424 #define OFPRR_IDLE_TIMEOUT 0x00U
425 #define OFPRR_HARD_TIMEOUT 0x01U
426 #define OFPRR_DELETE 0x02U
427 static const struct tok ofprr_str
[] = {
428 { OFPRR_IDLE_TIMEOUT
, "IDLE_TIMEOUT" },
429 { OFPRR_HARD_TIMEOUT
, "HARD_TIMEOUT" },
430 { OFPRR_DELETE
, "DELETE" },
434 #define OFPPR_ADD 0x00U
435 #define OFPPR_DELETE 0x01U
436 #define OFPPR_MODIFY 0x02U
437 static const struct tok ofppr_str
[] = {
438 { OFPPR_ADD
, "ADD" },
439 { OFPPR_DELETE
, "DELETE" },
440 { OFPPR_MODIFY
, "MODIFY" },
444 #define OFPET_HELLO_FAILED 0x0000U
445 #define OFPET_BAD_REQUEST 0x0001U
446 #define OFPET_BAD_ACTION 0x0002U
447 #define OFPET_FLOW_MOD_FAILED 0x0003U
448 #define OFPET_PORT_MOD_FAILED 0x0004U
449 #define OFPET_QUEUE_OP_FAILED 0x0005U
450 static const struct tok ofpet_str
[] = {
451 { OFPET_HELLO_FAILED
, "HELLO_FAILED" },
452 { OFPET_BAD_REQUEST
, "BAD_REQUEST" },
453 { OFPET_BAD_ACTION
, "BAD_ACTION" },
454 { OFPET_FLOW_MOD_FAILED
, "FLOW_MOD_FAILED" },
455 { OFPET_PORT_MOD_FAILED
, "PORT_MOD_FAILED" },
456 { OFPET_QUEUE_OP_FAILED
, "QUEUE_OP_FAILED" },
459 #define OFPET_MAX OFPET_QUEUE_OP_FAILED /* for of10_error_print() */
461 #define OFPHFC_INCOMPATIBLE 0x0000U
462 #define OFPHFC_EPERM 0x0001U
463 static const struct tok ofphfc_str
[] = {
464 { OFPHFC_INCOMPATIBLE
, "INCOMPATIBLE" },
465 { OFPHFC_EPERM
, "EPERM" },
469 #define OFPBRC_BAD_VERSION 0x0000U
470 #define OFPBRC_BAD_TYPE 0x0001U
471 #define OFPBRC_BAD_STAT 0x0002U
472 #define OFPBRC_BAD_VENDOR 0x0003U
473 #define OFPBRC_BAD_SUBTYPE 0x0004U
474 #define OFPBRC_EPERM 0x0005U
475 #define OFPBRC_BAD_LEN 0x0006U
476 #define OFPBRC_BUFFER_EMPTY 0x0007U
477 #define OFPBRC_BUFFER_UNKNOWN 0x0008U
478 static const struct tok ofpbrc_str
[] = {
479 { OFPBRC_BAD_VERSION
, "BAD_VERSION" },
480 { OFPBRC_BAD_TYPE
, "BAD_TYPE" },
481 { OFPBRC_BAD_STAT
, "BAD_STAT" },
482 { OFPBRC_BAD_VENDOR
, "BAD_VENDOR" },
483 { OFPBRC_BAD_SUBTYPE
, "BAD_SUBTYPE" },
484 { OFPBRC_EPERM
, "EPERM" },
485 { OFPBRC_BAD_LEN
, "BAD_LEN" },
486 { OFPBRC_BUFFER_EMPTY
, "BUFFER_EMPTY" },
487 { OFPBRC_BUFFER_UNKNOWN
, "BUFFER_UNKNOWN" },
491 #define OFPBAC_BAD_TYPE 0x0000U
492 #define OFPBAC_BAD_LEN 0x0001U
493 #define OFPBAC_BAD_VENDOR 0x0002U
494 #define OFPBAC_BAD_VENDOR_TYPE 0x0003U
495 #define OFPBAC_BAD_OUT_PORT 0x0004U
496 #define OFPBAC_BAD_ARGUMENT 0x0005U
497 #define OFPBAC_EPERM 0x0006U
498 #define OFPBAC_TOO_MANY 0x0007U
499 #define OFPBAC_BAD_QUEUE 0x0008U
500 static const struct tok ofpbac_str
[] = {
501 { OFPBAC_BAD_TYPE
, "BAD_TYPE" },
502 { OFPBAC_BAD_LEN
, "BAD_LEN" },
503 { OFPBAC_BAD_VENDOR
, "BAD_VENDOR" },
504 { OFPBAC_BAD_VENDOR_TYPE
, "BAD_VENDOR_TYPE" },
505 { OFPBAC_BAD_OUT_PORT
, "BAD_OUT_PORT" },
506 { OFPBAC_BAD_ARGUMENT
, "BAD_ARGUMENT" },
507 { OFPBAC_EPERM
, "EPERM" },
508 { OFPBAC_TOO_MANY
, "TOO_MANY" },
509 { OFPBAC_BAD_QUEUE
, "BAD_QUEUE" },
513 #define OFPFMFC_ALL_TABLES_FULL 0x0000U
514 #define OFPFMFC_OVERLAP 0x0001U
515 #define OFPFMFC_EPERM 0x0002U
516 #define OFPFMFC_BAD_EMERG_TIMEOUT 0x0003U
517 #define OFPFMFC_BAD_COMMAND 0x0004U
518 #define OFPFMFC_UNSUPPORTED 0x0005U
519 static const struct tok ofpfmfc_str
[] = {
520 { OFPFMFC_ALL_TABLES_FULL
, "ALL_TABLES_FULL" },
521 { OFPFMFC_OVERLAP
, "OVERLAP" },
522 { OFPFMFC_EPERM
, "EPERM" },
523 { OFPFMFC_BAD_EMERG_TIMEOUT
, "BAD_EMERG_TIMEOUT" },
524 { OFPFMFC_BAD_COMMAND
, "BAD_COMMAND" },
525 { OFPFMFC_UNSUPPORTED
, "UNSUPPORTED" },
529 #define OFPPMFC_BAD_PORT 0x0000U
530 #define OFPPMFC_BAD_HW_ADDR 0x0001U
531 static const struct tok ofppmfc_str
[] = {
532 { OFPPMFC_BAD_PORT
, "BAD_PORT" },
533 { OFPPMFC_BAD_HW_ADDR
, "BAD_HW_ADDR" },
537 #define OFPQOFC_BAD_PORT 0x0000U
538 #define OFPQOFC_BAD_QUEUE 0x0001U
539 #define OFPQOFC_EPERM 0x0002U
540 static const struct tok ofpqofc_str
[] = {
541 { OFPQOFC_BAD_PORT
, "BAD_PORT" },
542 { OFPQOFC_BAD_QUEUE
, "BAD_QUEUE" },
543 { OFPQOFC_EPERM
, "EPERM" },
547 /* lengths (fixed or minimal) of particular protocol structures */
548 #define OF_SWITCH_CONFIG_FIXLEN 12
549 #define OF_PHY_PORT_FIXLEN 48
550 #define OF_FEATURES_REPLY_MINLEN 32
551 #define OF_PORT_STATUS_FIXLEN 64
552 #define OF_PORT_MOD_FIXLEN 32
553 #define OF_PACKET_IN_MINLEN 20 /* with 2 mock octets */
554 #define OF_ACTION_MINLEN 8
555 #define OF_PACKET_OUT_MINLEN 16
556 #define OF_MATCH_FIXLEN 40
557 #define OF_FLOW_MOD_MINLEN 72
558 #define OF_FLOW_REMOVED_FIXLEN 88
559 #define OF_ERROR_MSG_MINLEN 12
560 #define OF_STATS_REQUEST_MINLEN 12
561 #define OF_STATS_REPLY_MINLEN 12
562 #define OF_DESC_STATS_REPLY_FIXLEN 1056
563 #define OF_FLOW_STATS_REQUEST_FIXLEN 44
564 #define OF_FLOW_STATS_REPLY_MINLEN 88
565 #define OF_AGGREGATE_STATS_REPLY_FIXLEN 24
566 #define OF_TABLE_STATS_REPLY_FIXLEN 64
567 #define OF_PORT_STATS_REQUEST_FIXLEN 8
568 #define OF_PORT_STATS_REPLY_FIXLEN 104
569 #define OF_VENDOR_MINLEN 12
570 #define OF_QUEUE_PROP_MINLEN 8
571 #define OF_QUEUE_PROP_MIN_RATE_FIXLEN 16
572 #define OF_PACKET_QUEUE_MINLEN 8
573 #define OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN 12
574 #define OF_QUEUE_GET_CONFIG_REPLY_MINLEN 16
575 #define OF_QUEUE_STATS_REQUEST_FIXLEN 8
576 #define OF_QUEUE_STATS_REPLY_FIXLEN 32
578 /* miscellaneous constants from [OF10] */
579 #define OFP_MAX_TABLE_NAME_LEN 32
580 #define OFP_MAX_PORT_NAME_LEN 16
581 #define DESC_STR_LEN 256
582 #define SERIAL_NUM_LEN 32
583 #define OFP_VLAN_NONE 0xffffU
585 /* vendor extensions */
586 #define BSN_SET_IP_MASK 0
587 #define BSN_GET_IP_MASK_REQUEST 1
588 #define BSN_GET_IP_MASK_REPLY 2
589 #define BSN_SET_MIRRORING 3
590 #define BSN_GET_MIRRORING_REQUEST 4
591 #define BSN_GET_MIRRORING_REPLY 5
592 #define BSN_SHELL_COMMAND 6
593 #define BSN_SHELL_OUTPUT 7
594 #define BSN_SHELL_STATUS 8
595 #define BSN_GET_INTERFACES_REQUEST 9
596 #define BSN_GET_INTERFACES_REPLY 10
597 #define BSN_SET_PKTIN_SUPPRESSION_REQUEST 11
598 #define BSN_SET_L2_TABLE_REQUEST 12
599 #define BSN_GET_L2_TABLE_REQUEST 13
600 #define BSN_GET_L2_TABLE_REPLY 14
601 #define BSN_VIRTUAL_PORT_CREATE_REQUEST 15
602 #define BSN_VIRTUAL_PORT_CREATE_REPLY 16
603 #define BSN_VIRTUAL_PORT_REMOVE_REQUEST 17
604 #define BSN_BW_ENABLE_SET_REQUEST 18
605 #define BSN_BW_ENABLE_GET_REQUEST 19
606 #define BSN_BW_ENABLE_GET_REPLY 20
607 #define BSN_BW_CLEAR_DATA_REQUEST 21
608 #define BSN_BW_CLEAR_DATA_REPLY 22
609 #define BSN_BW_ENABLE_SET_REPLY 23
610 #define BSN_SET_L2_TABLE_REPLY 24
611 #define BSN_SET_PKTIN_SUPPRESSION_REPLY 25
612 #define BSN_VIRTUAL_PORT_REMOVE_REPLY 26
613 #define BSN_HYBRID_GET_REQUEST 27
614 #define BSN_HYBRID_GET_REPLY 28
617 #define BSN_PDU_TX_REQUEST 31
618 #define BSN_PDU_TX_REPLY 32
619 #define BSN_PDU_RX_REQUEST 33
620 #define BSN_PDU_RX_REPLY 34
621 #define BSN_PDU_RX_TIMEOUT 35
623 static const struct tok bsn_subtype_str
[] = {
624 { BSN_SET_IP_MASK
, "SET_IP_MASK" },
625 { BSN_GET_IP_MASK_REQUEST
, "GET_IP_MASK_REQUEST" },
626 { BSN_GET_IP_MASK_REPLY
, "GET_IP_MASK_REPLY" },
627 { BSN_SET_MIRRORING
, "SET_MIRRORING" },
628 { BSN_GET_MIRRORING_REQUEST
, "GET_MIRRORING_REQUEST" },
629 { BSN_GET_MIRRORING_REPLY
, "GET_MIRRORING_REPLY" },
630 { BSN_SHELL_COMMAND
, "SHELL_COMMAND" },
631 { BSN_SHELL_OUTPUT
, "SHELL_OUTPUT" },
632 { BSN_SHELL_STATUS
, "SHELL_STATUS" },
633 { BSN_GET_INTERFACES_REQUEST
, "GET_INTERFACES_REQUEST" },
634 { BSN_GET_INTERFACES_REPLY
, "GET_INTERFACES_REPLY" },
635 { BSN_SET_PKTIN_SUPPRESSION_REQUEST
, "SET_PKTIN_SUPPRESSION_REQUEST" },
636 { BSN_SET_L2_TABLE_REQUEST
, "SET_L2_TABLE_REQUEST" },
637 { BSN_GET_L2_TABLE_REQUEST
, "GET_L2_TABLE_REQUEST" },
638 { BSN_GET_L2_TABLE_REPLY
, "GET_L2_TABLE_REPLY" },
639 { BSN_VIRTUAL_PORT_CREATE_REQUEST
, "VIRTUAL_PORT_CREATE_REQUEST" },
640 { BSN_VIRTUAL_PORT_CREATE_REPLY
, "VIRTUAL_PORT_CREATE_REPLY" },
641 { BSN_VIRTUAL_PORT_REMOVE_REQUEST
, "VIRTUAL_PORT_REMOVE_REQUEST" },
642 { BSN_BW_ENABLE_SET_REQUEST
, "BW_ENABLE_SET_REQUEST" },
643 { BSN_BW_ENABLE_GET_REQUEST
, "BW_ENABLE_GET_REQUEST" },
644 { BSN_BW_ENABLE_GET_REPLY
, "BW_ENABLE_GET_REPLY" },
645 { BSN_BW_CLEAR_DATA_REQUEST
, "BW_CLEAR_DATA_REQUEST" },
646 { BSN_BW_CLEAR_DATA_REPLY
, "BW_CLEAR_DATA_REPLY" },
647 { BSN_BW_ENABLE_SET_REPLY
, "BW_ENABLE_SET_REPLY" },
648 { BSN_SET_L2_TABLE_REPLY
, "SET_L2_TABLE_REPLY" },
649 { BSN_SET_PKTIN_SUPPRESSION_REPLY
, "SET_PKTIN_SUPPRESSION_REPLY" },
650 { BSN_VIRTUAL_PORT_REMOVE_REPLY
, "VIRTUAL_PORT_REMOVE_REPLY" },
651 { BSN_HYBRID_GET_REQUEST
, "HYBRID_GET_REQUEST" },
652 { BSN_HYBRID_GET_REPLY
, "HYBRID_GET_REPLY" },
653 { BSN_PDU_TX_REQUEST
, "PDU_TX_REQUEST" },
654 { BSN_PDU_TX_REPLY
, "PDU_TX_REPLY" },
655 { BSN_PDU_RX_REQUEST
, "PDU_RX_REQUEST" },
656 { BSN_PDU_RX_REPLY
, "PDU_RX_REPLY" },
657 { BSN_PDU_RX_TIMEOUT
, "PDU_RX_TIMEOUT" },
661 #define BSN_ACTION_MIRROR 1
662 #define BSN_ACTION_SET_TUNNEL_DST 2
664 #define BSN_ACTION_CHECKSUM 4
666 static const struct tok bsn_action_subtype_str
[] = {
667 { BSN_ACTION_MIRROR
, "MIRROR" },
668 { BSN_ACTION_SET_TUNNEL_DST
, "SET_TUNNEL_DST" },
669 { BSN_ACTION_CHECKSUM
, "CHECKSUM" },
673 static const struct tok bsn_mirror_copy_stage_str
[] = {
679 static const struct tok bsn_onoff_str
[] = {
685 /* [OF10] Section 5.1 */
686 const char * of10_msgtype_str(const uint8_t type
)
688 return tok2str(ofpt_str
, "invalid (0x%02x)", type
);
692 vlan_str(const uint16_t vid
)
694 static char buf
[sizeof("65535 (bogus)")];
696 if (vid
== OFP_VLAN_NONE
)
698 snprintf(buf
, sizeof(buf
), "%u%s", vid
,
699 (vid
> 0 && vid
< 0x0fff) ? "" : " (bogus)");
704 pcp_str(const uint8_t pcp
)
706 static char buf
[sizeof("255 (bogus)")];
707 snprintf(buf
, sizeof(buf
), "%u%s", pcp
,
708 pcp
<= 7 ? "" : " (bogus)");
713 of10_bitmap_print(netdissect_options
*ndo
,
714 const struct tok
*t
, const uint32_t v
, const uint32_t u
)
716 const char *sep
= " (";
721 for (; t
->s
!= NULL
; t
++)
723 ND_PRINT("%s%s", sep
, t
->s
);
726 /* unassigned bits? */
727 ND_PRINT((v
& u
) ? ") (bogus)" : ")");
731 of10_bsn_message_print(netdissect_options
*ndo
,
732 const u_char
*cp
, u_int len
)
739 subtype
= GET_BE_U_4(cp
);
741 ND_PRINT("\n\t subtype %s", tok2str(bsn_subtype_str
, "unknown (0x%08x)", subtype
));
743 case BSN_GET_IP_MASK_REQUEST
:
746 * 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
747 * +---------------+---------------+---------------+---------------+
749 * +---------------+---------------+---------------+---------------+
751 * +---------------+---------------+---------------+---------------+
753 * +---------------+---------------+---------------+---------------+
759 ND_PRINT(", index %u", GET_U_1(cp
));
762 /* Always the last field, check bounds. */
765 case BSN_SET_IP_MASK
:
766 case BSN_GET_IP_MASK_REPLY
:
769 * 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
770 * +---------------+---------------+---------------+---------------+
772 * +---------------+---------------+---------------+---------------+
774 * +---------------+---------------+---------------+---------------+
776 * +---------------+---------------+---------------+---------------+
782 ND_PRINT(", index %u", GET_U_1(cp
));
787 ND_PRINT(", mask %s", GET_IPADDR_STRING(cp
));
789 case BSN_SET_MIRRORING
:
790 case BSN_GET_MIRRORING_REQUEST
:
791 case BSN_GET_MIRRORING_REPLY
:
794 * 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
795 * +---------------+---------------+---------------+---------------+
797 * +---------------+---------------+---------------+---------------+
798 * | report m. p. | pad |
799 * +---------------+---------------+---------------+---------------+
804 /* report_mirror_ports */
805 ND_PRINT(", report_mirror_ports %s",
806 tok2str(bsn_onoff_str
, "bogus (%u)", GET_U_1(cp
)));
809 /* Always the last field, check bounds. */
812 case BSN_GET_INTERFACES_REQUEST
:
813 case BSN_GET_L2_TABLE_REQUEST
:
814 case BSN_BW_ENABLE_GET_REQUEST
:
815 case BSN_BW_CLEAR_DATA_REQUEST
:
816 case BSN_HYBRID_GET_REQUEST
:
819 * 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
820 * +---------------+---------------+---------------+---------------+
822 * +---------------+---------------+---------------+---------------+
828 case BSN_VIRTUAL_PORT_REMOVE_REQUEST
:
831 * 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
832 * +---------------+---------------+---------------+---------------+
834 * +---------------+---------------+---------------+---------------+
836 * +---------------+---------------+---------------+---------------+
842 ND_PRINT(", vport_no %u", GET_BE_U_4(cp
));
844 case BSN_SHELL_COMMAND
:
847 * 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
848 * +---------------+---------------+---------------+---------------+
850 * +---------------+---------------+---------------+---------------+
852 * +---------------+---------------+---------------+---------------+
854 * +---------------+---------------+--------
860 ND_PRINT(", service %u", GET_BE_U_4(cp
));
863 ND_PRINT(", data '");
864 nd_printn(ndo
, cp
, len
, NULL
);
867 case BSN_SHELL_OUTPUT
:
870 * 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
871 * +---------------+---------------+---------------+---------------+
873 * +---------------+---------------+---------------+---------------+
875 * +---------------+---------------+--------
878 /* already checked that len >= 4 */
880 ND_PRINT(", data '");
881 nd_printn(ndo
, cp
, len
, NULL
);
884 case BSN_SHELL_STATUS
:
887 * 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
888 * +---------------+---------------+---------------+---------------+
890 * +---------------+---------------+---------------+---------------+
892 * +---------------+---------------+---------------+---------------+
898 ND_PRINT(", status 0x%08x", GET_BE_U_4(cp
));
901 ND_TCHECK_LEN(cp
, len
);
905 invalid
: /* skip the undersized data */
906 nd_print_invalid(ndo
);
907 ND_TCHECK_LEN(cp
, len
);
911 of10_bsn_actions_print(netdissect_options
*ndo
,
912 const u_char
*cp
, u_int len
)
914 uint32_t subtype
, vlan_tag
;
919 subtype
= GET_BE_U_4(cp
);
921 ND_PRINT("\n\t subtype %s", tok2str(bsn_action_subtype_str
, "unknown (0x%08x)", subtype
));
923 case BSN_ACTION_MIRROR
:
926 * 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
927 * +---------------+---------------+---------------+---------------+
929 * +---------------+---------------+---------------+---------------+
931 * +---------------+---------------+---------------+---------------+
933 * +---------------+---------------+---------------+---------------+
934 * | copy_stage | pad |
935 * +---------------+---------------+---------------+---------------+
941 ND_PRINT(", dest_port %u", GET_BE_U_4(cp
));
944 vlan_tag
= GET_BE_U_4(cp
);
946 switch (vlan_tag
>> 16) {
948 ND_PRINT(", vlan_tag none");
950 case ETHERTYPE_8021Q
:
951 ND_PRINT(", vlan_tag 802.1Q (%s)", ieee8021q_tci_string(vlan_tag
& 0xffff));
954 ND_PRINT(", vlan_tag unknown (0x%04x)", vlan_tag
>> 16);
957 ND_PRINT(", copy_stage %s",
958 tok2str(bsn_mirror_copy_stage_str
, "unknown (%u)", GET_U_1(cp
)));
961 /* Always the last field, check bounds. */
965 ND_TCHECK_LEN(cp
, len
);
970 nd_print_invalid(ndo
);
971 ND_TCHECK_LEN(cp
, len
);
975 of10_vendor_action_print(netdissect_options
*ndo
,
976 const u_char
*cp
, u_int len
)
979 void (*decoder
)(netdissect_options
*, const u_char
*, u_int
);
984 vendor
= GET_BE_U_4(cp
);
986 ND_PRINT(", vendor 0x%08x (%s)", vendor
, of_vendor_name(vendor
));
989 vendor
== OUI_BSN
? of10_bsn_actions_print
:
991 decoder(ndo
, cp
, len
);
994 invalid
: /* skip the undersized data */
995 nd_print_invalid(ndo
);
996 ND_TCHECK_LEN(cp
, len
);
1000 of10_vendor_message_print(netdissect_options
*ndo
,
1001 const u_char
*cp
, u_int len
)
1004 void (*decoder
)(netdissect_options
*, const u_char
*, u_int
);
1009 vendor
= GET_BE_U_4(cp
);
1011 ND_PRINT(", vendor 0x%08x (%s)", vendor
, of_vendor_name(vendor
));
1014 vendor
== OUI_BSN
? of10_bsn_message_print
:
1016 decoder(ndo
, cp
, len
);
1019 invalid
: /* skip the undersized data */
1020 nd_print_invalid(ndo
);
1021 ND_TCHECK_LEN(cp
, len
);
1024 /* Vendor ID is mandatory, data is optional. */
1026 of10_vendor_data_print(netdissect_options
*ndo
,
1027 const u_char
*cp
, u_int len
)
1034 vendor
= GET_BE_U_4(cp
);
1036 ND_PRINT(", vendor 0x%08x (%s)", vendor
, of_vendor_name(vendor
));
1038 of_data_print(ndo
, cp
, len
);
1041 invalid
: /* skip the undersized data */
1042 nd_print_invalid(ndo
);
1043 ND_TCHECK_LEN(cp
, len
);
1047 of10_packet_data_print(netdissect_options
*ndo
,
1048 const u_char
*cp
, const u_int len
)
1053 ND_PRINT("\n\t data (%u octets)", len
);
1054 if (ndo
->ndo_vflag
< 3) {
1055 ND_TCHECK_LEN(cp
, len
);
1058 ndo
->ndo_vflag
-= 3;
1059 ND_PRINT(", frame decoding below\n");
1060 ether_print(ndo
, cp
, len
, ND_BYTES_AVAILABLE_AFTER(cp
), NULL
, NULL
);
1061 ndo
->ndo_vflag
+= 3;
1064 /* [OF10] Section 5.2.1 */
1066 of10_phy_ports_print(netdissect_options
*ndo
,
1067 const u_char
*cp
, u_int len
)
1070 if (len
< OF_PHY_PORT_FIXLEN
)
1073 ND_PRINT("\n\t port_no %s",
1074 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1077 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp
));
1078 OF_FWD(MAC_ADDR_LEN
);
1080 ND_PRINT(", name '");
1081 (void)nd_print(ndo
, cp
, cp
+ OFP_MAX_PORT_NAME_LEN
);
1083 OF_FWD(OFP_MAX_PORT_NAME_LEN
);
1085 if (ndo
->ndo_vflag
< 2) {
1090 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp
));
1091 of10_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
1094 ND_PRINT("\n\t state 0x%08x", GET_BE_U_4(cp
));
1095 of10_bitmap_print(ndo
, ofpps_bm
, GET_BE_U_4(cp
), OFPPS_U
);
1098 ND_PRINT("\n\t curr 0x%08x", GET_BE_U_4(cp
));
1099 of10_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1102 ND_PRINT("\n\t advertised 0x%08x", GET_BE_U_4(cp
));
1103 of10_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1106 ND_PRINT("\n\t supported 0x%08x", GET_BE_U_4(cp
));
1107 of10_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1110 ND_PRINT("\n\t peer 0x%08x", GET_BE_U_4(cp
));
1111 of10_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1116 invalid
: /* skip the undersized trailing data */
1117 nd_print_invalid(ndo
);
1118 ND_TCHECK_LEN(cp
, len
);
1121 /* [OF10] Section 5.2.2 */
1123 of10_queue_props_print(netdissect_options
*ndo
,
1124 const u_char
*cp
, u_int len
)
1127 uint16_t property
, plen
;
1128 u_char plen_bogus
= 0, skip
= 0;
1130 if (len
< OF_QUEUE_PROP_MINLEN
)
1133 property
= GET_BE_U_2(cp
);
1135 ND_PRINT("\n\t property %s", tok2str(ofpqt_str
, "invalid (0x%04x)", property
));
1137 plen
= GET_BE_U_2(cp
);
1139 ND_PRINT(", len %u", plen
);
1140 if (plen
< OF_QUEUE_PROP_MINLEN
|| plen
> len
+ 4)
1143 /* Sometimes the last field, check bounds. */
1145 /* property-specific constraints and decoding */
1148 plen_bogus
= plen
!= OF_QUEUE_PROP_MINLEN
;
1150 case OFPQT_MIN_RATE
:
1151 plen_bogus
= plen
!= OF_QUEUE_PROP_MIN_RATE_FIXLEN
;
1157 ND_PRINT(" (bogus)");
1162 * plen >= OF_QUEUE_PROP_MINLEN
1163 * cp is OF_QUEUE_PROP_MINLEN bytes in
1165 OF_CHK_FWD(plen
- OF_QUEUE_PROP_MINLEN
);
1168 if (property
== OFPQT_MIN_RATE
) { /* the only case of property decoding */
1170 uint16_t rate
= GET_BE_U_2(cp
);
1173 ND_PRINT(", rate disabled");
1175 ND_PRINT(", rate %u.%u%%", rate
/ 10, rate
% 10);
1177 /* Sometimes the last field, check bounds. */
1183 invalid
: /* skip the rest of queue properties */
1184 nd_print_invalid(ndo
);
1185 ND_TCHECK_LEN(cp
, len
);
1190 of10_queues_print(netdissect_options
*ndo
,
1191 const u_char
*cp
, u_int len
)
1196 if (len
< OF_PACKET_QUEUE_MINLEN
)
1199 ND_PRINT("\n\t queue_id %u", GET_BE_U_4(cp
));
1202 desclen
= GET_BE_U_2(cp
);
1204 ND_PRINT(", len %u", desclen
);
1205 if (desclen
< OF_PACKET_QUEUE_MINLEN
|| desclen
> len
+ 6)
1208 /* Sometimes the last field, check bounds. */
1211 if (ndo
->ndo_vflag
>= 2)
1212 of10_queue_props_print(ndo
, cp
, desclen
- OF_PACKET_QUEUE_MINLEN
);
1214 ND_TCHECK_LEN(cp
, desclen
- OF_PACKET_QUEUE_MINLEN
);
1215 OF_FWD(desclen
- OF_PACKET_QUEUE_MINLEN
);
1219 invalid
: /* skip the rest of queues */
1220 nd_print_invalid(ndo
);
1221 ND_TCHECK_LEN(cp
, len
);
1224 /* [OF10] Section 5.2.3 */
1226 of10_match_print(netdissect_options
*ndo
,
1227 const char *pfx
, const u_char
*cp
)
1233 const char *field_name
;
1236 wildcards
= GET_BE_U_4(cp
);
1237 if (wildcards
& OFPFW_U
)
1238 ND_PRINT("%swildcards 0x%08x (bogus)", pfx
, wildcards
);
1241 if (! (wildcards
& OFPFW_IN_PORT
))
1242 ND_PRINT("%smatch in_port %s", pfx
,
1243 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1246 if (! (wildcards
& OFPFW_DL_SRC
))
1247 ND_PRINT("%smatch dl_src %s", pfx
, GET_ETHERADDR_STRING(cp
));
1250 if (! (wildcards
& OFPFW_DL_DST
))
1251 ND_PRINT("%smatch dl_dst %s", pfx
, GET_ETHERADDR_STRING(cp
));
1254 if (! (wildcards
& OFPFW_DL_VLAN
))
1255 ND_PRINT("%smatch dl_vlan %s", pfx
, vlan_str(GET_BE_U_2(cp
)));
1258 if (! (wildcards
& OFPFW_DL_VLAN_PCP
))
1259 ND_PRINT("%smatch dl_vlan_pcp %s", pfx
, pcp_str(GET_U_1(cp
)));
1264 dl_type
= GET_BE_U_2(cp
);
1266 if (! (wildcards
& OFPFW_DL_TYPE
))
1267 ND_PRINT("%smatch dl_type 0x%04x", pfx
, dl_type
);
1269 if (! (wildcards
& OFPFW_NW_TOS
))
1270 ND_PRINT("%smatch nw_tos 0x%02x", pfx
, GET_U_1(cp
));
1273 nw_proto
= GET_U_1(cp
);
1275 if (! (wildcards
& OFPFW_NW_PROTO
)) {
1276 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_ARP
1277 ? "arp_opcode" : "nw_proto";
1278 ND_PRINT("%smatch %s %u", pfx
, field_name
, nw_proto
);
1283 nw_bits
= (wildcards
& OFPFW_NW_SRC_MASK
) >> OFPFW_NW_SRC_SHIFT
;
1285 ND_PRINT("%smatch nw_src %s/%u", pfx
, GET_IPADDR_STRING(cp
), 32 - nw_bits
);
1288 nw_bits
= (wildcards
& OFPFW_NW_DST_MASK
) >> OFPFW_NW_DST_SHIFT
;
1290 ND_PRINT("%smatch nw_dst %s/%u", pfx
, GET_IPADDR_STRING(cp
), 32 - nw_bits
);
1293 if (! (wildcards
& OFPFW_TP_SRC
)) {
1294 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_IP
1295 && ! (wildcards
& OFPFW_NW_PROTO
) && nw_proto
== IPPROTO_ICMP
1296 ? "icmp_type" : "tp_src";
1297 ND_PRINT("%smatch %s %u", pfx
, field_name
, GET_BE_U_2(cp
));
1301 /* The last unconditional check was at nw_proto, so have an "else" here. */
1302 if (! (wildcards
& OFPFW_TP_DST
)) {
1303 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_IP
1304 && ! (wildcards
& OFPFW_NW_PROTO
) && nw_proto
== IPPROTO_ICMP
1305 ? "icmp_code" : "tp_dst";
1306 ND_PRINT("%smatch %s %u", pfx
, field_name
, GET_BE_U_2(cp
));
1312 /* [OF10] Section 5.2.4 */
1314 of10_actions_print(netdissect_options
*ndo
,
1315 const char *pfx
, const u_char
*cp
, u_int len
)
1318 uint16_t type
, alen
, output_port
;
1319 u_char alen_bogus
= 0, skip
= 0;
1321 if (len
< OF_ACTION_MINLEN
)
1324 type
= GET_BE_U_2(cp
);
1326 ND_PRINT("%saction type %s", pfx
, tok2str(ofpat_str
, "invalid (0x%04x)", type
));
1328 alen
= GET_BE_U_2(cp
);
1330 ND_PRINT(", len %u", alen
);
1332 * The 4-byte "pad" in the specification is not a field of the
1333 * action header, but a placeholder to illustrate the 64-bit
1334 * alignment requirement. Action type specific case blocks
1335 * below fetch these 4 bytes.
1338 /* On action size underrun/overrun skip the rest of the action list. */
1339 if (alen
< OF_ACTION_MINLEN
|| alen
> len
+ 4)
1342 * After validating the basic length constraint it will be safe
1343 * to skip the current action if the action size is not valid
1344 * for the type or the type is invalid.
1348 case OFPAT_SET_VLAN_VID
:
1349 case OFPAT_SET_VLAN_PCP
:
1350 case OFPAT_STRIP_VLAN
:
1351 case OFPAT_SET_NW_SRC
:
1352 case OFPAT_SET_NW_DST
:
1353 case OFPAT_SET_NW_TOS
:
1354 case OFPAT_SET_TP_SRC
:
1355 case OFPAT_SET_TP_DST
:
1356 alen_bogus
= alen
!= 8;
1358 case OFPAT_SET_DL_SRC
:
1359 case OFPAT_SET_DL_DST
:
1361 alen_bogus
= alen
!= 16;
1364 alen_bogus
= alen
% 8 != 0; /* already >= 8 so far */
1370 ND_PRINT(" (bogus)");
1375 * alen >= OF_ACTION_MINLEN
1378 OF_CHK_FWD(alen
- 4);
1381 /* OK to decode the rest of the action structure */
1385 output_port
= GET_BE_U_2(cp
);
1387 ND_PRINT(", port %s", tok2str(ofpp_str
, "%u", output_port
));
1389 if (output_port
== OFPP_CONTROLLER
)
1390 ND_PRINT(", max_len %u", GET_BE_U_2(cp
));
1395 case OFPAT_SET_VLAN_VID
:
1397 ND_PRINT(", vlan_vid %s", vlan_str(GET_BE_U_2(cp
)));
1400 /* Sometimes the last field, check bounds. */
1403 case OFPAT_SET_VLAN_PCP
:
1405 ND_PRINT(", vlan_pcp %s", pcp_str(GET_U_1(cp
)));
1408 /* Sometimes the last field, check bounds. */
1411 case OFPAT_SET_DL_SRC
:
1412 case OFPAT_SET_DL_DST
:
1414 ND_PRINT(", dl_addr %s", GET_ETHERADDR_STRING(cp
));
1415 OF_FWD(MAC_ADDR_LEN
);
1417 /* Sometimes the last field, check bounds. */
1420 case OFPAT_SET_NW_SRC
:
1421 case OFPAT_SET_NW_DST
:
1423 ND_PRINT(", nw_addr %s", GET_IPADDR_STRING(cp
));
1426 case OFPAT_SET_NW_TOS
:
1428 ND_PRINT(", nw_tos 0x%02x", GET_U_1(cp
));
1431 /* Sometimes the last field, check bounds. */
1434 case OFPAT_SET_TP_SRC
:
1435 case OFPAT_SET_TP_DST
:
1437 ND_PRINT(", tp_port %u", GET_BE_U_2(cp
));
1440 /* Sometimes the last field, check bounds. */
1445 ND_PRINT(", port %s",
1446 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1451 ND_PRINT(", queue_id %s",
1452 tok2str(ofpq_str
, "%u", GET_BE_U_4(cp
)));
1456 of10_vendor_action_print(ndo
, cp
, alen
- 4);
1459 case OFPAT_STRIP_VLAN
:
1461 /* Sometimes the last field, check bounds. */
1468 invalid
: /* skip the rest of actions */
1469 nd_print_invalid(ndo
);
1470 ND_TCHECK_LEN(cp
, len
);
1473 /* [OF10] Section 5.3.1 */
1475 of10_features_reply_print(netdissect_options
*ndo
,
1476 const u_char
*cp
, u_int len
)
1479 ND_PRINT("\n\t dpid 0x%016" PRIx64
, GET_BE_U_8(cp
));
1482 ND_PRINT(", n_buffers %u", GET_BE_U_4(cp
));
1485 ND_PRINT(", n_tables %u", GET_U_1(cp
));
1490 ND_PRINT("\n\t capabilities 0x%08x", GET_BE_U_4(cp
));
1491 of10_bitmap_print(ndo
, ofp_capabilities_bm
, GET_BE_U_4(cp
), OFPCAP_U
);
1494 ND_PRINT("\n\t actions 0x%08x", GET_BE_U_4(cp
));
1495 of10_bitmap_print(ndo
, ofpat_bm
, GET_BE_U_4(cp
), OFPAT_U
);
1498 of10_phy_ports_print(ndo
, cp
, len
);
1501 /* [OF10] Section 5.3.3 */
1503 of10_flow_mod_print(netdissect_options
*ndo
,
1504 const u_char
*cp
, u_int len
)
1509 of10_match_print(ndo
, "\n\t ", cp
);
1510 OF_FWD(OF_MATCH_FIXLEN
);
1512 ND_PRINT("\n\t cookie 0x%016" PRIx64
, GET_BE_U_8(cp
));
1515 command
= GET_BE_U_2(cp
);
1516 ND_PRINT(", command %s", tok2str(ofpfc_str
, "invalid (0x%04x)", command
));
1520 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp
));
1524 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp
));
1528 ND_PRINT(", priority %u", GET_BE_U_2(cp
));
1531 if (command
== OFPFC_ADD
|| command
== OFPFC_MODIFY
||
1532 command
== OFPFC_MODIFY_STRICT
)
1533 ND_PRINT(", buffer_id %s",
1534 tok2str(bufferid_str
, "0x%08x", GET_BE_U_4(cp
)));
1537 if (command
== OFPFC_DELETE
|| command
== OFPFC_DELETE_STRICT
)
1538 ND_PRINT(", out_port %s",
1539 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1542 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp
));
1543 of10_bitmap_print(ndo
, ofpff_bm
, GET_BE_U_2(cp
), OFPFF_U
);
1546 of10_actions_print(ndo
, "\n\t ", cp
, len
);
1551 of10_port_mod_print(netdissect_options
*ndo
,
1555 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1558 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp
));
1561 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp
));
1562 of10_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
1565 ND_PRINT("\n\t mask 0x%08x", GET_BE_U_4(cp
));
1566 of10_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
1569 ND_PRINT("\n\t advertise 0x%08x", GET_BE_U_4(cp
));
1570 of10_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1573 /* Always the last field, check bounds. */
1577 /* [OF10] Section 5.3.5 */
1579 of10_stats_request_print(netdissect_options
*ndo
,
1580 const u_char
*cp
, u_int len
)
1585 type
= GET_BE_U_2(cp
);
1587 ND_PRINT("\n\t type %s", tok2str(ofpst_str
, "invalid (0x%04x)", type
));
1589 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp
));
1591 ND_PRINT(" (bogus)");
1593 /* type-specific body of one of fixed lengths */
1601 case OFPST_AGGREGATE
:
1602 if (len
!= OF_FLOW_STATS_REQUEST_FIXLEN
)
1605 of10_match_print(ndo
, "\n\t ", cp
);
1606 OF_FWD(OF_MATCH_FIXLEN
);
1608 ND_PRINT("\n\t table_id %s",
1609 tok2str(tableid_str
, "%u", GET_U_1(cp
)));
1614 ND_PRINT(", out_port %s",
1615 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1618 if (len
!= OF_PORT_STATS_REQUEST_FIXLEN
)
1621 ND_PRINT("\n\t port_no %s",
1622 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1625 /* Always the last field, check bounds. */
1629 if (len
!= OF_QUEUE_STATS_REQUEST_FIXLEN
)
1632 ND_PRINT("\n\t port_no %s",
1633 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1638 ND_PRINT(", queue_id %s",
1639 tok2str(ofpq_str
, "%u", GET_BE_U_4(cp
)));
1642 of10_vendor_data_print(ndo
, cp
, len
);
1647 invalid
: /* skip the message body */
1648 nd_print_invalid(ndo
);
1649 ND_TCHECK_LEN(cp
, len
);
1654 of10_desc_stats_reply_print(netdissect_options
*ndo
,
1655 const u_char
*cp
, u_int len
)
1657 if (len
!= OF_DESC_STATS_REPLY_FIXLEN
)
1660 ND_PRINT("\n\t mfr_desc '");
1661 (void)nd_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1663 OF_FWD(DESC_STR_LEN
);
1665 ND_PRINT("\n\t hw_desc '");
1666 (void)nd_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1668 OF_FWD(DESC_STR_LEN
);
1670 ND_PRINT("\n\t sw_desc '");
1671 (void)nd_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1673 OF_FWD(DESC_STR_LEN
);
1675 ND_PRINT("\n\t serial_num '");
1676 (void)nd_print(ndo
, cp
, cp
+ SERIAL_NUM_LEN
);
1678 OF_FWD(SERIAL_NUM_LEN
);
1680 ND_PRINT("\n\t dp_desc '");
1681 (void)nd_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1685 invalid
: /* skip the message body */
1686 nd_print_invalid(ndo
);
1687 ND_TCHECK_LEN(cp
, len
);
1692 of10_flow_stats_reply_print(netdissect_options
*ndo
,
1693 const u_char
*cp
, u_int len
)
1698 if (len
< OF_FLOW_STATS_REPLY_MINLEN
)
1701 entry_len
= GET_BE_U_2(cp
);
1702 ND_PRINT("\n\t length %u", entry_len
);
1703 if (entry_len
< OF_FLOW_STATS_REPLY_MINLEN
|| entry_len
> len
)
1707 ND_PRINT(", table_id %s",
1708 tok2str(tableid_str
, "%u", GET_U_1(cp
)));
1713 of10_match_print(ndo
, "\n\t ", cp
);
1714 OF_FWD(OF_MATCH_FIXLEN
);
1716 ND_PRINT("\n\t duration_sec %u", GET_BE_U_4(cp
));
1719 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp
));
1722 ND_PRINT(", priority %u", GET_BE_U_2(cp
));
1725 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp
));
1728 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp
));
1733 ND_PRINT(", cookie 0x%016" PRIx64
, GET_BE_U_8(cp
));
1736 ND_PRINT(", packet_count %" PRIu64
, GET_BE_U_8(cp
));
1739 ND_PRINT(", byte_count %" PRIu64
, GET_BE_U_8(cp
));
1742 of10_actions_print(ndo
, "\n\t ", cp
, entry_len
- OF_FLOW_STATS_REPLY_MINLEN
);
1743 OF_FWD(entry_len
- OF_FLOW_STATS_REPLY_MINLEN
);
1747 invalid
: /* skip the rest of flow statistics entries */
1748 nd_print_invalid(ndo
);
1749 ND_TCHECK_LEN(cp
, len
);
1754 of10_aggregate_stats_reply_print(netdissect_options
*ndo
,
1755 const u_char
*cp
, u_int len
)
1757 if (len
!= OF_AGGREGATE_STATS_REPLY_FIXLEN
)
1760 ND_PRINT("\n\t packet_count %" PRIu64
, GET_BE_U_8(cp
));
1763 ND_PRINT(", byte_count %" PRIu64
, GET_BE_U_8(cp
));
1766 ND_PRINT(", flow_count %u", GET_BE_U_4(cp
));
1769 /* Always the last field, check bounds. */
1773 invalid
: /* skip the message body */
1774 nd_print_invalid(ndo
);
1775 ND_TCHECK_LEN(cp
, len
);
1780 of10_table_stats_reply_print(netdissect_options
*ndo
,
1781 const u_char
*cp
, u_int len
)
1784 if (len
< OF_TABLE_STATS_REPLY_FIXLEN
)
1787 ND_PRINT("\n\t table_id %s",
1788 tok2str(tableid_str
, "%u", GET_U_1(cp
)));
1793 ND_PRINT(", name '");
1794 (void)nd_print(ndo
, cp
, cp
+ OFP_MAX_TABLE_NAME_LEN
);
1796 OF_FWD(OFP_MAX_TABLE_NAME_LEN
);
1798 ND_PRINT("\n\t wildcards 0x%08x", GET_BE_U_4(cp
));
1799 of10_bitmap_print(ndo
, ofpfw_bm
, GET_BE_U_4(cp
), OFPFW_U
);
1802 ND_PRINT("\n\t max_entries %u", GET_BE_U_4(cp
));
1805 ND_PRINT(", active_count %u", GET_BE_U_4(cp
));
1808 ND_PRINT(", lookup_count %" PRIu64
, GET_BE_U_8(cp
));
1811 ND_PRINT(", matched_count %" PRIu64
, GET_BE_U_8(cp
));
1816 invalid
: /* skip the undersized trailing data */
1817 nd_print_invalid(ndo
);
1818 ND_TCHECK_LEN(cp
, len
);
1823 of10_port_stats_reply_print(netdissect_options
*ndo
,
1824 const u_char
*cp
, u_int len
)
1827 if (len
< OF_PORT_STATS_REPLY_FIXLEN
)
1830 ND_PRINT("\n\t port_no %s",
1831 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1833 if (ndo
->ndo_vflag
< 2) {
1834 OF_CHK_FWD(OF_PORT_STATS_REPLY_FIXLEN
- 2);
1840 ND_PRINT(", rx_packets %" PRIu64
, GET_BE_U_8(cp
));
1843 ND_PRINT(", tx_packets %" PRIu64
, GET_BE_U_8(cp
));
1846 ND_PRINT(", rx_bytes %" PRIu64
, GET_BE_U_8(cp
));
1849 ND_PRINT(", tx_bytes %" PRIu64
, GET_BE_U_8(cp
));
1852 ND_PRINT(", rx_dropped %" PRIu64
, GET_BE_U_8(cp
));
1855 ND_PRINT(", tx_dropped %" PRIu64
, GET_BE_U_8(cp
));
1858 ND_PRINT(", rx_errors %" PRIu64
, GET_BE_U_8(cp
));
1861 ND_PRINT(", tx_errors %" PRIu64
, GET_BE_U_8(cp
));
1864 ND_PRINT(", rx_frame_err %" PRIu64
, GET_BE_U_8(cp
));
1867 ND_PRINT(", rx_over_err %" PRIu64
, GET_BE_U_8(cp
));
1870 ND_PRINT(", rx_crc_err %" PRIu64
, GET_BE_U_8(cp
));
1873 ND_PRINT(", collisions %" PRIu64
, GET_BE_U_8(cp
));
1878 invalid
: /* skip the undersized trailing data */
1879 nd_print_invalid(ndo
);
1880 ND_TCHECK_LEN(cp
, len
);
1885 of10_queue_stats_reply_print(netdissect_options
*ndo
,
1886 const u_char
*cp
, u_int len
)
1889 if (len
< OF_QUEUE_STATS_REPLY_FIXLEN
)
1892 ND_PRINT("\n\t port_no %s",
1893 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1898 ND_PRINT(", queue_id %u", GET_BE_U_4(cp
));
1901 ND_PRINT(", tx_bytes %" PRIu64
, GET_BE_U_8(cp
));
1904 ND_PRINT(", tx_packets %" PRIu64
, GET_BE_U_8(cp
));
1907 ND_PRINT(", tx_errors %" PRIu64
, GET_BE_U_8(cp
));
1912 invalid
: /* skip the undersized trailing data */
1913 nd_print_invalid(ndo
);
1914 ND_TCHECK_LEN(cp
, len
);
1919 of10_stats_reply_print(netdissect_options
*ndo
,
1920 const u_char
*cp
, u_int len
)
1925 type
= GET_BE_U_2(cp
);
1926 ND_PRINT("\n\t type %s", tok2str(ofpst_str
, "invalid (0x%04x)", type
));
1929 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp
));
1930 of10_bitmap_print(ndo
, ofpsf_reply_bm
, GET_BE_U_2(cp
), OFPSF_REPLY_U
);
1933 if (ndo
->ndo_vflag
> 0) {
1934 void (*decoder
)(netdissect_options
*, const u_char
*, u_int
) =
1935 type
== OFPST_DESC
? of10_desc_stats_reply_print
:
1936 type
== OFPST_FLOW
? of10_flow_stats_reply_print
:
1937 type
== OFPST_AGGREGATE
? of10_aggregate_stats_reply_print
:
1938 type
== OFPST_TABLE
? of10_table_stats_reply_print
:
1939 type
== OFPST_PORT
? of10_port_stats_reply_print
:
1940 type
== OFPST_QUEUE
? of10_queue_stats_reply_print
:
1941 type
== OFPST_VENDOR
? of10_vendor_data_print
:
1943 if (decoder
!= NULL
) {
1944 decoder(ndo
, cp
, len
);
1948 ND_TCHECK_LEN(cp
, len
);
1951 /* [OF10] Section 5.3.6 */
1953 of10_packet_out_print(netdissect_options
*ndo
,
1954 const u_char
*cp
, u_int len
)
1956 uint16_t actions_len
;
1959 ND_PRINT("\n\t buffer_id 0x%08x", GET_BE_U_4(cp
));
1962 ND_PRINT(", in_port %s", tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1965 actions_len
= GET_BE_U_2(cp
);
1967 if (actions_len
> len
)
1970 of10_actions_print(ndo
, "\n\t ", cp
, actions_len
);
1971 OF_FWD(actions_len
);
1973 of10_packet_data_print(ndo
, cp
, len
);
1976 invalid
: /* skip the rest of the message body */
1977 nd_print_invalid(ndo
);
1978 ND_TCHECK_LEN(cp
, len
);
1981 /* [OF10] Section 5.4.1 */
1983 of10_packet_in_print(netdissect_options
*ndo
,
1984 const u_char
*cp
, u_int len
)
1987 ND_PRINT("\n\t buffer_id %s",
1988 tok2str(bufferid_str
, "0x%08x", GET_BE_U_4(cp
)));
1991 ND_PRINT(", total_len %u", GET_BE_U_2(cp
));
1994 ND_PRINT(", in_port %s", tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1997 ND_PRINT(", reason %s",
1998 tok2str(ofpr_str
, "invalid (0x%02x)", GET_U_1(cp
)));
2001 /* Sometimes the last field, check bounds. */
2004 of10_packet_data_print(ndo
, cp
, len
);
2007 /* [OF10] Section 5.4.2 */
2009 of10_flow_removed_print(netdissect_options
*ndo
,
2013 of10_match_print(ndo
, "\n\t ", cp
);
2014 cp
+= OF_MATCH_FIXLEN
;
2016 ND_PRINT("\n\t cookie 0x%016" PRIx64
, GET_BE_U_8(cp
));
2020 ND_PRINT(", priority %u", GET_BE_U_2(cp
));
2023 ND_PRINT(", reason %s",
2024 tok2str(ofprr_str
, "unknown (0x%02x)", GET_U_1(cp
)));
2029 ND_PRINT(", duration_sec %u", GET_BE_U_4(cp
));
2032 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp
));
2036 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp
));
2041 ND_PRINT(", packet_count %" PRIu64
, GET_BE_U_8(cp
));
2044 ND_PRINT(", byte_count %" PRIu64
, GET_BE_U_8(cp
));
2047 /* [OF10] Section 5.4.4 */
2049 of10_error_print(netdissect_options
*ndo
,
2050 const u_char
*cp
, u_int len
)
2052 uint16_t type
, code
;
2053 const struct tok
*code_str
[OFPET_MAX
+ 1] = {
2054 /* [OFPET_HELLO_FAILED ] = */ ofphfc_str
,
2055 /* [OFPET_BAD_REQUEST ] = */ ofpbrc_str
,
2056 /* [OFPET_BAD_ACTION ] = */ ofpbac_str
,
2057 /* [OFPET_FLOW_MOD_FAILED] = */ ofpfmfc_str
,
2058 /* [OFPET_PORT_MOD_FAILED] = */ ofppmfc_str
,
2059 /* [OFPET_QUEUE_OP_FAILED] = */ ofpqofc_str
,
2063 type
= GET_BE_U_2(cp
);
2065 ND_PRINT("\n\t type %s", tok2str(ofpet_str
, "invalid (0x%04x)", type
));
2067 code
= GET_BE_U_2(cp
);
2069 if (type
<= OFPET_MAX
&& code_str
[type
] != NULL
)
2070 ND_PRINT(", code %s",
2071 tok2str(code_str
[type
], "invalid (0x%04x)", code
));
2073 ND_PRINT(", code invalid (0x%04x)", code
);
2075 of_data_print(ndo
, cp
, len
);
2079 of10_message_print(netdissect_options
*ndo
,
2080 const u_char
*cp
, uint16_t len
, const uint8_t type
)
2083 * Here "cp" and "len" stand for the message part beyond the common
2084 * OpenFlow 1.0 header, if any. Subtract OF_HEADER_FIXLEN from the
2085 * type-specific lengths, which include the header length, when (and
2086 * only when) validating the length in this function. No other code
2087 * in this file needs to take OF_HEADER_FIXLEN into account.
2089 * Most message types are longer than just the header, and the length
2090 * constraints may be complex. When possible, validate the constraint
2091 * completely here, otherwise check that the message is long enough to
2092 * begin the decoding and let the lower-layer function do any remaining
2096 /* OpenFlow header only. */
2097 case OFPT_FEATURES_REQUEST
: /* [OF10] Section 5.3.1 */
2098 case OFPT_GET_CONFIG_REQUEST
: /* [OF10] Section 5.3.2 */
2099 case OFPT_BARRIER_REQUEST
: /* [OF10] Section 5.3.7 */
2100 case OFPT_BARRIER_REPLY
: /* ibid */
2105 /* OpenFlow header and fixed-size message body. */
2106 case OFPT_SET_CONFIG
: /* [OF10] Section 5.3.2 */
2107 case OFPT_GET_CONFIG_REPLY
: /* ibid */
2108 if (len
!= OF_SWITCH_CONFIG_FIXLEN
- OF_HEADER_FIXLEN
)
2110 if (ndo
->ndo_vflag
< 1)
2113 ND_PRINT("\n\t flags %s",
2114 tok2str(ofp_config_str
, "invalid (0x%04x)",
2118 ND_PRINT(", miss_send_len %u", GET_BE_U_2(cp
));
2121 if (len
!= OF_PORT_MOD_FIXLEN
- OF_HEADER_FIXLEN
)
2123 if (ndo
->ndo_vflag
< 1)
2125 of10_port_mod_print(ndo
, cp
);
2127 case OFPT_QUEUE_GET_CONFIG_REQUEST
: /* [OF10] Section 5.3.4 */
2128 if (len
!= OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN
- OF_HEADER_FIXLEN
)
2130 if (ndo
->ndo_vflag
< 1)
2133 ND_PRINT("\n\t port %s",
2134 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
2137 /* Always the last field, check bounds. */
2140 case OFPT_FLOW_REMOVED
:
2141 if (len
!= OF_FLOW_REMOVED_FIXLEN
- OF_HEADER_FIXLEN
)
2143 if (ndo
->ndo_vflag
< 1)
2145 of10_flow_removed_print(ndo
, cp
);
2147 case OFPT_PORT_STATUS
: /* [OF10] Section 5.4.3 */
2148 if (len
!= OF_PORT_STATUS_FIXLEN
- OF_HEADER_FIXLEN
)
2150 if (ndo
->ndo_vflag
< 1)
2153 ND_PRINT("\n\t reason %s",
2154 tok2str(ofppr_str
, "invalid (0x%02x)", GET_U_1(cp
)));
2157 /* No need to check bounds, more data follows. */
2160 of10_phy_ports_print(ndo
, cp
, len
);
2163 /* OpenFlow header, fixed-size message body and n * fixed-size data units. */
2164 case OFPT_FEATURES_REPLY
:
2165 if (len
< OF_FEATURES_REPLY_MINLEN
- OF_HEADER_FIXLEN
)
2167 if (ndo
->ndo_vflag
< 1)
2169 of10_features_reply_print(ndo
, cp
, len
);
2172 /* OpenFlow header and variable-size data. */
2173 case OFPT_HELLO
: /* [OF10] Section 5.5.1 */
2174 case OFPT_ECHO_REQUEST
: /* [OF10] Section 5.5.2 */
2175 case OFPT_ECHO_REPLY
: /* [OF10] Section 5.5.3 */
2176 if (ndo
->ndo_vflag
< 1)
2178 of_data_print(ndo
, cp
, len
);
2181 /* OpenFlow header, fixed-size message body and variable-size data. */
2183 if (len
< OF_ERROR_MSG_MINLEN
- OF_HEADER_FIXLEN
)
2185 if (ndo
->ndo_vflag
< 1)
2187 of10_error_print(ndo
, cp
, len
);
2190 /* [OF10] Section 5.5.4 */
2191 if (len
< OF_VENDOR_MINLEN
- OF_HEADER_FIXLEN
)
2193 if (ndo
->ndo_vflag
< 1)
2195 of10_vendor_message_print(ndo
, cp
, len
);
2197 case OFPT_PACKET_IN
:
2198 /* 2 mock octets count in OF_PACKET_IN_MINLEN but not in len */
2199 if (len
< OF_PACKET_IN_MINLEN
- 2 - OF_HEADER_FIXLEN
)
2201 if (ndo
->ndo_vflag
< 1)
2203 of10_packet_in_print(ndo
, cp
, len
);
2206 /* a. OpenFlow header. */
2207 /* b. OpenFlow header and one of the fixed-size message bodies. */
2208 /* c. OpenFlow header, fixed-size message body and variable-size data. */
2209 case OFPT_STATS_REQUEST
:
2210 if (len
< OF_STATS_REQUEST_MINLEN
- OF_HEADER_FIXLEN
)
2212 if (ndo
->ndo_vflag
< 1)
2214 of10_stats_request_print(ndo
, cp
, len
);
2217 /* a. OpenFlow header and fixed-size message body. */
2218 /* b. OpenFlow header and n * fixed-size data units. */
2219 /* c. OpenFlow header and n * variable-size data units. */
2220 /* d. OpenFlow header, fixed-size message body and variable-size data. */
2221 case OFPT_STATS_REPLY
:
2222 if (len
< OF_STATS_REPLY_MINLEN
- OF_HEADER_FIXLEN
)
2224 if (ndo
->ndo_vflag
< 1)
2226 of10_stats_reply_print(ndo
, cp
, len
);
2229 /* OpenFlow header and n * variable-size data units and variable-size data. */
2230 case OFPT_PACKET_OUT
:
2231 if (len
< OF_PACKET_OUT_MINLEN
- OF_HEADER_FIXLEN
)
2233 if (ndo
->ndo_vflag
< 1)
2235 of10_packet_out_print(ndo
, cp
, len
);
2238 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2240 if (len
< OF_FLOW_MOD_MINLEN
- OF_HEADER_FIXLEN
)
2242 if (ndo
->ndo_vflag
< 1)
2244 of10_flow_mod_print(ndo
, cp
, len
);
2247 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2248 case OFPT_QUEUE_GET_CONFIG_REPLY
: /* [OF10] Section 5.3.4 */
2249 if (len
< OF_QUEUE_GET_CONFIG_REPLY_MINLEN
- OF_HEADER_FIXLEN
)
2251 if (ndo
->ndo_vflag
< 1)
2254 ND_PRINT("\n\t port %s",
2255 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
2258 /* Sometimes the last field, check bounds. */
2261 of10_queues_print(ndo
, cp
, len
);
2263 } /* switch (type) */
2265 * Not a recognised type or did not print the details, fall back to
2268 ND_TCHECK_LEN(cp
, len
);
2271 invalid
: /* skip the message body */
2272 nd_print_invalid(ndo
);
2273 ND_TCHECK_LEN(cp
, len
);