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_ports_print(netdissect_options
*ndo
,
1056 const u_char
*cp
, u_int len
)
1061 if (len
< OF_PHY_PORT_FIXLEN
)
1064 ND_PRINT("\n\t port_no %s",
1065 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1068 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp
));
1069 OF_FWD(MAC_ADDR_LEN
);
1071 ND_PRINT(", name '");
1072 (void)nd_print(ndo
, cp
, cp
+ OFP_MAX_PORT_NAME_LEN
);
1074 OF_FWD(OFP_MAX_PORT_NAME_LEN
);
1076 if (ndo
->ndo_vflag
< 2) {
1081 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp
));
1082 of_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
1085 state
= GET_BE_U_4(cp
);
1087 * Decode the code point and the single bit separately, but
1088 * format the result as a single sequence of comma-separated
1089 * strings (see the comments at the OFPPS_ props).
1091 ND_PRINT("\n\t state 0x%08x (%s%s)%s", state
,
1092 tok2str(ofpps_stp_str
, "", state
& OFPPS_STP_MASK
),
1093 state
& OFPPS_LINK_DOWN
? ", LINK_DOWN" : "",
1094 state
& OFPPS_U
? " (bogus)" : "");
1097 ND_PRINT("\n\t curr 0x%08x", GET_BE_U_4(cp
));
1098 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1101 ND_PRINT("\n\t advertised 0x%08x", GET_BE_U_4(cp
));
1102 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1105 ND_PRINT("\n\t supported 0x%08x", GET_BE_U_4(cp
));
1106 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1109 ND_PRINT("\n\t peer 0x%08x", GET_BE_U_4(cp
));
1110 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1115 invalid
: /* skip the undersized trailing data */
1116 nd_print_invalid(ndo
);
1117 ND_TCHECK_LEN(cp
, len
);
1120 /* [OF10] Section 5.2.2 */
1122 of10_queue_props_print(netdissect_options
*ndo
,
1123 const u_char
*cp
, u_int len
)
1126 uint16_t property
, plen
;
1127 u_char plen_bogus
= 0, skip
= 0;
1129 if (len
< OF_QUEUE_PROP_MINLEN
)
1132 property
= GET_BE_U_2(cp
);
1134 ND_PRINT("\n\t property %s", tok2str(ofpqt_str
, "invalid (0x%04x)", property
));
1136 plen
= GET_BE_U_2(cp
);
1138 ND_PRINT(", len %u", plen
);
1139 if (plen
< OF_QUEUE_PROP_MINLEN
|| plen
> len
+ 4)
1142 /* Sometimes the last field, check bounds. */
1144 /* property-specific constraints and decoding */
1147 plen_bogus
= plen
!= OF_QUEUE_PROP_MINLEN
;
1149 case OFPQT_MIN_RATE
:
1150 plen_bogus
= plen
!= OF_QUEUE_PROP_MIN_RATE_FIXLEN
;
1156 ND_PRINT(" (bogus)");
1161 * plen >= OF_QUEUE_PROP_MINLEN
1162 * cp is OF_QUEUE_PROP_MINLEN bytes in
1164 OF_CHK_FWD(plen
- OF_QUEUE_PROP_MINLEN
);
1167 if (property
== OFPQT_MIN_RATE
) { /* the only case of property decoding */
1169 uint16_t rate
= GET_BE_U_2(cp
);
1172 ND_PRINT(", rate disabled");
1174 ND_PRINT(", rate %u.%u%%", rate
/ 10, rate
% 10);
1176 /* Sometimes the last field, check bounds. */
1182 invalid
: /* skip the rest of queue properties */
1183 nd_print_invalid(ndo
);
1184 ND_TCHECK_LEN(cp
, len
);
1189 of10_queues_print(netdissect_options
*ndo
,
1190 const u_char
*cp
, u_int len
)
1195 if (len
< OF_PACKET_QUEUE_MINLEN
)
1198 ND_PRINT("\n\t queue_id %u", GET_BE_U_4(cp
));
1201 desclen
= GET_BE_U_2(cp
);
1203 ND_PRINT(", len %u", desclen
);
1204 if (desclen
< OF_PACKET_QUEUE_MINLEN
|| desclen
> len
+ 6)
1207 /* Sometimes the last field, check bounds. */
1210 if (ndo
->ndo_vflag
>= 2)
1211 of10_queue_props_print(ndo
, cp
, desclen
- OF_PACKET_QUEUE_MINLEN
);
1213 ND_TCHECK_LEN(cp
, desclen
- OF_PACKET_QUEUE_MINLEN
);
1214 OF_FWD(desclen
- OF_PACKET_QUEUE_MINLEN
);
1218 invalid
: /* skip the rest of queues */
1219 nd_print_invalid(ndo
);
1220 ND_TCHECK_LEN(cp
, len
);
1223 /* [OF10] Section 5.2.3 */
1225 of10_match_print(netdissect_options
*ndo
,
1226 const char *pfx
, const u_char
*cp
)
1232 const char *field_name
;
1235 wildcards
= GET_BE_U_4(cp
);
1236 if (wildcards
& OFPFW_U
)
1237 ND_PRINT("%swildcards 0x%08x (bogus)", pfx
, wildcards
);
1240 if (! (wildcards
& OFPFW_IN_PORT
))
1241 ND_PRINT("%smatch in_port %s", pfx
,
1242 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1245 if (! (wildcards
& OFPFW_DL_SRC
))
1246 ND_PRINT("%smatch dl_src %s", pfx
, GET_ETHERADDR_STRING(cp
));
1249 if (! (wildcards
& OFPFW_DL_DST
))
1250 ND_PRINT("%smatch dl_dst %s", pfx
, GET_ETHERADDR_STRING(cp
));
1253 if (! (wildcards
& OFPFW_DL_VLAN
))
1254 ND_PRINT("%smatch dl_vlan %s", pfx
, vlan_str(GET_BE_U_2(cp
)));
1257 if (! (wildcards
& OFPFW_DL_VLAN_PCP
))
1258 ND_PRINT("%smatch dl_vlan_pcp %s", pfx
, pcp_str(GET_U_1(cp
)));
1263 dl_type
= GET_BE_U_2(cp
);
1265 if (! (wildcards
& OFPFW_DL_TYPE
))
1266 ND_PRINT("%smatch dl_type 0x%04x", pfx
, dl_type
);
1268 if (! (wildcards
& OFPFW_NW_TOS
))
1269 ND_PRINT("%smatch nw_tos 0x%02x", pfx
, GET_U_1(cp
));
1272 nw_proto
= GET_U_1(cp
);
1274 if (! (wildcards
& OFPFW_NW_PROTO
)) {
1275 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_ARP
1276 ? "arp_opcode" : "nw_proto";
1277 ND_PRINT("%smatch %s %u", pfx
, field_name
, nw_proto
);
1282 nw_bits
= (wildcards
& OFPFW_NW_SRC_MASK
) >> OFPFW_NW_SRC_SHIFT
;
1284 ND_PRINT("%smatch nw_src %s/%u", pfx
, GET_IPADDR_STRING(cp
), 32 - nw_bits
);
1287 nw_bits
= (wildcards
& OFPFW_NW_DST_MASK
) >> OFPFW_NW_DST_SHIFT
;
1289 ND_PRINT("%smatch nw_dst %s/%u", pfx
, GET_IPADDR_STRING(cp
), 32 - nw_bits
);
1292 if (! (wildcards
& OFPFW_TP_SRC
)) {
1293 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_IP
1294 && ! (wildcards
& OFPFW_NW_PROTO
) && nw_proto
== IPPROTO_ICMP
1295 ? "icmp_type" : "tp_src";
1296 ND_PRINT("%smatch %s %u", pfx
, field_name
, GET_BE_U_2(cp
));
1300 /* The last unconditional check was at nw_proto, so have an "else" here. */
1301 if (! (wildcards
& OFPFW_TP_DST
)) {
1302 field_name
= ! (wildcards
& OFPFW_DL_TYPE
) && dl_type
== ETHERTYPE_IP
1303 && ! (wildcards
& OFPFW_NW_PROTO
) && nw_proto
== IPPROTO_ICMP
1304 ? "icmp_code" : "tp_dst";
1305 ND_PRINT("%smatch %s %u", pfx
, field_name
, GET_BE_U_2(cp
));
1311 /* [OF10] Section 5.2.4 */
1313 of10_actions_print(netdissect_options
*ndo
,
1314 const char *pfx
, const u_char
*cp
, u_int len
)
1317 uint16_t type
, alen
, output_port
;
1318 u_char alen_bogus
= 0, skip
= 0;
1320 if (len
< OF_ACTION_MINLEN
)
1323 type
= GET_BE_U_2(cp
);
1325 ND_PRINT("%saction type %s", pfx
, tok2str(ofpat_str
, "invalid (0x%04x)", type
));
1327 alen
= GET_BE_U_2(cp
);
1329 ND_PRINT(", len %u", alen
);
1331 * The 4-byte "pad" in the specification is not a field of the
1332 * action header, but a placeholder to illustrate the 64-bit
1333 * alignment requirement. Action type specific case blocks
1334 * below fetch these 4 bytes.
1337 /* On action size underrun/overrun skip the rest of the action list. */
1338 if (alen
< OF_ACTION_MINLEN
|| alen
> len
+ 4)
1341 * After validating the basic length constraint it will be safe
1342 * to skip the current action if the action size is not valid
1343 * for the type or the type is invalid.
1347 case OFPAT_SET_VLAN_VID
:
1348 case OFPAT_SET_VLAN_PCP
:
1349 case OFPAT_STRIP_VLAN
:
1350 case OFPAT_SET_NW_SRC
:
1351 case OFPAT_SET_NW_DST
:
1352 case OFPAT_SET_NW_TOS
:
1353 case OFPAT_SET_TP_SRC
:
1354 case OFPAT_SET_TP_DST
:
1355 alen_bogus
= alen
!= 8;
1357 case OFPAT_SET_DL_SRC
:
1358 case OFPAT_SET_DL_DST
:
1360 alen_bogus
= alen
!= 16;
1363 alen_bogus
= alen
% 8 != 0; /* already >= 8 so far */
1369 ND_PRINT(" (bogus)");
1374 * alen >= OF_ACTION_MINLEN
1377 OF_CHK_FWD(alen
- 4);
1380 /* OK to decode the rest of the action structure */
1384 output_port
= GET_BE_U_2(cp
);
1386 ND_PRINT(", port %s", tok2str(ofpp_str
, "%u", output_port
));
1388 if (output_port
== OFPP_CONTROLLER
)
1389 ND_PRINT(", max_len %u", GET_BE_U_2(cp
));
1394 case OFPAT_SET_VLAN_VID
:
1396 ND_PRINT(", vlan_vid %s", vlan_str(GET_BE_U_2(cp
)));
1399 /* Sometimes the last field, check bounds. */
1402 case OFPAT_SET_VLAN_PCP
:
1404 ND_PRINT(", vlan_pcp %s", pcp_str(GET_U_1(cp
)));
1407 /* Sometimes the last field, check bounds. */
1410 case OFPAT_SET_DL_SRC
:
1411 case OFPAT_SET_DL_DST
:
1413 ND_PRINT(", dl_addr %s", GET_ETHERADDR_STRING(cp
));
1414 OF_FWD(MAC_ADDR_LEN
);
1416 /* Sometimes the last field, check bounds. */
1419 case OFPAT_SET_NW_SRC
:
1420 case OFPAT_SET_NW_DST
:
1422 ND_PRINT(", nw_addr %s", GET_IPADDR_STRING(cp
));
1425 case OFPAT_SET_NW_TOS
:
1427 ND_PRINT(", nw_tos 0x%02x", GET_U_1(cp
));
1430 /* Sometimes the last field, check bounds. */
1433 case OFPAT_SET_TP_SRC
:
1434 case OFPAT_SET_TP_DST
:
1436 ND_PRINT(", tp_port %u", GET_BE_U_2(cp
));
1439 /* Sometimes the last field, check bounds. */
1444 ND_PRINT(", port %s",
1445 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1450 ND_PRINT(", queue_id %s",
1451 tok2str(ofpq_str
, "%u", GET_BE_U_4(cp
)));
1455 of10_vendor_action_print(ndo
, cp
, alen
- 4);
1458 case OFPAT_STRIP_VLAN
:
1460 /* Sometimes the last field, check bounds. */
1467 invalid
: /* skip the rest of actions */
1468 nd_print_invalid(ndo
);
1469 ND_TCHECK_LEN(cp
, len
);
1472 /* [OF10] Section 5.3.1 */
1474 of10_features_reply_print(netdissect_options
*ndo
,
1475 const u_char
*cp
, u_int len
)
1478 ND_PRINT("\n\t dpid 0x%016" PRIx64
, GET_BE_U_8(cp
));
1481 ND_PRINT(", n_buffers %u", GET_BE_U_4(cp
));
1484 ND_PRINT(", n_tables %u", GET_U_1(cp
));
1489 ND_PRINT("\n\t capabilities 0x%08x", GET_BE_U_4(cp
));
1490 of_bitmap_print(ndo
, ofp_capabilities_bm
, GET_BE_U_4(cp
), OFPCAP_U
);
1493 ND_PRINT("\n\t actions 0x%08x", GET_BE_U_4(cp
));
1494 of_bitmap_print(ndo
, ofpat_bm
, GET_BE_U_4(cp
), OFPAT_U
);
1497 of10_phy_ports_print(ndo
, cp
, len
);
1500 /* [OF10] Section 5.3.3 */
1502 of10_flow_mod_print(netdissect_options
*ndo
,
1503 const u_char
*cp
, u_int len
)
1508 of10_match_print(ndo
, "\n\t ", cp
);
1509 OF_FWD(OF_MATCH_FIXLEN
);
1511 ND_PRINT("\n\t cookie 0x%016" PRIx64
, GET_BE_U_8(cp
));
1514 command
= GET_BE_U_2(cp
);
1515 ND_PRINT(", command %s", tok2str(ofpfc_str
, "invalid (0x%04x)", command
));
1519 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp
));
1523 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp
));
1527 ND_PRINT(", priority %u", GET_BE_U_2(cp
));
1530 if (command
== OFPFC_ADD
|| command
== OFPFC_MODIFY
||
1531 command
== OFPFC_MODIFY_STRICT
)
1532 ND_PRINT(", buffer_id %s",
1533 tok2str(bufferid_str
, "0x%08x", GET_BE_U_4(cp
)));
1536 if (command
== OFPFC_DELETE
|| command
== OFPFC_DELETE_STRICT
)
1537 ND_PRINT(", out_port %s",
1538 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1541 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp
));
1542 of_bitmap_print(ndo
, ofpff_bm
, GET_BE_U_2(cp
), OFPFF_U
);
1545 of10_actions_print(ndo
, "\n\t ", cp
, len
);
1550 of10_port_mod_print(netdissect_options
*ndo
,
1554 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1557 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp
));
1560 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp
));
1561 of_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
1564 ND_PRINT("\n\t mask 0x%08x", GET_BE_U_4(cp
));
1565 of_bitmap_print(ndo
, ofppc_bm
, GET_BE_U_4(cp
), OFPPC_U
);
1568 ND_PRINT("\n\t advertise 0x%08x", GET_BE_U_4(cp
));
1569 of_bitmap_print(ndo
, ofppf_bm
, GET_BE_U_4(cp
), OFPPF_U
);
1572 /* Always the last field, check bounds. */
1576 /* [OF10] Section 5.3.5 */
1578 of10_stats_request_print(netdissect_options
*ndo
,
1579 const u_char
*cp
, u_int len
)
1584 type
= GET_BE_U_2(cp
);
1586 ND_PRINT("\n\t type %s", tok2str(ofpst_str
, "invalid (0x%04x)", type
));
1588 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp
));
1590 ND_PRINT(" (bogus)");
1592 /* type-specific body of one of fixed lengths */
1600 case OFPST_AGGREGATE
:
1601 if (len
!= OF_FLOW_STATS_REQUEST_FIXLEN
)
1604 of10_match_print(ndo
, "\n\t ", cp
);
1605 OF_FWD(OF_MATCH_FIXLEN
);
1607 ND_PRINT("\n\t table_id %s",
1608 tok2str(tableid_str
, "%u", GET_U_1(cp
)));
1613 ND_PRINT(", out_port %s",
1614 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1617 if (len
!= OF_PORT_STATS_REQUEST_FIXLEN
)
1620 ND_PRINT("\n\t port_no %s",
1621 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1624 /* Always the last field, check bounds. */
1628 if (len
!= OF_QUEUE_STATS_REQUEST_FIXLEN
)
1631 ND_PRINT("\n\t port_no %s",
1632 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1637 ND_PRINT(", queue_id %s",
1638 tok2str(ofpq_str
, "%u", GET_BE_U_4(cp
)));
1641 of10_vendor_data_print(ndo
, cp
, len
);
1646 invalid
: /* skip the message body */
1647 nd_print_invalid(ndo
);
1648 ND_TCHECK_LEN(cp
, len
);
1653 of10_desc_stats_reply_print(netdissect_options
*ndo
,
1654 const u_char
*cp
, u_int len
)
1656 if (len
!= OF_DESC_STATS_REPLY_FIXLEN
)
1659 ND_PRINT("\n\t mfr_desc '");
1660 (void)nd_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1662 OF_FWD(DESC_STR_LEN
);
1664 ND_PRINT("\n\t hw_desc '");
1665 (void)nd_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1667 OF_FWD(DESC_STR_LEN
);
1669 ND_PRINT("\n\t sw_desc '");
1670 (void)nd_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1672 OF_FWD(DESC_STR_LEN
);
1674 ND_PRINT("\n\t serial_num '");
1675 (void)nd_print(ndo
, cp
, cp
+ SERIAL_NUM_LEN
);
1677 OF_FWD(SERIAL_NUM_LEN
);
1679 ND_PRINT("\n\t dp_desc '");
1680 (void)nd_print(ndo
, cp
, cp
+ DESC_STR_LEN
);
1684 invalid
: /* skip the message body */
1685 nd_print_invalid(ndo
);
1686 ND_TCHECK_LEN(cp
, len
);
1691 of10_flow_stats_reply_print(netdissect_options
*ndo
,
1692 const u_char
*cp
, u_int len
)
1697 if (len
< OF_FLOW_STATS_REPLY_MINLEN
)
1700 entry_len
= GET_BE_U_2(cp
);
1701 ND_PRINT("\n\t length %u", entry_len
);
1702 if (entry_len
< OF_FLOW_STATS_REPLY_MINLEN
|| entry_len
> len
)
1706 ND_PRINT(", table_id %s",
1707 tok2str(tableid_str
, "%u", GET_U_1(cp
)));
1712 of10_match_print(ndo
, "\n\t ", cp
);
1713 OF_FWD(OF_MATCH_FIXLEN
);
1715 ND_PRINT("\n\t duration_sec %u", GET_BE_U_4(cp
));
1718 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp
));
1721 ND_PRINT(", priority %u", GET_BE_U_2(cp
));
1724 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp
));
1727 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp
));
1732 ND_PRINT(", cookie 0x%016" PRIx64
, GET_BE_U_8(cp
));
1735 ND_PRINT(", packet_count %" PRIu64
, GET_BE_U_8(cp
));
1738 ND_PRINT(", byte_count %" PRIu64
, GET_BE_U_8(cp
));
1741 of10_actions_print(ndo
, "\n\t ", cp
, entry_len
- OF_FLOW_STATS_REPLY_MINLEN
);
1742 OF_FWD(entry_len
- OF_FLOW_STATS_REPLY_MINLEN
);
1746 invalid
: /* skip the rest of flow statistics entries */
1747 nd_print_invalid(ndo
);
1748 ND_TCHECK_LEN(cp
, len
);
1753 of10_aggregate_stats_reply_print(netdissect_options
*ndo
,
1754 const u_char
*cp
, u_int len
)
1756 if (len
!= OF_AGGREGATE_STATS_REPLY_FIXLEN
)
1759 ND_PRINT("\n\t packet_count %" PRIu64
, GET_BE_U_8(cp
));
1762 ND_PRINT(", byte_count %" PRIu64
, GET_BE_U_8(cp
));
1765 ND_PRINT(", flow_count %u", GET_BE_U_4(cp
));
1768 /* Always the last field, check bounds. */
1772 invalid
: /* skip the message body */
1773 nd_print_invalid(ndo
);
1774 ND_TCHECK_LEN(cp
, len
);
1779 of10_table_stats_reply_print(netdissect_options
*ndo
,
1780 const u_char
*cp
, u_int len
)
1783 if (len
< OF_TABLE_STATS_REPLY_FIXLEN
)
1786 ND_PRINT("\n\t table_id %s",
1787 tok2str(tableid_str
, "%u", GET_U_1(cp
)));
1792 ND_PRINT(", name '");
1793 (void)nd_print(ndo
, cp
, cp
+ OFP_MAX_TABLE_NAME_LEN
);
1795 OF_FWD(OFP_MAX_TABLE_NAME_LEN
);
1797 ND_PRINT("\n\t wildcards 0x%08x", GET_BE_U_4(cp
));
1798 of_bitmap_print(ndo
, ofpfw_bm
, GET_BE_U_4(cp
), OFPFW_U
);
1801 ND_PRINT("\n\t max_entries %u", GET_BE_U_4(cp
));
1804 ND_PRINT(", active_count %u", GET_BE_U_4(cp
));
1807 ND_PRINT(", lookup_count %" PRIu64
, GET_BE_U_8(cp
));
1810 ND_PRINT(", matched_count %" PRIu64
, GET_BE_U_8(cp
));
1815 invalid
: /* skip the undersized trailing data */
1816 nd_print_invalid(ndo
);
1817 ND_TCHECK_LEN(cp
, len
);
1822 of10_port_stats_reply_print(netdissect_options
*ndo
,
1823 const u_char
*cp
, u_int len
)
1826 if (len
< OF_PORT_STATS_REPLY_FIXLEN
)
1829 ND_PRINT("\n\t port_no %s",
1830 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1832 if (ndo
->ndo_vflag
< 2) {
1833 OF_CHK_FWD(OF_PORT_STATS_REPLY_FIXLEN
- 2);
1839 ND_PRINT(", rx_packets %" PRIu64
, GET_BE_U_8(cp
));
1842 ND_PRINT(", tx_packets %" PRIu64
, GET_BE_U_8(cp
));
1845 ND_PRINT(", rx_bytes %" PRIu64
, GET_BE_U_8(cp
));
1848 ND_PRINT(", tx_bytes %" PRIu64
, GET_BE_U_8(cp
));
1851 ND_PRINT(", rx_dropped %" PRIu64
, GET_BE_U_8(cp
));
1854 ND_PRINT(", tx_dropped %" PRIu64
, GET_BE_U_8(cp
));
1857 ND_PRINT(", rx_errors %" PRIu64
, GET_BE_U_8(cp
));
1860 ND_PRINT(", tx_errors %" PRIu64
, GET_BE_U_8(cp
));
1863 ND_PRINT(", rx_frame_err %" PRIu64
, GET_BE_U_8(cp
));
1866 ND_PRINT(", rx_over_err %" PRIu64
, GET_BE_U_8(cp
));
1869 ND_PRINT(", rx_crc_err %" PRIu64
, GET_BE_U_8(cp
));
1872 ND_PRINT(", collisions %" PRIu64
, GET_BE_U_8(cp
));
1877 invalid
: /* skip the undersized trailing data */
1878 nd_print_invalid(ndo
);
1879 ND_TCHECK_LEN(cp
, len
);
1884 of10_queue_stats_reply_print(netdissect_options
*ndo
,
1885 const u_char
*cp
, u_int len
)
1888 if (len
< OF_QUEUE_STATS_REPLY_FIXLEN
)
1891 ND_PRINT("\n\t port_no %s",
1892 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1897 ND_PRINT(", queue_id %u", GET_BE_U_4(cp
));
1900 ND_PRINT(", tx_bytes %" PRIu64
, GET_BE_U_8(cp
));
1903 ND_PRINT(", tx_packets %" PRIu64
, GET_BE_U_8(cp
));
1906 ND_PRINT(", tx_errors %" PRIu64
, GET_BE_U_8(cp
));
1911 invalid
: /* skip the undersized trailing data */
1912 nd_print_invalid(ndo
);
1913 ND_TCHECK_LEN(cp
, len
);
1918 of10_stats_reply_print(netdissect_options
*ndo
,
1919 const u_char
*cp
, u_int len
)
1924 type
= GET_BE_U_2(cp
);
1925 ND_PRINT("\n\t type %s", tok2str(ofpst_str
, "invalid (0x%04x)", type
));
1928 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp
));
1929 of_bitmap_print(ndo
, ofpsf_reply_bm
, GET_BE_U_2(cp
), OFPSF_REPLY_U
);
1932 if (ndo
->ndo_vflag
> 0) {
1933 void (*decoder
)(netdissect_options
*, const u_char
*, u_int
) =
1934 type
== OFPST_DESC
? of10_desc_stats_reply_print
:
1935 type
== OFPST_FLOW
? of10_flow_stats_reply_print
:
1936 type
== OFPST_AGGREGATE
? of10_aggregate_stats_reply_print
:
1937 type
== OFPST_TABLE
? of10_table_stats_reply_print
:
1938 type
== OFPST_PORT
? of10_port_stats_reply_print
:
1939 type
== OFPST_QUEUE
? of10_queue_stats_reply_print
:
1940 type
== OFPST_VENDOR
? of10_vendor_data_print
:
1942 if (decoder
!= NULL
) {
1943 decoder(ndo
, cp
, len
);
1947 ND_TCHECK_LEN(cp
, len
);
1950 /* [OF10] Section 5.3.6 */
1952 of10_packet_out_print(netdissect_options
*ndo
,
1953 const u_char
*cp
, u_int len
)
1955 uint16_t actions_len
;
1958 ND_PRINT("\n\t buffer_id 0x%08x", GET_BE_U_4(cp
));
1961 ND_PRINT(", in_port %s", tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1964 actions_len
= GET_BE_U_2(cp
);
1966 if (actions_len
> len
)
1969 of10_actions_print(ndo
, "\n\t ", cp
, actions_len
);
1970 OF_FWD(actions_len
);
1972 of10_packet_data_print(ndo
, cp
, len
);
1975 invalid
: /* skip the rest of the message body */
1976 nd_print_invalid(ndo
);
1977 ND_TCHECK_LEN(cp
, len
);
1980 /* [OF10] Section 5.4.1 */
1982 of10_packet_in_print(netdissect_options
*ndo
,
1983 const u_char
*cp
, u_int len
)
1986 ND_PRINT("\n\t buffer_id %s",
1987 tok2str(bufferid_str
, "0x%08x", GET_BE_U_4(cp
)));
1990 ND_PRINT(", total_len %u", GET_BE_U_2(cp
));
1993 ND_PRINT(", in_port %s", tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
1996 ND_PRINT(", reason %s",
1997 tok2str(ofpr_str
, "invalid (0x%02x)", GET_U_1(cp
)));
2000 /* Sometimes the last field, check bounds. */
2003 of10_packet_data_print(ndo
, cp
, len
);
2006 /* [OF10] Section 5.4.2 */
2008 of10_flow_removed_print(netdissect_options
*ndo
,
2012 of10_match_print(ndo
, "\n\t ", cp
);
2013 cp
+= OF_MATCH_FIXLEN
;
2015 ND_PRINT("\n\t cookie 0x%016" PRIx64
, GET_BE_U_8(cp
));
2019 ND_PRINT(", priority %u", GET_BE_U_2(cp
));
2022 ND_PRINT(", reason %s",
2023 tok2str(ofprr_str
, "unknown (0x%02x)", GET_U_1(cp
)));
2028 ND_PRINT(", duration_sec %u", GET_BE_U_4(cp
));
2031 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp
));
2035 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp
));
2040 ND_PRINT(", packet_count %" PRIu64
, GET_BE_U_8(cp
));
2043 ND_PRINT(", byte_count %" PRIu64
, GET_BE_U_8(cp
));
2046 /* [OF10] Section 5.4.4 */
2048 of10_error_print(netdissect_options
*ndo
,
2049 const u_char
*cp
, u_int len
)
2051 uint16_t type
, code
;
2052 const struct tok
*code_str
;
2055 type
= GET_BE_U_2(cp
);
2057 ND_PRINT("\n\t type %s", tok2str(ofpet_str
, "invalid (0x%04x)", type
));
2059 code
= GET_BE_U_2(cp
);
2061 code_str
= uint2tokary(of10_ofpet2tokary
, type
);
2062 if (code_str
!= NULL
)
2063 ND_PRINT(", code %s",
2064 tok2str(code_str
, "invalid (0x%04x)", code
));
2066 ND_PRINT(", code invalid (0x%04x)", code
);
2068 of_data_print(ndo
, cp
, len
);
2072 of10_message_print(netdissect_options
*ndo
,
2073 const u_char
*cp
, uint16_t len
, const uint8_t type
)
2076 * Here "cp" and "len" stand for the message part beyond the common
2077 * OpenFlow 1.0 header, if any. Subtract OF_HEADER_FIXLEN from the
2078 * type-specific lengths, which include the header length, when (and
2079 * only when) validating the length in this function. No other code
2080 * in this file needs to take OF_HEADER_FIXLEN into account.
2082 * Most message types are longer than just the header, and the length
2083 * constraints may be complex. When possible, validate the constraint
2084 * completely here, otherwise check that the message is long enough to
2085 * begin the decoding and let the lower-layer function do any remaining
2089 /* OpenFlow header only. */
2090 case OFPT_FEATURES_REQUEST
: /* [OF10] Section 5.3.1 */
2091 case OFPT_GET_CONFIG_REQUEST
: /* [OF10] Section 5.3.2 */
2092 case OFPT_BARRIER_REQUEST
: /* [OF10] Section 5.3.7 */
2093 case OFPT_BARRIER_REPLY
: /* ibid */
2098 /* OpenFlow header and fixed-size message body. */
2099 case OFPT_SET_CONFIG
: /* [OF10] Section 5.3.2 */
2100 case OFPT_GET_CONFIG_REPLY
: /* ibid */
2101 if (len
!= OF_SWITCH_CONFIG_FIXLEN
- OF_HEADER_FIXLEN
)
2103 if (ndo
->ndo_vflag
< 1)
2106 ND_PRINT("\n\t flags %s",
2107 tok2str(ofp_config_str
, "invalid (0x%04x)",
2111 ND_PRINT(", miss_send_len %u", GET_BE_U_2(cp
));
2114 if (len
!= OF_PORT_MOD_FIXLEN
- OF_HEADER_FIXLEN
)
2116 if (ndo
->ndo_vflag
< 1)
2118 of10_port_mod_print(ndo
, cp
);
2120 case OFPT_QUEUE_GET_CONFIG_REQUEST
: /* [OF10] Section 5.3.4 */
2121 if (len
!= OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN
- OF_HEADER_FIXLEN
)
2123 if (ndo
->ndo_vflag
< 1)
2126 ND_PRINT("\n\t port %s",
2127 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
2130 /* Always the last field, check bounds. */
2133 case OFPT_FLOW_REMOVED
:
2134 if (len
!= OF_FLOW_REMOVED_FIXLEN
- OF_HEADER_FIXLEN
)
2136 if (ndo
->ndo_vflag
< 1)
2138 of10_flow_removed_print(ndo
, cp
);
2140 case OFPT_PORT_STATUS
: /* [OF10] Section 5.4.3 */
2141 if (len
!= OF_PORT_STATUS_FIXLEN
- OF_HEADER_FIXLEN
)
2143 if (ndo
->ndo_vflag
< 1)
2146 ND_PRINT("\n\t reason %s",
2147 tok2str(ofppr_str
, "invalid (0x%02x)", GET_U_1(cp
)));
2150 /* No need to check bounds, more data follows. */
2153 of10_phy_ports_print(ndo
, cp
, len
);
2156 /* OpenFlow header, fixed-size message body and n * fixed-size data units. */
2157 case OFPT_FEATURES_REPLY
:
2158 if (len
< OF_FEATURES_REPLY_MINLEN
- OF_HEADER_FIXLEN
)
2160 if (ndo
->ndo_vflag
< 1)
2162 of10_features_reply_print(ndo
, cp
, len
);
2165 /* OpenFlow header and variable-size data. */
2166 case OFPT_HELLO
: /* [OF10] Section 5.5.1 */
2167 case OFPT_ECHO_REQUEST
: /* [OF10] Section 5.5.2 */
2168 case OFPT_ECHO_REPLY
: /* [OF10] Section 5.5.3 */
2169 if (ndo
->ndo_vflag
< 1)
2171 of_data_print(ndo
, cp
, len
);
2174 /* OpenFlow header, fixed-size message body and variable-size data. */
2176 if (len
< OF_ERROR_MSG_MINLEN
- OF_HEADER_FIXLEN
)
2178 if (ndo
->ndo_vflag
< 1)
2180 of10_error_print(ndo
, cp
, len
);
2183 /* [OF10] Section 5.5.4 */
2184 if (len
< OF_VENDOR_MINLEN
- OF_HEADER_FIXLEN
)
2186 if (ndo
->ndo_vflag
< 1)
2188 of10_vendor_message_print(ndo
, cp
, len
);
2190 case OFPT_PACKET_IN
:
2191 /* 2 mock octets count in OF_PACKET_IN_MINLEN but not in len */
2192 if (len
< OF_PACKET_IN_MINLEN
- 2 - OF_HEADER_FIXLEN
)
2194 if (ndo
->ndo_vflag
< 1)
2196 of10_packet_in_print(ndo
, cp
, len
);
2199 /* a. OpenFlow header. */
2200 /* b. OpenFlow header and one of the fixed-size message bodies. */
2201 /* c. OpenFlow header, fixed-size message body and variable-size data. */
2202 case OFPT_STATS_REQUEST
:
2203 if (len
< OF_STATS_REQUEST_MINLEN
- OF_HEADER_FIXLEN
)
2205 if (ndo
->ndo_vflag
< 1)
2207 of10_stats_request_print(ndo
, cp
, len
);
2210 /* a. OpenFlow header and fixed-size message body. */
2211 /* b. OpenFlow header and n * fixed-size data units. */
2212 /* c. OpenFlow header and n * variable-size data units. */
2213 /* d. OpenFlow header, fixed-size message body and variable-size data. */
2214 case OFPT_STATS_REPLY
:
2215 if (len
< OF_STATS_REPLY_MINLEN
- OF_HEADER_FIXLEN
)
2217 if (ndo
->ndo_vflag
< 1)
2219 of10_stats_reply_print(ndo
, cp
, len
);
2222 /* OpenFlow header and n * variable-size data units and variable-size data. */
2223 case OFPT_PACKET_OUT
:
2224 if (len
< OF_PACKET_OUT_MINLEN
- OF_HEADER_FIXLEN
)
2226 if (ndo
->ndo_vflag
< 1)
2228 of10_packet_out_print(ndo
, cp
, len
);
2231 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2233 if (len
< OF_FLOW_MOD_MINLEN
- OF_HEADER_FIXLEN
)
2235 if (ndo
->ndo_vflag
< 1)
2237 of10_flow_mod_print(ndo
, cp
, len
);
2240 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2241 case OFPT_QUEUE_GET_CONFIG_REPLY
: /* [OF10] Section 5.3.4 */
2242 if (len
< OF_QUEUE_GET_CONFIG_REPLY_MINLEN
- OF_HEADER_FIXLEN
)
2244 if (ndo
->ndo_vflag
< 1)
2247 ND_PRINT("\n\t port %s",
2248 tok2str(ofpp_str
, "%u", GET_BE_U_2(cp
)));
2251 /* Sometimes the last field, check bounds. */
2254 of10_queues_print(ndo
, cp
, len
);
2256 } /* switch (type) */
2258 * Not a recognised type or did not print the details, fall back to
2261 ND_TCHECK_LEN(cp
, len
);
2264 invalid
: /* skip the message body */
2265 nd_print_invalid(ndo
);
2266 ND_TCHECK_LEN(cp
, len
);