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 | \
148 * [OF10] lists all FPPS_ constants in one enum, but they mean a 1-bit bitmap
149 * in the least significant octet and a 2-bit code point in the next octet.
150 * Remember to mix or to separate these two parts as the context requires.
152 #define OFPPS_LINK_DOWN (1U << 0) /* bitmap */
153 #define OFPPS_STP_LISTEN (0U << 8) /* code point */
154 #define OFPPS_STP_LEARN (1U << 8) /* code point */
155 #define OFPPS_STP_FORWARD (2U << 8) /* code point */
156 #define OFPPS_STP_BLOCK (3U << 8) /* code point */
157 #define OFPPS_STP_MASK (3U << 8) /* code point bitmask */
158 static const struct tok ofpps_stp_str
[] = {
159 { OFPPS_STP_LISTEN
, "STP_LISTEN" },
160 { OFPPS_STP_LEARN
, "STP_LEARN" },
161 { OFPPS_STP_FORWARD
, "STP_FORWARD" },
162 { OFPPS_STP_BLOCK
, "STP_BLOCK" },
165 #define OFPPS_U (~(OFPPS_LINK_DOWN | OFPPS_STP_LISTEN | OFPPS_STP_LEARN | \
166 OFPPS_STP_FORWARD | OFPPS_STP_BLOCK))
168 #define OFPP_MAX 0xff00U
169 #define OFPP_IN_PORT 0xfff8U
170 #define OFPP_TABLE 0xfff9U
171 #define OFPP_NORMAL 0xfffaU
172 #define OFPP_FLOOD 0xfffbU
173 #define OFPP_ALL 0xfffcU
174 #define OFPP_CONTROLLER 0xfffdU
175 #define OFPP_LOCAL 0xfffeU
176 #define OFPP_NONE 0xffffU
177 static const struct tok ofpp_str
[] = {
179 { OFPP_IN_PORT
, "IN_PORT" },
180 { OFPP_TABLE
, "TABLE" },
181 { OFPP_NORMAL
, "NORMAL" },
182 { OFPP_FLOOD
, "FLOOD" },
184 { OFPP_CONTROLLER
, "CONTROLLER" },
185 { OFPP_LOCAL
, "LOCAL" },
186 { OFPP_NONE
, "NONE" },
190 #define OFPPF_10MB_HD (1U << 0)
191 #define OFPPF_10MB_FD (1U << 1)
192 #define OFPPF_100MB_HD (1U << 2)
193 #define OFPPF_100MB_FD (1U << 3)
194 #define OFPPF_1GB_HD (1U << 4)
195 #define OFPPF_1GB_FD (1U << 5)
196 #define OFPPF_10GB_FD (1U << 6)
197 #define OFPPF_COPPER (1U << 7)
198 #define OFPPF_FIBER (1U << 8)
199 #define OFPPF_AUTONEG (1U << 9)
200 #define OFPPF_PAUSE (1U <<10)
201 #define OFPPF_PAUSE_ASYM (1U <<11)
202 static const struct tok ofppf_bm
[] = {
203 { OFPPF_10MB_HD
, "10MB_HD" },
204 { OFPPF_10MB_FD
, "10MB_FD" },
205 { OFPPF_100MB_HD
, "100MB_HD" },
206 { OFPPF_100MB_FD
, "100MB_FD" },
207 { OFPPF_1GB_HD
, "1GB_HD" },
208 { OFPPF_1GB_FD
, "1GB_FD" },
209 { OFPPF_10GB_FD
, "10GB_FD" },
210 { OFPPF_COPPER
, "COPPER" },
211 { OFPPF_FIBER
, "FIBER" },
212 { OFPPF_AUTONEG
, "AUTONEG" },
213 { OFPPF_PAUSE
, "PAUSE" },
214 { OFPPF_PAUSE_ASYM
, "PAUSE_ASYM" },
217 #define OFPPF_U (~(OFPPF_10MB_HD | OFPPF_10MB_FD | OFPPF_100MB_HD | \
218 OFPPF_100MB_FD | OFPPF_1GB_HD | OFPPF_1GB_FD | \
219 OFPPF_10GB_FD | OFPPF_COPPER | OFPPF_FIBER | \
220 OFPPF_AUTONEG | OFPPF_PAUSE | OFPPF_PAUSE_ASYM))
222 #define OFPQT_NONE 0x0000
223 #define OFPQT_MIN_RATE 0x0001
224 static const struct tok ofpqt_str
[] = {
225 { OFPQT_NONE
, "NONE" },
226 { OFPQT_MIN_RATE
, "MIN_RATE" },
230 #define OFPFW_IN_PORT (1U <<0)
231 #define OFPFW_DL_VLAN (1U <<1)
232 #define OFPFW_DL_SRC (1U <<2)
233 #define OFPFW_DL_DST (1U <<3)
234 #define OFPFW_DL_TYPE (1U <<4)
235 #define OFPFW_NW_PROTO (1U <<5)
236 #define OFPFW_TP_SRC (1U <<6)
237 #define OFPFW_TP_DST (1U <<7)
238 #define OFPFW_NW_SRC_SHIFT 8
239 #define OFPFW_NW_SRC_BITS 6
240 #define OFPFW_NW_SRC_MASK (((1U <<OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT)
241 #define OFPFW_NW_DST_SHIFT 14
242 #define OFPFW_NW_DST_BITS 6
243 #define OFPFW_NW_DST_MASK (((1U <<OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT)
244 #define OFPFW_DL_VLAN_PCP (1U <<20)
245 #define OFPFW_NW_TOS (1U <<21)
246 #define OFPFW_ALL ((1U <<22) - 1)
247 static const struct tok ofpfw_bm
[] = {
248 { OFPFW_IN_PORT
, "IN_PORT" },
249 { OFPFW_DL_VLAN
, "DL_VLAN" },
250 { OFPFW_DL_SRC
, "DL_SRC" },
251 { OFPFW_DL_DST
, "DL_DST" },
252 { OFPFW_DL_TYPE
, "DL_TYPE" },
253 { OFPFW_NW_PROTO
, "NW_PROTO" },
254 { OFPFW_TP_SRC
, "TP_SRC" },
255 { OFPFW_TP_DST
, "TP_DST" },
256 { OFPFW_DL_VLAN_PCP
, "DL_VLAN_PCP" },
257 { OFPFW_NW_TOS
, "NW_TOS" },
260 /* The above array does not include bits 8~13 (OFPFW_NW_SRC_*) and 14~19
261 * (OFPFW_NW_DST_*), which are not a part of the bitmap and require decoding
262 * other than that of tok2str(). The macro below includes these bits such that
263 * they are not reported as bogus in the decoding. */
264 #define OFPFW_U (~(OFPFW_ALL))
266 #define OFPAT_OUTPUT 0x0000U
267 #define OFPAT_SET_VLAN_VID 0x0001U
268 #define OFPAT_SET_VLAN_PCP 0x0002U
269 #define OFPAT_STRIP_VLAN 0x0003U
270 #define OFPAT_SET_DL_SRC 0x0004U
271 #define OFPAT_SET_DL_DST 0x0005U
272 #define OFPAT_SET_NW_SRC 0x0006U
273 #define OFPAT_SET_NW_DST 0x0007U
274 #define OFPAT_SET_NW_TOS 0x0008U
275 #define OFPAT_SET_TP_SRC 0x0009U
276 #define OFPAT_SET_TP_DST 0x000aU
277 #define OFPAT_ENQUEUE 0x000bU
278 #define OFPAT_VENDOR 0xffffU
279 static const struct tok ofpat_str
[] = {
280 { OFPAT_OUTPUT
, "OUTPUT" },
281 { OFPAT_SET_VLAN_VID
, "SET_VLAN_VID" },
282 { OFPAT_SET_VLAN_PCP
, "SET_VLAN_PCP" },
283 { OFPAT_STRIP_VLAN
, "STRIP_VLAN" },
284 { OFPAT_SET_DL_SRC
, "SET_DL_SRC" },
285 { OFPAT_SET_DL_DST
, "SET_DL_DST" },
286 { OFPAT_SET_NW_SRC
, "SET_NW_SRC" },
287 { OFPAT_SET_NW_DST
, "SET_NW_DST" },
288 { OFPAT_SET_NW_TOS
, "SET_NW_TOS" },
289 { OFPAT_SET_TP_SRC
, "SET_TP_SRC" },
290 { OFPAT_SET_TP_DST
, "SET_TP_DST" },
291 { OFPAT_ENQUEUE
, "ENQUEUE" },
292 { OFPAT_VENDOR
, "VENDOR" },
296 /* bit-shifted, w/o vendor action */
297 static const struct tok ofpat_bm
[] = {
298 { 1U <<OFPAT_OUTPUT
, "OUTPUT" },
299 { 1U <<OFPAT_SET_VLAN_VID
, "SET_VLAN_VID" },
300 { 1U <<OFPAT_SET_VLAN_PCP
, "SET_VLAN_PCP" },
301 { 1U <<OFPAT_STRIP_VLAN
, "STRIP_VLAN" },
302 { 1U <<OFPAT_SET_DL_SRC
, "SET_DL_SRC" },
303 { 1U <<OFPAT_SET_DL_DST
, "SET_DL_DST" },
304 { 1U <<OFPAT_SET_NW_SRC
, "SET_NW_SRC" },
305 { 1U <<OFPAT_SET_NW_DST
, "SET_NW_DST" },
306 { 1U <<OFPAT_SET_NW_TOS
, "SET_NW_TOS" },
307 { 1U <<OFPAT_SET_TP_SRC
, "SET_TP_SRC" },
308 { 1U <<OFPAT_SET_TP_DST
, "SET_TP_DST" },
309 { 1U <<OFPAT_ENQUEUE
, "ENQUEUE" },
312 #define OFPAT_U (~(1U <<OFPAT_OUTPUT | 1U <<OFPAT_SET_VLAN_VID | \
313 1U <<OFPAT_SET_VLAN_PCP | 1U <<OFPAT_STRIP_VLAN | \
314 1U <<OFPAT_SET_DL_SRC | 1U <<OFPAT_SET_DL_DST | \
315 1U <<OFPAT_SET_NW_SRC | 1U <<OFPAT_SET_NW_DST | \
316 1U <<OFPAT_SET_NW_TOS | 1U <<OFPAT_SET_TP_SRC | \
317 1U <<OFPAT_SET_TP_DST | 1U <<OFPAT_ENQUEUE))
319 #define OFPC_FLOW_STATS (1U <<0)
320 #define OFPC_TABLE_STATS (1U <<1)
321 #define OFPC_PORT_STATS (1U <<2)
322 #define OFPC_STP (1U <<3)
323 #define OFPC_RESERVED (1U <<4)
324 #define OFPC_IP_REASM (1U <<5)
325 #define OFPC_QUEUE_STATS (1U <<6)
326 #define OFPC_ARP_MATCH_IP (1U <<7)
327 static const struct tok ofp_capabilities_bm
[] = {
328 { OFPC_FLOW_STATS
, "FLOW_STATS" },
329 { OFPC_TABLE_STATS
, "TABLE_STATS" },
330 { OFPC_PORT_STATS
, "PORT_STATS" },
332 { OFPC_RESERVED
, "RESERVED" }, /* not in the mask below */
333 { OFPC_IP_REASM
, "IP_REASM" },
334 { OFPC_QUEUE_STATS
, "QUEUE_STATS" },
335 { OFPC_ARP_MATCH_IP
, "ARP_MATCH_IP" },
338 #define OFPCAP_U (~(OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS | \
339 OFPC_STP | OFPC_IP_REASM | OFPC_QUEUE_STATS | \
342 #define OFPC_FRAG_NORMAL 0x0000U
343 #define OFPC_FRAG_DROP 0x0001U
344 #define OFPC_FRAG_REASM 0x0002U
345 #define OFPC_FRAG_MASK 0x0003U
346 static const struct tok ofp_config_str
[] = {
347 { OFPC_FRAG_NORMAL
, "FRAG_NORMAL" },
348 { OFPC_FRAG_DROP
, "FRAG_DROP" },
349 { OFPC_FRAG_REASM
, "FRAG_REASM" },
353 #define OFPFC_ADD 0x0000U
354 #define OFPFC_MODIFY 0x0001U
355 #define OFPFC_MODIFY_STRICT 0x0002U
356 #define OFPFC_DELETE 0x0003U
357 #define OFPFC_DELETE_STRICT 0x0004U
358 static const struct tok ofpfc_str
[] = {
359 { OFPFC_ADD
, "ADD" },
360 { OFPFC_MODIFY
, "MODIFY" },
361 { OFPFC_MODIFY_STRICT
, "MODIFY_STRICT" },
362 { OFPFC_DELETE
, "DELETE" },
363 { OFPFC_DELETE_STRICT
, "DELETE_STRICT" },
367 static const struct tok bufferid_str
[] = {
368 { 0xffffffff, "NONE" },
372 #define OFPFF_SEND_FLOW_REM (1U <<0)
373 #define OFPFF_CHECK_OVERLAP (1U <<1)
374 #define OFPFF_EMERG (1U <<2)
375 static const struct tok ofpff_bm
[] = {
376 { OFPFF_SEND_FLOW_REM
, "SEND_FLOW_REM" },
377 { OFPFF_CHECK_OVERLAP
, "CHECK_OVERLAP" },
378 { OFPFF_EMERG
, "EMERG" },
381 #define OFPFF_U (~(OFPFF_SEND_FLOW_REM | OFPFF_CHECK_OVERLAP | OFPFF_EMERG))
383 #define OFPST_DESC 0x0000U
384 #define OFPST_FLOW 0x0001U
385 #define OFPST_AGGREGATE 0x0002U
386 #define OFPST_TABLE 0x0003U
387 #define OFPST_PORT 0x0004U
388 #define OFPST_QUEUE 0x0005U
389 #define OFPST_VENDOR 0xffffU
390 static const struct tok ofpst_str
[] = {
391 { OFPST_DESC
, "DESC" },
392 { OFPST_FLOW
, "FLOW" },
393 { OFPST_AGGREGATE
, "AGGREGATE" },
394 { OFPST_TABLE
, "TABLE" },
395 { OFPST_PORT
, "PORT" },
396 { OFPST_QUEUE
, "QUEUE" },
397 { OFPST_VENDOR
, "VENDOR" },
401 static const struct tok tableid_str
[] = {
407 #define OFPQ_ALL 0xffffffffU
408 static const struct tok ofpq_str
[] = {
413 #define OFPSF_REPLY_MORE 0x0001U
414 static const struct tok ofpsf_reply_bm
[] = {
415 { OFPSF_REPLY_MORE
, "MORE" },
418 #define OFPSF_REPLY_U (~(OFPSF_REPLY_MORE))
420 #define OFPR_NO_MATCH 0x00U
421 #define OFPR_ACTION 0x01U
422 static const struct tok ofpr_str
[] = {
423 { OFPR_NO_MATCH
, "NO_MATCH" },
424 { OFPR_ACTION
, "ACTION" },
428 #define OFPRR_IDLE_TIMEOUT 0x00U
429 #define OFPRR_HARD_TIMEOUT 0x01U
430 #define OFPRR_DELETE 0x02U
431 static const struct tok ofprr_str
[] = {
432 { OFPRR_IDLE_TIMEOUT
, "IDLE_TIMEOUT" },
433 { OFPRR_HARD_TIMEOUT
, "HARD_TIMEOUT" },
434 { OFPRR_DELETE
, "DELETE" },
438 #define OFPPR_ADD 0x00U
439 #define OFPPR_DELETE 0x01U
440 #define OFPPR_MODIFY 0x02U
441 static const struct tok ofppr_str
[] = {
442 { OFPPR_ADD
, "ADD" },
443 { OFPPR_DELETE
, "DELETE" },
444 { OFPPR_MODIFY
, "MODIFY" },
448 #define OFPET_HELLO_FAILED 0x0000U
449 #define OFPET_BAD_REQUEST 0x0001U
450 #define OFPET_BAD_ACTION 0x0002U
451 #define OFPET_FLOW_MOD_FAILED 0x0003U
452 #define OFPET_PORT_MOD_FAILED 0x0004U
453 #define OFPET_QUEUE_OP_FAILED 0x0005U
454 static const struct tok ofpet_str
[] = {
455 { OFPET_HELLO_FAILED
, "HELLO_FAILED" },
456 { OFPET_BAD_REQUEST
, "BAD_REQUEST" },
457 { OFPET_BAD_ACTION
, "BAD_ACTION" },
458 { OFPET_FLOW_MOD_FAILED
, "FLOW_MOD_FAILED" },
459 { OFPET_PORT_MOD_FAILED
, "PORT_MOD_FAILED" },
460 { OFPET_QUEUE_OP_FAILED
, "QUEUE_OP_FAILED" },
464 #define OFPHFC_INCOMPATIBLE 0x0000U
465 #define OFPHFC_EPERM 0x0001U
466 static const struct tok ofphfc_str
[] = {
467 { OFPHFC_INCOMPATIBLE
, "INCOMPATIBLE" },
468 { OFPHFC_EPERM
, "EPERM" },
472 #define OFPBRC_BAD_VERSION 0x0000U
473 #define OFPBRC_BAD_TYPE 0x0001U
474 #define OFPBRC_BAD_STAT 0x0002U
475 #define OFPBRC_BAD_VENDOR 0x0003U
476 #define OFPBRC_BAD_SUBTYPE 0x0004U
477 #define OFPBRC_EPERM 0x0005U
478 #define OFPBRC_BAD_LEN 0x0006U
479 #define OFPBRC_BUFFER_EMPTY 0x0007U
480 #define OFPBRC_BUFFER_UNKNOWN 0x0008U
481 static const struct tok ofpbrc_str
[] = {
482 { OFPBRC_BAD_VERSION
, "BAD_VERSION" },
483 { OFPBRC_BAD_TYPE
, "BAD_TYPE" },
484 { OFPBRC_BAD_STAT
, "BAD_STAT" },
485 { OFPBRC_BAD_VENDOR
, "BAD_VENDOR" },
486 { OFPBRC_BAD_SUBTYPE
, "BAD_SUBTYPE" },
487 { OFPBRC_EPERM
, "EPERM" },
488 { OFPBRC_BAD_LEN
, "BAD_LEN" },
489 { OFPBRC_BUFFER_EMPTY
, "BUFFER_EMPTY" },
490 { OFPBRC_BUFFER_UNKNOWN
, "BUFFER_UNKNOWN" },
494 #define OFPBAC_BAD_TYPE 0x0000U
495 #define OFPBAC_BAD_LEN 0x0001U
496 #define OFPBAC_BAD_VENDOR 0x0002U
497 #define OFPBAC_BAD_VENDOR_TYPE 0x0003U
498 #define OFPBAC_BAD_OUT_PORT 0x0004U
499 #define OFPBAC_BAD_ARGUMENT 0x0005U
500 #define OFPBAC_EPERM 0x0006U
501 #define OFPBAC_TOO_MANY 0x0007U
502 #define OFPBAC_BAD_QUEUE 0x0008U
503 static const struct tok ofpbac_str
[] = {
504 { OFPBAC_BAD_TYPE
, "BAD_TYPE" },
505 { OFPBAC_BAD_LEN
, "BAD_LEN" },
506 { OFPBAC_BAD_VENDOR
, "BAD_VENDOR" },
507 { OFPBAC_BAD_VENDOR_TYPE
, "BAD_VENDOR_TYPE" },
508 { OFPBAC_BAD_OUT_PORT
, "BAD_OUT_PORT" },
509 { OFPBAC_BAD_ARGUMENT
, "BAD_ARGUMENT" },
510 { OFPBAC_EPERM
, "EPERM" },
511 { OFPBAC_TOO_MANY
, "TOO_MANY" },
512 { OFPBAC_BAD_QUEUE
, "BAD_QUEUE" },
516 #define OFPFMFC_ALL_TABLES_FULL 0x0000U
517 #define OFPFMFC_OVERLAP 0x0001U
518 #define OFPFMFC_EPERM 0x0002U
519 #define OFPFMFC_BAD_EMERG_TIMEOUT 0x0003U
520 #define OFPFMFC_BAD_COMMAND 0x0004U
521 #define OFPFMFC_UNSUPPORTED 0x0005U
522 static const struct tok ofpfmfc_str
[] = {
523 { OFPFMFC_ALL_TABLES_FULL
, "ALL_TABLES_FULL" },
524 { OFPFMFC_OVERLAP
, "OVERLAP" },
525 { OFPFMFC_EPERM
, "EPERM" },
526 { OFPFMFC_BAD_EMERG_TIMEOUT
, "BAD_EMERG_TIMEOUT" },
527 { OFPFMFC_BAD_COMMAND
, "BAD_COMMAND" },
528 { OFPFMFC_UNSUPPORTED
, "UNSUPPORTED" },
532 #define OFPPMFC_BAD_PORT 0x0000U
533 #define OFPPMFC_BAD_HW_ADDR 0x0001U
534 static const struct tok ofppmfc_str
[] = {
535 { OFPPMFC_BAD_PORT
, "BAD_PORT" },
536 { OFPPMFC_BAD_HW_ADDR
, "BAD_HW_ADDR" },
540 #define OFPQOFC_BAD_PORT 0x0000U
541 #define OFPQOFC_BAD_QUEUE 0x0001U
542 #define OFPQOFC_EPERM 0x0002U
543 static const struct tok ofpqofc_str
[] = {
544 { OFPQOFC_BAD_PORT
, "BAD_PORT" },
545 { OFPQOFC_BAD_QUEUE
, "BAD_QUEUE" },
546 { OFPQOFC_EPERM
, "EPERM" },
550 static const struct uint_tokary of10_ofpet2tokary
[] = {
551 { OFPET_HELLO_FAILED
, ofphfc_str
},
552 { OFPET_BAD_REQUEST
, ofpbrc_str
},
553 { OFPET_BAD_ACTION
, ofpbac_str
},
554 { OFPET_FLOW_MOD_FAILED
, ofpfmfc_str
},
555 { OFPET_PORT_MOD_FAILED
, ofppmfc_str
},
556 { OFPET_QUEUE_OP_FAILED
, ofpqofc_str
},
557 /* uint2tokary() does not use array termination. */
560 /* lengths (fixed or minimal) of particular protocol structures */
561 #define OF_SWITCH_CONFIG_FIXLEN 12
562 #define OF_PHY_PORT_FIXLEN 48
563 #define OF_FEATURES_REPLY_MINLEN 32
564 #define OF_PORT_STATUS_FIXLEN 64
565 #define OF_PORT_MOD_FIXLEN 32
566 #define OF_PACKET_IN_MINLEN 20 /* with 2 mock octets */
567 #define OF_ACTION_MINLEN 8
568 #define OF_PACKET_OUT_MINLEN 16
569 #define OF_MATCH_FIXLEN 40
570 #define OF_FLOW_MOD_MINLEN 72
571 #define OF_FLOW_REMOVED_FIXLEN 88
572 #define OF_ERROR_MSG_MINLEN 12
573 #define OF_STATS_REQUEST_MINLEN 12
574 #define OF_STATS_REPLY_MINLEN 12
575 #define OF_DESC_STATS_REPLY_FIXLEN 1056
576 #define OF_FLOW_STATS_REQUEST_FIXLEN 44
577 #define OF_FLOW_STATS_REPLY_MINLEN 88
578 #define OF_AGGREGATE_STATS_REPLY_FIXLEN 24
579 #define OF_TABLE_STATS_REPLY_FIXLEN 64
580 #define OF_PORT_STATS_REQUEST_FIXLEN 8
581 #define OF_PORT_STATS_REPLY_FIXLEN 104
582 #define OF_VENDOR_MINLEN 12
583 #define OF_QUEUE_PROP_MINLEN 8
584 #define OF_QUEUE_PROP_MIN_RATE_FIXLEN 16
585 #define OF_PACKET_QUEUE_MINLEN 8
586 #define OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN 12
587 #define OF_QUEUE_GET_CONFIG_REPLY_MINLEN 16
588 #define OF_QUEUE_STATS_REQUEST_FIXLEN 8
589 #define OF_QUEUE_STATS_REPLY_FIXLEN 32
591 /* miscellaneous constants from [OF10] */
592 #define OFP_MAX_TABLE_NAME_LEN 32
593 #define OFP_MAX_PORT_NAME_LEN 16
594 #define DESC_STR_LEN 256
595 #define SERIAL_NUM_LEN 32
596 #define OFP_VLAN_NONE 0xffffU
598 /* vendor extensions */
599 #define BSN_SET_IP_MASK 0
600 #define BSN_GET_IP_MASK_REQUEST 1
601 #define BSN_GET_IP_MASK_REPLY 2
602 #define BSN_SET_MIRRORING 3
603 #define BSN_GET_MIRRORING_REQUEST 4
604 #define BSN_GET_MIRRORING_REPLY 5
605 #define BSN_SHELL_COMMAND 6
606 #define BSN_SHELL_OUTPUT 7
607 #define BSN_SHELL_STATUS 8
608 #define BSN_GET_INTERFACES_REQUEST 9
609 #define BSN_GET_INTERFACES_REPLY 10
610 #define BSN_SET_PKTIN_SUPPRESSION_REQUEST 11
611 #define BSN_SET_L2_TABLE_REQUEST 12
612 #define BSN_GET_L2_TABLE_REQUEST 13
613 #define BSN_GET_L2_TABLE_REPLY 14
614 #define BSN_VIRTUAL_PORT_CREATE_REQUEST 15
615 #define BSN_VIRTUAL_PORT_CREATE_REPLY 16
616 #define BSN_VIRTUAL_PORT_REMOVE_REQUEST 17
617 #define BSN_BW_ENABLE_SET_REQUEST 18
618 #define BSN_BW_ENABLE_GET_REQUEST 19
619 #define BSN_BW_ENABLE_GET_REPLY 20
620 #define BSN_BW_CLEAR_DATA_REQUEST 21
621 #define BSN_BW_CLEAR_DATA_REPLY 22
622 #define BSN_BW_ENABLE_SET_REPLY 23
623 #define BSN_SET_L2_TABLE_REPLY 24
624 #define BSN_SET_PKTIN_SUPPRESSION_REPLY 25
625 #define BSN_VIRTUAL_PORT_REMOVE_REPLY 26
626 #define BSN_HYBRID_GET_REQUEST 27
627 #define BSN_HYBRID_GET_REPLY 28
630 #define BSN_PDU_TX_REQUEST 31
631 #define BSN_PDU_TX_REPLY 32
632 #define BSN_PDU_RX_REQUEST 33
633 #define BSN_PDU_RX_REPLY 34
634 #define BSN_PDU_RX_TIMEOUT 35
636 static const struct tok bsn_subtype_str
[] = {
637 { BSN_SET_IP_MASK
, "SET_IP_MASK" },
638 { BSN_GET_IP_MASK_REQUEST
, "GET_IP_MASK_REQUEST" },
639 { BSN_GET_IP_MASK_REPLY
, "GET_IP_MASK_REPLY" },
640 { BSN_SET_MIRRORING
, "SET_MIRRORING" },
641 { BSN_GET_MIRRORING_REQUEST
, "GET_MIRRORING_REQUEST" },
642 { BSN_GET_MIRRORING_REPLY
, "GET_MIRRORING_REPLY" },
643 { BSN_SHELL_COMMAND
, "SHELL_COMMAND" },
644 { BSN_SHELL_OUTPUT
, "SHELL_OUTPUT" },
645 { BSN_SHELL_STATUS
, "SHELL_STATUS" },
646 { BSN_GET_INTERFACES_REQUEST
, "GET_INTERFACES_REQUEST" },
647 { BSN_GET_INTERFACES_REPLY
, "GET_INTERFACES_REPLY" },
648 { BSN_SET_PKTIN_SUPPRESSION_REQUEST
, "SET_PKTIN_SUPPRESSION_REQUEST" },
649 { BSN_SET_L2_TABLE_REQUEST
, "SET_L2_TABLE_REQUEST" },
650 { BSN_GET_L2_TABLE_REQUEST
, "GET_L2_TABLE_REQUEST" },
651 { BSN_GET_L2_TABLE_REPLY
, "GET_L2_TABLE_REPLY" },
652 { BSN_VIRTUAL_PORT_CREATE_REQUEST
, "VIRTUAL_PORT_CREATE_REQUEST" },
653 { BSN_VIRTUAL_PORT_CREATE_REPLY
, "VIRTUAL_PORT_CREATE_REPLY" },
654 { BSN_VIRTUAL_PORT_REMOVE_REQUEST
, "VIRTUAL_PORT_REMOVE_REQUEST" },
655 { BSN_BW_ENABLE_SET_REQUEST
, "BW_ENABLE_SET_REQUEST" },
656 { BSN_BW_ENABLE_GET_REQUEST
, "BW_ENABLE_GET_REQUEST" },
657 { BSN_BW_ENABLE_GET_REPLY
, "BW_ENABLE_GET_REPLY" },
658 { BSN_BW_CLEAR_DATA_REQUEST
, "BW_CLEAR_DATA_REQUEST" },
659 { BSN_BW_CLEAR_DATA_REPLY
, "BW_CLEAR_DATA_REPLY" },
660 { BSN_BW_ENABLE_SET_REPLY
, "BW_ENABLE_SET_REPLY" },
661 { BSN_SET_L2_TABLE_REPLY
, "SET_L2_TABLE_REPLY" },
662 { BSN_SET_PKTIN_SUPPRESSION_REPLY
, "SET_PKTIN_SUPPRESSION_REPLY" },
663 { BSN_VIRTUAL_PORT_REMOVE_REPLY
, "VIRTUAL_PORT_REMOVE_REPLY" },
664 { BSN_HYBRID_GET_REQUEST
, "HYBRID_GET_REQUEST" },
665 { BSN_HYBRID_GET_REPLY
, "HYBRID_GET_REPLY" },
666 { BSN_PDU_TX_REQUEST
, "PDU_TX_REQUEST" },
667 { BSN_PDU_TX_REPLY
, "PDU_TX_REPLY" },
668 { BSN_PDU_RX_REQUEST
, "PDU_RX_REQUEST" },
669 { BSN_PDU_RX_REPLY
, "PDU_RX_REPLY" },
670 { BSN_PDU_RX_TIMEOUT
, "PDU_RX_TIMEOUT" },
674 #define BSN_ACTION_MIRROR 1
675 #define BSN_ACTION_SET_TUNNEL_DST 2
677 #define BSN_ACTION_CHECKSUM 4
679 static const struct tok bsn_action_subtype_str
[] = {
680 { BSN_ACTION_MIRROR
, "MIRROR" },
681 { BSN_ACTION_SET_TUNNEL_DST
, "SET_TUNNEL_DST" },
682 { BSN_ACTION_CHECKSUM
, "CHECKSUM" },
686 static const struct tok bsn_mirror_copy_stage_str
[] = {
692 static const struct tok bsn_onoff_str
[] = {
698 /* [OF10] Section 5.1 */
699 const char * of10_msgtype_str(const uint8_t type
)
701 return tok2str(ofpt_str
, "invalid (0x%02x)", type
);
705 vlan_str(const uint16_t vid
)
707 static char buf
[sizeof("65535 (bogus)")];
709 if (vid
== OFP_VLAN_NONE
)
711 snprintf(buf
, sizeof(buf
), "%u%s", vid
,
712 (vid
> 0 && vid
< 0x0fff) ? "" : " (bogus)");
717 pcp_str(const uint8_t pcp
)
719 static char buf
[sizeof("255 (bogus)")];
720 snprintf(buf
, sizeof(buf
), "%u%s", pcp
,
721 pcp
<= 7 ? "" : " (bogus)");
726 of10_bsn_message_print(netdissect_options
*ndo
,
727 const u_char
*cp
, u_int len
)
734 subtype
= GET_BE_U_4(cp
);
736 ND_PRINT("\n\t subtype %s", tok2str(bsn_subtype_str
, "unknown (0x%08x)", subtype
));
738 case BSN_GET_IP_MASK_REQUEST
:
741 * 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
742 * +---------------+---------------+---------------+---------------+
744 * +---------------+---------------+---------------+---------------+
746 * +---------------+---------------+---------------+---------------+
748 * +---------------+---------------+---------------+---------------+
754 ND_PRINT(", index %u", GET_U_1(cp
));
757 /* Always the last field, check bounds. */
760 case BSN_SET_IP_MASK
:
761 case BSN_GET_IP_MASK_REPLY
:
764 * 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
765 * +---------------+---------------+---------------+---------------+
767 * +---------------+---------------+---------------+---------------+
769 * +---------------+---------------+---------------+---------------+
771 * +---------------+---------------+---------------+---------------+
777 ND_PRINT(", index %u", GET_U_1(cp
));
782 ND_PRINT(", mask %s", GET_IPADDR_STRING(cp
));
784 case BSN_SET_MIRRORING
:
785 case BSN_GET_MIRRORING_REQUEST
:
786 case BSN_GET_MIRRORING_REPLY
:
789 * 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
790 * +---------------+---------------+---------------+---------------+
792 * +---------------+---------------+---------------+---------------+
793 * | report m. p. | pad |
794 * +---------------+---------------+---------------+---------------+
799 /* report_mirror_ports */
800 ND_PRINT(", report_mirror_ports %s",
801 tok2str(bsn_onoff_str
, "bogus (%u)", GET_U_1(cp
)));
804 /* Always the last field, check bounds. */
807 case BSN_GET_INTERFACES_REQUEST
:
808 case BSN_GET_L2_TABLE_REQUEST
:
809 case BSN_BW_ENABLE_GET_REQUEST
:
810 case BSN_BW_CLEAR_DATA_REQUEST
:
811 case BSN_HYBRID_GET_REQUEST
:
814 * 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
815 * +---------------+---------------+---------------+---------------+
817 * +---------------+---------------+---------------+---------------+
823 case BSN_VIRTUAL_PORT_REMOVE_REQUEST
:
826 * 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
827 * +---------------+---------------+---------------+---------------+
829 * +---------------+---------------+---------------+---------------+
831 * +---------------+---------------+---------------+---------------+
837 ND_PRINT(", vport_no %u", GET_BE_U_4(cp
));
839 case BSN_SHELL_COMMAND
:
842 * 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
843 * +---------------+---------------+---------------+---------------+
845 * +---------------+---------------+---------------+---------------+
847 * +---------------+---------------+---------------+---------------+
849 * +---------------+---------------+--------
855 ND_PRINT(", service %u", GET_BE_U_4(cp
));
858 ND_PRINT(", data '");
859 nd_printn(ndo
, cp
, len
, NULL
);
862 case BSN_SHELL_OUTPUT
:
865 * 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
866 * +---------------+---------------+---------------+---------------+
868 * +---------------+---------------+---------------+---------------+
870 * +---------------+---------------+--------
873 /* already checked that len >= 4 */
875 ND_PRINT(", data '");
876 nd_printn(ndo
, cp
, len
, NULL
);
879 case BSN_SHELL_STATUS
:
882 * 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
883 * +---------------+---------------+---------------+---------------+
885 * +---------------+---------------+---------------+---------------+
887 * +---------------+---------------+---------------+---------------+
893 ND_PRINT(", status 0x%08x", GET_BE_U_4(cp
));
896 ND_TCHECK_LEN(cp
, len
);
900 invalid
: /* skip the undersized data */
901 nd_print_invalid(ndo
);
902 ND_TCHECK_LEN(cp
, len
);
906 of10_bsn_actions_print(netdissect_options
*ndo
,
907 const u_char
*cp
, u_int len
)
909 uint32_t subtype
, vlan_tag
;
914 subtype
= GET_BE_U_4(cp
);
916 ND_PRINT("\n\t subtype %s", tok2str(bsn_action_subtype_str
, "unknown (0x%08x)", subtype
));
918 case BSN_ACTION_MIRROR
:
921 * 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
922 * +---------------+---------------+---------------+---------------+
924 * +---------------+---------------+---------------+---------------+
926 * +---------------+---------------+---------------+---------------+
928 * +---------------+---------------+---------------+---------------+
929 * | copy_stage | pad |
930 * +---------------+---------------+---------------+---------------+
936 ND_PRINT(", dest_port %u", GET_BE_U_4(cp
));
939 vlan_tag
= GET_BE_U_4(cp
);
941 switch (vlan_tag
>> 16) {
943 ND_PRINT(", vlan_tag none");
945 case ETHERTYPE_8021Q
:
946 ND_PRINT(", vlan_tag 802.1Q (%s)", ieee8021q_tci_string(vlan_tag
& 0xffff));
949 ND_PRINT(", vlan_tag unknown (0x%04x)", vlan_tag
>> 16);
952 ND_PRINT(", copy_stage %s",
953 tok2str(bsn_mirror_copy_stage_str
, "unknown (%u)", GET_U_1(cp
)));
956 /* Always the last field, check bounds. */
960 ND_TCHECK_LEN(cp
, len
);
965 nd_print_invalid(ndo
);
966 ND_TCHECK_LEN(cp
, len
);
970 of10_vendor_action_print(netdissect_options
*ndo
,
971 const u_char
*cp
, u_int len
)
974 void (*decoder
)(netdissect_options
*, const u_char
*, u_int
);
979 vendor
= GET_BE_U_4(cp
);
981 ND_PRINT(", vendor 0x%08x (%s)", vendor
, of_vendor_name(vendor
));
984 vendor
== OUI_BSN
? of10_bsn_actions_print
:
986 decoder(ndo
, cp
, len
);
989 invalid
: /* skip the undersized data */
990 nd_print_invalid(ndo
);
991 ND_TCHECK_LEN(cp
, len
);
994 /* [OF10] Section 5.5.4 */
996 of10_vendor_message_print(netdissect_options
*ndo
,
997 const u_char
*cp
, u_int len
)
1000 void (*decoder
)(netdissect_options
*, const u_char
*, u_int
);
1003 vendor
= GET_BE_U_4(cp
);
1005 ND_PRINT(", vendor 0x%08x (%s)", vendor
, of_vendor_name(vendor
));
1008 vendor
== OUI_BSN
? of10_bsn_message_print
:
1010 decoder(ndo
, cp
, len
);
1013 /* Vendor ID is mandatory, data is optional. */
1015 of10_vendor_data_print(netdissect_options
*ndo
,
1016 const u_char
*cp
, u_int len
)
1023 vendor
= GET_BE_U_4(cp
);
1025 ND_PRINT(", vendor 0x%08x (%s)", vendor
, of_vendor_name(vendor
));
1027 of_data_print(ndo
, cp
, len
);
1030 invalid
: /* skip the undersized data */
1031 nd_print_invalid(ndo
);
1032 ND_TCHECK_LEN(cp
, len
);
1036 of10_packet_data_print(netdissect_options
*ndo
,
1037 const u_char
*cp
, const u_int len
)
1042 ND_PRINT("\n\t data (%u octets)", len
);
1043 if (ndo
->ndo_vflag
< 3) {
1044 ND_TCHECK_LEN(cp
, len
);
1047 ndo
->ndo_vflag
-= 3;
1048 ND_PRINT(", frame decoding below\n");
1049 ether_print(ndo
, cp
, len
, ND_BYTES_AVAILABLE_AFTER(cp
), NULL
, NULL
);
1050 ndo
->ndo_vflag
+= 3;
1053 /* [OF10] Section 5.2.1 */
1055 of10_phy_port_print(netdissect_options
*ndo
,
1061 ND_PRINT("\n\t port_no %s",
1062 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1065 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp
));
1068 ND_PRINT(", name '");
1069 (void)nd_print(ndo
, cp
, cp
+ OFP_MAX_PORT_NAME_LEN
);
1071 cp
+= OFP_MAX_PORT_NAME_LEN
;
1073 if (ndo
->ndo_vflag
< 2) {
1074 ND_TCHECK_LEN(cp
, 24);
1078 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp
));
1079 of_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
1082 state
= GET_BE_U_4(cp
);
1084 * Decode the code point and the single bit separately, but
1085 * format the result as a single sequence of comma-separated
1086 * strings (see the comments at the OFPPS_ props).
1088 ND_PRINT("\n\t state 0x%08x (%s%s)%s", state
,
1089 tok2str(ofpps_stp_str
, "", state
& OFPPS_STP_MASK
),
1090 state
& OFPPS_LINK_DOWN
? ", LINK_DOWN" : "",
1091 state
& OFPPS_U
? " (bogus)" : "");
1094 ND_PRINT("\n\t curr 0x%08x", GET_BE_U_4(cp
));
1095 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1098 ND_PRINT("\n\t advertised 0x%08x", GET_BE_U_4(cp
));
1099 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1102 ND_PRINT("\n\t supported 0x%08x", GET_BE_U_4(cp
));
1103 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1106 ND_PRINT("\n\t peer 0x%08x", GET_BE_U_4(cp
));
1107 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1110 /* [OF10] Section 5.2.2 */
1112 of10_queue_props_print(netdissect_options
*ndo
,
1113 const u_char
*cp
, u_int len
)
1116 uint16_t property
, plen
;
1117 u_char plen_bogus
= 0, skip
= 0;
1119 if (len
< OF_QUEUE_PROP_MINLEN
)
1122 property
= GET_BE_U_2(cp
);
1124 ND_PRINT("\n\t property %s", tok2str(ofpqt_str
, "invalid (0x%04x)", property
));
1126 plen
= GET_BE_U_2(cp
);
1128 ND_PRINT(", len %u", plen
);
1129 if (plen
< OF_QUEUE_PROP_MINLEN
|| plen
> len
+ 4)
1132 /* Sometimes the last field, check bounds. */
1134 /* property-specific constraints and decoding */
1137 plen_bogus
= plen
!= OF_QUEUE_PROP_MINLEN
;
1139 case OFPQT_MIN_RATE
:
1140 plen_bogus
= plen
!= OF_QUEUE_PROP_MIN_RATE_FIXLEN
;
1146 ND_PRINT(" (bogus)");
1151 * plen >= OF_QUEUE_PROP_MINLEN
1152 * cp is OF_QUEUE_PROP_MINLEN bytes in
1154 OF_CHK_FWD(plen
- OF_QUEUE_PROP_MINLEN
);
1157 if (property
== OFPQT_MIN_RATE
) { /* the only case of property decoding */
1159 uint16_t rate
= GET_BE_U_2(cp
);
1162 ND_PRINT(", rate disabled");
1164 ND_PRINT(", rate %u.%u%%", rate
/ 10, rate
% 10);
1166 /* Sometimes the last field, check bounds. */
1172 invalid
: /* skip the rest of queue properties */
1173 nd_print_invalid(ndo
);
1174 ND_TCHECK_LEN(cp
, len
);
1179 of10_queues_print(netdissect_options
*ndo
,
1180 const u_char
*cp
, u_int len
)
1185 if (len
< OF_PACKET_QUEUE_MINLEN
)
1188 ND_PRINT("\n\t queue_id %u", GET_BE_U_4(cp
));
1191 desclen
= GET_BE_U_2(cp
);
1193 ND_PRINT(", len %u", desclen
);
1194 if (desclen
< OF_PACKET_QUEUE_MINLEN
|| desclen
> len
+ 6)
1197 /* Sometimes the last field, check bounds. */
1200 if (ndo
->ndo_vflag
>= 2)
1201 of10_queue_props_print(ndo
, cp
, desclen
- OF_PACKET_QUEUE_MINLEN
);
1203 ND_TCHECK_LEN(cp
, desclen
- OF_PACKET_QUEUE_MINLEN
);
1204 OF_FWD(desclen
- OF_PACKET_QUEUE_MINLEN
);
1208 invalid
: /* skip the rest of queues */
1209 nd_print_invalid(ndo
);
1210 ND_TCHECK_LEN(cp
, len
);
1213 /* [OF10] Section 5.2.3 */
1215 of10_match_print(netdissect_options
*ndo
,
1216 const char *pfx
, const u_char
*cp
)
1222 const char *field_name
;
1225 wildcards
= GET_BE_U_4(cp
);
1226 if (wildcards
& OFPFW_U
)
1227 ND_PRINT("%swildcards 0x%08x (bogus)", pfx
, wildcards
);
1230 if (! (wildcards
& OFPFW_IN_PORT
))
1231 ND_PRINT("%smatch in_port %s", pfx
,
1232 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1235 if (! (wildcards
& OFPFW_DL_SRC
))
1236 ND_PRINT("%smatch dl_src %s", pfx
, GET_ETHERADDR_STRING(cp
));
1239 if (! (wildcards
& OFPFW_DL_DST
))
1240 ND_PRINT("%smatch dl_dst %s", pfx
, GET_ETHERADDR_STRING(cp
));
1243 if (! (wildcards
& OFPFW_DL_VLAN
))
1244 ND_PRINT("%smatch dl_vlan %s", pfx
, vlan_str(GET_BE_U_2(cp
)));
1247 if (! (wildcards
& OFPFW_DL_VLAN_PCP
))
1248 ND_PRINT("%smatch dl_vlan_pcp %s", pfx
, pcp_str(GET_U_1(cp
)));
1253 dl_type
= GET_BE_U_2(cp
);
1255 if (! (wildcards
& OFPFW_DL_TYPE
))
1256 ND_PRINT("%smatch dl_type 0x%04x", pfx
, dl_type
);
1258 if (! (wildcards
& OFPFW_NW_TOS
))
1259 ND_PRINT("%smatch nw_tos 0x%02x", pfx
, GET_U_1(cp
));
1262 nw_proto
= GET_U_1(cp
);
1264 if (! (wildcards
& OFPFW_NW_PROTO
)) {
1265 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_ARP
1266 ? "arp_opcode" : "nw_proto";
1267 ND_PRINT("%smatch %s %u", pfx
, field_name
, nw_proto
);
1272 nw_bits
= (wildcards
& OFPFW_NW_SRC_MASK
) >> OFPFW_NW_SRC_SHIFT
;
1274 ND_PRINT("%smatch nw_src %s/%u", pfx
, GET_IPADDR_STRING(cp
), 32 - nw_bits
);
1277 nw_bits
= (wildcards
& OFPFW_NW_DST_MASK
) >> OFPFW_NW_DST_SHIFT
;
1279 ND_PRINT("%smatch nw_dst %s/%u", pfx
, GET_IPADDR_STRING(cp
), 32 - nw_bits
);
1282 if (! (wildcards
& OFPFW_TP_SRC
)) {
1283 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_IP
1284 && ! (wildcards
& OFPFW_NW_PROTO
) && nw_proto
== IPPROTO_ICMP
1285 ? "icmp_type" : "tp_src";
1286 ND_PRINT("%smatch %s %u", pfx
, field_name
, GET_BE_U_2(cp
));
1290 /* The last unconditional check was at nw_proto, so have an "else" here. */
1291 if (! (wildcards
& OFPFW_TP_DST
)) {
1292 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_IP
1293 && ! (wildcards
& OFPFW_NW_PROTO
) && nw_proto
== IPPROTO_ICMP
1294 ? "icmp_code" : "tp_dst";
1295 ND_PRINT("%smatch %s %u", pfx
, field_name
, GET_BE_U_2(cp
));
1301 /* [OF10] Section 5.2.4 */
1303 of10_actions_print(netdissect_options
*ndo
,
1304 const char *pfx
, const u_char
*cp
, u_int len
)
1307 uint16_t type
, alen
, output_port
;
1308 u_char alen_bogus
= 0, skip
= 0;
1310 if (len
< OF_ACTION_MINLEN
)
1313 type
= GET_BE_U_2(cp
);
1315 ND_PRINT("%saction type %s", pfx
, tok2str(ofpat_str
, "invalid (0x%04x)", type
));
1317 alen
= GET_BE_U_2(cp
);
1319 ND_PRINT(", len %u", alen
);
1321 * The 4-byte "pad" in the specification is not a field of the
1322 * action header, but a placeholder to illustrate the 64-bit
1323 * alignment requirement. Action type specific case blocks
1324 * below fetch these 4 bytes.
1327 /* On action size underrun/overrun skip the rest of the action list. */
1328 if (alen
< OF_ACTION_MINLEN
|| alen
> len
+ 4)
1331 * After validating the basic length constraint it will be safe
1332 * to skip the current action if the action size is not valid
1333 * for the type or the type is invalid.
1337 case OFPAT_SET_VLAN_VID
:
1338 case OFPAT_SET_VLAN_PCP
:
1339 case OFPAT_STRIP_VLAN
:
1340 case OFPAT_SET_NW_SRC
:
1341 case OFPAT_SET_NW_DST
:
1342 case OFPAT_SET_NW_TOS
:
1343 case OFPAT_SET_TP_SRC
:
1344 case OFPAT_SET_TP_DST
:
1345 alen_bogus
= alen
!= 8;
1347 case OFPAT_SET_DL_SRC
:
1348 case OFPAT_SET_DL_DST
:
1350 alen_bogus
= alen
!= 16;
1353 alen_bogus
= alen
% 8 != 0; /* already >= 8 so far */
1359 ND_PRINT(" (bogus)");
1364 * alen >= OF_ACTION_MINLEN
1367 OF_CHK_FWD(alen
- 4);
1370 /* OK to decode the rest of the action structure */
1374 output_port
= GET_BE_U_2(cp
);
1376 ND_PRINT(", port %s", tok2str(ofpp_str
, "%u", output_port
));
1378 if (output_port
== OFPP_CONTROLLER
)
1379 ND_PRINT(", max_len %u", GET_BE_U_2(cp
));
1384 case OFPAT_SET_VLAN_VID
:
1386 ND_PRINT(", vlan_vid %s", vlan_str(GET_BE_U_2(cp
)));
1389 /* Sometimes the last field, check bounds. */
1392 case OFPAT_SET_VLAN_PCP
:
1394 ND_PRINT(", vlan_pcp %s", pcp_str(GET_U_1(cp
)));
1397 /* Sometimes the last field, check bounds. */
1400 case OFPAT_SET_DL_SRC
:
1401 case OFPAT_SET_DL_DST
:
1403 ND_PRINT(", dl_addr %s", GET_ETHERADDR_STRING(cp
));
1404 OF_FWD(MAC_ADDR_LEN
);
1406 /* Sometimes the last field, check bounds. */
1409 case OFPAT_SET_NW_SRC
:
1410 case OFPAT_SET_NW_DST
:
1412 ND_PRINT(", nw_addr %s", GET_IPADDR_STRING(cp
));
1415 case OFPAT_SET_NW_TOS
:
1417 ND_PRINT(", nw_tos 0x%02x", GET_U_1(cp
));
1420 /* Sometimes the last field, check bounds. */
1423 case OFPAT_SET_TP_SRC
:
1424 case OFPAT_SET_TP_DST
:
1426 ND_PRINT(", tp_port %u", GET_BE_U_2(cp
));
1429 /* Sometimes the last field, check bounds. */
1434 ND_PRINT(", port %s",
1435 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1440 ND_PRINT(", queue_id %s",
1441 tok2str(ofpq_str
, "%u", GET_BE_U_4(cp
)));
1445 of10_vendor_action_print(ndo
, cp
, alen
- 4);
1448 case OFPAT_STRIP_VLAN
:
1450 /* Sometimes the last field, check bounds. */
1457 invalid
: /* skip the rest of actions */
1458 nd_print_invalid(ndo
);
1459 ND_TCHECK_LEN(cp
, len
);
1462 /* [OF10] Section 5.3.1 */
1464 of10_features_reply_print(netdissect_options
*ndo
,
1465 const u_char
*cp
, u_int len
)
1468 ND_PRINT("\n\t dpid 0x%016" PRIx64
, GET_BE_U_8(cp
));
1471 ND_PRINT(", n_buffers %u", GET_BE_U_4(cp
));
1474 ND_PRINT(", n_tables %u", GET_U_1(cp
));
1479 ND_PRINT("\n\t capabilities 0x%08x", GET_BE_U_4(cp
));
1480 of_bitmap_print(ndo
, ofp_capabilities_bm
, GET_BE_U_4(cp
), OFPCAP_U
);
1483 ND_PRINT("\n\t actions 0x%08x", GET_BE_U_4(cp
));
1484 of_bitmap_print(ndo
, ofpat_bm
, GET_BE_U_4(cp
), OFPAT_U
);
1488 if (len
< OF_PHY_PORT_FIXLEN
)
1490 of10_phy_port_print(ndo
, cp
);
1491 OF_FWD(OF_PHY_PORT_FIXLEN
);
1495 invalid
: /* skip the undersized trailing data */
1496 nd_print_invalid(ndo
);
1497 ND_TCHECK_LEN(cp
, len
);
1500 /* [OF10] Section 5.3.2 */
1502 of10_switch_config_msg_print(netdissect_options
*ndo
,
1506 ND_PRINT("\n\t flags %s",
1507 tok2str(ofp_config_str
, "invalid (0x%04x)", GET_BE_U_2(cp
)));
1510 ND_PRINT(", miss_send_len %u", GET_BE_U_2(cp
));
1513 /* [OF10] Section 5.3.3 */
1515 of10_flow_mod_print(netdissect_options
*ndo
,
1516 const u_char
*cp
, u_int len
)
1521 of10_match_print(ndo
, "\n\t ", cp
);
1522 OF_FWD(OF_MATCH_FIXLEN
);
1524 ND_PRINT("\n\t cookie 0x%016" PRIx64
, GET_BE_U_8(cp
));
1527 command
= GET_BE_U_2(cp
);
1528 ND_PRINT(", command %s", tok2str(ofpfc_str
, "invalid (0x%04x)", command
));
1532 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp
));
1536 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp
));
1540 ND_PRINT(", priority %u", GET_BE_U_2(cp
));
1543 if (command
== OFPFC_ADD
|| command
== OFPFC_MODIFY
||
1544 command
== OFPFC_MODIFY_STRICT
)
1545 ND_PRINT(", buffer_id %s",
1546 tok2str(bufferid_str
, "0x%08x", GET_BE_U_4(cp
)));
1549 if (command
== OFPFC_DELETE
|| command
== OFPFC_DELETE_STRICT
)
1550 ND_PRINT(", out_port %s",
1551 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1554 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp
));
1555 of_bitmap_print(ndo
, ofpff_bm
, GET_BE_U_2(cp
), OFPFF_U
);
1558 of10_actions_print(ndo
, "\n\t ", cp
, len
);
1563 of10_port_mod_print(netdissect_options
*ndo
,
1567 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1570 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp
));
1573 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp
));
1574 of_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
1577 ND_PRINT("\n\t mask 0x%08x", GET_BE_U_4(cp
));
1578 of_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
1581 ND_PRINT("\n\t advertise 0x%08x", GET_BE_U_4(cp
));
1582 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1585 /* Always the last field, check bounds. */
1589 /* [OF10] Section 5.3.4 */
1591 of10_queue_get_config_request_print(netdissect_options
*ndo
,
1595 ND_PRINT("\n\t port %s", tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1598 /* Always the last field, check bounds. */
1604 of10_queue_get_config_reply_print(netdissect_options
*ndo
,
1605 const u_char
*cp
, u_int len
)
1608 ND_PRINT("\n\t port %s", tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1611 /* Sometimes the last field, check bounds. */
1614 of10_queues_print(ndo
, cp
, len
);
1617 /* [OF10] Section 5.3.5 */
1619 of10_stats_request_print(netdissect_options
*ndo
,
1620 const u_char
*cp
, u_int len
)
1625 type
= GET_BE_U_2(cp
);
1627 ND_PRINT("\n\t type %s", tok2str(ofpst_str
, "invalid (0x%04x)", type
));
1629 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp
));
1631 ND_PRINT(" (bogus)");
1633 /* type-specific body of one of fixed lengths */
1641 case OFPST_AGGREGATE
:
1642 if (len
!= OF_FLOW_STATS_REQUEST_FIXLEN
)
1645 of10_match_print(ndo
, "\n\t ", cp
);
1646 OF_FWD(OF_MATCH_FIXLEN
);
1648 ND_PRINT("\n\t table_id %s",
1649 tok2str(tableid_str
, "%u", GET_U_1(cp
)));
1654 ND_PRINT(", out_port %s",
1655 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1658 if (len
!= OF_PORT_STATS_REQUEST_FIXLEN
)
1661 ND_PRINT("\n\t port_no %s",
1662 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1665 /* Always the last field, check bounds. */
1669 if (len
!= OF_QUEUE_STATS_REQUEST_FIXLEN
)
1672 ND_PRINT("\n\t port_no %s",
1673 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1678 ND_PRINT(", queue_id %s",
1679 tok2str(ofpq_str
, "%u", GET_BE_U_4(cp
)));
1682 of10_vendor_data_print(ndo
, cp
, len
);
1687 invalid
: /* skip the message body */
1688 nd_print_invalid(ndo
);
1689 ND_TCHECK_LEN(cp
, len
);
1694 of10_desc_stats_reply_print(netdissect_options
*ndo
,
1695 const u_char
*cp
, u_int len
)
1697 if (len
!= OF_DESC_STATS_REPLY_FIXLEN
)
1700 ND_PRINT("\n\t mfr_desc '");
1701 (void)nd_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1703 OF_FWD(DESC_STR_LEN
);
1705 ND_PRINT("\n\t hw_desc '");
1706 (void)nd_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1708 OF_FWD(DESC_STR_LEN
);
1710 ND_PRINT("\n\t sw_desc '");
1711 (void)nd_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1713 OF_FWD(DESC_STR_LEN
);
1715 ND_PRINT("\n\t serial_num '");
1716 (void)nd_print(ndo
, cp
, cp
+ SERIAL_NUM_LEN
);
1718 OF_FWD(SERIAL_NUM_LEN
);
1720 ND_PRINT("\n\t dp_desc '");
1721 (void)nd_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1725 invalid
: /* skip the message body */
1726 nd_print_invalid(ndo
);
1727 ND_TCHECK_LEN(cp
, len
);
1732 of10_flow_stats_reply_print(netdissect_options
*ndo
,
1733 const u_char
*cp
, u_int len
)
1738 if (len
< OF_FLOW_STATS_REPLY_MINLEN
)
1741 entry_len
= GET_BE_U_2(cp
);
1742 ND_PRINT("\n\t length %u", entry_len
);
1743 if (entry_len
< OF_FLOW_STATS_REPLY_MINLEN
|| entry_len
> len
)
1747 ND_PRINT(", table_id %s",
1748 tok2str(tableid_str
, "%u", GET_U_1(cp
)));
1753 of10_match_print(ndo
, "\n\t ", cp
);
1754 OF_FWD(OF_MATCH_FIXLEN
);
1756 ND_PRINT("\n\t duration_sec %u", GET_BE_U_4(cp
));
1759 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp
));
1762 ND_PRINT(", priority %u", GET_BE_U_2(cp
));
1765 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp
));
1768 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp
));
1773 ND_PRINT(", cookie 0x%016" PRIx64
, GET_BE_U_8(cp
));
1776 ND_PRINT(", packet_count %" PRIu64
, GET_BE_U_8(cp
));
1779 ND_PRINT(", byte_count %" PRIu64
, GET_BE_U_8(cp
));
1782 of10_actions_print(ndo
, "\n\t ", cp
, entry_len
- OF_FLOW_STATS_REPLY_MINLEN
);
1783 OF_FWD(entry_len
- OF_FLOW_STATS_REPLY_MINLEN
);
1787 invalid
: /* skip the rest of flow statistics entries */
1788 nd_print_invalid(ndo
);
1789 ND_TCHECK_LEN(cp
, len
);
1794 of10_aggregate_stats_reply_print(netdissect_options
*ndo
,
1795 const u_char
*cp
, u_int len
)
1797 if (len
!= OF_AGGREGATE_STATS_REPLY_FIXLEN
)
1800 ND_PRINT("\n\t packet_count %" PRIu64
, GET_BE_U_8(cp
));
1803 ND_PRINT(", byte_count %" PRIu64
, GET_BE_U_8(cp
));
1806 ND_PRINT(", flow_count %u", GET_BE_U_4(cp
));
1809 /* Always the last field, check bounds. */
1813 invalid
: /* skip the message body */
1814 nd_print_invalid(ndo
);
1815 ND_TCHECK_LEN(cp
, len
);
1820 of10_table_stats_reply_print(netdissect_options
*ndo
,
1821 const u_char
*cp
, u_int len
)
1824 if (len
< OF_TABLE_STATS_REPLY_FIXLEN
)
1827 ND_PRINT("\n\t table_id %s",
1828 tok2str(tableid_str
, "%u", GET_U_1(cp
)));
1833 ND_PRINT(", name '");
1834 (void)nd_print(ndo
, cp
, cp
+ OFP_MAX_TABLE_NAME_LEN
);
1836 OF_FWD(OFP_MAX_TABLE_NAME_LEN
);
1838 ND_PRINT("\n\t wildcards 0x%08x", GET_BE_U_4(cp
));
1839 of_bitmap_print(ndo
, ofpfw_bm
, GET_BE_U_4(cp
), OFPFW_U
);
1842 ND_PRINT("\n\t max_entries %u", GET_BE_U_4(cp
));
1845 ND_PRINT(", active_count %u", GET_BE_U_4(cp
));
1848 ND_PRINT(", lookup_count %" PRIu64
, GET_BE_U_8(cp
));
1851 ND_PRINT(", matched_count %" PRIu64
, GET_BE_U_8(cp
));
1856 invalid
: /* skip the undersized trailing data */
1857 nd_print_invalid(ndo
);
1858 ND_TCHECK_LEN(cp
, len
);
1863 of10_port_stats_reply_print(netdissect_options
*ndo
,
1864 const u_char
*cp
, u_int len
)
1867 if (len
< OF_PORT_STATS_REPLY_FIXLEN
)
1870 ND_PRINT("\n\t port_no %s",
1871 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1873 if (ndo
->ndo_vflag
< 2) {
1874 OF_CHK_FWD(OF_PORT_STATS_REPLY_FIXLEN
- 2);
1880 ND_PRINT(", rx_packets %" PRIu64
, GET_BE_U_8(cp
));
1883 ND_PRINT(", tx_packets %" PRIu64
, GET_BE_U_8(cp
));
1886 ND_PRINT(", rx_bytes %" PRIu64
, GET_BE_U_8(cp
));
1889 ND_PRINT(", tx_bytes %" PRIu64
, GET_BE_U_8(cp
));
1892 ND_PRINT(", rx_dropped %" PRIu64
, GET_BE_U_8(cp
));
1895 ND_PRINT(", tx_dropped %" PRIu64
, GET_BE_U_8(cp
));
1898 ND_PRINT(", rx_errors %" PRIu64
, GET_BE_U_8(cp
));
1901 ND_PRINT(", tx_errors %" PRIu64
, GET_BE_U_8(cp
));
1904 ND_PRINT(", rx_frame_err %" PRIu64
, GET_BE_U_8(cp
));
1907 ND_PRINT(", rx_over_err %" PRIu64
, GET_BE_U_8(cp
));
1910 ND_PRINT(", rx_crc_err %" PRIu64
, GET_BE_U_8(cp
));
1913 ND_PRINT(", collisions %" PRIu64
, GET_BE_U_8(cp
));
1918 invalid
: /* skip the undersized trailing data */
1919 nd_print_invalid(ndo
);
1920 ND_TCHECK_LEN(cp
, len
);
1925 of10_queue_stats_reply_print(netdissect_options
*ndo
,
1926 const u_char
*cp
, u_int len
)
1929 if (len
< OF_QUEUE_STATS_REPLY_FIXLEN
)
1932 ND_PRINT("\n\t port_no %s",
1933 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1938 ND_PRINT(", queue_id %u", GET_BE_U_4(cp
));
1941 ND_PRINT(", tx_bytes %" PRIu64
, GET_BE_U_8(cp
));
1944 ND_PRINT(", tx_packets %" PRIu64
, GET_BE_U_8(cp
));
1947 ND_PRINT(", tx_errors %" PRIu64
, GET_BE_U_8(cp
));
1952 invalid
: /* skip the undersized trailing data */
1953 nd_print_invalid(ndo
);
1954 ND_TCHECK_LEN(cp
, len
);
1959 of10_stats_reply_print(netdissect_options
*ndo
,
1960 const u_char
*cp
, u_int len
)
1965 type
= GET_BE_U_2(cp
);
1966 ND_PRINT("\n\t type %s", tok2str(ofpst_str
, "invalid (0x%04x)", type
));
1969 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp
));
1970 of_bitmap_print(ndo
, ofpsf_reply_bm
, GET_BE_U_2(cp
), OFPSF_REPLY_U
);
1973 if (ndo
->ndo_vflag
> 0) {
1974 void (*decoder
)(netdissect_options
*, const u_char
*, u_int
) =
1975 type
== OFPST_DESC
? of10_desc_stats_reply_print
:
1976 type
== OFPST_FLOW
? of10_flow_stats_reply_print
:
1977 type
== OFPST_AGGREGATE
? of10_aggregate_stats_reply_print
:
1978 type
== OFPST_TABLE
? of10_table_stats_reply_print
:
1979 type
== OFPST_PORT
? of10_port_stats_reply_print
:
1980 type
== OFPST_QUEUE
? of10_queue_stats_reply_print
:
1981 type
== OFPST_VENDOR
? of10_vendor_data_print
:
1983 if (decoder
!= NULL
) {
1984 decoder(ndo
, cp
, len
);
1988 ND_TCHECK_LEN(cp
, len
);
1991 /* [OF10] Section 5.3.6 */
1993 of10_packet_out_print(netdissect_options
*ndo
,
1994 const u_char
*cp
, u_int len
)
1996 uint16_t actions_len
;
1999 ND_PRINT("\n\t buffer_id 0x%08x", GET_BE_U_4(cp
));
2002 ND_PRINT(", in_port %s", tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
2005 actions_len
= GET_BE_U_2(cp
);
2007 if (actions_len
> len
)
2010 of10_actions_print(ndo
, "\n\t ", cp
, actions_len
);
2011 OF_FWD(actions_len
);
2013 of10_packet_data_print(ndo
, cp
, len
);
2016 invalid
: /* skip the rest of the message body */
2017 nd_print_invalid(ndo
);
2018 ND_TCHECK_LEN(cp
, len
);
2021 /* [OF10] Section 5.4.1 */
2023 of10_packet_in_print(netdissect_options
*ndo
,
2024 const u_char
*cp
, u_int len
)
2027 ND_PRINT("\n\t buffer_id %s",
2028 tok2str(bufferid_str
, "0x%08x", GET_BE_U_4(cp
)));
2031 ND_PRINT(", total_len %u", GET_BE_U_2(cp
));
2034 ND_PRINT(", in_port %s", tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
2037 ND_PRINT(", reason %s",
2038 tok2str(ofpr_str
, "invalid (0x%02x)", GET_U_1(cp
)));
2041 /* Sometimes the last field, check bounds. */
2044 of10_packet_data_print(ndo
, cp
, len
);
2047 /* [OF10] Section 5.4.2 */
2049 of10_flow_removed_print(netdissect_options
*ndo
,
2053 of10_match_print(ndo
, "\n\t ", cp
);
2054 cp
+= OF_MATCH_FIXLEN
;
2056 ND_PRINT("\n\t cookie 0x%016" PRIx64
, GET_BE_U_8(cp
));
2060 ND_PRINT(", priority %u", GET_BE_U_2(cp
));
2063 ND_PRINT(", reason %s",
2064 tok2str(ofprr_str
, "unknown (0x%02x)", GET_U_1(cp
)));
2069 ND_PRINT(", duration_sec %u", GET_BE_U_4(cp
));
2072 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp
));
2076 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp
));
2081 ND_PRINT(", packet_count %" PRIu64
, GET_BE_U_8(cp
));
2084 ND_PRINT(", byte_count %" PRIu64
, GET_BE_U_8(cp
));
2087 /* [OF10] Section 5.4.3 */
2089 of10_port_status_print(netdissect_options
*ndo
,
2093 ND_PRINT("\n\t reason %s",
2094 tok2str(ofppr_str
, "invalid (0x%02x)", GET_U_1(cp
)));
2097 /* No need to check bounds, more data follows. */
2100 of10_phy_port_print(ndo
, cp
);
2103 /* [OF10] Section 5.4.4 */
2105 of10_error_print(netdissect_options
*ndo
,
2106 const u_char
*cp
, u_int len
)
2108 uint16_t type
, code
;
2109 const struct tok
*code_str
;
2112 type
= GET_BE_U_2(cp
);
2114 ND_PRINT("\n\t type %s", tok2str(ofpet_str
, "invalid (0x%04x)", type
));
2116 code
= GET_BE_U_2(cp
);
2118 code_str
= uint2tokary(of10_ofpet2tokary
, type
);
2119 if (code_str
!= NULL
)
2120 ND_PRINT(", code %s",
2121 tok2str(code_str
, "invalid (0x%04x)", code
));
2123 ND_PRINT(", code invalid (0x%04x)", code
);
2125 of_data_print(ndo
, cp
, len
);
2129 of10_message_print(netdissect_options
*ndo
,
2130 const u_char
*cp
, uint16_t len
, const uint8_t type
)
2133 * Here "cp" and "len" stand for the message part beyond the common
2134 * OpenFlow 1.0 header, if any. Subtract OF_HEADER_FIXLEN from the
2135 * type-specific lengths, which include the header length, when (and
2136 * only when) validating the length in this function. No other code
2137 * in this file needs to take OF_HEADER_FIXLEN into account.
2139 * Most message types are longer than just the header, and the length
2140 * constraints may be complex. When possible, validate the constraint
2141 * completely here, otherwise check that the message is long enough to
2142 * begin the decoding and let the lower-layer function do any remaining
2146 /* OpenFlow header only. */
2147 case OFPT_FEATURES_REQUEST
: /* [OF10] Section 5.3.1 */
2148 case OFPT_GET_CONFIG_REQUEST
: /* [OF10] Section 5.3.2 */
2149 case OFPT_BARRIER_REQUEST
: /* [OF10] Section 5.3.7 */
2150 case OFPT_BARRIER_REPLY
: /* ibid */
2155 /* OpenFlow header and fixed-size message body. */
2156 case OFPT_SET_CONFIG
: /* [OF10] Section 5.3.2 */
2157 case OFPT_GET_CONFIG_REPLY
: /* ibid */
2158 if (len
!= OF_SWITCH_CONFIG_FIXLEN
- OF_HEADER_FIXLEN
)
2160 if (ndo
->ndo_vflag
< 1)
2162 of10_switch_config_msg_print(ndo
, cp
);
2165 if (len
!= OF_PORT_MOD_FIXLEN
- OF_HEADER_FIXLEN
)
2167 if (ndo
->ndo_vflag
< 1)
2169 of10_port_mod_print(ndo
, cp
);
2171 case OFPT_QUEUE_GET_CONFIG_REQUEST
: /* [OF10] Section 5.3.4 */
2172 if (len
!= OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN
- OF_HEADER_FIXLEN
)
2174 if (ndo
->ndo_vflag
< 1)
2176 of10_queue_get_config_request_print(ndo
, cp
);
2178 case OFPT_FLOW_REMOVED
:
2179 if (len
!= OF_FLOW_REMOVED_FIXLEN
- OF_HEADER_FIXLEN
)
2181 if (ndo
->ndo_vflag
< 1)
2183 of10_flow_removed_print(ndo
, cp
);
2185 case OFPT_PORT_STATUS
: /* [OF10] Section 5.4.3 */
2186 if (len
!= OF_PORT_STATUS_FIXLEN
- OF_HEADER_FIXLEN
)
2188 if (ndo
->ndo_vflag
< 1)
2190 of10_port_status_print(ndo
, cp
);
2193 /* OpenFlow header, fixed-size message body and n * fixed-size data units. */
2194 case OFPT_FEATURES_REPLY
:
2195 if (len
< OF_FEATURES_REPLY_MINLEN
- OF_HEADER_FIXLEN
)
2197 if (ndo
->ndo_vflag
< 1)
2199 of10_features_reply_print(ndo
, cp
, len
);
2202 /* OpenFlow header and variable-size data. */
2203 case OFPT_HELLO
: /* [OF10] Section 5.5.1 */
2204 case OFPT_ECHO_REQUEST
: /* [OF10] Section 5.5.2 */
2205 case OFPT_ECHO_REPLY
: /* [OF10] Section 5.5.3 */
2206 if (ndo
->ndo_vflag
< 1)
2208 of_data_print(ndo
, cp
, len
);
2211 /* OpenFlow header, fixed-size message body and variable-size data. */
2213 if (len
< OF_ERROR_MSG_MINLEN
- OF_HEADER_FIXLEN
)
2215 if (ndo
->ndo_vflag
< 1)
2217 of10_error_print(ndo
, cp
, len
);
2220 /* [OF10] Section 5.5.4 */
2221 if (len
< OF_VENDOR_MINLEN
- OF_HEADER_FIXLEN
)
2223 if (ndo
->ndo_vflag
< 1)
2225 of10_vendor_message_print(ndo
, cp
, len
);
2227 case OFPT_PACKET_IN
:
2228 /* 2 mock octets count in OF_PACKET_IN_MINLEN but not in len */
2229 if (len
< OF_PACKET_IN_MINLEN
- 2 - OF_HEADER_FIXLEN
)
2231 if (ndo
->ndo_vflag
< 1)
2233 of10_packet_in_print(ndo
, cp
, len
);
2236 /* a. OpenFlow header. */
2237 /* b. OpenFlow header and one of the fixed-size message bodies. */
2238 /* c. OpenFlow header, fixed-size message body and variable-size data. */
2239 case OFPT_STATS_REQUEST
:
2240 if (len
< OF_STATS_REQUEST_MINLEN
- OF_HEADER_FIXLEN
)
2242 if (ndo
->ndo_vflag
< 1)
2244 of10_stats_request_print(ndo
, cp
, len
);
2247 /* a. OpenFlow header and fixed-size message body. */
2248 /* b. OpenFlow header and n * fixed-size data units. */
2249 /* c. OpenFlow header and n * variable-size data units. */
2250 /* d. OpenFlow header, fixed-size message body and variable-size data. */
2251 case OFPT_STATS_REPLY
:
2252 if (len
< OF_STATS_REPLY_MINLEN
- OF_HEADER_FIXLEN
)
2254 if (ndo
->ndo_vflag
< 1)
2256 of10_stats_reply_print(ndo
, cp
, len
);
2259 /* OpenFlow header and n * variable-size data units and variable-size data. */
2260 case OFPT_PACKET_OUT
:
2261 if (len
< OF_PACKET_OUT_MINLEN
- OF_HEADER_FIXLEN
)
2263 if (ndo
->ndo_vflag
< 1)
2265 of10_packet_out_print(ndo
, cp
, len
);
2268 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2270 if (len
< OF_FLOW_MOD_MINLEN
- OF_HEADER_FIXLEN
)
2272 if (ndo
->ndo_vflag
< 1)
2274 of10_flow_mod_print(ndo
, cp
, len
);
2277 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2278 case OFPT_QUEUE_GET_CONFIG_REPLY
: /* [OF10] Section 5.3.4 */
2279 if (len
< OF_QUEUE_GET_CONFIG_REPLY_MINLEN
- OF_HEADER_FIXLEN
)
2281 if (ndo
->ndo_vflag
< 1)
2283 of10_queue_get_config_reply_print(ndo
, cp
, len
);
2285 } /* switch (type) */
2287 * Not a recognised type or did not print the details, fall back to
2290 ND_TCHECK_LEN(cp
, len
);
2293 invalid
: /* skip the message body */
2294 nd_print_invalid(ndo
);
2295 ND_TCHECK_LEN(cp
, len
);