]> The Tcpdump Group git mirrors - tcpdump/blob - print-openflow-1.0.c
d942fd8f8b1bae1362f9125608beb085acabd34a
[tcpdump] / print-openflow-1.0.c
1 /*
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:
8 *
9 * [OF10] https://www.opennetworking.org/wp-content/uploads/2013/04/openflow-spec-v1.0.0.pdf
10 *
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
20 * the next data item.
21 *
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
27 * the nested frames.
28 *
29 * Partial decoding of Big Switch Networks vendor extensions is done after the
30 * oftest (OpenFlow Testing Framework) and Loxigen (library generator) source
31 * code.
32 *
33 *
34 * Copyright (c) 2013 The TCPDUMP project
35 * All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
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.
45 *
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.
58 */
59
60 /* \summary: OpenFlow protocol version 1.0 printer */
61
62 #ifdef HAVE_CONFIG_H
63 #include <config.h>
64 #endif
65
66 #include "netdissect-stdinc.h"
67
68 #define ND_LONGJMP_FROM_TCHECK
69 #include "netdissect.h"
70 #include "extract.h"
71 #include "addrtoname.h"
72 #include "ethertype.h"
73 #include "ipproto.h"
74 #include "oui.h"
75 #include "openflow.h"
76
77
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 #define OFPT_MAX OFPT_QUEUE_GET_CONFIG_REPLY
101
102 #define OFPPC_PORT_DOWN (1U <<0)
103 #define OFPPC_NO_STP (1U <<1)
104 #define OFPPC_NO_RECV (1U <<2)
105 #define OFPPC_NO_RECV_STP (1U <<3)
106 #define OFPPC_NO_FLOOD (1U <<4)
107 #define OFPPC_NO_FWD (1U <<5)
108 #define OFPPC_NO_PACKET_IN (1U <<6)
109 static const struct tok ofppc_bm[] = {
110 { OFPPC_PORT_DOWN, "PORT_DOWN" },
111 { OFPPC_NO_STP, "NO_STP" },
112 { OFPPC_NO_RECV, "NO_RECV" },
113 { OFPPC_NO_RECV_STP, "NO_RECV_STP" },
114 { OFPPC_NO_FLOOD, "NO_FLOOD" },
115 { OFPPC_NO_FWD, "NO_FWD" },
116 { OFPPC_NO_PACKET_IN, "NO_PACKET_IN" },
117 { 0, NULL }
118 };
119 #define OFPPC_U (~(OFPPC_PORT_DOWN | OFPPC_NO_STP | OFPPC_NO_RECV | \
120 OFPPC_NO_RECV_STP | OFPPC_NO_FLOOD | OFPPC_NO_FWD | \
121 OFPPC_NO_PACKET_IN))
122
123 /*
124 * [OF10] lists all FPPS_ constants in one enum, but they mean a 1-bit bitmap
125 * in the least significant octet and a 2-bit code point in the next octet.
126 * Remember to mix or to separate these two parts as the context requires.
127 */
128 #define OFPPS_LINK_DOWN (1U << 0) /* bitmap */
129 #define OFPPS_STP_LISTEN (0U << 8) /* code point */
130 #define OFPPS_STP_LEARN (1U << 8) /* code point */
131 #define OFPPS_STP_FORWARD (2U << 8) /* code point */
132 #define OFPPS_STP_BLOCK (3U << 8) /* code point */
133 #define OFPPS_STP_MASK (3U << 8) /* code point bitmask */
134 static const struct tok ofpps_stp_str[] = {
135 { OFPPS_STP_LISTEN, "STP_LISTEN" },
136 { OFPPS_STP_LEARN, "STP_LEARN" },
137 { OFPPS_STP_FORWARD, "STP_FORWARD" },
138 { OFPPS_STP_BLOCK, "STP_BLOCK" },
139 { 0, NULL }
140 };
141 #define OFPPS_U (~(OFPPS_LINK_DOWN | OFPPS_STP_LISTEN | OFPPS_STP_LEARN | \
142 OFPPS_STP_FORWARD | OFPPS_STP_BLOCK))
143
144 #define OFPP_MAX 0xff00U
145 #define OFPP_IN_PORT 0xfff8U
146 #define OFPP_TABLE 0xfff9U
147 #define OFPP_NORMAL 0xfffaU
148 #define OFPP_FLOOD 0xfffbU
149 #define OFPP_ALL 0xfffcU
150 #define OFPP_CONTROLLER 0xfffdU
151 #define OFPP_LOCAL 0xfffeU
152 #define OFPP_NONE 0xffffU
153 static const struct tok ofpp_str[] = {
154 { OFPP_MAX, "MAX" },
155 { OFPP_IN_PORT, "IN_PORT" },
156 { OFPP_TABLE, "TABLE" },
157 { OFPP_NORMAL, "NORMAL" },
158 { OFPP_FLOOD, "FLOOD" },
159 { OFPP_ALL, "ALL" },
160 { OFPP_CONTROLLER, "CONTROLLER" },
161 { OFPP_LOCAL, "LOCAL" },
162 { OFPP_NONE, "NONE" },
163 { 0, NULL }
164 };
165
166 #define OFPPF_10MB_HD (1U << 0)
167 #define OFPPF_10MB_FD (1U << 1)
168 #define OFPPF_100MB_HD (1U << 2)
169 #define OFPPF_100MB_FD (1U << 3)
170 #define OFPPF_1GB_HD (1U << 4)
171 #define OFPPF_1GB_FD (1U << 5)
172 #define OFPPF_10GB_FD (1U << 6)
173 #define OFPPF_COPPER (1U << 7)
174 #define OFPPF_FIBER (1U << 8)
175 #define OFPPF_AUTONEG (1U << 9)
176 #define OFPPF_PAUSE (1U <<10)
177 #define OFPPF_PAUSE_ASYM (1U <<11)
178 static const struct tok ofppf_bm[] = {
179 { OFPPF_10MB_HD, "10MB_HD" },
180 { OFPPF_10MB_FD, "10MB_FD" },
181 { OFPPF_100MB_HD, "100MB_HD" },
182 { OFPPF_100MB_FD, "100MB_FD" },
183 { OFPPF_1GB_HD, "1GB_HD" },
184 { OFPPF_1GB_FD, "1GB_FD" },
185 { OFPPF_10GB_FD, "10GB_FD" },
186 { OFPPF_COPPER, "COPPER" },
187 { OFPPF_FIBER, "FIBER" },
188 { OFPPF_AUTONEG, "AUTONEG" },
189 { OFPPF_PAUSE, "PAUSE" },
190 { OFPPF_PAUSE_ASYM, "PAUSE_ASYM" },
191 { 0, NULL }
192 };
193 #define OFPPF_U (~(OFPPF_10MB_HD | OFPPF_10MB_FD | OFPPF_100MB_HD | \
194 OFPPF_100MB_FD | OFPPF_1GB_HD | OFPPF_1GB_FD | \
195 OFPPF_10GB_FD | OFPPF_COPPER | OFPPF_FIBER | \
196 OFPPF_AUTONEG | OFPPF_PAUSE | OFPPF_PAUSE_ASYM))
197
198 #define OFPQT_NONE 0x0000
199 #define OFPQT_MIN_RATE 0x0001
200 static const struct tok ofpqt_str[] = {
201 { OFPQT_NONE, "NONE" },
202 { OFPQT_MIN_RATE, "MIN_RATE" },
203 { 0, NULL }
204 };
205
206 #define OFPFW_IN_PORT (1U <<0)
207 #define OFPFW_DL_VLAN (1U <<1)
208 #define OFPFW_DL_SRC (1U <<2)
209 #define OFPFW_DL_DST (1U <<3)
210 #define OFPFW_DL_TYPE (1U <<4)
211 #define OFPFW_NW_PROTO (1U <<5)
212 #define OFPFW_TP_SRC (1U <<6)
213 #define OFPFW_TP_DST (1U <<7)
214 #define OFPFW_NW_SRC_SHIFT 8
215 #define OFPFW_NW_SRC_BITS 6
216 #define OFPFW_NW_SRC_MASK (((1U <<OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT)
217 #define OFPFW_NW_DST_SHIFT 14
218 #define OFPFW_NW_DST_BITS 6
219 #define OFPFW_NW_DST_MASK (((1U <<OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT)
220 #define OFPFW_DL_VLAN_PCP (1U <<20)
221 #define OFPFW_NW_TOS (1U <<21)
222 #define OFPFW_ALL ((1U <<22) - 1)
223 static const struct tok ofpfw_bm[] = {
224 { OFPFW_IN_PORT, "IN_PORT" },
225 { OFPFW_DL_VLAN, "DL_VLAN" },
226 { OFPFW_DL_SRC, "DL_SRC" },
227 { OFPFW_DL_DST, "DL_DST" },
228 { OFPFW_DL_TYPE, "DL_TYPE" },
229 { OFPFW_NW_PROTO, "NW_PROTO" },
230 { OFPFW_TP_SRC, "TP_SRC" },
231 { OFPFW_TP_DST, "TP_DST" },
232 { OFPFW_DL_VLAN_PCP, "DL_VLAN_PCP" },
233 { OFPFW_NW_TOS, "NW_TOS" },
234 { 0, NULL }
235 };
236 /* The above array does not include bits 8~13 (OFPFW_NW_SRC_*) and 14~19
237 * (OFPFW_NW_DST_*), which are not a part of the bitmap and require decoding
238 * other than that of tok2str(). The macro below includes these bits such that
239 * they are not reported as bogus in the decoding. */
240 #define OFPFW_U (~(OFPFW_ALL))
241
242 #define OFPAT_OUTPUT 0x0000U
243 #define OFPAT_SET_VLAN_VID 0x0001U
244 #define OFPAT_SET_VLAN_PCP 0x0002U
245 #define OFPAT_STRIP_VLAN 0x0003U
246 #define OFPAT_SET_DL_SRC 0x0004U
247 #define OFPAT_SET_DL_DST 0x0005U
248 #define OFPAT_SET_NW_SRC 0x0006U
249 #define OFPAT_SET_NW_DST 0x0007U
250 #define OFPAT_SET_NW_TOS 0x0008U
251 #define OFPAT_SET_TP_SRC 0x0009U
252 #define OFPAT_SET_TP_DST 0x000aU
253 #define OFPAT_ENQUEUE 0x000bU
254 #define OFPAT_VENDOR 0xffffU
255 static const struct tok ofpat_str[] = {
256 { OFPAT_OUTPUT, "OUTPUT" },
257 { OFPAT_SET_VLAN_VID, "SET_VLAN_VID" },
258 { OFPAT_SET_VLAN_PCP, "SET_VLAN_PCP" },
259 { OFPAT_STRIP_VLAN, "STRIP_VLAN" },
260 { OFPAT_SET_DL_SRC, "SET_DL_SRC" },
261 { OFPAT_SET_DL_DST, "SET_DL_DST" },
262 { OFPAT_SET_NW_SRC, "SET_NW_SRC" },
263 { OFPAT_SET_NW_DST, "SET_NW_DST" },
264 { OFPAT_SET_NW_TOS, "SET_NW_TOS" },
265 { OFPAT_SET_TP_SRC, "SET_TP_SRC" },
266 { OFPAT_SET_TP_DST, "SET_TP_DST" },
267 { OFPAT_ENQUEUE, "ENQUEUE" },
268 { OFPAT_VENDOR, "VENDOR" },
269 { 0, NULL }
270 };
271
272 /* bit-shifted, w/o vendor action */
273 static const struct tok ofpat_bm[] = {
274 { 1U <<OFPAT_OUTPUT, "OUTPUT" },
275 { 1U <<OFPAT_SET_VLAN_VID, "SET_VLAN_VID" },
276 { 1U <<OFPAT_SET_VLAN_PCP, "SET_VLAN_PCP" },
277 { 1U <<OFPAT_STRIP_VLAN, "STRIP_VLAN" },
278 { 1U <<OFPAT_SET_DL_SRC, "SET_DL_SRC" },
279 { 1U <<OFPAT_SET_DL_DST, "SET_DL_DST" },
280 { 1U <<OFPAT_SET_NW_SRC, "SET_NW_SRC" },
281 { 1U <<OFPAT_SET_NW_DST, "SET_NW_DST" },
282 { 1U <<OFPAT_SET_NW_TOS, "SET_NW_TOS" },
283 { 1U <<OFPAT_SET_TP_SRC, "SET_TP_SRC" },
284 { 1U <<OFPAT_SET_TP_DST, "SET_TP_DST" },
285 { 1U <<OFPAT_ENQUEUE, "ENQUEUE" },
286 { 0, NULL }
287 };
288 #define OFPAT_U (~(1U <<OFPAT_OUTPUT | 1U <<OFPAT_SET_VLAN_VID | \
289 1U <<OFPAT_SET_VLAN_PCP | 1U <<OFPAT_STRIP_VLAN | \
290 1U <<OFPAT_SET_DL_SRC | 1U <<OFPAT_SET_DL_DST | \
291 1U <<OFPAT_SET_NW_SRC | 1U <<OFPAT_SET_NW_DST | \
292 1U <<OFPAT_SET_NW_TOS | 1U <<OFPAT_SET_TP_SRC | \
293 1U <<OFPAT_SET_TP_DST | 1U <<OFPAT_ENQUEUE))
294
295 #define OFPC_FLOW_STATS (1U <<0)
296 #define OFPC_TABLE_STATS (1U <<1)
297 #define OFPC_PORT_STATS (1U <<2)
298 #define OFPC_STP (1U <<3)
299 #define OFPC_RESERVED (1U <<4)
300 #define OFPC_IP_REASM (1U <<5)
301 #define OFPC_QUEUE_STATS (1U <<6)
302 #define OFPC_ARP_MATCH_IP (1U <<7)
303 static const struct tok ofp_capabilities_bm[] = {
304 { OFPC_FLOW_STATS, "FLOW_STATS" },
305 { OFPC_TABLE_STATS, "TABLE_STATS" },
306 { OFPC_PORT_STATS, "PORT_STATS" },
307 { OFPC_STP, "STP" },
308 { OFPC_RESERVED, "RESERVED" }, /* not in the mask below */
309 { OFPC_IP_REASM, "IP_REASM" },
310 { OFPC_QUEUE_STATS, "QUEUE_STATS" },
311 { OFPC_ARP_MATCH_IP, "ARP_MATCH_IP" },
312 { 0, NULL }
313 };
314 #define OFPCAP_U (~(OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS | \
315 OFPC_STP | OFPC_IP_REASM | OFPC_QUEUE_STATS | \
316 OFPC_ARP_MATCH_IP))
317
318 #define OFPC_FRAG_NORMAL 0x0000U
319 #define OFPC_FRAG_DROP 0x0001U
320 #define OFPC_FRAG_REASM 0x0002U
321 static const struct tok ofp_config_str[] = {
322 { OFPC_FRAG_NORMAL, "FRAG_NORMAL" },
323 { OFPC_FRAG_DROP, "FRAG_DROP" },
324 { OFPC_FRAG_REASM, "FRAG_REASM" },
325 { 0, NULL }
326 };
327
328 #define OFPFC_ADD 0x0000U
329 #define OFPFC_MODIFY 0x0001U
330 #define OFPFC_MODIFY_STRICT 0x0002U
331 #define OFPFC_DELETE 0x0003U
332 #define OFPFC_DELETE_STRICT 0x0004U
333 static const struct tok ofpfc_str[] = {
334 { OFPFC_ADD, "ADD" },
335 { OFPFC_MODIFY, "MODIFY" },
336 { OFPFC_MODIFY_STRICT, "MODIFY_STRICT" },
337 { OFPFC_DELETE, "DELETE" },
338 { OFPFC_DELETE_STRICT, "DELETE_STRICT" },
339 { 0, NULL }
340 };
341
342 static const struct tok bufferid_str[] = {
343 { 0xffffffff, "NONE" },
344 { 0, NULL }
345 };
346
347 #define OFPFF_SEND_FLOW_REM (1U <<0)
348 #define OFPFF_CHECK_OVERLAP (1U <<1)
349 #define OFPFF_EMERG (1U <<2)
350 static const struct tok ofpff_bm[] = {
351 { OFPFF_SEND_FLOW_REM, "SEND_FLOW_REM" },
352 { OFPFF_CHECK_OVERLAP, "CHECK_OVERLAP" },
353 { OFPFF_EMERG, "EMERG" },
354 { 0, NULL }
355 };
356 #define OFPFF_U (~(OFPFF_SEND_FLOW_REM | OFPFF_CHECK_OVERLAP | OFPFF_EMERG))
357
358 #define OFPST_DESC 0x0000U
359 #define OFPST_FLOW 0x0001U
360 #define OFPST_AGGREGATE 0x0002U
361 #define OFPST_TABLE 0x0003U
362 #define OFPST_PORT 0x0004U
363 #define OFPST_QUEUE 0x0005U
364 #define OFPST_VENDOR 0xffffU
365 static const struct tok ofpst_str[] = {
366 { OFPST_DESC, "DESC" },
367 { OFPST_FLOW, "FLOW" },
368 { OFPST_AGGREGATE, "AGGREGATE" },
369 { OFPST_TABLE, "TABLE" },
370 { OFPST_PORT, "PORT" },
371 { OFPST_QUEUE, "QUEUE" },
372 { OFPST_VENDOR, "VENDOR" },
373 { 0, NULL }
374 };
375
376 static const struct tok tableid_str[] = {
377 { 0xfeU, "EMERG" },
378 { 0xffU, "ALL" },
379 { 0, NULL }
380 };
381
382 #define OFPQ_ALL 0xffffffffU
383 static const struct tok ofpq_str[] = {
384 { OFPQ_ALL, "ALL" },
385 { 0, NULL }
386 };
387
388 #define OFPSF_REPLY_MORE 0x0001U
389 static const struct tok ofpsf_reply_bm[] = {
390 { OFPSF_REPLY_MORE, "MORE" },
391 { 0, NULL }
392 };
393 #define OFPSF_REPLY_U (~(OFPSF_REPLY_MORE))
394
395 #define OFPR_NO_MATCH 0x00U
396 #define OFPR_ACTION 0x01U
397 static const struct tok ofpr_str[] = {
398 { OFPR_NO_MATCH, "NO_MATCH" },
399 { OFPR_ACTION, "ACTION" },
400 { 0, NULL }
401 };
402
403 #define OFPRR_IDLE_TIMEOUT 0x00U
404 #define OFPRR_HARD_TIMEOUT 0x01U
405 #define OFPRR_DELETE 0x02U
406 static const struct tok ofprr_str[] = {
407 { OFPRR_IDLE_TIMEOUT, "IDLE_TIMEOUT" },
408 { OFPRR_HARD_TIMEOUT, "HARD_TIMEOUT" },
409 { OFPRR_DELETE, "DELETE" },
410 { 0, NULL }
411 };
412
413 #define OFPPR_ADD 0x00U
414 #define OFPPR_DELETE 0x01U
415 #define OFPPR_MODIFY 0x02U
416 static const struct tok ofppr_str[] = {
417 { OFPPR_ADD, "ADD" },
418 { OFPPR_DELETE, "DELETE" },
419 { OFPPR_MODIFY, "MODIFY" },
420 { 0, NULL }
421 };
422
423 #define OFPET_HELLO_FAILED 0x0000U
424 #define OFPET_BAD_REQUEST 0x0001U
425 #define OFPET_BAD_ACTION 0x0002U
426 #define OFPET_FLOW_MOD_FAILED 0x0003U
427 #define OFPET_PORT_MOD_FAILED 0x0004U
428 #define OFPET_QUEUE_OP_FAILED 0x0005U
429 static const struct tok ofpet_str[] = {
430 { OFPET_HELLO_FAILED, "HELLO_FAILED" },
431 { OFPET_BAD_REQUEST, "BAD_REQUEST" },
432 { OFPET_BAD_ACTION, "BAD_ACTION" },
433 { OFPET_FLOW_MOD_FAILED, "FLOW_MOD_FAILED" },
434 { OFPET_PORT_MOD_FAILED, "PORT_MOD_FAILED" },
435 { OFPET_QUEUE_OP_FAILED, "QUEUE_OP_FAILED" },
436 { 0, NULL }
437 };
438
439 #define OFPHFC_INCOMPATIBLE 0x0000U
440 #define OFPHFC_EPERM 0x0001U
441 static const struct tok ofphfc_str[] = {
442 { OFPHFC_INCOMPATIBLE, "INCOMPATIBLE" },
443 { OFPHFC_EPERM, "EPERM" },
444 { 0, NULL }
445 };
446
447 #define OFPBRC_BAD_VERSION 0x0000U
448 #define OFPBRC_BAD_TYPE 0x0001U
449 #define OFPBRC_BAD_STAT 0x0002U
450 #define OFPBRC_BAD_VENDOR 0x0003U
451 #define OFPBRC_BAD_SUBTYPE 0x0004U
452 #define OFPBRC_EPERM 0x0005U
453 #define OFPBRC_BAD_LEN 0x0006U
454 #define OFPBRC_BUFFER_EMPTY 0x0007U
455 #define OFPBRC_BUFFER_UNKNOWN 0x0008U
456 static const struct tok ofpbrc_str[] = {
457 { OFPBRC_BAD_VERSION, "BAD_VERSION" },
458 { OFPBRC_BAD_TYPE, "BAD_TYPE" },
459 { OFPBRC_BAD_STAT, "BAD_STAT" },
460 { OFPBRC_BAD_VENDOR, "BAD_VENDOR" },
461 { OFPBRC_BAD_SUBTYPE, "BAD_SUBTYPE" },
462 { OFPBRC_EPERM, "EPERM" },
463 { OFPBRC_BAD_LEN, "BAD_LEN" },
464 { OFPBRC_BUFFER_EMPTY, "BUFFER_EMPTY" },
465 { OFPBRC_BUFFER_UNKNOWN, "BUFFER_UNKNOWN" },
466 { 0, NULL }
467 };
468
469 #define OFPBAC_BAD_TYPE 0x0000U
470 #define OFPBAC_BAD_LEN 0x0001U
471 #define OFPBAC_BAD_VENDOR 0x0002U
472 #define OFPBAC_BAD_VENDOR_TYPE 0x0003U
473 #define OFPBAC_BAD_OUT_PORT 0x0004U
474 #define OFPBAC_BAD_ARGUMENT 0x0005U
475 #define OFPBAC_EPERM 0x0006U
476 #define OFPBAC_TOO_MANY 0x0007U
477 #define OFPBAC_BAD_QUEUE 0x0008U
478 static const struct tok ofpbac_str[] = {
479 { OFPBAC_BAD_TYPE, "BAD_TYPE" },
480 { OFPBAC_BAD_LEN, "BAD_LEN" },
481 { OFPBAC_BAD_VENDOR, "BAD_VENDOR" },
482 { OFPBAC_BAD_VENDOR_TYPE, "BAD_VENDOR_TYPE" },
483 { OFPBAC_BAD_OUT_PORT, "BAD_OUT_PORT" },
484 { OFPBAC_BAD_ARGUMENT, "BAD_ARGUMENT" },
485 { OFPBAC_EPERM, "EPERM" },
486 { OFPBAC_TOO_MANY, "TOO_MANY" },
487 { OFPBAC_BAD_QUEUE, "BAD_QUEUE" },
488 { 0, NULL }
489 };
490
491 #define OFPFMFC_ALL_TABLES_FULL 0x0000U
492 #define OFPFMFC_OVERLAP 0x0001U
493 #define OFPFMFC_EPERM 0x0002U
494 #define OFPFMFC_BAD_EMERG_TIMEOUT 0x0003U
495 #define OFPFMFC_BAD_COMMAND 0x0004U
496 #define OFPFMFC_UNSUPPORTED 0x0005U
497 static const struct tok ofpfmfc_str[] = {
498 { OFPFMFC_ALL_TABLES_FULL, "ALL_TABLES_FULL" },
499 { OFPFMFC_OVERLAP, "OVERLAP" },
500 { OFPFMFC_EPERM, "EPERM" },
501 { OFPFMFC_BAD_EMERG_TIMEOUT, "BAD_EMERG_TIMEOUT" },
502 { OFPFMFC_BAD_COMMAND, "BAD_COMMAND" },
503 { OFPFMFC_UNSUPPORTED, "UNSUPPORTED" },
504 { 0, NULL }
505 };
506
507 #define OFPPMFC_BAD_PORT 0x0000U
508 #define OFPPMFC_BAD_HW_ADDR 0x0001U
509 static const struct tok ofppmfc_str[] = {
510 { OFPPMFC_BAD_PORT, "BAD_PORT" },
511 { OFPPMFC_BAD_HW_ADDR, "BAD_HW_ADDR" },
512 { 0, NULL }
513 };
514
515 #define OFPQOFC_BAD_PORT 0x0000U
516 #define OFPQOFC_BAD_QUEUE 0x0001U
517 #define OFPQOFC_EPERM 0x0002U
518 static const struct tok ofpqofc_str[] = {
519 { OFPQOFC_BAD_PORT, "BAD_PORT" },
520 { OFPQOFC_BAD_QUEUE, "BAD_QUEUE" },
521 { OFPQOFC_EPERM, "EPERM" },
522 { 0, NULL }
523 };
524
525 static const struct uint_tokary of10_ofpet2tokary[] = {
526 { OFPET_HELLO_FAILED, ofphfc_str },
527 { OFPET_BAD_REQUEST, ofpbrc_str },
528 { OFPET_BAD_ACTION, ofpbac_str },
529 { OFPET_FLOW_MOD_FAILED, ofpfmfc_str },
530 { OFPET_PORT_MOD_FAILED, ofppmfc_str },
531 { OFPET_QUEUE_OP_FAILED, ofpqofc_str },
532 /* uint2tokary() does not use array termination. */
533 };
534
535 /* lengths (fixed or minimal) of particular message types, where not 0 */
536 #define OF_SWITCH_CONFIG_FIXLEN (12U - OF_HEADER_FIXLEN)
537 #define OF_FEATURES_REPLY_MINLEN (32U - OF_HEADER_FIXLEN)
538 #define OF_PORT_STATUS_FIXLEN (64U - OF_HEADER_FIXLEN)
539 #define OF_PORT_MOD_FIXLEN (32U - OF_HEADER_FIXLEN)
540 #define OF_PACKET_IN_MINLEN (20U - OF_HEADER_FIXLEN) /* with 2 mock octets */
541 #define OF_PACKET_OUT_MINLEN (16U - OF_HEADER_FIXLEN)
542 #define OF_FLOW_MOD_MINLEN (72U - OF_HEADER_FIXLEN)
543 #define OF_FLOW_REMOVED_FIXLEN (88U - OF_HEADER_FIXLEN)
544 #define OF_ERROR_MSG_MINLEN (12U - OF_HEADER_FIXLEN)
545 #define OF_STATS_REQUEST_MINLEN (12U - OF_HEADER_FIXLEN)
546 #define OF_STATS_REPLY_MINLEN (12U - OF_HEADER_FIXLEN)
547 #define OF_VENDOR_MINLEN (12U - OF_HEADER_FIXLEN)
548 #define OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN (12U - OF_HEADER_FIXLEN)
549 #define OF_QUEUE_GET_CONFIG_REPLY_MINLEN (16U - OF_HEADER_FIXLEN)
550
551 /* lengths (fixed or minimal) of particular protocol structures */
552 #define OF_PHY_PORT_FIXLEN 48
553 #define OF_ACTION_MINLEN 8U
554 #define OF_MATCH_FIXLEN 40
555 #define OF_DESC_STATS_REPLY_FIXLEN 1056
556 #define OF_FLOW_STATS_REQUEST_FIXLEN 44
557 #define OF_FLOW_STATS_REPLY_MINLEN 88
558 #define OF_AGGREGATE_STATS_REPLY_FIXLEN 24
559 #define OF_TABLE_STATS_REPLY_FIXLEN 64
560 #define OF_PORT_STATS_REQUEST_FIXLEN 8
561 #define OF_PORT_STATS_REPLY_FIXLEN 104
562 #define OF_QUEUE_PROP_MINLEN 8
563 #define OF_QUEUE_PROP_MIN_RATE_FIXLEN 16
564 #define OF_PACKET_QUEUE_MINLEN 8
565 #define OF_QUEUE_STATS_REQUEST_FIXLEN 8
566 #define OF_QUEUE_STATS_REPLY_FIXLEN 32
567
568 /* miscellaneous constants from [OF10] */
569 #define OFP_MAX_TABLE_NAME_LEN 32
570 #define OFP_MAX_PORT_NAME_LEN 16
571 #define DESC_STR_LEN 256
572 #define SERIAL_NUM_LEN 32
573 #define OFP_VLAN_NONE 0xffffU
574
575 /* vendor extensions */
576 #define BSN_SET_IP_MASK 0
577 #define BSN_GET_IP_MASK_REQUEST 1
578 #define BSN_GET_IP_MASK_REPLY 2
579 #define BSN_SET_MIRRORING 3
580 #define BSN_GET_MIRRORING_REQUEST 4
581 #define BSN_GET_MIRRORING_REPLY 5
582 #define BSN_SHELL_COMMAND 6
583 #define BSN_SHELL_OUTPUT 7
584 #define BSN_SHELL_STATUS 8
585 #define BSN_GET_INTERFACES_REQUEST 9
586 #define BSN_GET_INTERFACES_REPLY 10
587 #define BSN_SET_PKTIN_SUPPRESSION_REQUEST 11
588 #define BSN_SET_L2_TABLE_REQUEST 12
589 #define BSN_GET_L2_TABLE_REQUEST 13
590 #define BSN_GET_L2_TABLE_REPLY 14
591 #define BSN_VIRTUAL_PORT_CREATE_REQUEST 15
592 #define BSN_VIRTUAL_PORT_CREATE_REPLY 16
593 #define BSN_VIRTUAL_PORT_REMOVE_REQUEST 17
594 #define BSN_BW_ENABLE_SET_REQUEST 18
595 #define BSN_BW_ENABLE_GET_REQUEST 19
596 #define BSN_BW_ENABLE_GET_REPLY 20
597 #define BSN_BW_CLEAR_DATA_REQUEST 21
598 #define BSN_BW_CLEAR_DATA_REPLY 22
599 #define BSN_BW_ENABLE_SET_REPLY 23
600 #define BSN_SET_L2_TABLE_REPLY 24
601 #define BSN_SET_PKTIN_SUPPRESSION_REPLY 25
602 #define BSN_VIRTUAL_PORT_REMOVE_REPLY 26
603 #define BSN_HYBRID_GET_REQUEST 27
604 #define BSN_HYBRID_GET_REPLY 28
605 /* 29 */
606 /* 30 */
607 #define BSN_PDU_TX_REQUEST 31
608 #define BSN_PDU_TX_REPLY 32
609 #define BSN_PDU_RX_REQUEST 33
610 #define BSN_PDU_RX_REPLY 34
611 #define BSN_PDU_RX_TIMEOUT 35
612
613 static const struct tok bsn_subtype_str[] = {
614 { BSN_SET_IP_MASK, "SET_IP_MASK" },
615 { BSN_GET_IP_MASK_REQUEST, "GET_IP_MASK_REQUEST" },
616 { BSN_GET_IP_MASK_REPLY, "GET_IP_MASK_REPLY" },
617 { BSN_SET_MIRRORING, "SET_MIRRORING" },
618 { BSN_GET_MIRRORING_REQUEST, "GET_MIRRORING_REQUEST" },
619 { BSN_GET_MIRRORING_REPLY, "GET_MIRRORING_REPLY" },
620 { BSN_SHELL_COMMAND, "SHELL_COMMAND" },
621 { BSN_SHELL_OUTPUT, "SHELL_OUTPUT" },
622 { BSN_SHELL_STATUS, "SHELL_STATUS" },
623 { BSN_GET_INTERFACES_REQUEST, "GET_INTERFACES_REQUEST" },
624 { BSN_GET_INTERFACES_REPLY, "GET_INTERFACES_REPLY" },
625 { BSN_SET_PKTIN_SUPPRESSION_REQUEST, "SET_PKTIN_SUPPRESSION_REQUEST" },
626 { BSN_SET_L2_TABLE_REQUEST, "SET_L2_TABLE_REQUEST" },
627 { BSN_GET_L2_TABLE_REQUEST, "GET_L2_TABLE_REQUEST" },
628 { BSN_GET_L2_TABLE_REPLY, "GET_L2_TABLE_REPLY" },
629 { BSN_VIRTUAL_PORT_CREATE_REQUEST, "VIRTUAL_PORT_CREATE_REQUEST" },
630 { BSN_VIRTUAL_PORT_CREATE_REPLY, "VIRTUAL_PORT_CREATE_REPLY" },
631 { BSN_VIRTUAL_PORT_REMOVE_REQUEST, "VIRTUAL_PORT_REMOVE_REQUEST" },
632 { BSN_BW_ENABLE_SET_REQUEST, "BW_ENABLE_SET_REQUEST" },
633 { BSN_BW_ENABLE_GET_REQUEST, "BW_ENABLE_GET_REQUEST" },
634 { BSN_BW_ENABLE_GET_REPLY, "BW_ENABLE_GET_REPLY" },
635 { BSN_BW_CLEAR_DATA_REQUEST, "BW_CLEAR_DATA_REQUEST" },
636 { BSN_BW_CLEAR_DATA_REPLY, "BW_CLEAR_DATA_REPLY" },
637 { BSN_BW_ENABLE_SET_REPLY, "BW_ENABLE_SET_REPLY" },
638 { BSN_SET_L2_TABLE_REPLY, "SET_L2_TABLE_REPLY" },
639 { BSN_SET_PKTIN_SUPPRESSION_REPLY, "SET_PKTIN_SUPPRESSION_REPLY" },
640 { BSN_VIRTUAL_PORT_REMOVE_REPLY, "VIRTUAL_PORT_REMOVE_REPLY" },
641 { BSN_HYBRID_GET_REQUEST, "HYBRID_GET_REQUEST" },
642 { BSN_HYBRID_GET_REPLY, "HYBRID_GET_REPLY" },
643 { BSN_PDU_TX_REQUEST, "PDU_TX_REQUEST" },
644 { BSN_PDU_TX_REPLY, "PDU_TX_REPLY" },
645 { BSN_PDU_RX_REQUEST, "PDU_RX_REQUEST" },
646 { BSN_PDU_RX_REPLY, "PDU_RX_REPLY" },
647 { BSN_PDU_RX_TIMEOUT, "PDU_RX_TIMEOUT" },
648 { 0, NULL }
649 };
650
651 #define BSN_ACTION_MIRROR 1
652 #define BSN_ACTION_SET_TUNNEL_DST 2
653 /* 3 */
654 #define BSN_ACTION_CHECKSUM 4
655
656 static const struct tok bsn_action_subtype_str[] = {
657 { BSN_ACTION_MIRROR, "MIRROR" },
658 { BSN_ACTION_SET_TUNNEL_DST, "SET_TUNNEL_DST" },
659 { BSN_ACTION_CHECKSUM, "CHECKSUM" },
660 { 0, NULL }
661 };
662
663 static const struct tok bsn_mirror_copy_stage_str[] = {
664 { 0, "INGRESS" },
665 { 1, "EGRESS" },
666 { 0, NULL },
667 };
668
669 static const struct tok bsn_onoff_str[] = {
670 { 0, "OFF" },
671 { 1, "ON" },
672 { 0, NULL },
673 };
674
675 static const char *
676 vlan_str(const uint16_t vid)
677 {
678 static char buf[sizeof("65535 (bogus)")];
679
680 if (vid == OFP_VLAN_NONE)
681 return "NONE";
682 snprintf(buf, sizeof(buf), "%u%s", vid,
683 (vid > 0 && vid < 0x0fff) ? "" : " (bogus)");
684 return buf;
685 }
686
687 static const char *
688 pcp_str(const uint8_t pcp)
689 {
690 static char buf[sizeof("255 (bogus)")];
691 snprintf(buf, sizeof(buf), "%u%s", pcp,
692 pcp <= 7 ? "" : " (bogus)");
693 return buf;
694 }
695
696 static void
697 of10_bsn_message_print(netdissect_options *ndo,
698 const u_char *cp, u_int len)
699 {
700 uint32_t subtype;
701
702 if (len < 4)
703 goto invalid;
704 /* subtype */
705 subtype = GET_BE_U_4(cp);
706 OF_FWD(4);
707 ND_PRINT("\n\t subtype %s", tok2str(bsn_subtype_str, "unknown (0x%08x)", subtype));
708 switch (subtype) {
709 case BSN_GET_IP_MASK_REQUEST:
710 /*
711 * 0 1 2 3
712 * 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
713 * +---------------+---------------+---------------+---------------+
714 * | subtype |
715 * +---------------+---------------+---------------+---------------+
716 * | index | pad |
717 * +---------------+---------------+---------------+---------------+
718 * | pad |
719 * +---------------+---------------+---------------+---------------+
720 *
721 */
722 if (len != 8)
723 goto invalid;
724 /* index */
725 ND_PRINT(", index %u", GET_U_1(cp));
726 OF_FWD(1);
727 /* pad */
728 /* Always the last field, check bounds. */
729 ND_TCHECK_7(cp);
730 break;
731 case BSN_SET_IP_MASK:
732 case BSN_GET_IP_MASK_REPLY:
733 /*
734 * 0 1 2 3
735 * 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
736 * +---------------+---------------+---------------+---------------+
737 * | subtype |
738 * +---------------+---------------+---------------+---------------+
739 * | index | pad |
740 * +---------------+---------------+---------------+---------------+
741 * | mask |
742 * +---------------+---------------+---------------+---------------+
743 *
744 */
745 if (len != 8)
746 goto invalid;
747 /* index */
748 ND_PRINT(", index %u", GET_U_1(cp));
749 OF_FWD(1);
750 /* pad */
751 OF_FWD(3);
752 /* mask */
753 ND_PRINT(", mask %s", GET_IPADDR_STRING(cp));
754 break;
755 case BSN_SET_MIRRORING:
756 case BSN_GET_MIRRORING_REQUEST:
757 case BSN_GET_MIRRORING_REPLY:
758 /*
759 * 0 1 2 3
760 * 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
761 * +---------------+---------------+---------------+---------------+
762 * | subtype |
763 * +---------------+---------------+---------------+---------------+
764 * | report m. p. | pad |
765 * +---------------+---------------+---------------+---------------+
766 *
767 */
768 if (len != 4)
769 goto invalid;
770 /* report_mirror_ports */
771 ND_PRINT(", report_mirror_ports %s",
772 tok2str(bsn_onoff_str, "bogus (%u)", GET_U_1(cp)));
773 OF_FWD(1);
774 /* pad */
775 /* Always the last field, check bounds. */
776 ND_TCHECK_3(cp);
777 break;
778 case BSN_GET_INTERFACES_REQUEST:
779 case BSN_GET_L2_TABLE_REQUEST:
780 case BSN_BW_ENABLE_GET_REQUEST:
781 case BSN_BW_CLEAR_DATA_REQUEST:
782 case BSN_HYBRID_GET_REQUEST:
783 /*
784 * 0 1 2 3
785 * 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
786 * +---------------+---------------+---------------+---------------+
787 * | subtype |
788 * +---------------+---------------+---------------+---------------+
789 *
790 */
791 if (len)
792 goto invalid;
793 break;
794 case BSN_VIRTUAL_PORT_REMOVE_REQUEST:
795 /*
796 * 0 1 2 3
797 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
798 * +---------------+---------------+---------------+---------------+
799 * | subtype |
800 * +---------------+---------------+---------------+---------------+
801 * | vport_no |
802 * +---------------+---------------+---------------+---------------+
803 *
804 */
805 if (len != 4)
806 goto invalid;
807 /* vport_no */
808 ND_PRINT(", vport_no %u", GET_BE_U_4(cp));
809 break;
810 case BSN_SHELL_COMMAND:
811 /*
812 * 0 1 2 3
813 * 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
814 * +---------------+---------------+---------------+---------------+
815 * | subtype |
816 * +---------------+---------------+---------------+---------------+
817 * | service |
818 * +---------------+---------------+---------------+---------------+
819 * | data ...
820 * +---------------+---------------+--------
821 *
822 */
823 if (len < 4)
824 goto invalid;
825 /* service */
826 ND_PRINT(", service %u", GET_BE_U_4(cp));
827 OF_FWD(4);
828 /* data */
829 ND_PRINT(", data '");
830 nd_printjn(ndo, cp, len);
831 ND_PRINT("'");
832 break;
833 case BSN_SHELL_OUTPUT:
834 /*
835 * 0 1 2 3
836 * 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
837 * +---------------+---------------+---------------+---------------+
838 * | subtype |
839 * +---------------+---------------+---------------+---------------+
840 * | data ...
841 * +---------------+---------------+--------
842 *
843 */
844 /* already checked that len >= 4 */
845 /* data */
846 ND_PRINT(", data '");
847 nd_printjn(ndo, cp, len);
848 ND_PRINT("'");
849 break;
850 case BSN_SHELL_STATUS:
851 /*
852 * 0 1 2 3
853 * 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
854 * +---------------+---------------+---------------+---------------+
855 * | subtype |
856 * +---------------+---------------+---------------+---------------+
857 * | status |
858 * +---------------+---------------+---------------+---------------+
859 *
860 */
861 if (len != 4)
862 goto invalid;
863 /* status */
864 ND_PRINT(", status 0x%08x", GET_BE_U_4(cp));
865 break;
866 default:
867 ND_TCHECK_LEN(cp, len);
868 }
869 return;
870
871 invalid: /* skip the undersized data */
872 nd_print_invalid(ndo);
873 ND_TCHECK_LEN(cp, len);
874 }
875
876 static void
877 of10_bsn_actions_print(netdissect_options *ndo,
878 const u_char *cp, u_int len)
879 {
880 uint32_t subtype, vlan_tag;
881
882 if (len < 4)
883 goto invalid;
884 /* subtype */
885 subtype = GET_BE_U_4(cp);
886 OF_FWD(4);
887 ND_PRINT("\n\t subtype %s", tok2str(bsn_action_subtype_str, "unknown (0x%08x)", subtype));
888 switch (subtype) {
889 case BSN_ACTION_MIRROR:
890 /*
891 * 0 1 2 3
892 * 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
893 * +---------------+---------------+---------------+---------------+
894 * | subtype |
895 * +---------------+---------------+---------------+---------------+
896 * | dest_port |
897 * +---------------+---------------+---------------+---------------+
898 * | vlan_tag |
899 * +---------------+---------------+---------------+---------------+
900 * | copy_stage | pad |
901 * +---------------+---------------+---------------+---------------+
902 *
903 */
904 if (len != 12)
905 goto invalid;
906 /* dest_port */
907 ND_PRINT(", dest_port %u", GET_BE_U_4(cp));
908 OF_FWD(4);
909 /* vlan_tag */
910 vlan_tag = GET_BE_U_4(cp);
911 OF_FWD(4);
912 switch (vlan_tag >> 16) {
913 case 0:
914 ND_PRINT(", vlan_tag none");
915 break;
916 case ETHERTYPE_8021Q:
917 ND_PRINT(", vlan_tag 802.1Q (%s)", ieee8021q_tci_string(vlan_tag & 0xffff));
918 break;
919 default:
920 ND_PRINT(", vlan_tag unknown (0x%04x)", vlan_tag >> 16);
921 }
922 /* copy_stage */
923 ND_PRINT(", copy_stage %s",
924 tok2str(bsn_mirror_copy_stage_str, "unknown (%u)", GET_U_1(cp)));
925 OF_FWD(1);
926 /* pad */
927 /* Always the last field, check bounds. */
928 ND_TCHECK_3(cp);
929 break;
930 default:
931 ND_TCHECK_LEN(cp, len);
932 }
933 return;
934
935 invalid:
936 nd_print_invalid(ndo);
937 ND_TCHECK_LEN(cp, len);
938 }
939
940 static void
941 of10_vendor_action_print(netdissect_options *ndo,
942 const u_char *cp, u_int len)
943 {
944 uint32_t vendor;
945 void (*decoder)(netdissect_options *, const u_char *, u_int);
946
947 if (len < 4)
948 goto invalid;
949 /* vendor */
950 vendor = GET_BE_U_4(cp);
951 OF_FWD(4);
952 ND_PRINT(", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor));
953 /* data */
954 decoder =
955 vendor == OUI_BSN ? of10_bsn_actions_print :
956 of_data_print;
957 decoder(ndo, cp, len);
958 return;
959
960 invalid: /* skip the undersized data */
961 nd_print_invalid(ndo);
962 ND_TCHECK_LEN(cp, len);
963 }
964
965 /* [OF10] Section 5.5.4 */
966 static void
967 of10_vendor_message_print(netdissect_options *ndo,
968 const u_char *cp, u_int len)
969 {
970 uint32_t vendor;
971 void (*decoder)(netdissect_options *, const u_char *, u_int);
972
973 /* vendor */
974 vendor = GET_BE_U_4(cp);
975 OF_FWD(4);
976 ND_PRINT(", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor));
977 /* data */
978 decoder =
979 vendor == OUI_BSN ? of10_bsn_message_print :
980 of_data_print;
981 decoder(ndo, cp, len);
982 }
983
984 /* Vendor ID is mandatory, data is optional. */
985 static void
986 of10_vendor_data_print(netdissect_options *ndo,
987 const u_char *cp, u_int len)
988 {
989 uint32_t vendor;
990
991 if (len < 4)
992 goto invalid;
993 /* vendor */
994 vendor = GET_BE_U_4(cp);
995 OF_FWD(4);
996 ND_PRINT(", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor));
997 /* data */
998 of_data_print(ndo, cp, len);
999 return;
1000
1001 invalid: /* skip the undersized data */
1002 nd_print_invalid(ndo);
1003 ND_TCHECK_LEN(cp, len);
1004 }
1005
1006 static void
1007 of10_packet_data_print(netdissect_options *ndo,
1008 const u_char *cp, const u_int len)
1009 {
1010 if (len == 0)
1011 return;
1012 /* data */
1013 ND_PRINT("\n\t data (%u octets)", len);
1014 if (ndo->ndo_vflag < 3) {
1015 ND_TCHECK_LEN(cp, len);
1016 return;
1017 }
1018 ndo->ndo_vflag -= 3;
1019 ND_PRINT(", frame decoding below\n");
1020 /*
1021 * The encapsulated Ethernet frame is not necessarily the last
1022 * data of this packet (i.e. there may be more OpenFlow messages
1023 * after the current OFPT_PACKET_IN/OFPT_PACKET_OUT message, in
1024 * which case the current (outer) packet's snapshot end is not
1025 * what ether_print() needs to decode an Ethernet frame nested in
1026 * the middle of a TCP payload.
1027 */
1028 const u_char *snapend_save = ndo->ndo_snapend;
1029 ndo->ndo_snapend = ND_MIN(cp + len, ndo->ndo_snapend);
1030 ether_print(ndo, cp, len, ND_BYTES_AVAILABLE_AFTER(cp), NULL, NULL);
1031 ndo->ndo_snapend = snapend_save;
1032 ndo->ndo_vflag += 3;
1033 }
1034
1035 /* [OF10] Section 5.2.1 */
1036 static void
1037 of10_phy_port_print(netdissect_options *ndo,
1038 const u_char *cp)
1039 {
1040 uint32_t state;
1041
1042 /* port_no */
1043 ND_PRINT("\n\t port_no %s",
1044 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1045 cp += 2;
1046 /* hw_addr */
1047 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp));
1048 cp += MAC_ADDR_LEN;
1049 /* name */
1050 ND_PRINT(", name '");
1051 nd_printjnp(ndo, cp, OFP_MAX_PORT_NAME_LEN);
1052 ND_PRINT("'");
1053 cp += OFP_MAX_PORT_NAME_LEN;
1054
1055 if (ndo->ndo_vflag < 2) {
1056 ND_TCHECK_LEN(cp, 24);
1057 return;
1058 }
1059 /* config */
1060 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp));
1061 of_bitmap_print(ndo, ofppc_bm, GET_BE_U_4(cp), OFPPC_U);
1062 cp += 4;
1063 /* state */
1064 state = GET_BE_U_4(cp);
1065 /*
1066 * Decode the code point and the single bit separately, but
1067 * format the result as a single sequence of comma-separated
1068 * strings (see the comments at the OFPPS_ props).
1069 */
1070 ND_PRINT("\n\t state 0x%08x (%s%s)%s", state,
1071 tok2str(ofpps_stp_str, "", state & OFPPS_STP_MASK),
1072 state & OFPPS_LINK_DOWN ? ", LINK_DOWN" : "",
1073 state & OFPPS_U ? " (bogus)" : "");
1074 cp += 4;
1075 /* curr */
1076 ND_PRINT("\n\t curr 0x%08x", GET_BE_U_4(cp));
1077 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
1078 cp += 4;
1079 /* advertised */
1080 ND_PRINT("\n\t advertised 0x%08x", GET_BE_U_4(cp));
1081 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
1082 cp += 4;
1083 /* supported */
1084 ND_PRINT("\n\t supported 0x%08x", GET_BE_U_4(cp));
1085 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
1086 cp += 4;
1087 /* peer */
1088 ND_PRINT("\n\t peer 0x%08x", GET_BE_U_4(cp));
1089 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
1090 }
1091
1092 /* [OF10] Section 5.2.2 */
1093 static void
1094 of10_queue_props_print(netdissect_options *ndo,
1095 const u_char *cp, u_int len)
1096 {
1097 while (len) {
1098 uint16_t property, plen;
1099 u_char plen_bogus = 0, skip = 0;
1100
1101 if (len < OF_QUEUE_PROP_MINLEN)
1102 goto invalid;
1103 /* property */
1104 property = GET_BE_U_2(cp);
1105 OF_FWD(2);
1106 ND_PRINT("\n\t property %s", tok2str(ofpqt_str, "invalid (0x%04x)", property));
1107 /* len */
1108 plen = GET_BE_U_2(cp);
1109 OF_FWD(2);
1110 ND_PRINT(", len %u", plen);
1111 if (plen < OF_QUEUE_PROP_MINLEN || plen > len + 4)
1112 goto invalid;
1113 /* pad */
1114 /* Sometimes the last field, check bounds. */
1115 OF_CHK_FWD(4);
1116 /* property-specific constraints and decoding */
1117 switch (property) {
1118 case OFPQT_NONE:
1119 plen_bogus = plen != OF_QUEUE_PROP_MINLEN;
1120 break;
1121 case OFPQT_MIN_RATE:
1122 plen_bogus = plen != OF_QUEUE_PROP_MIN_RATE_FIXLEN;
1123 break;
1124 default:
1125 skip = 1;
1126 }
1127 if (plen_bogus) {
1128 ND_PRINT(" (bogus)");
1129 skip = 1;
1130 }
1131 if (skip) {
1132 /*
1133 * plen >= OF_QUEUE_PROP_MINLEN
1134 * cp is OF_QUEUE_PROP_MINLEN bytes in
1135 */
1136 OF_CHK_FWD(plen - OF_QUEUE_PROP_MINLEN);
1137 continue;
1138 }
1139 if (property == OFPQT_MIN_RATE) { /* the only case of property decoding */
1140 /* rate */
1141 uint16_t rate = GET_BE_U_2(cp);
1142 OF_FWD(2);
1143 if (rate > 1000)
1144 ND_PRINT(", rate disabled");
1145 else
1146 ND_PRINT(", rate %u.%u%%", rate / 10, rate % 10);
1147 /* pad */
1148 /* Sometimes the last field, check bounds. */
1149 OF_CHK_FWD(6);
1150 }
1151 } /* while */
1152 return;
1153
1154 invalid: /* skip the rest of queue properties */
1155 nd_print_invalid(ndo);
1156 ND_TCHECK_LEN(cp, len);
1157 }
1158
1159 /* ibid */
1160 static void
1161 of10_queues_print(netdissect_options *ndo,
1162 const u_char *cp, u_int len)
1163 {
1164 while (len) {
1165 uint16_t desclen;
1166
1167 if (len < OF_PACKET_QUEUE_MINLEN)
1168 goto invalid;
1169 /* queue_id */
1170 ND_PRINT("\n\t queue_id %u", GET_BE_U_4(cp));
1171 OF_FWD(4);
1172 /* len */
1173 desclen = GET_BE_U_2(cp);
1174 OF_FWD(2);
1175 ND_PRINT(", len %u", desclen);
1176 if (desclen < OF_PACKET_QUEUE_MINLEN || desclen > len + 6)
1177 goto invalid;
1178 /* pad */
1179 /* Sometimes the last field, check bounds. */
1180 OF_CHK_FWD(2);
1181 /* properties */
1182 if (ndo->ndo_vflag >= 2)
1183 of10_queue_props_print(ndo, cp, desclen - OF_PACKET_QUEUE_MINLEN);
1184 else
1185 ND_TCHECK_LEN(cp, desclen - OF_PACKET_QUEUE_MINLEN);
1186 OF_FWD(desclen - OF_PACKET_QUEUE_MINLEN);
1187 } /* while */
1188 return;
1189
1190 invalid: /* skip the rest of queues */
1191 nd_print_invalid(ndo);
1192 ND_TCHECK_LEN(cp, len);
1193 }
1194
1195 /* [OF10] Section 5.2.3 */
1196 static void
1197 of10_match_print(netdissect_options *ndo,
1198 const char *pfx, const u_char *cp)
1199 {
1200 uint32_t wildcards;
1201 uint16_t dl_type;
1202 uint8_t nw_proto;
1203 u_int nw_bits;
1204 const char *field_name;
1205
1206 /* wildcards */
1207 wildcards = GET_BE_U_4(cp);
1208 if (wildcards & OFPFW_U)
1209 ND_PRINT("%swildcards 0x%08x (bogus)", pfx, wildcards);
1210 cp += 4;
1211 /* in_port */
1212 if (! (wildcards & OFPFW_IN_PORT))
1213 ND_PRINT("%smatch in_port %s", pfx,
1214 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1215 cp += 2;
1216 /* dl_src */
1217 if (! (wildcards & OFPFW_DL_SRC))
1218 ND_PRINT("%smatch dl_src %s", pfx, GET_ETHERADDR_STRING(cp));
1219 cp += MAC_ADDR_LEN;
1220 /* dl_dst */
1221 if (! (wildcards & OFPFW_DL_DST))
1222 ND_PRINT("%smatch dl_dst %s", pfx, GET_ETHERADDR_STRING(cp));
1223 cp += MAC_ADDR_LEN;
1224 /* dl_vlan */
1225 if (! (wildcards & OFPFW_DL_VLAN))
1226 ND_PRINT("%smatch dl_vlan %s", pfx, vlan_str(GET_BE_U_2(cp)));
1227 cp += 2;
1228 /* dl_vlan_pcp */
1229 if (! (wildcards & OFPFW_DL_VLAN_PCP))
1230 ND_PRINT("%smatch dl_vlan_pcp %s", pfx, pcp_str(GET_U_1(cp)));
1231 cp += 1;
1232 /* pad1 */
1233 cp += 1;
1234 /* dl_type */
1235 dl_type = GET_BE_U_2(cp);
1236 cp += 2;
1237 if (! (wildcards & OFPFW_DL_TYPE))
1238 ND_PRINT("%smatch dl_type 0x%04x", pfx, dl_type);
1239 /* nw_tos */
1240 if (! (wildcards & OFPFW_NW_TOS))
1241 ND_PRINT("%smatch nw_tos 0x%02x", pfx, GET_U_1(cp));
1242 cp += 1;
1243 /* nw_proto */
1244 nw_proto = GET_U_1(cp);
1245 cp += 1;
1246 if (! (wildcards & OFPFW_NW_PROTO)) {
1247 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_ARP
1248 ? "arp_opcode" : "nw_proto";
1249 ND_PRINT("%smatch %s %u", pfx, field_name, nw_proto);
1250 }
1251 /* pad2 */
1252 cp += 2;
1253 /* nw_src */
1254 nw_bits = (wildcards & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT;
1255 if (nw_bits < 32)
1256 ND_PRINT("%smatch nw_src %s/%u", pfx, GET_IPADDR_STRING(cp), 32 - nw_bits);
1257 cp += 4;
1258 /* nw_dst */
1259 nw_bits = (wildcards & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT;
1260 if (nw_bits < 32)
1261 ND_PRINT("%smatch nw_dst %s/%u", pfx, GET_IPADDR_STRING(cp), 32 - nw_bits);
1262 cp += 4;
1263 /* tp_src */
1264 if (! (wildcards & OFPFW_TP_SRC)) {
1265 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_IP
1266 && ! (wildcards & OFPFW_NW_PROTO) && nw_proto == IPPROTO_ICMP
1267 ? "icmp_type" : "tp_src";
1268 ND_PRINT("%smatch %s %u", pfx, field_name, GET_BE_U_2(cp));
1269 }
1270 cp += 2;
1271 /* tp_dst */
1272 /* The last unconditional check was at nw_proto, so have an "else" here. */
1273 if (! (wildcards & OFPFW_TP_DST)) {
1274 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_IP
1275 && ! (wildcards & OFPFW_NW_PROTO) && nw_proto == IPPROTO_ICMP
1276 ? "icmp_code" : "tp_dst";
1277 ND_PRINT("%smatch %s %u", pfx, field_name, GET_BE_U_2(cp));
1278 }
1279 else
1280 ND_TCHECK_2(cp);
1281 }
1282
1283 /* [OF10] Section 5.2.4 */
1284 static void
1285 of10_actions_print(netdissect_options *ndo,
1286 const char *pfx, const u_char *cp, u_int len)
1287 {
1288 while (len) {
1289 uint16_t type, alen, output_port;
1290 u_char alen_bogus = 0, skip = 0;
1291
1292 ND_PRINT("%saction", pfx);
1293 ND_ICHECKMSG_U("remaining length", len, <, OF_ACTION_MINLEN);
1294 /* type */
1295 type = GET_BE_U_2(cp);
1296 OF_FWD(2);
1297 ND_PRINT(" type %s", tok2str(ofpat_str, "invalid (0x%04x)", type));
1298 /* length */
1299 alen = GET_BE_U_2(cp);
1300 OF_FWD(2);
1301 ND_PRINT(", len %u", alen);
1302 /*
1303 * The 4-byte "pad" in the specification is not a field of the
1304 * action header, but a placeholder to illustrate the 64-bit
1305 * alignment requirement. Action type specific case blocks
1306 * below fetch these 4 bytes.
1307 */
1308
1309 /* On action size underrun/overrun skip the rest of the action list. */
1310 ND_ICHECK_U(alen, <, OF_ACTION_MINLEN);
1311 ND_ICHECK_U(len, <, alen - 4U);
1312 /*
1313 * After validating the basic length constraint it will be safe
1314 * to skip the current action if the action size is not valid
1315 * for the type or the type is invalid.
1316 */
1317 switch (type) {
1318 case OFPAT_OUTPUT:
1319 case OFPAT_SET_VLAN_VID:
1320 case OFPAT_SET_VLAN_PCP:
1321 case OFPAT_STRIP_VLAN:
1322 case OFPAT_SET_NW_SRC:
1323 case OFPAT_SET_NW_DST:
1324 case OFPAT_SET_NW_TOS:
1325 case OFPAT_SET_TP_SRC:
1326 case OFPAT_SET_TP_DST:
1327 alen_bogus = alen != 8;
1328 break;
1329 case OFPAT_SET_DL_SRC:
1330 case OFPAT_SET_DL_DST:
1331 case OFPAT_ENQUEUE:
1332 alen_bogus = alen != 16;
1333 break;
1334 case OFPAT_VENDOR:
1335 alen_bogus = alen % 8 != 0; /* already >= 8 so far */
1336 break;
1337 default:
1338 skip = 1;
1339 }
1340 if (alen_bogus) {
1341 ND_PRINT(" (bogus)");
1342 skip = 1;
1343 }
1344 if (skip) {
1345 /*
1346 * alen >= OF_ACTION_MINLEN
1347 * cp is 4 bytes in
1348 */
1349 OF_CHK_FWD(alen - 4);
1350 continue;
1351 }
1352 /* OK to decode the rest of the action structure */
1353 switch (type) {
1354 case OFPAT_OUTPUT:
1355 /* port */
1356 output_port = GET_BE_U_2(cp);
1357 OF_FWD(2);
1358 ND_PRINT(", port %s", tok2str(ofpp_str, "%u", output_port));
1359 /* max_len */
1360 if (output_port == OFPP_CONTROLLER)
1361 ND_PRINT(", max_len %u", GET_BE_U_2(cp));
1362 else
1363 ND_TCHECK_2(cp);
1364 OF_FWD(2);
1365 break;
1366 case OFPAT_SET_VLAN_VID:
1367 /* vlan_vid */
1368 ND_PRINT(", vlan_vid %s", vlan_str(GET_BE_U_2(cp)));
1369 OF_FWD(2);
1370 /* pad */
1371 /* Sometimes the last field, check bounds. */
1372 OF_CHK_FWD(2);
1373 break;
1374 case OFPAT_SET_VLAN_PCP:
1375 /* vlan_pcp */
1376 ND_PRINT(", vlan_pcp %s", pcp_str(GET_U_1(cp)));
1377 OF_FWD(1);
1378 /* pad */
1379 /* Sometimes the last field, check bounds. */
1380 OF_CHK_FWD(3);
1381 break;
1382 case OFPAT_SET_DL_SRC:
1383 case OFPAT_SET_DL_DST:
1384 /* dl_addr */
1385 ND_PRINT(", dl_addr %s", GET_ETHERADDR_STRING(cp));
1386 OF_FWD(MAC_ADDR_LEN);
1387 /* pad */
1388 /* Sometimes the last field, check bounds. */
1389 OF_CHK_FWD(6);
1390 break;
1391 case OFPAT_SET_NW_SRC:
1392 case OFPAT_SET_NW_DST:
1393 /* nw_addr */
1394 ND_PRINT(", nw_addr %s", GET_IPADDR_STRING(cp));
1395 OF_FWD(4);
1396 break;
1397 case OFPAT_SET_NW_TOS:
1398 /* nw_tos */
1399 ND_PRINT(", nw_tos 0x%02x", GET_U_1(cp));
1400 OF_FWD(1);
1401 /* pad */
1402 /* Sometimes the last field, check bounds. */
1403 OF_CHK_FWD(3);
1404 break;
1405 case OFPAT_SET_TP_SRC:
1406 case OFPAT_SET_TP_DST:
1407 /* nw_tos */
1408 ND_PRINT(", tp_port %u", GET_BE_U_2(cp));
1409 OF_FWD(2);
1410 /* pad */
1411 /* Sometimes the last field, check bounds. */
1412 OF_CHK_FWD(2);
1413 break;
1414 case OFPAT_ENQUEUE:
1415 /* port */
1416 ND_PRINT(", port %s",
1417 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1418 OF_FWD(2);
1419 /* pad */
1420 OF_FWD(6);
1421 /* queue_id */
1422 ND_PRINT(", queue_id %s",
1423 tok2str(ofpq_str, "%u", GET_BE_U_4(cp)));
1424 OF_FWD(4);
1425 break;
1426 case OFPAT_VENDOR:
1427 of10_vendor_action_print(ndo, cp, alen - 4);
1428 OF_FWD(alen - 4);
1429 break;
1430 case OFPAT_STRIP_VLAN:
1431 /* pad */
1432 /* Sometimes the last field, check bounds. */
1433 OF_CHK_FWD(4);
1434 break;
1435 } /* switch */
1436 } /* while */
1437 return;
1438
1439 invalid: /* skip the rest of actions */
1440 nd_print_invalid(ndo);
1441 ND_TCHECK_LEN(cp, len);
1442 }
1443
1444 /* [OF10] Section 5.3.1 */
1445 static void
1446 of10_features_reply_print(netdissect_options *ndo,
1447 const u_char *cp, u_int len)
1448 {
1449 /* datapath_id */
1450 ND_PRINT("\n\t dpid 0x%016" PRIx64, GET_BE_U_8(cp));
1451 OF_FWD(8);
1452 /* n_buffers */
1453 ND_PRINT(", n_buffers %u", GET_BE_U_4(cp));
1454 OF_FWD(4);
1455 /* n_tables */
1456 ND_PRINT(", n_tables %u", GET_U_1(cp));
1457 OF_FWD(1);
1458 /* pad */
1459 OF_FWD(3);
1460 /* capabilities */
1461 ND_PRINT("\n\t capabilities 0x%08x", GET_BE_U_4(cp));
1462 of_bitmap_print(ndo, ofp_capabilities_bm, GET_BE_U_4(cp), OFPCAP_U);
1463 OF_FWD(4);
1464 /* actions */
1465 ND_PRINT("\n\t actions 0x%08x", GET_BE_U_4(cp));
1466 of_bitmap_print(ndo, ofpat_bm, GET_BE_U_4(cp), OFPAT_U);
1467 OF_FWD(4);
1468 /* ports */
1469 while (len) {
1470 if (len < OF_PHY_PORT_FIXLEN)
1471 goto invalid;
1472 of10_phy_port_print(ndo, cp);
1473 OF_FWD(OF_PHY_PORT_FIXLEN);
1474 }
1475 return;
1476
1477 invalid: /* skip the undersized trailing data */
1478 nd_print_invalid(ndo);
1479 ND_TCHECK_LEN(cp, len);
1480 }
1481
1482 /* [OF10] Section 5.3.2 */
1483 static void
1484 of10_switch_config_msg_print(netdissect_options *ndo,
1485 const u_char *cp, u_int len _U_)
1486 {
1487 /* flags */
1488 ND_PRINT("\n\t flags %s",
1489 tok2str(ofp_config_str, "invalid (0x%04x)", GET_BE_U_2(cp)));
1490 cp += 2;
1491 /* miss_send_len */
1492 ND_PRINT(", miss_send_len %u", GET_BE_U_2(cp));
1493 }
1494
1495 /* [OF10] Section 5.3.3 */
1496 static void
1497 of10_flow_mod_print(netdissect_options *ndo,
1498 const u_char *cp, u_int len)
1499 {
1500 uint16_t command;
1501
1502 /* match */
1503 of10_match_print(ndo, "\n\t ", cp);
1504 OF_FWD(OF_MATCH_FIXLEN);
1505 /* cookie */
1506 ND_PRINT("\n\t cookie 0x%016" PRIx64, GET_BE_U_8(cp));
1507 OF_FWD(8);
1508 /* command */
1509 command = GET_BE_U_2(cp);
1510 ND_PRINT(", command %s", tok2str(ofpfc_str, "invalid (0x%04x)", command));
1511 OF_FWD(2);
1512 /* idle_timeout */
1513 if (GET_BE_U_2(cp))
1514 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp));
1515 OF_FWD(2);
1516 /* hard_timeout */
1517 if (GET_BE_U_2(cp))
1518 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp));
1519 OF_FWD(2);
1520 /* priority */
1521 if (GET_BE_U_2(cp))
1522 ND_PRINT(", priority %u", GET_BE_U_2(cp));
1523 OF_FWD(2);
1524 /* buffer_id */
1525 if (command == OFPFC_ADD || command == OFPFC_MODIFY ||
1526 command == OFPFC_MODIFY_STRICT)
1527 ND_PRINT(", buffer_id %s",
1528 tok2str(bufferid_str, "0x%08x", GET_BE_U_4(cp)));
1529 OF_FWD(4);
1530 /* out_port */
1531 if (command == OFPFC_DELETE || command == OFPFC_DELETE_STRICT)
1532 ND_PRINT(", out_port %s",
1533 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1534 OF_FWD(2);
1535 /* flags */
1536 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp));
1537 of_bitmap_print(ndo, ofpff_bm, GET_BE_U_2(cp), OFPFF_U);
1538 OF_FWD(2);
1539 /* actions */
1540 of10_actions_print(ndo, "\n\t ", cp, len);
1541 }
1542
1543 /* ibid */
1544 static void
1545 of10_port_mod_print(netdissect_options *ndo,
1546 const u_char *cp, u_int len _U_)
1547 {
1548 /* port_no */
1549 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1550 cp += 2;
1551 /* hw_addr */
1552 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp));
1553 cp += MAC_ADDR_LEN;
1554 /* config */
1555 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp));
1556 of_bitmap_print(ndo, ofppc_bm, GET_BE_U_4(cp), OFPPC_U);
1557 cp += 4;
1558 /* mask */
1559 ND_PRINT("\n\t mask 0x%08x", GET_BE_U_4(cp));
1560 of_bitmap_print(ndo, ofppc_bm, GET_BE_U_4(cp), OFPPC_U);
1561 cp += 4;
1562 /* advertise */
1563 ND_PRINT("\n\t advertise 0x%08x", GET_BE_U_4(cp));
1564 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
1565 cp += 4;
1566 /* pad */
1567 /* Always the last field, check bounds. */
1568 ND_TCHECK_4(cp);
1569 }
1570
1571 /* [OF10] Section 5.3.4 */
1572 static void
1573 of10_queue_get_config_request_print(netdissect_options *ndo,
1574 const u_char *cp, u_int len _U_)
1575 {
1576 /* port */
1577 ND_PRINT("\n\t port %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1578 cp += 2;
1579 /* pad */
1580 /* Always the last field, check bounds. */
1581 ND_TCHECK_2(cp);
1582 }
1583
1584 /* ibid */
1585 static void
1586 of10_queue_get_config_reply_print(netdissect_options *ndo,
1587 const u_char *cp, u_int len)
1588 {
1589 /* port */
1590 ND_PRINT("\n\t port %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1591 OF_FWD(2);
1592 /* pad */
1593 /* Sometimes the last field, check bounds. */
1594 OF_CHK_FWD(6);
1595 /* queues */
1596 of10_queues_print(ndo, cp, len);
1597 }
1598
1599 /* [OF10] Section 5.3.5 */
1600 static void
1601 of10_stats_request_print(netdissect_options *ndo,
1602 const u_char *cp, u_int len)
1603 {
1604 uint16_t type;
1605
1606 /* type */
1607 type = GET_BE_U_2(cp);
1608 OF_FWD(2);
1609 ND_PRINT("\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type));
1610 /* flags */
1611 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp));
1612 if (GET_BE_U_2(cp))
1613 ND_PRINT(" (bogus)");
1614 OF_FWD(2);
1615 /* type-specific body of one of fixed lengths */
1616 switch(type) {
1617 case OFPST_DESC:
1618 case OFPST_TABLE:
1619 if (len)
1620 goto invalid;
1621 return;
1622 case OFPST_FLOW:
1623 case OFPST_AGGREGATE:
1624 if (len != OF_FLOW_STATS_REQUEST_FIXLEN)
1625 goto invalid;
1626 /* match */
1627 of10_match_print(ndo, "\n\t ", cp);
1628 OF_FWD(OF_MATCH_FIXLEN);
1629 /* table_id */
1630 ND_PRINT("\n\t table_id %s",
1631 tok2str(tableid_str, "%u", GET_U_1(cp)));
1632 OF_FWD(1);
1633 /* pad */
1634 OF_FWD(1);
1635 /* out_port */
1636 ND_PRINT(", out_port %s",
1637 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1638 return;
1639 case OFPST_PORT:
1640 if (len != OF_PORT_STATS_REQUEST_FIXLEN)
1641 goto invalid;
1642 /* port_no */
1643 ND_PRINT("\n\t port_no %s",
1644 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1645 OF_FWD(2);
1646 /* pad */
1647 /* Always the last field, check bounds. */
1648 OF_CHK_FWD(6);
1649 return;
1650 case OFPST_QUEUE:
1651 if (len != OF_QUEUE_STATS_REQUEST_FIXLEN)
1652 goto invalid;
1653 /* port_no */
1654 ND_PRINT("\n\t port_no %s",
1655 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1656 OF_FWD(2);
1657 /* pad */
1658 OF_FWD(2);
1659 /* queue_id */
1660 ND_PRINT(", queue_id %s",
1661 tok2str(ofpq_str, "%u", GET_BE_U_4(cp)));
1662 return;
1663 case OFPST_VENDOR:
1664 of10_vendor_data_print(ndo, cp, len);
1665 return;
1666 }
1667 return;
1668
1669 invalid: /* skip the message body */
1670 nd_print_invalid(ndo);
1671 ND_TCHECK_LEN(cp, len);
1672 }
1673
1674 /* ibid */
1675 static void
1676 of10_desc_stats_reply_print(netdissect_options *ndo,
1677 const u_char *cp, u_int len)
1678 {
1679 if (len != OF_DESC_STATS_REPLY_FIXLEN)
1680 goto invalid;
1681 /* mfr_desc */
1682 ND_PRINT("\n\t mfr_desc '");
1683 nd_printjnp(ndo, cp, DESC_STR_LEN);
1684 ND_PRINT("'");
1685 OF_FWD(DESC_STR_LEN);
1686 /* hw_desc */
1687 ND_PRINT("\n\t hw_desc '");
1688 nd_printjnp(ndo, cp, DESC_STR_LEN);
1689 ND_PRINT("'");
1690 OF_FWD(DESC_STR_LEN);
1691 /* sw_desc */
1692 ND_PRINT("\n\t sw_desc '");
1693 nd_printjnp(ndo, cp, DESC_STR_LEN);
1694 ND_PRINT("'");
1695 OF_FWD(DESC_STR_LEN);
1696 /* serial_num */
1697 ND_PRINT("\n\t serial_num '");
1698 nd_printjnp(ndo, cp, SERIAL_NUM_LEN);
1699 ND_PRINT("'");
1700 OF_FWD(SERIAL_NUM_LEN);
1701 /* dp_desc */
1702 ND_PRINT("\n\t dp_desc '");
1703 nd_printjnp(ndo, cp, DESC_STR_LEN);
1704 ND_PRINT("'");
1705 return;
1706
1707 invalid: /* skip the message body */
1708 nd_print_invalid(ndo);
1709 ND_TCHECK_LEN(cp, len);
1710 }
1711
1712 /* ibid */
1713 static void
1714 of10_flow_stats_reply_print(netdissect_options *ndo,
1715 const u_char *cp, u_int len)
1716 {
1717 while (len) {
1718 uint16_t entry_len;
1719
1720 ND_PRINT("\n\t");
1721 ND_ICHECKMSG_U("remaining length", len, <, OF_FLOW_STATS_REPLY_MINLEN);
1722 /* length */
1723 entry_len = GET_BE_U_2(cp);
1724 ND_PRINT(" length %u", entry_len);
1725 ND_ICHECK_U(entry_len, <, OF_FLOW_STATS_REPLY_MINLEN);
1726 ND_ICHECK_U(len, <, entry_len);
1727 OF_FWD(2);
1728 /* table_id */
1729 ND_PRINT(", table_id %s",
1730 tok2str(tableid_str, "%u", GET_U_1(cp)));
1731 OF_FWD(1);
1732 /* pad */
1733 OF_FWD(1);
1734 /* match */
1735 of10_match_print(ndo, "\n\t ", cp);
1736 OF_FWD(OF_MATCH_FIXLEN);
1737 /* duration_sec */
1738 ND_PRINT("\n\t duration_sec %u", GET_BE_U_4(cp));
1739 OF_FWD(4);
1740 /* duration_nsec */
1741 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp));
1742 OF_FWD(4);
1743 /* priority */
1744 ND_PRINT(", priority %u", GET_BE_U_2(cp));
1745 OF_FWD(2);
1746 /* idle_timeout */
1747 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp));
1748 OF_FWD(2);
1749 /* hard_timeout */
1750 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp));
1751 OF_FWD(2);
1752 /* pad2 */
1753 OF_FWD(6);
1754 /* cookie */
1755 ND_PRINT(", cookie 0x%016" PRIx64, GET_BE_U_8(cp));
1756 OF_FWD(8);
1757 /* packet_count */
1758 ND_PRINT(", packet_count %" PRIu64, GET_BE_U_8(cp));
1759 OF_FWD(8);
1760 /* byte_count */
1761 ND_PRINT(", byte_count %" PRIu64, GET_BE_U_8(cp));
1762 OF_FWD(8);
1763 /* actions */
1764 of10_actions_print(ndo, "\n\t ", cp, entry_len - OF_FLOW_STATS_REPLY_MINLEN);
1765 OF_FWD(entry_len - OF_FLOW_STATS_REPLY_MINLEN);
1766 } /* while */
1767 return;
1768
1769 invalid: /* skip the rest of flow statistics entries */
1770 nd_print_invalid(ndo);
1771 ND_TCHECK_LEN(cp, len);
1772 }
1773
1774 /* ibid */
1775 static void
1776 of10_aggregate_stats_reply_print(netdissect_options *ndo,
1777 const u_char *cp, u_int len)
1778 {
1779 if (len != OF_AGGREGATE_STATS_REPLY_FIXLEN)
1780 goto invalid;
1781 /* packet_count */
1782 ND_PRINT("\n\t packet_count %" PRIu64, GET_BE_U_8(cp));
1783 OF_FWD(8);
1784 /* byte_count */
1785 ND_PRINT(", byte_count %" PRIu64, GET_BE_U_8(cp));
1786 OF_FWD(8);
1787 /* flow_count */
1788 ND_PRINT(", flow_count %u", GET_BE_U_4(cp));
1789 OF_FWD(4);
1790 /* pad */
1791 /* Always the last field, check bounds. */
1792 ND_TCHECK_4(cp);
1793 return;
1794
1795 invalid: /* skip the message body */
1796 nd_print_invalid(ndo);
1797 ND_TCHECK_LEN(cp, len);
1798 }
1799
1800 /* ibid */
1801 static void
1802 of10_table_stats_reply_print(netdissect_options *ndo,
1803 const u_char *cp, u_int len)
1804 {
1805 while (len) {
1806 if (len < OF_TABLE_STATS_REPLY_FIXLEN)
1807 goto invalid;
1808 /* table_id */
1809 ND_PRINT("\n\t table_id %s",
1810 tok2str(tableid_str, "%u", GET_U_1(cp)));
1811 OF_FWD(1);
1812 /* pad */
1813 OF_FWD(3);
1814 /* name */
1815 ND_PRINT(", name '");
1816 nd_printjnp(ndo, cp, OFP_MAX_TABLE_NAME_LEN);
1817 ND_PRINT("'");
1818 OF_FWD(OFP_MAX_TABLE_NAME_LEN);
1819 /* wildcards */
1820 ND_PRINT("\n\t wildcards 0x%08x", GET_BE_U_4(cp));
1821 of_bitmap_print(ndo, ofpfw_bm, GET_BE_U_4(cp), OFPFW_U);
1822 OF_FWD(4);
1823 /* max_entries */
1824 ND_PRINT("\n\t max_entries %u", GET_BE_U_4(cp));
1825 OF_FWD(4);
1826 /* active_count */
1827 ND_PRINT(", active_count %u", GET_BE_U_4(cp));
1828 OF_FWD(4);
1829 /* lookup_count */
1830 ND_PRINT(", lookup_count %" PRIu64, GET_BE_U_8(cp));
1831 OF_FWD(8);
1832 /* matched_count */
1833 ND_PRINT(", matched_count %" PRIu64, GET_BE_U_8(cp));
1834 OF_FWD(8);
1835 } /* while */
1836 return;
1837
1838 invalid: /* skip the undersized trailing data */
1839 nd_print_invalid(ndo);
1840 ND_TCHECK_LEN(cp, len);
1841 }
1842
1843 /* ibid */
1844 static void
1845 of10_port_stats_reply_print(netdissect_options *ndo,
1846 const u_char *cp, u_int len)
1847 {
1848 while (len) {
1849 if (len < OF_PORT_STATS_REPLY_FIXLEN)
1850 goto invalid;
1851 /* port_no */
1852 ND_PRINT("\n\t port_no %s",
1853 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1854 OF_FWD(2);
1855 if (ndo->ndo_vflag < 2) {
1856 OF_CHK_FWD(OF_PORT_STATS_REPLY_FIXLEN - 2);
1857 continue;
1858 }
1859 /* pad */
1860 OF_FWD(6);
1861 /* rx_packets */
1862 ND_PRINT(", rx_packets %" PRIu64, GET_BE_U_8(cp));
1863 OF_FWD(8);
1864 /* tx_packets */
1865 ND_PRINT(", tx_packets %" PRIu64, GET_BE_U_8(cp));
1866 OF_FWD(8);
1867 /* rx_bytes */
1868 ND_PRINT(", rx_bytes %" PRIu64, GET_BE_U_8(cp));
1869 OF_FWD(8);
1870 /* tx_bytes */
1871 ND_PRINT(", tx_bytes %" PRIu64, GET_BE_U_8(cp));
1872 OF_FWD(8);
1873 /* rx_dropped */
1874 ND_PRINT(", rx_dropped %" PRIu64, GET_BE_U_8(cp));
1875 OF_FWD(8);
1876 /* tx_dropped */
1877 ND_PRINT(", tx_dropped %" PRIu64, GET_BE_U_8(cp));
1878 OF_FWD(8);
1879 /* rx_errors */
1880 ND_PRINT(", rx_errors %" PRIu64, GET_BE_U_8(cp));
1881 OF_FWD(8);
1882 /* tx_errors */
1883 ND_PRINT(", tx_errors %" PRIu64, GET_BE_U_8(cp));
1884 OF_FWD(8);
1885 /* rx_frame_err */
1886 ND_PRINT(", rx_frame_err %" PRIu64, GET_BE_U_8(cp));
1887 OF_FWD(8);
1888 /* rx_over_err */
1889 ND_PRINT(", rx_over_err %" PRIu64, GET_BE_U_8(cp));
1890 OF_FWD(8);
1891 /* rx_crc_err */
1892 ND_PRINT(", rx_crc_err %" PRIu64, GET_BE_U_8(cp));
1893 OF_FWD(8);
1894 /* collisions */
1895 ND_PRINT(", collisions %" PRIu64, GET_BE_U_8(cp));
1896 OF_FWD(8);
1897 } /* while */
1898 return;
1899
1900 invalid: /* skip the undersized trailing data */
1901 nd_print_invalid(ndo);
1902 ND_TCHECK_LEN(cp, len);
1903 }
1904
1905 /* ibid */
1906 static void
1907 of10_queue_stats_reply_print(netdissect_options *ndo,
1908 const u_char *cp, u_int len)
1909 {
1910 while (len) {
1911 if (len < OF_QUEUE_STATS_REPLY_FIXLEN)
1912 goto invalid;
1913 /* port_no */
1914 ND_PRINT("\n\t port_no %s",
1915 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1916 OF_FWD(2);
1917 /* pad */
1918 OF_FWD(2);
1919 /* queue_id */
1920 ND_PRINT(", queue_id %u", GET_BE_U_4(cp));
1921 OF_FWD(4);
1922 /* tx_bytes */
1923 ND_PRINT(", tx_bytes %" PRIu64, GET_BE_U_8(cp));
1924 OF_FWD(8);
1925 /* tx_packets */
1926 ND_PRINT(", tx_packets %" PRIu64, GET_BE_U_8(cp));
1927 OF_FWD(8);
1928 /* tx_errors */
1929 ND_PRINT(", tx_errors %" PRIu64, GET_BE_U_8(cp));
1930 OF_FWD(8);
1931 } /* while */
1932 return;
1933
1934 invalid: /* skip the undersized trailing data */
1935 nd_print_invalid(ndo);
1936 ND_TCHECK_LEN(cp, len);
1937 }
1938
1939 /* ibid */
1940 static void
1941 of10_stats_reply_print(netdissect_options *ndo,
1942 const u_char *cp, u_int len)
1943 {
1944 uint16_t type;
1945
1946 /* type */
1947 type = GET_BE_U_2(cp);
1948 ND_PRINT("\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type));
1949 OF_FWD(2);
1950 /* flags */
1951 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp));
1952 of_bitmap_print(ndo, ofpsf_reply_bm, GET_BE_U_2(cp), OFPSF_REPLY_U);
1953 OF_FWD(2);
1954
1955 if (ndo->ndo_vflag > 0) {
1956 void (*decoder)(netdissect_options *, const u_char *, u_int) =
1957 type == OFPST_DESC ? of10_desc_stats_reply_print :
1958 type == OFPST_FLOW ? of10_flow_stats_reply_print :
1959 type == OFPST_AGGREGATE ? of10_aggregate_stats_reply_print :
1960 type == OFPST_TABLE ? of10_table_stats_reply_print :
1961 type == OFPST_PORT ? of10_port_stats_reply_print :
1962 type == OFPST_QUEUE ? of10_queue_stats_reply_print :
1963 type == OFPST_VENDOR ? of10_vendor_data_print :
1964 NULL;
1965 if (decoder != NULL) {
1966 decoder(ndo, cp, len);
1967 return;
1968 }
1969 }
1970 ND_TCHECK_LEN(cp, len);
1971 }
1972
1973 /* [OF10] Section 5.3.6 */
1974 static void
1975 of10_packet_out_print(netdissect_options *ndo,
1976 const u_char *cp, u_int len)
1977 {
1978 uint16_t actions_len;
1979
1980 /* buffer_id */
1981 ND_PRINT("\n\t buffer_id 0x%08x", GET_BE_U_4(cp));
1982 OF_FWD(4);
1983 /* in_port */
1984 ND_PRINT(", in_port %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1985 OF_FWD(2);
1986 /* actions_len */
1987 actions_len = GET_BE_U_2(cp);
1988 ND_PRINT(", actions_len %u", actions_len);
1989 OF_FWD(2);
1990 ND_ICHECK_U(len, <, actions_len);
1991 /* actions */
1992 of10_actions_print(ndo, "\n\t ", cp, actions_len);
1993 OF_FWD(actions_len);
1994 /* data */
1995 of10_packet_data_print(ndo, cp, len);
1996 return;
1997
1998 invalid: /* skip the rest of the message body */
1999 nd_print_invalid(ndo);
2000 ND_TCHECK_LEN(cp, len);
2001 }
2002
2003 /* [OF10] Section 5.4.1 */
2004 static void
2005 of10_packet_in_print(netdissect_options *ndo,
2006 const u_char *cp, u_int len)
2007 {
2008 /* buffer_id */
2009 ND_PRINT("\n\t buffer_id %s",
2010 tok2str(bufferid_str, "0x%08x", GET_BE_U_4(cp)));
2011 OF_FWD(4);
2012 /* total_len */
2013 ND_PRINT(", total_len %u", GET_BE_U_2(cp));
2014 OF_FWD(2);
2015 /* in_port */
2016 ND_PRINT(", in_port %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
2017 OF_FWD(2);
2018 /* reason */
2019 ND_PRINT(", reason %s",
2020 tok2str(ofpr_str, "invalid (0x%02x)", GET_U_1(cp)));
2021 OF_FWD(1);
2022 /* pad */
2023 /* Sometimes the last field, check bounds. */
2024 OF_CHK_FWD(1);
2025 /* data */
2026 of10_packet_data_print(ndo, cp, len);
2027 }
2028
2029 /* [OF10] Section 5.4.2 */
2030 static void
2031 of10_flow_removed_print(netdissect_options *ndo,
2032 const u_char *cp, u_int len _U_)
2033 {
2034 /* match */
2035 of10_match_print(ndo, "\n\t ", cp);
2036 cp += OF_MATCH_FIXLEN;
2037 /* cookie */
2038 ND_PRINT("\n\t cookie 0x%016" PRIx64, GET_BE_U_8(cp));
2039 cp += 8;
2040 /* priority */
2041 if (GET_BE_U_2(cp))
2042 ND_PRINT(", priority %u", GET_BE_U_2(cp));
2043 cp += 2;
2044 /* reason */
2045 ND_PRINT(", reason %s",
2046 tok2str(ofprr_str, "unknown (0x%02x)", GET_U_1(cp)));
2047 cp += 1;
2048 /* pad */
2049 cp += 1;
2050 /* duration_sec */
2051 ND_PRINT(", duration_sec %u", GET_BE_U_4(cp));
2052 cp += 4;
2053 /* duration_nsec */
2054 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp));
2055 cp += 4;
2056 /* idle_timeout */
2057 if (GET_BE_U_2(cp))
2058 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp));
2059 cp += 2;
2060 /* pad2 */
2061 cp += 2;
2062 /* packet_count */
2063 ND_PRINT(", packet_count %" PRIu64, GET_BE_U_8(cp));
2064 cp += 8;
2065 /* byte_count */
2066 ND_PRINT(", byte_count %" PRIu64, GET_BE_U_8(cp));
2067 }
2068
2069 /* [OF10] Section 5.4.3 */
2070 static void
2071 of10_port_status_print(netdissect_options *ndo,
2072 const u_char *cp, u_int len _U_)
2073 {
2074 /* reason */
2075 ND_PRINT("\n\t reason %s",
2076 tok2str(ofppr_str, "invalid (0x%02x)", GET_U_1(cp)));
2077 cp += 1;
2078 /* pad */
2079 /* No need to check bounds, more data follows. */
2080 cp += 7;
2081 /* desc */
2082 of10_phy_port_print(ndo, cp);
2083 }
2084
2085 /* [OF10] Section 5.4.4 */
2086 static void
2087 of10_error_print(netdissect_options *ndo,
2088 const u_char *cp, u_int len)
2089 {
2090 uint16_t type, code;
2091 const struct tok *code_str;
2092
2093 /* type */
2094 type = GET_BE_U_2(cp);
2095 OF_FWD(2);
2096 ND_PRINT("\n\t type %s", tok2str(ofpet_str, "invalid (0x%04x)", type));
2097 /* code */
2098 code = GET_BE_U_2(cp);
2099 OF_FWD(2);
2100 code_str = uint2tokary(of10_ofpet2tokary, type);
2101 if (code_str != NULL)
2102 ND_PRINT(", code %s",
2103 tok2str(code_str, "invalid (0x%04x)", code));
2104 else
2105 ND_PRINT(", code invalid (0x%04x)", code);
2106 /* data */
2107 of_data_print(ndo, cp, len);
2108 }
2109
2110 static const struct of_msgtypeinfo of10_msgtypeinfo[OFPT_MAX + 1] = {
2111 /*
2112 * [OF10] Section 5.5.1
2113 * Variable-size data.
2114 */
2115 {
2116 "HELLO", of_data_print,
2117 REQ_MINLEN, 0
2118 },
2119 /*
2120 * [OF10] Section 5.4.4
2121 * A fixed-size message body and variable-size data.
2122 */
2123 {
2124 "ERROR", of10_error_print,
2125 REQ_MINLEN, OF_ERROR_MSG_MINLEN
2126 },
2127 /*
2128 * [OF10] Section 5.5.2
2129 * Variable-size data.
2130 */
2131 {
2132 "ECHO_REQUEST", of_data_print,
2133 REQ_MINLEN, 0
2134 },
2135 /*
2136 * [OF10] Section 5.5.3
2137 * Variable-size data.
2138 */
2139 {
2140 "ECHO_REPLY", of_data_print,
2141 REQ_MINLEN, 0
2142 },
2143 /*
2144 * [OF10] Section 5.5.4
2145 * A fixed-size message body and variable-size data.
2146 */
2147 {
2148 "VENDOR", of10_vendor_message_print,
2149 REQ_MINLEN, OF_VENDOR_MINLEN
2150 },
2151 /*
2152 * [OF10] Section 5.3.1
2153 * No message body.
2154 */
2155 {
2156 "FEATURES_REQUEST", NULL,
2157 REQ_FIXLEN, 0
2158 },
2159 /*
2160 * [OF10] Section 5.3.1
2161 * A fixed-size message body and n * fixed-size data units.
2162 */
2163 {
2164 "FEATURES_REPLY", of10_features_reply_print,
2165 REQ_MINLEN, OF_FEATURES_REPLY_MINLEN
2166 },
2167 /*
2168 * [OF10] Section 5.3.2
2169 * No message body.
2170 */
2171 {
2172 "GET_CONFIG_REQUEST", NULL,
2173 REQ_FIXLEN, 0
2174 },
2175 /*
2176 * [OF10] Section 5.3.2
2177 * A fixed-size message body.
2178 */
2179 {
2180 "GET_CONFIG_REPLY", of10_switch_config_msg_print,
2181 REQ_FIXLEN, OF_SWITCH_CONFIG_FIXLEN
2182 },
2183 /*
2184 * [OF10] Section 5.3.2
2185 * A fixed-size message body.
2186 */
2187 {
2188 "SET_CONFIG", of10_switch_config_msg_print,
2189 REQ_FIXLEN, OF_SWITCH_CONFIG_FIXLEN
2190 },
2191 /*
2192 * [OF10] Section 5.4.1
2193 * A fixed-size message body and variable-size data.
2194 * (The 2 mock octets count in OF_PACKET_IN_MINLEN only.)
2195 */
2196 {
2197 "PACKET_IN", of10_packet_in_print,
2198 REQ_MINLEN, OF_PACKET_IN_MINLEN - 2
2199 },
2200 /*
2201 * [OF10] Section 5.4.2
2202 * A fixed-size message body.
2203 */
2204 {
2205 "FLOW_REMOVED", of10_flow_removed_print,
2206 REQ_FIXLEN, OF_FLOW_REMOVED_FIXLEN
2207 },
2208 /*
2209 * [OF10] Section 5.4.3
2210 * A fixed-size message body.
2211 */
2212 {
2213 "PORT_STATUS", of10_port_status_print,
2214 REQ_FIXLEN, OF_PORT_STATUS_FIXLEN
2215 },
2216 /*
2217 * [OF10] Section 5.3.6
2218 * A fixed-size message body, n * variable-size data units and
2219 * variable-size data.
2220 */
2221 {
2222 "PACKET_OUT", of10_packet_out_print,
2223 REQ_MINLEN, OF_PACKET_OUT_MINLEN
2224 },
2225 /*
2226 * [OF10] Section 5.3.3
2227 * A fixed-size message body and n * variable-size data units.
2228 */
2229 {
2230 "FLOW_MOD", of10_flow_mod_print,
2231 REQ_MINLEN, OF_FLOW_MOD_MINLEN
2232 },
2233 /*
2234 * [OF10] Section 5.3.3
2235 * A fixed-size message body.
2236 */
2237 {
2238 "PORT_MOD", of10_port_mod_print,
2239 REQ_FIXLEN, OF_PORT_MOD_FIXLEN
2240 },
2241 /*
2242 * [OF10] Section 5.3.5
2243 * A fixed-size message body and possibly more data of varying size
2244 * and structure.
2245 */
2246 {
2247 "STATS_REQUEST", of10_stats_request_print,
2248 REQ_MINLEN, OF_STATS_REQUEST_MINLEN
2249 },
2250 /*
2251 * [OF10] Section 5.3.5
2252 * A fixed-size message body and possibly more data of varying size
2253 * and structure.
2254 */
2255 {
2256 "STATS_REPLY", of10_stats_reply_print,
2257 REQ_MINLEN, OF_STATS_REPLY_MINLEN
2258 },
2259 /*
2260 * [OF10] Section 5.3.7
2261 * No message body.
2262 */
2263 {
2264 "BARRIER_REQUEST", NULL,
2265 REQ_FIXLEN, 0
2266 },
2267 /*
2268 * [OF10] Section 5.3.7
2269 * No message body.
2270 */
2271 {
2272 "BARRIER_REPLY", NULL,
2273 REQ_FIXLEN, 0
2274 },
2275 /*
2276 * [OF10] Section 5.3.4
2277 * A fixed-size message body.
2278 */
2279 {
2280 "QUEUE_GET_CONFIG_REQUEST", of10_queue_get_config_request_print,
2281 REQ_FIXLEN, OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN
2282 },
2283 /*
2284 * [OF10] Section 5.3.4
2285 * A fixed-size message body and n * variable-size data units.
2286 */
2287 {
2288 "QUEUE_GET_CONFIG_REPLY", of10_queue_get_config_reply_print,
2289 REQ_MINLEN, OF_QUEUE_GET_CONFIG_REPLY_MINLEN
2290 },
2291 };
2292
2293 const struct of_msgtypeinfo *
2294 of10_identify_msgtype(const uint8_t type)
2295 {
2296 return type <= OFPT_MAX ? &of10_msgtypeinfo[type] : NULL;
2297 }