]> The Tcpdump Group git mirrors - tcpdump/blob - print-openflow-1.0.c
OpenFlow 1.0: Simplify of10_vendor_message_print().
[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 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" },
123 { 0, NULL }
124 };
125
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" },
141 { 0, NULL }
142 };
143 #define OFPPC_U (~(OFPPC_PORT_DOWN | OFPPC_NO_STP | OFPPC_NO_RECV | \
144 OFPPC_NO_RECV_STP | OFPPC_NO_FLOOD | OFPPC_NO_FWD | \
145 OFPPC_NO_PACKET_IN))
146
147 /*
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.
151 */
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" },
163 { 0, NULL }
164 };
165 #define OFPPS_U (~(OFPPS_LINK_DOWN | OFPPS_STP_LISTEN | OFPPS_STP_LEARN | \
166 OFPPS_STP_FORWARD | OFPPS_STP_BLOCK))
167
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[] = {
178 { OFPP_MAX, "MAX" },
179 { OFPP_IN_PORT, "IN_PORT" },
180 { OFPP_TABLE, "TABLE" },
181 { OFPP_NORMAL, "NORMAL" },
182 { OFPP_FLOOD, "FLOOD" },
183 { OFPP_ALL, "ALL" },
184 { OFPP_CONTROLLER, "CONTROLLER" },
185 { OFPP_LOCAL, "LOCAL" },
186 { OFPP_NONE, "NONE" },
187 { 0, NULL }
188 };
189
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" },
215 { 0, NULL }
216 };
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))
221
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" },
227 { 0, NULL }
228 };
229
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" },
258 { 0, NULL }
259 };
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))
265
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" },
293 { 0, NULL }
294 };
295
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" },
310 { 0, NULL }
311 };
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))
318
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" },
331 { OFPC_STP, "STP" },
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" },
336 { 0, NULL }
337 };
338 #define OFPCAP_U (~(OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS | \
339 OFPC_STP | OFPC_IP_REASM | OFPC_QUEUE_STATS | \
340 OFPC_ARP_MATCH_IP))
341
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" },
350 { 0, NULL }
351 };
352
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" },
364 { 0, NULL }
365 };
366
367 static const struct tok bufferid_str[] = {
368 { 0xffffffff, "NONE" },
369 { 0, NULL }
370 };
371
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" },
379 { 0, NULL }
380 };
381 #define OFPFF_U (~(OFPFF_SEND_FLOW_REM | OFPFF_CHECK_OVERLAP | OFPFF_EMERG))
382
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" },
398 { 0, NULL }
399 };
400
401 static const struct tok tableid_str[] = {
402 { 0xfeU, "EMERG" },
403 { 0xffU, "ALL" },
404 { 0, NULL }
405 };
406
407 #define OFPQ_ALL 0xffffffffU
408 static const struct tok ofpq_str[] = {
409 { OFPQ_ALL, "ALL" },
410 { 0, NULL }
411 };
412
413 #define OFPSF_REPLY_MORE 0x0001U
414 static const struct tok ofpsf_reply_bm[] = {
415 { OFPSF_REPLY_MORE, "MORE" },
416 { 0, NULL }
417 };
418 #define OFPSF_REPLY_U (~(OFPSF_REPLY_MORE))
419
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" },
425 { 0, NULL }
426 };
427
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" },
435 { 0, NULL }
436 };
437
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" },
445 { 0, NULL }
446 };
447
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" },
461 { 0, NULL }
462 };
463
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" },
469 { 0, NULL }
470 };
471
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" },
491 { 0, NULL }
492 };
493
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" },
513 { 0, NULL }
514 };
515
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" },
529 { 0, NULL }
530 };
531
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" },
537 { 0, NULL }
538 };
539
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" },
547 { 0, NULL }
548 };
549
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. */
558 };
559
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
590
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
597
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
628 /* 29 */
629 /* 30 */
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
635
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" },
671 { 0, NULL }
672 };
673
674 #define BSN_ACTION_MIRROR 1
675 #define BSN_ACTION_SET_TUNNEL_DST 2
676 /* 3 */
677 #define BSN_ACTION_CHECKSUM 4
678
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" },
683 { 0, NULL }
684 };
685
686 static const struct tok bsn_mirror_copy_stage_str[] = {
687 { 0, "INGRESS" },
688 { 1, "EGRESS" },
689 { 0, NULL },
690 };
691
692 static const struct tok bsn_onoff_str[] = {
693 { 0, "OFF" },
694 { 1, "ON" },
695 { 0, NULL },
696 };
697
698 /* [OF10] Section 5.1 */
699 const char * of10_msgtype_str(const uint8_t type)
700 {
701 return tok2str(ofpt_str, "invalid (0x%02x)", type);
702 }
703
704 static const char *
705 vlan_str(const uint16_t vid)
706 {
707 static char buf[sizeof("65535 (bogus)")];
708
709 if (vid == OFP_VLAN_NONE)
710 return "NONE";
711 snprintf(buf, sizeof(buf), "%u%s", vid,
712 (vid > 0 && vid < 0x0fff) ? "" : " (bogus)");
713 return buf;
714 }
715
716 static const char *
717 pcp_str(const uint8_t pcp)
718 {
719 static char buf[sizeof("255 (bogus)")];
720 snprintf(buf, sizeof(buf), "%u%s", pcp,
721 pcp <= 7 ? "" : " (bogus)");
722 return buf;
723 }
724
725 static void
726 of10_bsn_message_print(netdissect_options *ndo,
727 const u_char *cp, u_int len)
728 {
729 uint32_t subtype;
730
731 if (len < 4)
732 goto invalid;
733 /* subtype */
734 subtype = GET_BE_U_4(cp);
735 OF_FWD(4);
736 ND_PRINT("\n\t subtype %s", tok2str(bsn_subtype_str, "unknown (0x%08x)", subtype));
737 switch (subtype) {
738 case BSN_GET_IP_MASK_REQUEST:
739 /*
740 * 0 1 2 3
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 * +---------------+---------------+---------------+---------------+
743 * | subtype |
744 * +---------------+---------------+---------------+---------------+
745 * | index | pad |
746 * +---------------+---------------+---------------+---------------+
747 * | pad |
748 * +---------------+---------------+---------------+---------------+
749 *
750 */
751 if (len != 8)
752 goto invalid;
753 /* index */
754 ND_PRINT(", index %u", GET_U_1(cp));
755 OF_FWD(1);
756 /* pad */
757 /* Always the last field, check bounds. */
758 ND_TCHECK_7(cp);
759 break;
760 case BSN_SET_IP_MASK:
761 case BSN_GET_IP_MASK_REPLY:
762 /*
763 * 0 1 2 3
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 * +---------------+---------------+---------------+---------------+
766 * | subtype |
767 * +---------------+---------------+---------------+---------------+
768 * | index | pad |
769 * +---------------+---------------+---------------+---------------+
770 * | mask |
771 * +---------------+---------------+---------------+---------------+
772 *
773 */
774 if (len != 8)
775 goto invalid;
776 /* index */
777 ND_PRINT(", index %u", GET_U_1(cp));
778 OF_FWD(1);
779 /* pad */
780 OF_FWD(3);
781 /* mask */
782 ND_PRINT(", mask %s", GET_IPADDR_STRING(cp));
783 break;
784 case BSN_SET_MIRRORING:
785 case BSN_GET_MIRRORING_REQUEST:
786 case BSN_GET_MIRRORING_REPLY:
787 /*
788 * 0 1 2 3
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 * +---------------+---------------+---------------+---------------+
791 * | subtype |
792 * +---------------+---------------+---------------+---------------+
793 * | report m. p. | pad |
794 * +---------------+---------------+---------------+---------------+
795 *
796 */
797 if (len != 4)
798 goto invalid;
799 /* report_mirror_ports */
800 ND_PRINT(", report_mirror_ports %s",
801 tok2str(bsn_onoff_str, "bogus (%u)", GET_U_1(cp)));
802 OF_FWD(1);
803 /* pad */
804 /* Always the last field, check bounds. */
805 ND_TCHECK_3(cp);
806 break;
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:
812 /*
813 * 0 1 2 3
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 * +---------------+---------------+---------------+---------------+
816 * | subtype |
817 * +---------------+---------------+---------------+---------------+
818 *
819 */
820 if (len)
821 goto invalid;
822 break;
823 case BSN_VIRTUAL_PORT_REMOVE_REQUEST:
824 /*
825 * 0 1 2 3
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 * +---------------+---------------+---------------+---------------+
828 * | subtype |
829 * +---------------+---------------+---------------+---------------+
830 * | vport_no |
831 * +---------------+---------------+---------------+---------------+
832 *
833 */
834 if (len != 4)
835 goto invalid;
836 /* vport_no */
837 ND_PRINT(", vport_no %u", GET_BE_U_4(cp));
838 break;
839 case BSN_SHELL_COMMAND:
840 /*
841 * 0 1 2 3
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 * +---------------+---------------+---------------+---------------+
844 * | subtype |
845 * +---------------+---------------+---------------+---------------+
846 * | service |
847 * +---------------+---------------+---------------+---------------+
848 * | data ...
849 * +---------------+---------------+--------
850 *
851 */
852 if (len < 4)
853 goto invalid;
854 /* service */
855 ND_PRINT(", service %u", GET_BE_U_4(cp));
856 OF_FWD(4);
857 /* data */
858 ND_PRINT(", data '");
859 nd_printn(ndo, cp, len, NULL);
860 ND_PRINT("'");
861 break;
862 case BSN_SHELL_OUTPUT:
863 /*
864 * 0 1 2 3
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 * +---------------+---------------+---------------+---------------+
867 * | subtype |
868 * +---------------+---------------+---------------+---------------+
869 * | data ...
870 * +---------------+---------------+--------
871 *
872 */
873 /* already checked that len >= 4 */
874 /* data */
875 ND_PRINT(", data '");
876 nd_printn(ndo, cp, len, NULL);
877 ND_PRINT("'");
878 break;
879 case BSN_SHELL_STATUS:
880 /*
881 * 0 1 2 3
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 * +---------------+---------------+---------------+---------------+
884 * | subtype |
885 * +---------------+---------------+---------------+---------------+
886 * | status |
887 * +---------------+---------------+---------------+---------------+
888 *
889 */
890 if (len != 4)
891 goto invalid;
892 /* status */
893 ND_PRINT(", status 0x%08x", GET_BE_U_4(cp));
894 break;
895 default:
896 ND_TCHECK_LEN(cp, len);
897 }
898 return;
899
900 invalid: /* skip the undersized data */
901 nd_print_invalid(ndo);
902 ND_TCHECK_LEN(cp, len);
903 }
904
905 static void
906 of10_bsn_actions_print(netdissect_options *ndo,
907 const u_char *cp, u_int len)
908 {
909 uint32_t subtype, vlan_tag;
910
911 if (len < 4)
912 goto invalid;
913 /* subtype */
914 subtype = GET_BE_U_4(cp);
915 OF_FWD(4);
916 ND_PRINT("\n\t subtype %s", tok2str(bsn_action_subtype_str, "unknown (0x%08x)", subtype));
917 switch (subtype) {
918 case BSN_ACTION_MIRROR:
919 /*
920 * 0 1 2 3
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 * +---------------+---------------+---------------+---------------+
923 * | subtype |
924 * +---------------+---------------+---------------+---------------+
925 * | dest_port |
926 * +---------------+---------------+---------------+---------------+
927 * | vlan_tag |
928 * +---------------+---------------+---------------+---------------+
929 * | copy_stage | pad |
930 * +---------------+---------------+---------------+---------------+
931 *
932 */
933 if (len != 12)
934 goto invalid;
935 /* dest_port */
936 ND_PRINT(", dest_port %u", GET_BE_U_4(cp));
937 OF_FWD(4);
938 /* vlan_tag */
939 vlan_tag = GET_BE_U_4(cp);
940 OF_FWD(4);
941 switch (vlan_tag >> 16) {
942 case 0:
943 ND_PRINT(", vlan_tag none");
944 break;
945 case ETHERTYPE_8021Q:
946 ND_PRINT(", vlan_tag 802.1Q (%s)", ieee8021q_tci_string(vlan_tag & 0xffff));
947 break;
948 default:
949 ND_PRINT(", vlan_tag unknown (0x%04x)", vlan_tag >> 16);
950 }
951 /* copy_stage */
952 ND_PRINT(", copy_stage %s",
953 tok2str(bsn_mirror_copy_stage_str, "unknown (%u)", GET_U_1(cp)));
954 OF_FWD(1);
955 /* pad */
956 /* Always the last field, check bounds. */
957 ND_TCHECK_3(cp);
958 break;
959 default:
960 ND_TCHECK_LEN(cp, len);
961 }
962 return;
963
964 invalid:
965 nd_print_invalid(ndo);
966 ND_TCHECK_LEN(cp, len);
967 }
968
969 static void
970 of10_vendor_action_print(netdissect_options *ndo,
971 const u_char *cp, u_int len)
972 {
973 uint32_t vendor;
974 void (*decoder)(netdissect_options *, const u_char *, u_int);
975
976 if (len < 4)
977 goto invalid;
978 /* vendor */
979 vendor = GET_BE_U_4(cp);
980 OF_FWD(4);
981 ND_PRINT(", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor));
982 /* data */
983 decoder =
984 vendor == OUI_BSN ? of10_bsn_actions_print :
985 of_data_print;
986 decoder(ndo, cp, len);
987 return;
988
989 invalid: /* skip the undersized data */
990 nd_print_invalid(ndo);
991 ND_TCHECK_LEN(cp, len);
992 }
993
994 /* [OF10] Section 5.5.4 */
995 static void
996 of10_vendor_message_print(netdissect_options *ndo,
997 const u_char *cp, u_int len)
998 {
999 uint32_t vendor;
1000 void (*decoder)(netdissect_options *, const u_char *, u_int);
1001
1002 /* vendor */
1003 vendor = GET_BE_U_4(cp);
1004 OF_FWD(4);
1005 ND_PRINT(", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor));
1006 /* data */
1007 decoder =
1008 vendor == OUI_BSN ? of10_bsn_message_print :
1009 of_data_print;
1010 decoder(ndo, cp, len);
1011 }
1012
1013 /* Vendor ID is mandatory, data is optional. */
1014 static void
1015 of10_vendor_data_print(netdissect_options *ndo,
1016 const u_char *cp, u_int len)
1017 {
1018 uint32_t vendor;
1019
1020 if (len < 4)
1021 goto invalid;
1022 /* vendor */
1023 vendor = GET_BE_U_4(cp);
1024 OF_FWD(4);
1025 ND_PRINT(", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor));
1026 /* data */
1027 of_data_print(ndo, cp, len);
1028 return;
1029
1030 invalid: /* skip the undersized data */
1031 nd_print_invalid(ndo);
1032 ND_TCHECK_LEN(cp, len);
1033 }
1034
1035 static void
1036 of10_packet_data_print(netdissect_options *ndo,
1037 const u_char *cp, const u_int len)
1038 {
1039 if (len == 0)
1040 return;
1041 /* data */
1042 ND_PRINT("\n\t data (%u octets)", len);
1043 if (ndo->ndo_vflag < 3) {
1044 ND_TCHECK_LEN(cp, len);
1045 return;
1046 }
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;
1051 }
1052
1053 /* [OF10] Section 5.2.1 */
1054 static void
1055 of10_phy_ports_print(netdissect_options *ndo,
1056 const u_char *cp, u_int len)
1057 {
1058 while (len) {
1059 uint32_t state;
1060
1061 if (len < OF_PHY_PORT_FIXLEN)
1062 goto invalid;
1063 /* port_no */
1064 ND_PRINT("\n\t port_no %s",
1065 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1066 OF_FWD(2);
1067 /* hw_addr */
1068 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp));
1069 OF_FWD(MAC_ADDR_LEN);
1070 /* name */
1071 ND_PRINT(", name '");
1072 (void)nd_print(ndo, cp, cp + OFP_MAX_PORT_NAME_LEN);
1073 ND_PRINT("'");
1074 OF_FWD(OFP_MAX_PORT_NAME_LEN);
1075
1076 if (ndo->ndo_vflag < 2) {
1077 OF_CHK_FWD(24);
1078 continue;
1079 }
1080 /* config */
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);
1083 OF_FWD(4);
1084 /* state */
1085 state = GET_BE_U_4(cp);
1086 /*
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).
1090 */
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)" : "");
1095 OF_FWD(4);
1096 /* curr */
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);
1099 OF_FWD(4);
1100 /* advertised */
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);
1103 OF_FWD(4);
1104 /* supported */
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);
1107 OF_FWD(4);
1108 /* peer */
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);
1111 OF_FWD(4);
1112 } /* while */
1113 return;
1114
1115 invalid: /* skip the undersized trailing data */
1116 nd_print_invalid(ndo);
1117 ND_TCHECK_LEN(cp, len);
1118 }
1119
1120 /* [OF10] Section 5.2.2 */
1121 static void
1122 of10_queue_props_print(netdissect_options *ndo,
1123 const u_char *cp, u_int len)
1124 {
1125 while (len) {
1126 uint16_t property, plen;
1127 u_char plen_bogus = 0, skip = 0;
1128
1129 if (len < OF_QUEUE_PROP_MINLEN)
1130 goto invalid;
1131 /* property */
1132 property = GET_BE_U_2(cp);
1133 OF_FWD(2);
1134 ND_PRINT("\n\t property %s", tok2str(ofpqt_str, "invalid (0x%04x)", property));
1135 /* len */
1136 plen = GET_BE_U_2(cp);
1137 OF_FWD(2);
1138 ND_PRINT(", len %u", plen);
1139 if (plen < OF_QUEUE_PROP_MINLEN || plen > len + 4)
1140 goto invalid;
1141 /* pad */
1142 /* Sometimes the last field, check bounds. */
1143 OF_CHK_FWD(4);
1144 /* property-specific constraints and decoding */
1145 switch (property) {
1146 case OFPQT_NONE:
1147 plen_bogus = plen != OF_QUEUE_PROP_MINLEN;
1148 break;
1149 case OFPQT_MIN_RATE:
1150 plen_bogus = plen != OF_QUEUE_PROP_MIN_RATE_FIXLEN;
1151 break;
1152 default:
1153 skip = 1;
1154 }
1155 if (plen_bogus) {
1156 ND_PRINT(" (bogus)");
1157 skip = 1;
1158 }
1159 if (skip) {
1160 /*
1161 * plen >= OF_QUEUE_PROP_MINLEN
1162 * cp is OF_QUEUE_PROP_MINLEN bytes in
1163 */
1164 OF_CHK_FWD(plen - OF_QUEUE_PROP_MINLEN);
1165 continue;
1166 }
1167 if (property == OFPQT_MIN_RATE) { /* the only case of property decoding */
1168 /* rate */
1169 uint16_t rate = GET_BE_U_2(cp);
1170 OF_FWD(2);
1171 if (rate > 1000)
1172 ND_PRINT(", rate disabled");
1173 else
1174 ND_PRINT(", rate %u.%u%%", rate / 10, rate % 10);
1175 /* pad */
1176 /* Sometimes the last field, check bounds. */
1177 OF_CHK_FWD(6);
1178 }
1179 } /* while */
1180 return;
1181
1182 invalid: /* skip the rest of queue properties */
1183 nd_print_invalid(ndo);
1184 ND_TCHECK_LEN(cp, len);
1185 }
1186
1187 /* ibid */
1188 static void
1189 of10_queues_print(netdissect_options *ndo,
1190 const u_char *cp, u_int len)
1191 {
1192 while (len) {
1193 uint16_t desclen;
1194
1195 if (len < OF_PACKET_QUEUE_MINLEN)
1196 goto invalid;
1197 /* queue_id */
1198 ND_PRINT("\n\t queue_id %u", GET_BE_U_4(cp));
1199 OF_FWD(4);
1200 /* len */
1201 desclen = GET_BE_U_2(cp);
1202 OF_FWD(2);
1203 ND_PRINT(", len %u", desclen);
1204 if (desclen < OF_PACKET_QUEUE_MINLEN || desclen > len + 6)
1205 goto invalid;
1206 /* pad */
1207 /* Sometimes the last field, check bounds. */
1208 OF_CHK_FWD(2);
1209 /* properties */
1210 if (ndo->ndo_vflag >= 2)
1211 of10_queue_props_print(ndo, cp, desclen - OF_PACKET_QUEUE_MINLEN);
1212 else
1213 ND_TCHECK_LEN(cp, desclen - OF_PACKET_QUEUE_MINLEN);
1214 OF_FWD(desclen - OF_PACKET_QUEUE_MINLEN);
1215 } /* while */
1216 return;
1217
1218 invalid: /* skip the rest of queues */
1219 nd_print_invalid(ndo);
1220 ND_TCHECK_LEN(cp, len);
1221 }
1222
1223 /* [OF10] Section 5.2.3 */
1224 static void
1225 of10_match_print(netdissect_options *ndo,
1226 const char *pfx, const u_char *cp)
1227 {
1228 uint32_t wildcards;
1229 uint16_t dl_type;
1230 uint8_t nw_proto;
1231 u_int nw_bits;
1232 const char *field_name;
1233
1234 /* wildcards */
1235 wildcards = GET_BE_U_4(cp);
1236 if (wildcards & OFPFW_U)
1237 ND_PRINT("%swildcards 0x%08x (bogus)", pfx, wildcards);
1238 cp += 4;
1239 /* in_port */
1240 if (! (wildcards & OFPFW_IN_PORT))
1241 ND_PRINT("%smatch in_port %s", pfx,
1242 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1243 cp += 2;
1244 /* dl_src */
1245 if (! (wildcards & OFPFW_DL_SRC))
1246 ND_PRINT("%smatch dl_src %s", pfx, GET_ETHERADDR_STRING(cp));
1247 cp += MAC_ADDR_LEN;
1248 /* dl_dst */
1249 if (! (wildcards & OFPFW_DL_DST))
1250 ND_PRINT("%smatch dl_dst %s", pfx, GET_ETHERADDR_STRING(cp));
1251 cp += MAC_ADDR_LEN;
1252 /* dl_vlan */
1253 if (! (wildcards & OFPFW_DL_VLAN))
1254 ND_PRINT("%smatch dl_vlan %s", pfx, vlan_str(GET_BE_U_2(cp)));
1255 cp += 2;
1256 /* dl_vlan_pcp */
1257 if (! (wildcards & OFPFW_DL_VLAN_PCP))
1258 ND_PRINT("%smatch dl_vlan_pcp %s", pfx, pcp_str(GET_U_1(cp)));
1259 cp += 1;
1260 /* pad1 */
1261 cp += 1;
1262 /* dl_type */
1263 dl_type = GET_BE_U_2(cp);
1264 cp += 2;
1265 if (! (wildcards & OFPFW_DL_TYPE))
1266 ND_PRINT("%smatch dl_type 0x%04x", pfx, dl_type);
1267 /* nw_tos */
1268 if (! (wildcards & OFPFW_NW_TOS))
1269 ND_PRINT("%smatch nw_tos 0x%02x", pfx, GET_U_1(cp));
1270 cp += 1;
1271 /* nw_proto */
1272 nw_proto = GET_U_1(cp);
1273 cp += 1;
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);
1278 }
1279 /* pad2 */
1280 cp += 2;
1281 /* nw_src */
1282 nw_bits = (wildcards & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT;
1283 if (nw_bits < 32)
1284 ND_PRINT("%smatch nw_src %s/%u", pfx, GET_IPADDR_STRING(cp), 32 - nw_bits);
1285 cp += 4;
1286 /* nw_dst */
1287 nw_bits = (wildcards & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT;
1288 if (nw_bits < 32)
1289 ND_PRINT("%smatch nw_dst %s/%u", pfx, GET_IPADDR_STRING(cp), 32 - nw_bits);
1290 cp += 4;
1291 /* tp_src */
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));
1297 }
1298 cp += 2;
1299 /* tp_dst */
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));
1306 }
1307 else
1308 ND_TCHECK_2(cp);
1309 }
1310
1311 /* [OF10] Section 5.2.4 */
1312 static void
1313 of10_actions_print(netdissect_options *ndo,
1314 const char *pfx, const u_char *cp, u_int len)
1315 {
1316 while (len) {
1317 uint16_t type, alen, output_port;
1318 u_char alen_bogus = 0, skip = 0;
1319
1320 if (len < OF_ACTION_MINLEN)
1321 goto invalid;
1322 /* type */
1323 type = GET_BE_U_2(cp);
1324 OF_FWD(2);
1325 ND_PRINT("%saction type %s", pfx, tok2str(ofpat_str, "invalid (0x%04x)", type));
1326 /* length */
1327 alen = GET_BE_U_2(cp);
1328 OF_FWD(2);
1329 ND_PRINT(", len %u", alen);
1330 /*
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.
1335 */
1336
1337 /* On action size underrun/overrun skip the rest of the action list. */
1338 if (alen < OF_ACTION_MINLEN || alen > len + 4)
1339 goto invalid;
1340 /*
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.
1344 */
1345 switch (type) {
1346 case OFPAT_OUTPUT:
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;
1356 break;
1357 case OFPAT_SET_DL_SRC:
1358 case OFPAT_SET_DL_DST:
1359 case OFPAT_ENQUEUE:
1360 alen_bogus = alen != 16;
1361 break;
1362 case OFPAT_VENDOR:
1363 alen_bogus = alen % 8 != 0; /* already >= 8 so far */
1364 break;
1365 default:
1366 skip = 1;
1367 }
1368 if (alen_bogus) {
1369 ND_PRINT(" (bogus)");
1370 skip = 1;
1371 }
1372 if (skip) {
1373 /*
1374 * alen >= OF_ACTION_MINLEN
1375 * cp is 4 bytes in
1376 */
1377 OF_CHK_FWD(alen - 4);
1378 continue;
1379 }
1380 /* OK to decode the rest of the action structure */
1381 switch (type) {
1382 case OFPAT_OUTPUT:
1383 /* port */
1384 output_port = GET_BE_U_2(cp);
1385 OF_FWD(2);
1386 ND_PRINT(", port %s", tok2str(ofpp_str, "%u", output_port));
1387 /* max_len */
1388 if (output_port == OFPP_CONTROLLER)
1389 ND_PRINT(", max_len %u", GET_BE_U_2(cp));
1390 else
1391 ND_TCHECK_2(cp);
1392 OF_FWD(2);
1393 break;
1394 case OFPAT_SET_VLAN_VID:
1395 /* vlan_vid */
1396 ND_PRINT(", vlan_vid %s", vlan_str(GET_BE_U_2(cp)));
1397 OF_FWD(2);
1398 /* pad */
1399 /* Sometimes the last field, check bounds. */
1400 OF_CHK_FWD(2);
1401 break;
1402 case OFPAT_SET_VLAN_PCP:
1403 /* vlan_pcp */
1404 ND_PRINT(", vlan_pcp %s", pcp_str(GET_U_1(cp)));
1405 OF_FWD(1);
1406 /* pad */
1407 /* Sometimes the last field, check bounds. */
1408 OF_CHK_FWD(3);
1409 break;
1410 case OFPAT_SET_DL_SRC:
1411 case OFPAT_SET_DL_DST:
1412 /* dl_addr */
1413 ND_PRINT(", dl_addr %s", GET_ETHERADDR_STRING(cp));
1414 OF_FWD(MAC_ADDR_LEN);
1415 /* pad */
1416 /* Sometimes the last field, check bounds. */
1417 OF_CHK_FWD(6);
1418 break;
1419 case OFPAT_SET_NW_SRC:
1420 case OFPAT_SET_NW_DST:
1421 /* nw_addr */
1422 ND_PRINT(", nw_addr %s", GET_IPADDR_STRING(cp));
1423 OF_FWD(4);
1424 break;
1425 case OFPAT_SET_NW_TOS:
1426 /* nw_tos */
1427 ND_PRINT(", nw_tos 0x%02x", GET_U_1(cp));
1428 OF_FWD(1);
1429 /* pad */
1430 /* Sometimes the last field, check bounds. */
1431 OF_CHK_FWD(3);
1432 break;
1433 case OFPAT_SET_TP_SRC:
1434 case OFPAT_SET_TP_DST:
1435 /* nw_tos */
1436 ND_PRINT(", tp_port %u", GET_BE_U_2(cp));
1437 OF_FWD(2);
1438 /* pad */
1439 /* Sometimes the last field, check bounds. */
1440 OF_CHK_FWD(2);
1441 break;
1442 case OFPAT_ENQUEUE:
1443 /* port */
1444 ND_PRINT(", port %s",
1445 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1446 OF_FWD(2);
1447 /* pad */
1448 OF_FWD(6);
1449 /* queue_id */
1450 ND_PRINT(", queue_id %s",
1451 tok2str(ofpq_str, "%u", GET_BE_U_4(cp)));
1452 OF_FWD(4);
1453 break;
1454 case OFPAT_VENDOR:
1455 of10_vendor_action_print(ndo, cp, alen - 4);
1456 OF_FWD(alen - 4);
1457 break;
1458 case OFPAT_STRIP_VLAN:
1459 /* pad */
1460 /* Sometimes the last field, check bounds. */
1461 OF_CHK_FWD(4);
1462 break;
1463 } /* switch */
1464 } /* while */
1465 return;
1466
1467 invalid: /* skip the rest of actions */
1468 nd_print_invalid(ndo);
1469 ND_TCHECK_LEN(cp, len);
1470 }
1471
1472 /* [OF10] Section 5.3.1 */
1473 static void
1474 of10_features_reply_print(netdissect_options *ndo,
1475 const u_char *cp, u_int len)
1476 {
1477 /* datapath_id */
1478 ND_PRINT("\n\t dpid 0x%016" PRIx64, GET_BE_U_8(cp));
1479 OF_FWD(8);
1480 /* n_buffers */
1481 ND_PRINT(", n_buffers %u", GET_BE_U_4(cp));
1482 OF_FWD(4);
1483 /* n_tables */
1484 ND_PRINT(", n_tables %u", GET_U_1(cp));
1485 OF_FWD(1);
1486 /* pad */
1487 OF_FWD(3);
1488 /* capabilities */
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);
1491 OF_FWD(4);
1492 /* actions */
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);
1495 OF_FWD(4);
1496 /* ports */
1497 of10_phy_ports_print(ndo, cp, len);
1498 }
1499
1500 /* [OF10] Section 5.3.3 */
1501 static void
1502 of10_flow_mod_print(netdissect_options *ndo,
1503 const u_char *cp, u_int len)
1504 {
1505 uint16_t command;
1506
1507 /* match */
1508 of10_match_print(ndo, "\n\t ", cp);
1509 OF_FWD(OF_MATCH_FIXLEN);
1510 /* cookie */
1511 ND_PRINT("\n\t cookie 0x%016" PRIx64, GET_BE_U_8(cp));
1512 OF_FWD(8);
1513 /* command */
1514 command = GET_BE_U_2(cp);
1515 ND_PRINT(", command %s", tok2str(ofpfc_str, "invalid (0x%04x)", command));
1516 OF_FWD(2);
1517 /* idle_timeout */
1518 if (GET_BE_U_2(cp))
1519 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp));
1520 OF_FWD(2);
1521 /* hard_timeout */
1522 if (GET_BE_U_2(cp))
1523 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp));
1524 OF_FWD(2);
1525 /* priority */
1526 if (GET_BE_U_2(cp))
1527 ND_PRINT(", priority %u", GET_BE_U_2(cp));
1528 OF_FWD(2);
1529 /* buffer_id */
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)));
1534 OF_FWD(4);
1535 /* out_port */
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)));
1539 OF_FWD(2);
1540 /* flags */
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);
1543 OF_FWD(2);
1544 /* actions */
1545 of10_actions_print(ndo, "\n\t ", cp, len);
1546 }
1547
1548 /* ibid */
1549 static void
1550 of10_port_mod_print(netdissect_options *ndo,
1551 const u_char *cp)
1552 {
1553 /* port_no */
1554 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1555 cp += 2;
1556 /* hw_addr */
1557 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp));
1558 cp += MAC_ADDR_LEN;
1559 /* config */
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);
1562 cp += 4;
1563 /* mask */
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);
1566 cp += 4;
1567 /* advertise */
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);
1570 cp += 4;
1571 /* pad */
1572 /* Always the last field, check bounds. */
1573 ND_TCHECK_4(cp);
1574 }
1575
1576 /* [OF10] Section 5.3.5 */
1577 static void
1578 of10_stats_request_print(netdissect_options *ndo,
1579 const u_char *cp, u_int len)
1580 {
1581 uint16_t type;
1582
1583 /* type */
1584 type = GET_BE_U_2(cp);
1585 OF_FWD(2);
1586 ND_PRINT("\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type));
1587 /* flags */
1588 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp));
1589 if (GET_BE_U_2(cp))
1590 ND_PRINT(" (bogus)");
1591 OF_FWD(2);
1592 /* type-specific body of one of fixed lengths */
1593 switch(type) {
1594 case OFPST_DESC:
1595 case OFPST_TABLE:
1596 if (len)
1597 goto invalid;
1598 return;
1599 case OFPST_FLOW:
1600 case OFPST_AGGREGATE:
1601 if (len != OF_FLOW_STATS_REQUEST_FIXLEN)
1602 goto invalid;
1603 /* match */
1604 of10_match_print(ndo, "\n\t ", cp);
1605 OF_FWD(OF_MATCH_FIXLEN);
1606 /* table_id */
1607 ND_PRINT("\n\t table_id %s",
1608 tok2str(tableid_str, "%u", GET_U_1(cp)));
1609 OF_FWD(1);
1610 /* pad */
1611 OF_FWD(1);
1612 /* out_port */
1613 ND_PRINT(", out_port %s",
1614 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1615 return;
1616 case OFPST_PORT:
1617 if (len != OF_PORT_STATS_REQUEST_FIXLEN)
1618 goto invalid;
1619 /* port_no */
1620 ND_PRINT("\n\t port_no %s",
1621 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1622 OF_FWD(2);
1623 /* pad */
1624 /* Always the last field, check bounds. */
1625 OF_CHK_FWD(6);
1626 return;
1627 case OFPST_QUEUE:
1628 if (len != OF_QUEUE_STATS_REQUEST_FIXLEN)
1629 goto invalid;
1630 /* port_no */
1631 ND_PRINT("\n\t port_no %s",
1632 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1633 OF_FWD(2);
1634 /* pad */
1635 OF_FWD(2);
1636 /* queue_id */
1637 ND_PRINT(", queue_id %s",
1638 tok2str(ofpq_str, "%u", GET_BE_U_4(cp)));
1639 return;
1640 case OFPST_VENDOR:
1641 of10_vendor_data_print(ndo, cp, len);
1642 return;
1643 }
1644 return;
1645
1646 invalid: /* skip the message body */
1647 nd_print_invalid(ndo);
1648 ND_TCHECK_LEN(cp, len);
1649 }
1650
1651 /* ibid */
1652 static void
1653 of10_desc_stats_reply_print(netdissect_options *ndo,
1654 const u_char *cp, u_int len)
1655 {
1656 if (len != OF_DESC_STATS_REPLY_FIXLEN)
1657 goto invalid;
1658 /* mfr_desc */
1659 ND_PRINT("\n\t mfr_desc '");
1660 (void)nd_print(ndo, cp, cp + DESC_STR_LEN);
1661 ND_PRINT("'");
1662 OF_FWD(DESC_STR_LEN);
1663 /* hw_desc */
1664 ND_PRINT("\n\t hw_desc '");
1665 (void)nd_print(ndo, cp, cp + DESC_STR_LEN);
1666 ND_PRINT("'");
1667 OF_FWD(DESC_STR_LEN);
1668 /* sw_desc */
1669 ND_PRINT("\n\t sw_desc '");
1670 (void)nd_print(ndo, cp, cp + DESC_STR_LEN);
1671 ND_PRINT("'");
1672 OF_FWD(DESC_STR_LEN);
1673 /* serial_num */
1674 ND_PRINT("\n\t serial_num '");
1675 (void)nd_print(ndo, cp, cp + SERIAL_NUM_LEN);
1676 ND_PRINT("'");
1677 OF_FWD(SERIAL_NUM_LEN);
1678 /* dp_desc */
1679 ND_PRINT("\n\t dp_desc '");
1680 (void)nd_print(ndo, cp, cp + DESC_STR_LEN);
1681 ND_PRINT("'");
1682 return;
1683
1684 invalid: /* skip the message body */
1685 nd_print_invalid(ndo);
1686 ND_TCHECK_LEN(cp, len);
1687 }
1688
1689 /* ibid */
1690 static void
1691 of10_flow_stats_reply_print(netdissect_options *ndo,
1692 const u_char *cp, u_int len)
1693 {
1694 while (len) {
1695 uint16_t entry_len;
1696
1697 if (len < OF_FLOW_STATS_REPLY_MINLEN)
1698 goto invalid;
1699 /* length */
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)
1703 goto invalid;
1704 OF_FWD(2);
1705 /* table_id */
1706 ND_PRINT(", table_id %s",
1707 tok2str(tableid_str, "%u", GET_U_1(cp)));
1708 OF_FWD(1);
1709 /* pad */
1710 OF_FWD(1);
1711 /* match */
1712 of10_match_print(ndo, "\n\t ", cp);
1713 OF_FWD(OF_MATCH_FIXLEN);
1714 /* duration_sec */
1715 ND_PRINT("\n\t duration_sec %u", GET_BE_U_4(cp));
1716 OF_FWD(4);
1717 /* duration_nsec */
1718 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp));
1719 OF_FWD(4);
1720 /* priority */
1721 ND_PRINT(", priority %u", GET_BE_U_2(cp));
1722 OF_FWD(2);
1723 /* idle_timeout */
1724 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp));
1725 OF_FWD(2);
1726 /* hard_timeout */
1727 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp));
1728 OF_FWD(2);
1729 /* pad2 */
1730 OF_FWD(6);
1731 /* cookie */
1732 ND_PRINT(", cookie 0x%016" PRIx64, GET_BE_U_8(cp));
1733 OF_FWD(8);
1734 /* packet_count */
1735 ND_PRINT(", packet_count %" PRIu64, GET_BE_U_8(cp));
1736 OF_FWD(8);
1737 /* byte_count */
1738 ND_PRINT(", byte_count %" PRIu64, GET_BE_U_8(cp));
1739 OF_FWD(8);
1740 /* actions */
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);
1743 } /* while */
1744 return;
1745
1746 invalid: /* skip the rest of flow statistics entries */
1747 nd_print_invalid(ndo);
1748 ND_TCHECK_LEN(cp, len);
1749 }
1750
1751 /* ibid */
1752 static void
1753 of10_aggregate_stats_reply_print(netdissect_options *ndo,
1754 const u_char *cp, u_int len)
1755 {
1756 if (len != OF_AGGREGATE_STATS_REPLY_FIXLEN)
1757 goto invalid;
1758 /* packet_count */
1759 ND_PRINT("\n\t packet_count %" PRIu64, GET_BE_U_8(cp));
1760 OF_FWD(8);
1761 /* byte_count */
1762 ND_PRINT(", byte_count %" PRIu64, GET_BE_U_8(cp));
1763 OF_FWD(8);
1764 /* flow_count */
1765 ND_PRINT(", flow_count %u", GET_BE_U_4(cp));
1766 OF_FWD(4);
1767 /* pad */
1768 /* Always the last field, check bounds. */
1769 ND_TCHECK_4(cp);
1770 return;
1771
1772 invalid: /* skip the message body */
1773 nd_print_invalid(ndo);
1774 ND_TCHECK_LEN(cp, len);
1775 }
1776
1777 /* ibid */
1778 static void
1779 of10_table_stats_reply_print(netdissect_options *ndo,
1780 const u_char *cp, u_int len)
1781 {
1782 while (len) {
1783 if (len < OF_TABLE_STATS_REPLY_FIXLEN)
1784 goto invalid;
1785 /* table_id */
1786 ND_PRINT("\n\t table_id %s",
1787 tok2str(tableid_str, "%u", GET_U_1(cp)));
1788 OF_FWD(1);
1789 /* pad */
1790 OF_FWD(3);
1791 /* name */
1792 ND_PRINT(", name '");
1793 (void)nd_print(ndo, cp, cp + OFP_MAX_TABLE_NAME_LEN);
1794 ND_PRINT("'");
1795 OF_FWD(OFP_MAX_TABLE_NAME_LEN);
1796 /* wildcards */
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);
1799 OF_FWD(4);
1800 /* max_entries */
1801 ND_PRINT("\n\t max_entries %u", GET_BE_U_4(cp));
1802 OF_FWD(4);
1803 /* active_count */
1804 ND_PRINT(", active_count %u", GET_BE_U_4(cp));
1805 OF_FWD(4);
1806 /* lookup_count */
1807 ND_PRINT(", lookup_count %" PRIu64, GET_BE_U_8(cp));
1808 OF_FWD(8);
1809 /* matched_count */
1810 ND_PRINT(", matched_count %" PRIu64, GET_BE_U_8(cp));
1811 OF_FWD(8);
1812 } /* while */
1813 return;
1814
1815 invalid: /* skip the undersized trailing data */
1816 nd_print_invalid(ndo);
1817 ND_TCHECK_LEN(cp, len);
1818 }
1819
1820 /* ibid */
1821 static void
1822 of10_port_stats_reply_print(netdissect_options *ndo,
1823 const u_char *cp, u_int len)
1824 {
1825 while (len) {
1826 if (len < OF_PORT_STATS_REPLY_FIXLEN)
1827 goto invalid;
1828 /* port_no */
1829 ND_PRINT("\n\t port_no %s",
1830 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1831 OF_FWD(2);
1832 if (ndo->ndo_vflag < 2) {
1833 OF_CHK_FWD(OF_PORT_STATS_REPLY_FIXLEN - 2);
1834 continue;
1835 }
1836 /* pad */
1837 OF_FWD(6);
1838 /* rx_packets */
1839 ND_PRINT(", rx_packets %" PRIu64, GET_BE_U_8(cp));
1840 OF_FWD(8);
1841 /* tx_packets */
1842 ND_PRINT(", tx_packets %" PRIu64, GET_BE_U_8(cp));
1843 OF_FWD(8);
1844 /* rx_bytes */
1845 ND_PRINT(", rx_bytes %" PRIu64, GET_BE_U_8(cp));
1846 OF_FWD(8);
1847 /* tx_bytes */
1848 ND_PRINT(", tx_bytes %" PRIu64, GET_BE_U_8(cp));
1849 OF_FWD(8);
1850 /* rx_dropped */
1851 ND_PRINT(", rx_dropped %" PRIu64, GET_BE_U_8(cp));
1852 OF_FWD(8);
1853 /* tx_dropped */
1854 ND_PRINT(", tx_dropped %" PRIu64, GET_BE_U_8(cp));
1855 OF_FWD(8);
1856 /* rx_errors */
1857 ND_PRINT(", rx_errors %" PRIu64, GET_BE_U_8(cp));
1858 OF_FWD(8);
1859 /* tx_errors */
1860 ND_PRINT(", tx_errors %" PRIu64, GET_BE_U_8(cp));
1861 OF_FWD(8);
1862 /* rx_frame_err */
1863 ND_PRINT(", rx_frame_err %" PRIu64, GET_BE_U_8(cp));
1864 OF_FWD(8);
1865 /* rx_over_err */
1866 ND_PRINT(", rx_over_err %" PRIu64, GET_BE_U_8(cp));
1867 OF_FWD(8);
1868 /* rx_crc_err */
1869 ND_PRINT(", rx_crc_err %" PRIu64, GET_BE_U_8(cp));
1870 OF_FWD(8);
1871 /* collisions */
1872 ND_PRINT(", collisions %" PRIu64, GET_BE_U_8(cp));
1873 OF_FWD(8);
1874 } /* while */
1875 return;
1876
1877 invalid: /* skip the undersized trailing data */
1878 nd_print_invalid(ndo);
1879 ND_TCHECK_LEN(cp, len);
1880 }
1881
1882 /* ibid */
1883 static void
1884 of10_queue_stats_reply_print(netdissect_options *ndo,
1885 const u_char *cp, u_int len)
1886 {
1887 while (len) {
1888 if (len < OF_QUEUE_STATS_REPLY_FIXLEN)
1889 goto invalid;
1890 /* port_no */
1891 ND_PRINT("\n\t port_no %s",
1892 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1893 OF_FWD(2);
1894 /* pad */
1895 OF_FWD(2);
1896 /* queue_id */
1897 ND_PRINT(", queue_id %u", GET_BE_U_4(cp));
1898 OF_FWD(4);
1899 /* tx_bytes */
1900 ND_PRINT(", tx_bytes %" PRIu64, GET_BE_U_8(cp));
1901 OF_FWD(8);
1902 /* tx_packets */
1903 ND_PRINT(", tx_packets %" PRIu64, GET_BE_U_8(cp));
1904 OF_FWD(8);
1905 /* tx_errors */
1906 ND_PRINT(", tx_errors %" PRIu64, GET_BE_U_8(cp));
1907 OF_FWD(8);
1908 } /* while */
1909 return;
1910
1911 invalid: /* skip the undersized trailing data */
1912 nd_print_invalid(ndo);
1913 ND_TCHECK_LEN(cp, len);
1914 }
1915
1916 /* ibid */
1917 static void
1918 of10_stats_reply_print(netdissect_options *ndo,
1919 const u_char *cp, u_int len)
1920 {
1921 uint16_t type;
1922
1923 /* type */
1924 type = GET_BE_U_2(cp);
1925 ND_PRINT("\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type));
1926 OF_FWD(2);
1927 /* flags */
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);
1930 OF_FWD(2);
1931
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 :
1941 NULL;
1942 if (decoder != NULL) {
1943 decoder(ndo, cp, len);
1944 return;
1945 }
1946 }
1947 ND_TCHECK_LEN(cp, len);
1948 }
1949
1950 /* [OF10] Section 5.3.6 */
1951 static void
1952 of10_packet_out_print(netdissect_options *ndo,
1953 const u_char *cp, u_int len)
1954 {
1955 uint16_t actions_len;
1956
1957 /* buffer_id */
1958 ND_PRINT("\n\t buffer_id 0x%08x", GET_BE_U_4(cp));
1959 OF_FWD(4);
1960 /* in_port */
1961 ND_PRINT(", in_port %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1962 OF_FWD(2);
1963 /* actions_len */
1964 actions_len = GET_BE_U_2(cp);
1965 OF_FWD(2);
1966 if (actions_len > len)
1967 goto invalid;
1968 /* actions */
1969 of10_actions_print(ndo, "\n\t ", cp, actions_len);
1970 OF_FWD(actions_len);
1971 /* data */
1972 of10_packet_data_print(ndo, cp, len);
1973 return;
1974
1975 invalid: /* skip the rest of the message body */
1976 nd_print_invalid(ndo);
1977 ND_TCHECK_LEN(cp, len);
1978 }
1979
1980 /* [OF10] Section 5.4.1 */
1981 static void
1982 of10_packet_in_print(netdissect_options *ndo,
1983 const u_char *cp, u_int len)
1984 {
1985 /* buffer_id */
1986 ND_PRINT("\n\t buffer_id %s",
1987 tok2str(bufferid_str, "0x%08x", GET_BE_U_4(cp)));
1988 OF_FWD(4);
1989 /* total_len */
1990 ND_PRINT(", total_len %u", GET_BE_U_2(cp));
1991 OF_FWD(2);
1992 /* in_port */
1993 ND_PRINT(", in_port %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1994 OF_FWD(2);
1995 /* reason */
1996 ND_PRINT(", reason %s",
1997 tok2str(ofpr_str, "invalid (0x%02x)", GET_U_1(cp)));
1998 OF_FWD(1);
1999 /* pad */
2000 /* Sometimes the last field, check bounds. */
2001 OF_CHK_FWD(1);
2002 /* data */
2003 of10_packet_data_print(ndo, cp, len);
2004 }
2005
2006 /* [OF10] Section 5.4.2 */
2007 static void
2008 of10_flow_removed_print(netdissect_options *ndo,
2009 const u_char *cp)
2010 {
2011 /* match */
2012 of10_match_print(ndo, "\n\t ", cp);
2013 cp += OF_MATCH_FIXLEN;
2014 /* cookie */
2015 ND_PRINT("\n\t cookie 0x%016" PRIx64, GET_BE_U_8(cp));
2016 cp += 8;
2017 /* priority */
2018 if (GET_BE_U_2(cp))
2019 ND_PRINT(", priority %u", GET_BE_U_2(cp));
2020 cp += 2;
2021 /* reason */
2022 ND_PRINT(", reason %s",
2023 tok2str(ofprr_str, "unknown (0x%02x)", GET_U_1(cp)));
2024 cp += 1;
2025 /* pad */
2026 cp += 1;
2027 /* duration_sec */
2028 ND_PRINT(", duration_sec %u", GET_BE_U_4(cp));
2029 cp += 4;
2030 /* duration_nsec */
2031 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp));
2032 cp += 4;
2033 /* idle_timeout */
2034 if (GET_BE_U_2(cp))
2035 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp));
2036 cp += 2;
2037 /* pad2 */
2038 cp += 2;
2039 /* packet_count */
2040 ND_PRINT(", packet_count %" PRIu64, GET_BE_U_8(cp));
2041 cp += 8;
2042 /* byte_count */
2043 ND_PRINT(", byte_count %" PRIu64, GET_BE_U_8(cp));
2044 }
2045
2046 /* [OF10] Section 5.4.4 */
2047 static void
2048 of10_error_print(netdissect_options *ndo,
2049 const u_char *cp, u_int len)
2050 {
2051 uint16_t type, code;
2052 const struct tok *code_str;
2053
2054 /* type */
2055 type = GET_BE_U_2(cp);
2056 OF_FWD(2);
2057 ND_PRINT("\n\t type %s", tok2str(ofpet_str, "invalid (0x%04x)", type));
2058 /* code */
2059 code = GET_BE_U_2(cp);
2060 OF_FWD(2);
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));
2065 else
2066 ND_PRINT(", code invalid (0x%04x)", code);
2067 /* data */
2068 of_data_print(ndo, cp, len);
2069 }
2070
2071 void
2072 of10_message_print(netdissect_options *ndo,
2073 const u_char *cp, uint16_t len, const uint8_t type)
2074 {
2075 /*
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.
2081 *
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
2086 * validation.
2087 */
2088 switch (type) {
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 */
2094 if (len)
2095 goto invalid;
2096 return;
2097
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)
2102 goto invalid;
2103 if (ndo->ndo_vflag < 1)
2104 break;
2105 /* flags */
2106 ND_PRINT("\n\t flags %s",
2107 tok2str(ofp_config_str, "invalid (0x%04x)",
2108 GET_BE_U_2(cp)));
2109 OF_FWD(2);
2110 /* miss_send_len */
2111 ND_PRINT(", miss_send_len %u", GET_BE_U_2(cp));
2112 return;
2113 case OFPT_PORT_MOD:
2114 if (len != OF_PORT_MOD_FIXLEN - OF_HEADER_FIXLEN)
2115 goto invalid;
2116 if (ndo->ndo_vflag < 1)
2117 break;
2118 of10_port_mod_print(ndo, cp);
2119 return;
2120 case OFPT_QUEUE_GET_CONFIG_REQUEST: /* [OF10] Section 5.3.4 */
2121 if (len != OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN - OF_HEADER_FIXLEN)
2122 goto invalid;
2123 if (ndo->ndo_vflag < 1)
2124 break;
2125 /* port */
2126 ND_PRINT("\n\t port %s",
2127 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
2128 OF_FWD(2);
2129 /* pad */
2130 /* Always the last field, check bounds. */
2131 ND_TCHECK_2(cp);
2132 return;
2133 case OFPT_FLOW_REMOVED:
2134 if (len != OF_FLOW_REMOVED_FIXLEN - OF_HEADER_FIXLEN)
2135 goto invalid;
2136 if (ndo->ndo_vflag < 1)
2137 break;
2138 of10_flow_removed_print(ndo, cp);
2139 return;
2140 case OFPT_PORT_STATUS: /* [OF10] Section 5.4.3 */
2141 if (len != OF_PORT_STATUS_FIXLEN - OF_HEADER_FIXLEN)
2142 goto invalid;
2143 if (ndo->ndo_vflag < 1)
2144 break;
2145 /* reason */
2146 ND_PRINT("\n\t reason %s",
2147 tok2str(ofppr_str, "invalid (0x%02x)", GET_U_1(cp)));
2148 OF_FWD(1);
2149 /* pad */
2150 /* No need to check bounds, more data follows. */
2151 OF_FWD(7);
2152 /* desc */
2153 of10_phy_ports_print(ndo, cp, len);
2154 return;
2155
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)
2159 goto invalid;
2160 if (ndo->ndo_vflag < 1)
2161 break;
2162 of10_features_reply_print(ndo, cp, len);
2163 return;
2164
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)
2170 break;
2171 of_data_print(ndo, cp, len);
2172 return;
2173
2174 /* OpenFlow header, fixed-size message body and variable-size data. */
2175 case OFPT_ERROR:
2176 if (len < OF_ERROR_MSG_MINLEN - OF_HEADER_FIXLEN)
2177 goto invalid;
2178 if (ndo->ndo_vflag < 1)
2179 break;
2180 of10_error_print(ndo, cp, len);
2181 return;
2182 case OFPT_VENDOR:
2183 /* [OF10] Section 5.5.4 */
2184 if (len < OF_VENDOR_MINLEN - OF_HEADER_FIXLEN)
2185 goto invalid;
2186 if (ndo->ndo_vflag < 1)
2187 break;
2188 of10_vendor_message_print(ndo, cp, len);
2189 return;
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)
2193 goto invalid;
2194 if (ndo->ndo_vflag < 1)
2195 break;
2196 of10_packet_in_print(ndo, cp, len);
2197 return;
2198
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)
2204 goto invalid;
2205 if (ndo->ndo_vflag < 1)
2206 break;
2207 of10_stats_request_print(ndo, cp, len);
2208 return;
2209
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)
2216 goto invalid;
2217 if (ndo->ndo_vflag < 1)
2218 break;
2219 of10_stats_reply_print(ndo, cp, len);
2220 return;
2221
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)
2225 goto invalid;
2226 if (ndo->ndo_vflag < 1)
2227 break;
2228 of10_packet_out_print(ndo, cp, len);
2229 return;
2230
2231 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2232 case OFPT_FLOW_MOD:
2233 if (len < OF_FLOW_MOD_MINLEN - OF_HEADER_FIXLEN)
2234 goto invalid;
2235 if (ndo->ndo_vflag < 1)
2236 break;
2237 of10_flow_mod_print(ndo, cp, len);
2238 return;
2239
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)
2243 goto invalid;
2244 if (ndo->ndo_vflag < 1)
2245 break;
2246 /* port */
2247 ND_PRINT("\n\t port %s",
2248 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
2249 OF_FWD(2);
2250 /* pad */
2251 /* Sometimes the last field, check bounds. */
2252 OF_CHK_FWD(6);
2253 /* queues */
2254 of10_queues_print(ndo, cp, len);
2255 return;
2256 } /* switch (type) */
2257 /*
2258 * Not a recognised type or did not print the details, fall back to
2259 * a bounds check.
2260 */
2261 ND_TCHECK_LEN(cp, len);
2262 return;
2263
2264 invalid: /* skip the message body */
2265 nd_print_invalid(ndo);
2266 ND_TCHECK_LEN(cp, len);
2267 }