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