]> The Tcpdump Group git mirrors - tcpdump/blob - print-openflow-1.0.c
OpenFlow: Make one more function shared.
[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_bsn_message_print(netdissect_options *ndo,
714 const u_char *cp, u_int len)
715 {
716 uint32_t subtype;
717
718 if (len < 4)
719 goto invalid;
720 /* subtype */
721 subtype = GET_BE_U_4(cp);
722 OF_FWD(4);
723 ND_PRINT("\n\t subtype %s", tok2str(bsn_subtype_str, "unknown (0x%08x)", subtype));
724 switch (subtype) {
725 case BSN_GET_IP_MASK_REQUEST:
726 /*
727 * 0 1 2 3
728 * 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
729 * +---------------+---------------+---------------+---------------+
730 * | subtype |
731 * +---------------+---------------+---------------+---------------+
732 * | index | pad |
733 * +---------------+---------------+---------------+---------------+
734 * | pad |
735 * +---------------+---------------+---------------+---------------+
736 *
737 */
738 if (len != 8)
739 goto invalid;
740 /* index */
741 ND_PRINT(", index %u", GET_U_1(cp));
742 OF_FWD(1);
743 /* pad */
744 /* Always the last field, check bounds. */
745 ND_TCHECK_7(cp);
746 break;
747 case BSN_SET_IP_MASK:
748 case BSN_GET_IP_MASK_REPLY:
749 /*
750 * 0 1 2 3
751 * 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
752 * +---------------+---------------+---------------+---------------+
753 * | subtype |
754 * +---------------+---------------+---------------+---------------+
755 * | index | pad |
756 * +---------------+---------------+---------------+---------------+
757 * | mask |
758 * +---------------+---------------+---------------+---------------+
759 *
760 */
761 if (len != 8)
762 goto invalid;
763 /* index */
764 ND_PRINT(", index %u", GET_U_1(cp));
765 OF_FWD(1);
766 /* pad */
767 OF_FWD(3);
768 /* mask */
769 ND_PRINT(", mask %s", GET_IPADDR_STRING(cp));
770 break;
771 case BSN_SET_MIRRORING:
772 case BSN_GET_MIRRORING_REQUEST:
773 case BSN_GET_MIRRORING_REPLY:
774 /*
775 * 0 1 2 3
776 * 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
777 * +---------------+---------------+---------------+---------------+
778 * | subtype |
779 * +---------------+---------------+---------------+---------------+
780 * | report m. p. | pad |
781 * +---------------+---------------+---------------+---------------+
782 *
783 */
784 if (len != 4)
785 goto invalid;
786 /* report_mirror_ports */
787 ND_PRINT(", report_mirror_ports %s",
788 tok2str(bsn_onoff_str, "bogus (%u)", GET_U_1(cp)));
789 OF_FWD(1);
790 /* pad */
791 /* Always the last field, check bounds. */
792 ND_TCHECK_3(cp);
793 break;
794 case BSN_GET_INTERFACES_REQUEST:
795 case BSN_GET_L2_TABLE_REQUEST:
796 case BSN_BW_ENABLE_GET_REQUEST:
797 case BSN_BW_CLEAR_DATA_REQUEST:
798 case BSN_HYBRID_GET_REQUEST:
799 /*
800 * 0 1 2 3
801 * 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
802 * +---------------+---------------+---------------+---------------+
803 * | subtype |
804 * +---------------+---------------+---------------+---------------+
805 *
806 */
807 if (len)
808 goto invalid;
809 break;
810 case BSN_VIRTUAL_PORT_REMOVE_REQUEST:
811 /*
812 * 0 1 2 3
813 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
814 * +---------------+---------------+---------------+---------------+
815 * | subtype |
816 * +---------------+---------------+---------------+---------------+
817 * | vport_no |
818 * +---------------+---------------+---------------+---------------+
819 *
820 */
821 if (len != 4)
822 goto invalid;
823 /* vport_no */
824 ND_PRINT(", vport_no %u", GET_BE_U_4(cp));
825 break;
826 case BSN_SHELL_COMMAND:
827 /*
828 * 0 1 2 3
829 * 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
830 * +---------------+---------------+---------------+---------------+
831 * | subtype |
832 * +---------------+---------------+---------------+---------------+
833 * | service |
834 * +---------------+---------------+---------------+---------------+
835 * | data ...
836 * +---------------+---------------+--------
837 *
838 */
839 if (len < 4)
840 goto invalid;
841 /* service */
842 ND_PRINT(", service %u", GET_BE_U_4(cp));
843 OF_FWD(4);
844 /* data */
845 ND_PRINT(", data '");
846 nd_printn(ndo, cp, len, NULL);
847 ND_PRINT("'");
848 break;
849 case BSN_SHELL_OUTPUT:
850 /*
851 * 0 1 2 3
852 * 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
853 * +---------------+---------------+---------------+---------------+
854 * | subtype |
855 * +---------------+---------------+---------------+---------------+
856 * | data ...
857 * +---------------+---------------+--------
858 *
859 */
860 /* already checked that len >= 4 */
861 /* data */
862 ND_PRINT(", data '");
863 nd_printn(ndo, cp, len, NULL);
864 ND_PRINT("'");
865 break;
866 case BSN_SHELL_STATUS:
867 /*
868 * 0 1 2 3
869 * 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
870 * +---------------+---------------+---------------+---------------+
871 * | subtype |
872 * +---------------+---------------+---------------+---------------+
873 * | status |
874 * +---------------+---------------+---------------+---------------+
875 *
876 */
877 if (len != 4)
878 goto invalid;
879 /* status */
880 ND_PRINT(", status 0x%08x", GET_BE_U_4(cp));
881 break;
882 default:
883 ND_TCHECK_LEN(cp, len);
884 }
885 return;
886
887 invalid: /* skip the undersized data */
888 nd_print_invalid(ndo);
889 ND_TCHECK_LEN(cp, len);
890 }
891
892 static void
893 of10_bsn_actions_print(netdissect_options *ndo,
894 const u_char *cp, u_int len)
895 {
896 uint32_t subtype, vlan_tag;
897
898 if (len < 4)
899 goto invalid;
900 /* subtype */
901 subtype = GET_BE_U_4(cp);
902 OF_FWD(4);
903 ND_PRINT("\n\t subtype %s", tok2str(bsn_action_subtype_str, "unknown (0x%08x)", subtype));
904 switch (subtype) {
905 case BSN_ACTION_MIRROR:
906 /*
907 * 0 1 2 3
908 * 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
909 * +---------------+---------------+---------------+---------------+
910 * | subtype |
911 * +---------------+---------------+---------------+---------------+
912 * | dest_port |
913 * +---------------+---------------+---------------+---------------+
914 * | vlan_tag |
915 * +---------------+---------------+---------------+---------------+
916 * | copy_stage | pad |
917 * +---------------+---------------+---------------+---------------+
918 *
919 */
920 if (len != 12)
921 goto invalid;
922 /* dest_port */
923 ND_PRINT(", dest_port %u", GET_BE_U_4(cp));
924 OF_FWD(4);
925 /* vlan_tag */
926 vlan_tag = GET_BE_U_4(cp);
927 OF_FWD(4);
928 switch (vlan_tag >> 16) {
929 case 0:
930 ND_PRINT(", vlan_tag none");
931 break;
932 case ETHERTYPE_8021Q:
933 ND_PRINT(", vlan_tag 802.1Q (%s)", ieee8021q_tci_string(vlan_tag & 0xffff));
934 break;
935 default:
936 ND_PRINT(", vlan_tag unknown (0x%04x)", vlan_tag >> 16);
937 }
938 /* copy_stage */
939 ND_PRINT(", copy_stage %s",
940 tok2str(bsn_mirror_copy_stage_str, "unknown (%u)", GET_U_1(cp)));
941 OF_FWD(1);
942 /* pad */
943 /* Always the last field, check bounds. */
944 ND_TCHECK_3(cp);
945 break;
946 default:
947 ND_TCHECK_LEN(cp, len);
948 }
949 return;
950
951 invalid:
952 nd_print_invalid(ndo);
953 ND_TCHECK_LEN(cp, len);
954 }
955
956 static void
957 of10_vendor_action_print(netdissect_options *ndo,
958 const u_char *cp, u_int len)
959 {
960 uint32_t vendor;
961 void (*decoder)(netdissect_options *, const u_char *, u_int);
962
963 if (len < 4)
964 goto invalid;
965 /* vendor */
966 vendor = GET_BE_U_4(cp);
967 OF_FWD(4);
968 ND_PRINT(", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor));
969 /* data */
970 decoder =
971 vendor == OUI_BSN ? of10_bsn_actions_print :
972 of_data_print;
973 decoder(ndo, cp, len);
974 return;
975
976 invalid: /* skip the undersized data */
977 nd_print_invalid(ndo);
978 ND_TCHECK_LEN(cp, len);
979 }
980
981 static void
982 of10_vendor_message_print(netdissect_options *ndo,
983 const u_char *cp, u_int len)
984 {
985 uint32_t vendor;
986 void (*decoder)(netdissect_options *, const u_char *, u_int);
987
988 if (len < 4)
989 goto invalid;
990 /* vendor */
991 vendor = GET_BE_U_4(cp);
992 OF_FWD(4);
993 ND_PRINT(", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor));
994 /* data */
995 decoder =
996 vendor == OUI_BSN ? of10_bsn_message_print :
997 of_data_print;
998 decoder(ndo, cp, len);
999 return;
1000
1001 invalid: /* skip the undersized data */
1002 nd_print_invalid(ndo);
1003 ND_TCHECK_LEN(cp, len);
1004 }
1005
1006 /* Vendor ID is mandatory, data is optional. */
1007 static void
1008 of10_vendor_data_print(netdissect_options *ndo,
1009 const u_char *cp, u_int len)
1010 {
1011 uint32_t vendor;
1012
1013 if (len < 4)
1014 goto invalid;
1015 /* vendor */
1016 vendor = GET_BE_U_4(cp);
1017 OF_FWD(4);
1018 ND_PRINT(", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor));
1019 /* data */
1020 of_data_print(ndo, cp, len);
1021 return;
1022
1023 invalid: /* skip the undersized data */
1024 nd_print_invalid(ndo);
1025 ND_TCHECK_LEN(cp, len);
1026 }
1027
1028 static void
1029 of10_packet_data_print(netdissect_options *ndo,
1030 const u_char *cp, const u_int len)
1031 {
1032 if (len == 0)
1033 return;
1034 /* data */
1035 ND_PRINT("\n\t data (%u octets)", len);
1036 if (ndo->ndo_vflag < 3) {
1037 ND_TCHECK_LEN(cp, len);
1038 return;
1039 }
1040 ndo->ndo_vflag -= 3;
1041 ND_PRINT(", frame decoding below\n");
1042 ether_print(ndo, cp, len, ND_BYTES_AVAILABLE_AFTER(cp), NULL, NULL);
1043 ndo->ndo_vflag += 3;
1044 }
1045
1046 /* [OF10] Section 5.2.1 */
1047 static void
1048 of10_phy_ports_print(netdissect_options *ndo,
1049 const u_char *cp, u_int len)
1050 {
1051 while (len) {
1052 if (len < OF_PHY_PORT_FIXLEN)
1053 goto invalid;
1054 /* port_no */
1055 ND_PRINT("\n\t port_no %s",
1056 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1057 OF_FWD(2);
1058 /* hw_addr */
1059 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp));
1060 OF_FWD(MAC_ADDR_LEN);
1061 /* name */
1062 ND_PRINT(", name '");
1063 (void)nd_print(ndo, cp, cp + OFP_MAX_PORT_NAME_LEN);
1064 ND_PRINT("'");
1065 OF_FWD(OFP_MAX_PORT_NAME_LEN);
1066
1067 if (ndo->ndo_vflag < 2) {
1068 OF_CHK_FWD(24);
1069 continue;
1070 }
1071 /* config */
1072 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp));
1073 of_bitmap_print(ndo, ofppc_bm, GET_BE_U_4(cp), OFPPC_U);
1074 OF_FWD(4);
1075 /* state */
1076 ND_PRINT("\n\t state 0x%08x", GET_BE_U_4(cp));
1077 of_bitmap_print(ndo, ofpps_bm, GET_BE_U_4(cp), OFPPS_U);
1078 OF_FWD(4);
1079 /* curr */
1080 ND_PRINT("\n\t curr 0x%08x", GET_BE_U_4(cp));
1081 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
1082 OF_FWD(4);
1083 /* advertised */
1084 ND_PRINT("\n\t advertised 0x%08x", GET_BE_U_4(cp));
1085 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
1086 OF_FWD(4);
1087 /* supported */
1088 ND_PRINT("\n\t supported 0x%08x", GET_BE_U_4(cp));
1089 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
1090 OF_FWD(4);
1091 /* peer */
1092 ND_PRINT("\n\t peer 0x%08x", GET_BE_U_4(cp));
1093 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
1094 OF_FWD(4);
1095 } /* while */
1096 return;
1097
1098 invalid: /* skip the undersized trailing data */
1099 nd_print_invalid(ndo);
1100 ND_TCHECK_LEN(cp, len);
1101 }
1102
1103 /* [OF10] Section 5.2.2 */
1104 static void
1105 of10_queue_props_print(netdissect_options *ndo,
1106 const u_char *cp, u_int len)
1107 {
1108 while (len) {
1109 uint16_t property, plen;
1110 u_char plen_bogus = 0, skip = 0;
1111
1112 if (len < OF_QUEUE_PROP_MINLEN)
1113 goto invalid;
1114 /* property */
1115 property = GET_BE_U_2(cp);
1116 OF_FWD(2);
1117 ND_PRINT("\n\t property %s", tok2str(ofpqt_str, "invalid (0x%04x)", property));
1118 /* len */
1119 plen = GET_BE_U_2(cp);
1120 OF_FWD(2);
1121 ND_PRINT(", len %u", plen);
1122 if (plen < OF_QUEUE_PROP_MINLEN || plen > len + 4)
1123 goto invalid;
1124 /* pad */
1125 /* Sometimes the last field, check bounds. */
1126 OF_CHK_FWD(4);
1127 /* property-specific constraints and decoding */
1128 switch (property) {
1129 case OFPQT_NONE:
1130 plen_bogus = plen != OF_QUEUE_PROP_MINLEN;
1131 break;
1132 case OFPQT_MIN_RATE:
1133 plen_bogus = plen != OF_QUEUE_PROP_MIN_RATE_FIXLEN;
1134 break;
1135 default:
1136 skip = 1;
1137 }
1138 if (plen_bogus) {
1139 ND_PRINT(" (bogus)");
1140 skip = 1;
1141 }
1142 if (skip) {
1143 /*
1144 * plen >= OF_QUEUE_PROP_MINLEN
1145 * cp is OF_QUEUE_PROP_MINLEN bytes in
1146 */
1147 OF_CHK_FWD(plen - OF_QUEUE_PROP_MINLEN);
1148 continue;
1149 }
1150 if (property == OFPQT_MIN_RATE) { /* the only case of property decoding */
1151 /* rate */
1152 uint16_t rate = GET_BE_U_2(cp);
1153 OF_FWD(2);
1154 if (rate > 1000)
1155 ND_PRINT(", rate disabled");
1156 else
1157 ND_PRINT(", rate %u.%u%%", rate / 10, rate % 10);
1158 /* pad */
1159 /* Sometimes the last field, check bounds. */
1160 OF_CHK_FWD(6);
1161 }
1162 } /* while */
1163 return;
1164
1165 invalid: /* skip the rest of queue properties */
1166 nd_print_invalid(ndo);
1167 ND_TCHECK_LEN(cp, len);
1168 }
1169
1170 /* ibid */
1171 static void
1172 of10_queues_print(netdissect_options *ndo,
1173 const u_char *cp, u_int len)
1174 {
1175 while (len) {
1176 uint16_t desclen;
1177
1178 if (len < OF_PACKET_QUEUE_MINLEN)
1179 goto invalid;
1180 /* queue_id */
1181 ND_PRINT("\n\t queue_id %u", GET_BE_U_4(cp));
1182 OF_FWD(4);
1183 /* len */
1184 desclen = GET_BE_U_2(cp);
1185 OF_FWD(2);
1186 ND_PRINT(", len %u", desclen);
1187 if (desclen < OF_PACKET_QUEUE_MINLEN || desclen > len + 6)
1188 goto invalid;
1189 /* pad */
1190 /* Sometimes the last field, check bounds. */
1191 OF_CHK_FWD(2);
1192 /* properties */
1193 if (ndo->ndo_vflag >= 2)
1194 of10_queue_props_print(ndo, cp, desclen - OF_PACKET_QUEUE_MINLEN);
1195 else
1196 ND_TCHECK_LEN(cp, desclen - OF_PACKET_QUEUE_MINLEN);
1197 OF_FWD(desclen - OF_PACKET_QUEUE_MINLEN);
1198 } /* while */
1199 return;
1200
1201 invalid: /* skip the rest of queues */
1202 nd_print_invalid(ndo);
1203 ND_TCHECK_LEN(cp, len);
1204 }
1205
1206 /* [OF10] Section 5.2.3 */
1207 static void
1208 of10_match_print(netdissect_options *ndo,
1209 const char *pfx, const u_char *cp)
1210 {
1211 uint32_t wildcards;
1212 uint16_t dl_type;
1213 uint8_t nw_proto;
1214 u_int nw_bits;
1215 const char *field_name;
1216
1217 /* wildcards */
1218 wildcards = GET_BE_U_4(cp);
1219 if (wildcards & OFPFW_U)
1220 ND_PRINT("%swildcards 0x%08x (bogus)", pfx, wildcards);
1221 cp += 4;
1222 /* in_port */
1223 if (! (wildcards & OFPFW_IN_PORT))
1224 ND_PRINT("%smatch in_port %s", pfx,
1225 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1226 cp += 2;
1227 /* dl_src */
1228 if (! (wildcards & OFPFW_DL_SRC))
1229 ND_PRINT("%smatch dl_src %s", pfx, GET_ETHERADDR_STRING(cp));
1230 cp += MAC_ADDR_LEN;
1231 /* dl_dst */
1232 if (! (wildcards & OFPFW_DL_DST))
1233 ND_PRINT("%smatch dl_dst %s", pfx, GET_ETHERADDR_STRING(cp));
1234 cp += MAC_ADDR_LEN;
1235 /* dl_vlan */
1236 if (! (wildcards & OFPFW_DL_VLAN))
1237 ND_PRINT("%smatch dl_vlan %s", pfx, vlan_str(GET_BE_U_2(cp)));
1238 cp += 2;
1239 /* dl_vlan_pcp */
1240 if (! (wildcards & OFPFW_DL_VLAN_PCP))
1241 ND_PRINT("%smatch dl_vlan_pcp %s", pfx, pcp_str(GET_U_1(cp)));
1242 cp += 1;
1243 /* pad1 */
1244 cp += 1;
1245 /* dl_type */
1246 dl_type = GET_BE_U_2(cp);
1247 cp += 2;
1248 if (! (wildcards & OFPFW_DL_TYPE))
1249 ND_PRINT("%smatch dl_type 0x%04x", pfx, dl_type);
1250 /* nw_tos */
1251 if (! (wildcards & OFPFW_NW_TOS))
1252 ND_PRINT("%smatch nw_tos 0x%02x", pfx, GET_U_1(cp));
1253 cp += 1;
1254 /* nw_proto */
1255 nw_proto = GET_U_1(cp);
1256 cp += 1;
1257 if (! (wildcards & OFPFW_NW_PROTO)) {
1258 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_ARP
1259 ? "arp_opcode" : "nw_proto";
1260 ND_PRINT("%smatch %s %u", pfx, field_name, nw_proto);
1261 }
1262 /* pad2 */
1263 cp += 2;
1264 /* nw_src */
1265 nw_bits = (wildcards & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT;
1266 if (nw_bits < 32)
1267 ND_PRINT("%smatch nw_src %s/%u", pfx, GET_IPADDR_STRING(cp), 32 - nw_bits);
1268 cp += 4;
1269 /* nw_dst */
1270 nw_bits = (wildcards & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT;
1271 if (nw_bits < 32)
1272 ND_PRINT("%smatch nw_dst %s/%u", pfx, GET_IPADDR_STRING(cp), 32 - nw_bits);
1273 cp += 4;
1274 /* tp_src */
1275 if (! (wildcards & OFPFW_TP_SRC)) {
1276 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_IP
1277 && ! (wildcards & OFPFW_NW_PROTO) && nw_proto == IPPROTO_ICMP
1278 ? "icmp_type" : "tp_src";
1279 ND_PRINT("%smatch %s %u", pfx, field_name, GET_BE_U_2(cp));
1280 }
1281 cp += 2;
1282 /* tp_dst */
1283 /* The last unconditional check was at nw_proto, so have an "else" here. */
1284 if (! (wildcards & OFPFW_TP_DST)) {
1285 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_IP
1286 && ! (wildcards & OFPFW_NW_PROTO) && nw_proto == IPPROTO_ICMP
1287 ? "icmp_code" : "tp_dst";
1288 ND_PRINT("%smatch %s %u", pfx, field_name, GET_BE_U_2(cp));
1289 }
1290 else
1291 ND_TCHECK_2(cp);
1292 }
1293
1294 /* [OF10] Section 5.2.4 */
1295 static void
1296 of10_actions_print(netdissect_options *ndo,
1297 const char *pfx, const u_char *cp, u_int len)
1298 {
1299 while (len) {
1300 uint16_t type, alen, output_port;
1301 u_char alen_bogus = 0, skip = 0;
1302
1303 if (len < OF_ACTION_MINLEN)
1304 goto invalid;
1305 /* type */
1306 type = GET_BE_U_2(cp);
1307 OF_FWD(2);
1308 ND_PRINT("%saction type %s", pfx, tok2str(ofpat_str, "invalid (0x%04x)", type));
1309 /* length */
1310 alen = GET_BE_U_2(cp);
1311 OF_FWD(2);
1312 ND_PRINT(", len %u", alen);
1313 /*
1314 * The 4-byte "pad" in the specification is not a field of the
1315 * action header, but a placeholder to illustrate the 64-bit
1316 * alignment requirement. Action type specific case blocks
1317 * below fetch these 4 bytes.
1318 */
1319
1320 /* On action size underrun/overrun skip the rest of the action list. */
1321 if (alen < OF_ACTION_MINLEN || alen > len + 4)
1322 goto invalid;
1323 /*
1324 * After validating the basic length constraint it will be safe
1325 * to skip the current action if the action size is not valid
1326 * for the type or the type is invalid.
1327 */
1328 switch (type) {
1329 case OFPAT_OUTPUT:
1330 case OFPAT_SET_VLAN_VID:
1331 case OFPAT_SET_VLAN_PCP:
1332 case OFPAT_STRIP_VLAN:
1333 case OFPAT_SET_NW_SRC:
1334 case OFPAT_SET_NW_DST:
1335 case OFPAT_SET_NW_TOS:
1336 case OFPAT_SET_TP_SRC:
1337 case OFPAT_SET_TP_DST:
1338 alen_bogus = alen != 8;
1339 break;
1340 case OFPAT_SET_DL_SRC:
1341 case OFPAT_SET_DL_DST:
1342 case OFPAT_ENQUEUE:
1343 alen_bogus = alen != 16;
1344 break;
1345 case OFPAT_VENDOR:
1346 alen_bogus = alen % 8 != 0; /* already >= 8 so far */
1347 break;
1348 default:
1349 skip = 1;
1350 }
1351 if (alen_bogus) {
1352 ND_PRINT(" (bogus)");
1353 skip = 1;
1354 }
1355 if (skip) {
1356 /*
1357 * alen >= OF_ACTION_MINLEN
1358 * cp is 4 bytes in
1359 */
1360 OF_CHK_FWD(alen - 4);
1361 continue;
1362 }
1363 /* OK to decode the rest of the action structure */
1364 switch (type) {
1365 case OFPAT_OUTPUT:
1366 /* port */
1367 output_port = GET_BE_U_2(cp);
1368 OF_FWD(2);
1369 ND_PRINT(", port %s", tok2str(ofpp_str, "%u", output_port));
1370 /* max_len */
1371 if (output_port == OFPP_CONTROLLER)
1372 ND_PRINT(", max_len %u", GET_BE_U_2(cp));
1373 else
1374 ND_TCHECK_2(cp);
1375 OF_FWD(2);
1376 break;
1377 case OFPAT_SET_VLAN_VID:
1378 /* vlan_vid */
1379 ND_PRINT(", vlan_vid %s", vlan_str(GET_BE_U_2(cp)));
1380 OF_FWD(2);
1381 /* pad */
1382 /* Sometimes the last field, check bounds. */
1383 OF_CHK_FWD(2);
1384 break;
1385 case OFPAT_SET_VLAN_PCP:
1386 /* vlan_pcp */
1387 ND_PRINT(", vlan_pcp %s", pcp_str(GET_U_1(cp)));
1388 OF_FWD(1);
1389 /* pad */
1390 /* Sometimes the last field, check bounds. */
1391 OF_CHK_FWD(3);
1392 break;
1393 case OFPAT_SET_DL_SRC:
1394 case OFPAT_SET_DL_DST:
1395 /* dl_addr */
1396 ND_PRINT(", dl_addr %s", GET_ETHERADDR_STRING(cp));
1397 OF_FWD(MAC_ADDR_LEN);
1398 /* pad */
1399 /* Sometimes the last field, check bounds. */
1400 OF_CHK_FWD(6);
1401 break;
1402 case OFPAT_SET_NW_SRC:
1403 case OFPAT_SET_NW_DST:
1404 /* nw_addr */
1405 ND_PRINT(", nw_addr %s", GET_IPADDR_STRING(cp));
1406 OF_FWD(4);
1407 break;
1408 case OFPAT_SET_NW_TOS:
1409 /* nw_tos */
1410 ND_PRINT(", nw_tos 0x%02x", GET_U_1(cp));
1411 OF_FWD(1);
1412 /* pad */
1413 /* Sometimes the last field, check bounds. */
1414 OF_CHK_FWD(3);
1415 break;
1416 case OFPAT_SET_TP_SRC:
1417 case OFPAT_SET_TP_DST:
1418 /* nw_tos */
1419 ND_PRINT(", tp_port %u", GET_BE_U_2(cp));
1420 OF_FWD(2);
1421 /* pad */
1422 /* Sometimes the last field, check bounds. */
1423 OF_CHK_FWD(2);
1424 break;
1425 case OFPAT_ENQUEUE:
1426 /* port */
1427 ND_PRINT(", port %s",
1428 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1429 OF_FWD(2);
1430 /* pad */
1431 OF_FWD(6);
1432 /* queue_id */
1433 ND_PRINT(", queue_id %s",
1434 tok2str(ofpq_str, "%u", GET_BE_U_4(cp)));
1435 OF_FWD(4);
1436 break;
1437 case OFPAT_VENDOR:
1438 of10_vendor_action_print(ndo, cp, alen - 4);
1439 OF_FWD(alen - 4);
1440 break;
1441 case OFPAT_STRIP_VLAN:
1442 /* pad */
1443 /* Sometimes the last field, check bounds. */
1444 OF_CHK_FWD(4);
1445 break;
1446 } /* switch */
1447 } /* while */
1448 return;
1449
1450 invalid: /* skip the rest of actions */
1451 nd_print_invalid(ndo);
1452 ND_TCHECK_LEN(cp, len);
1453 }
1454
1455 /* [OF10] Section 5.3.1 */
1456 static void
1457 of10_features_reply_print(netdissect_options *ndo,
1458 const u_char *cp, u_int len)
1459 {
1460 /* datapath_id */
1461 ND_PRINT("\n\t dpid 0x%016" PRIx64, GET_BE_U_8(cp));
1462 OF_FWD(8);
1463 /* n_buffers */
1464 ND_PRINT(", n_buffers %u", GET_BE_U_4(cp));
1465 OF_FWD(4);
1466 /* n_tables */
1467 ND_PRINT(", n_tables %u", GET_U_1(cp));
1468 OF_FWD(1);
1469 /* pad */
1470 OF_FWD(3);
1471 /* capabilities */
1472 ND_PRINT("\n\t capabilities 0x%08x", GET_BE_U_4(cp));
1473 of_bitmap_print(ndo, ofp_capabilities_bm, GET_BE_U_4(cp), OFPCAP_U);
1474 OF_FWD(4);
1475 /* actions */
1476 ND_PRINT("\n\t actions 0x%08x", GET_BE_U_4(cp));
1477 of_bitmap_print(ndo, ofpat_bm, GET_BE_U_4(cp), OFPAT_U);
1478 OF_FWD(4);
1479 /* ports */
1480 of10_phy_ports_print(ndo, cp, len);
1481 }
1482
1483 /* [OF10] Section 5.3.3 */
1484 static void
1485 of10_flow_mod_print(netdissect_options *ndo,
1486 const u_char *cp, u_int len)
1487 {
1488 uint16_t command;
1489
1490 /* match */
1491 of10_match_print(ndo, "\n\t ", cp);
1492 OF_FWD(OF_MATCH_FIXLEN);
1493 /* cookie */
1494 ND_PRINT("\n\t cookie 0x%016" PRIx64, GET_BE_U_8(cp));
1495 OF_FWD(8);
1496 /* command */
1497 command = GET_BE_U_2(cp);
1498 ND_PRINT(", command %s", tok2str(ofpfc_str, "invalid (0x%04x)", command));
1499 OF_FWD(2);
1500 /* idle_timeout */
1501 if (GET_BE_U_2(cp))
1502 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp));
1503 OF_FWD(2);
1504 /* hard_timeout */
1505 if (GET_BE_U_2(cp))
1506 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp));
1507 OF_FWD(2);
1508 /* priority */
1509 if (GET_BE_U_2(cp))
1510 ND_PRINT(", priority %u", GET_BE_U_2(cp));
1511 OF_FWD(2);
1512 /* buffer_id */
1513 if (command == OFPFC_ADD || command == OFPFC_MODIFY ||
1514 command == OFPFC_MODIFY_STRICT)
1515 ND_PRINT(", buffer_id %s",
1516 tok2str(bufferid_str, "0x%08x", GET_BE_U_4(cp)));
1517 OF_FWD(4);
1518 /* out_port */
1519 if (command == OFPFC_DELETE || command == OFPFC_DELETE_STRICT)
1520 ND_PRINT(", out_port %s",
1521 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1522 OF_FWD(2);
1523 /* flags */
1524 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp));
1525 of_bitmap_print(ndo, ofpff_bm, GET_BE_U_2(cp), OFPFF_U);
1526 OF_FWD(2);
1527 /* actions */
1528 of10_actions_print(ndo, "\n\t ", cp, len);
1529 }
1530
1531 /* ibid */
1532 static void
1533 of10_port_mod_print(netdissect_options *ndo,
1534 const u_char *cp)
1535 {
1536 /* port_no */
1537 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1538 cp += 2;
1539 /* hw_addr */
1540 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp));
1541 cp += MAC_ADDR_LEN;
1542 /* config */
1543 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp));
1544 of_bitmap_print(ndo, ofppc_bm, GET_BE_U_4(cp), OFPPC_U);
1545 cp += 4;
1546 /* mask */
1547 ND_PRINT("\n\t mask 0x%08x", GET_BE_U_4(cp));
1548 of_bitmap_print(ndo, ofppc_bm, GET_BE_U_4(cp), OFPPC_U);
1549 cp += 4;
1550 /* advertise */
1551 ND_PRINT("\n\t advertise 0x%08x", GET_BE_U_4(cp));
1552 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
1553 cp += 4;
1554 /* pad */
1555 /* Always the last field, check bounds. */
1556 ND_TCHECK_4(cp);
1557 }
1558
1559 /* [OF10] Section 5.3.5 */
1560 static void
1561 of10_stats_request_print(netdissect_options *ndo,
1562 const u_char *cp, u_int len)
1563 {
1564 uint16_t type;
1565
1566 /* type */
1567 type = GET_BE_U_2(cp);
1568 OF_FWD(2);
1569 ND_PRINT("\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type));
1570 /* flags */
1571 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp));
1572 if (GET_BE_U_2(cp))
1573 ND_PRINT(" (bogus)");
1574 OF_FWD(2);
1575 /* type-specific body of one of fixed lengths */
1576 switch(type) {
1577 case OFPST_DESC:
1578 case OFPST_TABLE:
1579 if (len)
1580 goto invalid;
1581 return;
1582 case OFPST_FLOW:
1583 case OFPST_AGGREGATE:
1584 if (len != OF_FLOW_STATS_REQUEST_FIXLEN)
1585 goto invalid;
1586 /* match */
1587 of10_match_print(ndo, "\n\t ", cp);
1588 OF_FWD(OF_MATCH_FIXLEN);
1589 /* table_id */
1590 ND_PRINT("\n\t table_id %s",
1591 tok2str(tableid_str, "%u", GET_U_1(cp)));
1592 OF_FWD(1);
1593 /* pad */
1594 OF_FWD(1);
1595 /* out_port */
1596 ND_PRINT(", out_port %s",
1597 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1598 return;
1599 case OFPST_PORT:
1600 if (len != OF_PORT_STATS_REQUEST_FIXLEN)
1601 goto invalid;
1602 /* port_no */
1603 ND_PRINT("\n\t port_no %s",
1604 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1605 OF_FWD(2);
1606 /* pad */
1607 /* Always the last field, check bounds. */
1608 OF_CHK_FWD(6);
1609 return;
1610 case OFPST_QUEUE:
1611 if (len != OF_QUEUE_STATS_REQUEST_FIXLEN)
1612 goto invalid;
1613 /* port_no */
1614 ND_PRINT("\n\t port_no %s",
1615 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1616 OF_FWD(2);
1617 /* pad */
1618 OF_FWD(2);
1619 /* queue_id */
1620 ND_PRINT(", queue_id %s",
1621 tok2str(ofpq_str, "%u", GET_BE_U_4(cp)));
1622 return;
1623 case OFPST_VENDOR:
1624 of10_vendor_data_print(ndo, cp, len);
1625 return;
1626 }
1627 return;
1628
1629 invalid: /* skip the message body */
1630 nd_print_invalid(ndo);
1631 ND_TCHECK_LEN(cp, len);
1632 }
1633
1634 /* ibid */
1635 static void
1636 of10_desc_stats_reply_print(netdissect_options *ndo,
1637 const u_char *cp, u_int len)
1638 {
1639 if (len != OF_DESC_STATS_REPLY_FIXLEN)
1640 goto invalid;
1641 /* mfr_desc */
1642 ND_PRINT("\n\t mfr_desc '");
1643 (void)nd_print(ndo, cp, cp + DESC_STR_LEN);
1644 ND_PRINT("'");
1645 OF_FWD(DESC_STR_LEN);
1646 /* hw_desc */
1647 ND_PRINT("\n\t hw_desc '");
1648 (void)nd_print(ndo, cp, cp + DESC_STR_LEN);
1649 ND_PRINT("'");
1650 OF_FWD(DESC_STR_LEN);
1651 /* sw_desc */
1652 ND_PRINT("\n\t sw_desc '");
1653 (void)nd_print(ndo, cp, cp + DESC_STR_LEN);
1654 ND_PRINT("'");
1655 OF_FWD(DESC_STR_LEN);
1656 /* serial_num */
1657 ND_PRINT("\n\t serial_num '");
1658 (void)nd_print(ndo, cp, cp + SERIAL_NUM_LEN);
1659 ND_PRINT("'");
1660 OF_FWD(SERIAL_NUM_LEN);
1661 /* dp_desc */
1662 ND_PRINT("\n\t dp_desc '");
1663 (void)nd_print(ndo, cp, cp + DESC_STR_LEN);
1664 ND_PRINT("'");
1665 return;
1666
1667 invalid: /* skip the message body */
1668 nd_print_invalid(ndo);
1669 ND_TCHECK_LEN(cp, len);
1670 }
1671
1672 /* ibid */
1673 static void
1674 of10_flow_stats_reply_print(netdissect_options *ndo,
1675 const u_char *cp, u_int len)
1676 {
1677 while (len) {
1678 uint16_t entry_len;
1679
1680 if (len < OF_FLOW_STATS_REPLY_MINLEN)
1681 goto invalid;
1682 /* length */
1683 entry_len = GET_BE_U_2(cp);
1684 ND_PRINT("\n\t length %u", entry_len);
1685 if (entry_len < OF_FLOW_STATS_REPLY_MINLEN || entry_len > len)
1686 goto invalid;
1687 OF_FWD(2);
1688 /* table_id */
1689 ND_PRINT(", table_id %s",
1690 tok2str(tableid_str, "%u", GET_U_1(cp)));
1691 OF_FWD(1);
1692 /* pad */
1693 OF_FWD(1);
1694 /* match */
1695 of10_match_print(ndo, "\n\t ", cp);
1696 OF_FWD(OF_MATCH_FIXLEN);
1697 /* duration_sec */
1698 ND_PRINT("\n\t duration_sec %u", GET_BE_U_4(cp));
1699 OF_FWD(4);
1700 /* duration_nsec */
1701 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp));
1702 OF_FWD(4);
1703 /* priority */
1704 ND_PRINT(", priority %u", GET_BE_U_2(cp));
1705 OF_FWD(2);
1706 /* idle_timeout */
1707 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp));
1708 OF_FWD(2);
1709 /* hard_timeout */
1710 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp));
1711 OF_FWD(2);
1712 /* pad2 */
1713 OF_FWD(6);
1714 /* cookie */
1715 ND_PRINT(", cookie 0x%016" PRIx64, GET_BE_U_8(cp));
1716 OF_FWD(8);
1717 /* packet_count */
1718 ND_PRINT(", packet_count %" PRIu64, GET_BE_U_8(cp));
1719 OF_FWD(8);
1720 /* byte_count */
1721 ND_PRINT(", byte_count %" PRIu64, GET_BE_U_8(cp));
1722 OF_FWD(8);
1723 /* actions */
1724 of10_actions_print(ndo, "\n\t ", cp, entry_len - OF_FLOW_STATS_REPLY_MINLEN);
1725 OF_FWD(entry_len - OF_FLOW_STATS_REPLY_MINLEN);
1726 } /* while */
1727 return;
1728
1729 invalid: /* skip the rest of flow statistics entries */
1730 nd_print_invalid(ndo);
1731 ND_TCHECK_LEN(cp, len);
1732 }
1733
1734 /* ibid */
1735 static void
1736 of10_aggregate_stats_reply_print(netdissect_options *ndo,
1737 const u_char *cp, u_int len)
1738 {
1739 if (len != OF_AGGREGATE_STATS_REPLY_FIXLEN)
1740 goto invalid;
1741 /* packet_count */
1742 ND_PRINT("\n\t packet_count %" PRIu64, GET_BE_U_8(cp));
1743 OF_FWD(8);
1744 /* byte_count */
1745 ND_PRINT(", byte_count %" PRIu64, GET_BE_U_8(cp));
1746 OF_FWD(8);
1747 /* flow_count */
1748 ND_PRINT(", flow_count %u", GET_BE_U_4(cp));
1749 OF_FWD(4);
1750 /* pad */
1751 /* Always the last field, check bounds. */
1752 ND_TCHECK_4(cp);
1753 return;
1754
1755 invalid: /* skip the message body */
1756 nd_print_invalid(ndo);
1757 ND_TCHECK_LEN(cp, len);
1758 }
1759
1760 /* ibid */
1761 static void
1762 of10_table_stats_reply_print(netdissect_options *ndo,
1763 const u_char *cp, u_int len)
1764 {
1765 while (len) {
1766 if (len < OF_TABLE_STATS_REPLY_FIXLEN)
1767 goto invalid;
1768 /* table_id */
1769 ND_PRINT("\n\t table_id %s",
1770 tok2str(tableid_str, "%u", GET_U_1(cp)));
1771 OF_FWD(1);
1772 /* pad */
1773 OF_FWD(3);
1774 /* name */
1775 ND_PRINT(", name '");
1776 (void)nd_print(ndo, cp, cp + OFP_MAX_TABLE_NAME_LEN);
1777 ND_PRINT("'");
1778 OF_FWD(OFP_MAX_TABLE_NAME_LEN);
1779 /* wildcards */
1780 ND_PRINT("\n\t wildcards 0x%08x", GET_BE_U_4(cp));
1781 of_bitmap_print(ndo, ofpfw_bm, GET_BE_U_4(cp), OFPFW_U);
1782 OF_FWD(4);
1783 /* max_entries */
1784 ND_PRINT("\n\t max_entries %u", GET_BE_U_4(cp));
1785 OF_FWD(4);
1786 /* active_count */
1787 ND_PRINT(", active_count %u", GET_BE_U_4(cp));
1788 OF_FWD(4);
1789 /* lookup_count */
1790 ND_PRINT(", lookup_count %" PRIu64, GET_BE_U_8(cp));
1791 OF_FWD(8);
1792 /* matched_count */
1793 ND_PRINT(", matched_count %" PRIu64, GET_BE_U_8(cp));
1794 OF_FWD(8);
1795 } /* while */
1796 return;
1797
1798 invalid: /* skip the undersized trailing data */
1799 nd_print_invalid(ndo);
1800 ND_TCHECK_LEN(cp, len);
1801 }
1802
1803 /* ibid */
1804 static void
1805 of10_port_stats_reply_print(netdissect_options *ndo,
1806 const u_char *cp, u_int len)
1807 {
1808 while (len) {
1809 if (len < OF_PORT_STATS_REPLY_FIXLEN)
1810 goto invalid;
1811 /* port_no */
1812 ND_PRINT("\n\t port_no %s",
1813 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1814 OF_FWD(2);
1815 if (ndo->ndo_vflag < 2) {
1816 OF_CHK_FWD(OF_PORT_STATS_REPLY_FIXLEN - 2);
1817 continue;
1818 }
1819 /* pad */
1820 OF_FWD(6);
1821 /* rx_packets */
1822 ND_PRINT(", rx_packets %" PRIu64, GET_BE_U_8(cp));
1823 OF_FWD(8);
1824 /* tx_packets */
1825 ND_PRINT(", tx_packets %" PRIu64, GET_BE_U_8(cp));
1826 OF_FWD(8);
1827 /* rx_bytes */
1828 ND_PRINT(", rx_bytes %" PRIu64, GET_BE_U_8(cp));
1829 OF_FWD(8);
1830 /* tx_bytes */
1831 ND_PRINT(", tx_bytes %" PRIu64, GET_BE_U_8(cp));
1832 OF_FWD(8);
1833 /* rx_dropped */
1834 ND_PRINT(", rx_dropped %" PRIu64, GET_BE_U_8(cp));
1835 OF_FWD(8);
1836 /* tx_dropped */
1837 ND_PRINT(", tx_dropped %" PRIu64, GET_BE_U_8(cp));
1838 OF_FWD(8);
1839 /* rx_errors */
1840 ND_PRINT(", rx_errors %" PRIu64, GET_BE_U_8(cp));
1841 OF_FWD(8);
1842 /* tx_errors */
1843 ND_PRINT(", tx_errors %" PRIu64, GET_BE_U_8(cp));
1844 OF_FWD(8);
1845 /* rx_frame_err */
1846 ND_PRINT(", rx_frame_err %" PRIu64, GET_BE_U_8(cp));
1847 OF_FWD(8);
1848 /* rx_over_err */
1849 ND_PRINT(", rx_over_err %" PRIu64, GET_BE_U_8(cp));
1850 OF_FWD(8);
1851 /* rx_crc_err */
1852 ND_PRINT(", rx_crc_err %" PRIu64, GET_BE_U_8(cp));
1853 OF_FWD(8);
1854 /* collisions */
1855 ND_PRINT(", collisions %" PRIu64, GET_BE_U_8(cp));
1856 OF_FWD(8);
1857 } /* while */
1858 return;
1859
1860 invalid: /* skip the undersized trailing data */
1861 nd_print_invalid(ndo);
1862 ND_TCHECK_LEN(cp, len);
1863 }
1864
1865 /* ibid */
1866 static void
1867 of10_queue_stats_reply_print(netdissect_options *ndo,
1868 const u_char *cp, u_int len)
1869 {
1870 while (len) {
1871 if (len < OF_QUEUE_STATS_REPLY_FIXLEN)
1872 goto invalid;
1873 /* port_no */
1874 ND_PRINT("\n\t port_no %s",
1875 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1876 OF_FWD(2);
1877 /* pad */
1878 OF_FWD(2);
1879 /* queue_id */
1880 ND_PRINT(", queue_id %u", GET_BE_U_4(cp));
1881 OF_FWD(4);
1882 /* tx_bytes */
1883 ND_PRINT(", tx_bytes %" PRIu64, GET_BE_U_8(cp));
1884 OF_FWD(8);
1885 /* tx_packets */
1886 ND_PRINT(", tx_packets %" PRIu64, GET_BE_U_8(cp));
1887 OF_FWD(8);
1888 /* tx_errors */
1889 ND_PRINT(", tx_errors %" PRIu64, GET_BE_U_8(cp));
1890 OF_FWD(8);
1891 } /* while */
1892 return;
1893
1894 invalid: /* skip the undersized trailing data */
1895 nd_print_invalid(ndo);
1896 ND_TCHECK_LEN(cp, len);
1897 }
1898
1899 /* ibid */
1900 static void
1901 of10_stats_reply_print(netdissect_options *ndo,
1902 const u_char *cp, u_int len)
1903 {
1904 uint16_t type;
1905
1906 /* type */
1907 type = GET_BE_U_2(cp);
1908 ND_PRINT("\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type));
1909 OF_FWD(2);
1910 /* flags */
1911 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp));
1912 of_bitmap_print(ndo, ofpsf_reply_bm, GET_BE_U_2(cp), OFPSF_REPLY_U);
1913 OF_FWD(2);
1914
1915 if (ndo->ndo_vflag > 0) {
1916 void (*decoder)(netdissect_options *, const u_char *, u_int) =
1917 type == OFPST_DESC ? of10_desc_stats_reply_print :
1918 type == OFPST_FLOW ? of10_flow_stats_reply_print :
1919 type == OFPST_AGGREGATE ? of10_aggregate_stats_reply_print :
1920 type == OFPST_TABLE ? of10_table_stats_reply_print :
1921 type == OFPST_PORT ? of10_port_stats_reply_print :
1922 type == OFPST_QUEUE ? of10_queue_stats_reply_print :
1923 type == OFPST_VENDOR ? of10_vendor_data_print :
1924 NULL;
1925 if (decoder != NULL) {
1926 decoder(ndo, cp, len);
1927 return;
1928 }
1929 }
1930 ND_TCHECK_LEN(cp, len);
1931 }
1932
1933 /* [OF10] Section 5.3.6 */
1934 static void
1935 of10_packet_out_print(netdissect_options *ndo,
1936 const u_char *cp, u_int len)
1937 {
1938 uint16_t actions_len;
1939
1940 /* buffer_id */
1941 ND_PRINT("\n\t buffer_id 0x%08x", GET_BE_U_4(cp));
1942 OF_FWD(4);
1943 /* in_port */
1944 ND_PRINT(", in_port %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1945 OF_FWD(2);
1946 /* actions_len */
1947 actions_len = GET_BE_U_2(cp);
1948 OF_FWD(2);
1949 if (actions_len > len)
1950 goto invalid;
1951 /* actions */
1952 of10_actions_print(ndo, "\n\t ", cp, actions_len);
1953 OF_FWD(actions_len);
1954 /* data */
1955 of10_packet_data_print(ndo, cp, len);
1956 return;
1957
1958 invalid: /* skip the rest of the message body */
1959 nd_print_invalid(ndo);
1960 ND_TCHECK_LEN(cp, len);
1961 }
1962
1963 /* [OF10] Section 5.4.1 */
1964 static void
1965 of10_packet_in_print(netdissect_options *ndo,
1966 const u_char *cp, u_int len)
1967 {
1968 /* buffer_id */
1969 ND_PRINT("\n\t buffer_id %s",
1970 tok2str(bufferid_str, "0x%08x", GET_BE_U_4(cp)));
1971 OF_FWD(4);
1972 /* total_len */
1973 ND_PRINT(", total_len %u", GET_BE_U_2(cp));
1974 OF_FWD(2);
1975 /* in_port */
1976 ND_PRINT(", in_port %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1977 OF_FWD(2);
1978 /* reason */
1979 ND_PRINT(", reason %s",
1980 tok2str(ofpr_str, "invalid (0x%02x)", GET_U_1(cp)));
1981 OF_FWD(1);
1982 /* pad */
1983 /* Sometimes the last field, check bounds. */
1984 OF_CHK_FWD(1);
1985 /* data */
1986 of10_packet_data_print(ndo, cp, len);
1987 }
1988
1989 /* [OF10] Section 5.4.2 */
1990 static void
1991 of10_flow_removed_print(netdissect_options *ndo,
1992 const u_char *cp)
1993 {
1994 /* match */
1995 of10_match_print(ndo, "\n\t ", cp);
1996 cp += OF_MATCH_FIXLEN;
1997 /* cookie */
1998 ND_PRINT("\n\t cookie 0x%016" PRIx64, GET_BE_U_8(cp));
1999 cp += 8;
2000 /* priority */
2001 if (GET_BE_U_2(cp))
2002 ND_PRINT(", priority %u", GET_BE_U_2(cp));
2003 cp += 2;
2004 /* reason */
2005 ND_PRINT(", reason %s",
2006 tok2str(ofprr_str, "unknown (0x%02x)", GET_U_1(cp)));
2007 cp += 1;
2008 /* pad */
2009 cp += 1;
2010 /* duration_sec */
2011 ND_PRINT(", duration_sec %u", GET_BE_U_4(cp));
2012 cp += 4;
2013 /* duration_nsec */
2014 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp));
2015 cp += 4;
2016 /* idle_timeout */
2017 if (GET_BE_U_2(cp))
2018 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp));
2019 cp += 2;
2020 /* pad2 */
2021 cp += 2;
2022 /* packet_count */
2023 ND_PRINT(", packet_count %" PRIu64, GET_BE_U_8(cp));
2024 cp += 8;
2025 /* byte_count */
2026 ND_PRINT(", byte_count %" PRIu64, GET_BE_U_8(cp));
2027 }
2028
2029 /* [OF10] Section 5.4.4 */
2030 static void
2031 of10_error_print(netdissect_options *ndo,
2032 const u_char *cp, u_int len)
2033 {
2034 uint16_t type, code;
2035 const struct tok *code_str[OFPET_MAX + 1] = {
2036 /* [OFPET_HELLO_FAILED ] = */ ofphfc_str,
2037 /* [OFPET_BAD_REQUEST ] = */ ofpbrc_str,
2038 /* [OFPET_BAD_ACTION ] = */ ofpbac_str,
2039 /* [OFPET_FLOW_MOD_FAILED] = */ ofpfmfc_str,
2040 /* [OFPET_PORT_MOD_FAILED] = */ ofppmfc_str,
2041 /* [OFPET_QUEUE_OP_FAILED] = */ ofpqofc_str,
2042 };
2043
2044 /* type */
2045 type = GET_BE_U_2(cp);
2046 OF_FWD(2);
2047 ND_PRINT("\n\t type %s", tok2str(ofpet_str, "invalid (0x%04x)", type));
2048 /* code */
2049 code = GET_BE_U_2(cp);
2050 OF_FWD(2);
2051 if (type <= OFPET_MAX && code_str[type] != NULL)
2052 ND_PRINT(", code %s",
2053 tok2str(code_str[type], "invalid (0x%04x)", code));
2054 else
2055 ND_PRINT(", code invalid (0x%04x)", code);
2056 /* data */
2057 of_data_print(ndo, cp, len);
2058 }
2059
2060 void
2061 of10_message_print(netdissect_options *ndo,
2062 const u_char *cp, uint16_t len, const uint8_t type)
2063 {
2064 /*
2065 * Here "cp" and "len" stand for the message part beyond the common
2066 * OpenFlow 1.0 header, if any. Subtract OF_HEADER_FIXLEN from the
2067 * type-specific lengths, which include the header length, when (and
2068 * only when) validating the length in this function. No other code
2069 * in this file needs to take OF_HEADER_FIXLEN into account.
2070 *
2071 * Most message types are longer than just the header, and the length
2072 * constraints may be complex. When possible, validate the constraint
2073 * completely here, otherwise check that the message is long enough to
2074 * begin the decoding and let the lower-layer function do any remaining
2075 * validation.
2076 */
2077 switch (type) {
2078 /* OpenFlow header only. */
2079 case OFPT_FEATURES_REQUEST: /* [OF10] Section 5.3.1 */
2080 case OFPT_GET_CONFIG_REQUEST: /* [OF10] Section 5.3.2 */
2081 case OFPT_BARRIER_REQUEST: /* [OF10] Section 5.3.7 */
2082 case OFPT_BARRIER_REPLY: /* ibid */
2083 if (len)
2084 goto invalid;
2085 return;
2086
2087 /* OpenFlow header and fixed-size message body. */
2088 case OFPT_SET_CONFIG: /* [OF10] Section 5.3.2 */
2089 case OFPT_GET_CONFIG_REPLY: /* ibid */
2090 if (len != OF_SWITCH_CONFIG_FIXLEN - OF_HEADER_FIXLEN)
2091 goto invalid;
2092 if (ndo->ndo_vflag < 1)
2093 break;
2094 /* flags */
2095 ND_PRINT("\n\t flags %s",
2096 tok2str(ofp_config_str, "invalid (0x%04x)",
2097 GET_BE_U_2(cp)));
2098 OF_FWD(2);
2099 /* miss_send_len */
2100 ND_PRINT(", miss_send_len %u", GET_BE_U_2(cp));
2101 return;
2102 case OFPT_PORT_MOD:
2103 if (len != OF_PORT_MOD_FIXLEN - OF_HEADER_FIXLEN)
2104 goto invalid;
2105 if (ndo->ndo_vflag < 1)
2106 break;
2107 of10_port_mod_print(ndo, cp);
2108 return;
2109 case OFPT_QUEUE_GET_CONFIG_REQUEST: /* [OF10] Section 5.3.4 */
2110 if (len != OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN - OF_HEADER_FIXLEN)
2111 goto invalid;
2112 if (ndo->ndo_vflag < 1)
2113 break;
2114 /* port */
2115 ND_PRINT("\n\t port %s",
2116 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
2117 OF_FWD(2);
2118 /* pad */
2119 /* Always the last field, check bounds. */
2120 ND_TCHECK_2(cp);
2121 return;
2122 case OFPT_FLOW_REMOVED:
2123 if (len != OF_FLOW_REMOVED_FIXLEN - OF_HEADER_FIXLEN)
2124 goto invalid;
2125 if (ndo->ndo_vflag < 1)
2126 break;
2127 of10_flow_removed_print(ndo, cp);
2128 return;
2129 case OFPT_PORT_STATUS: /* [OF10] Section 5.4.3 */
2130 if (len != OF_PORT_STATUS_FIXLEN - OF_HEADER_FIXLEN)
2131 goto invalid;
2132 if (ndo->ndo_vflag < 1)
2133 break;
2134 /* reason */
2135 ND_PRINT("\n\t reason %s",
2136 tok2str(ofppr_str, "invalid (0x%02x)", GET_U_1(cp)));
2137 OF_FWD(1);
2138 /* pad */
2139 /* No need to check bounds, more data follows. */
2140 OF_FWD(7);
2141 /* desc */
2142 of10_phy_ports_print(ndo, cp, len);
2143 return;
2144
2145 /* OpenFlow header, fixed-size message body and n * fixed-size data units. */
2146 case OFPT_FEATURES_REPLY:
2147 if (len < OF_FEATURES_REPLY_MINLEN - OF_HEADER_FIXLEN)
2148 goto invalid;
2149 if (ndo->ndo_vflag < 1)
2150 break;
2151 of10_features_reply_print(ndo, cp, len);
2152 return;
2153
2154 /* OpenFlow header and variable-size data. */
2155 case OFPT_HELLO: /* [OF10] Section 5.5.1 */
2156 case OFPT_ECHO_REQUEST: /* [OF10] Section 5.5.2 */
2157 case OFPT_ECHO_REPLY: /* [OF10] Section 5.5.3 */
2158 if (ndo->ndo_vflag < 1)
2159 break;
2160 of_data_print(ndo, cp, len);
2161 return;
2162
2163 /* OpenFlow header, fixed-size message body and variable-size data. */
2164 case OFPT_ERROR:
2165 if (len < OF_ERROR_MSG_MINLEN - OF_HEADER_FIXLEN)
2166 goto invalid;
2167 if (ndo->ndo_vflag < 1)
2168 break;
2169 of10_error_print(ndo, cp, len);
2170 return;
2171 case OFPT_VENDOR:
2172 /* [OF10] Section 5.5.4 */
2173 if (len < OF_VENDOR_MINLEN - OF_HEADER_FIXLEN)
2174 goto invalid;
2175 if (ndo->ndo_vflag < 1)
2176 break;
2177 of10_vendor_message_print(ndo, cp, len);
2178 return;
2179 case OFPT_PACKET_IN:
2180 /* 2 mock octets count in OF_PACKET_IN_MINLEN but not in len */
2181 if (len < OF_PACKET_IN_MINLEN - 2 - OF_HEADER_FIXLEN)
2182 goto invalid;
2183 if (ndo->ndo_vflag < 1)
2184 break;
2185 of10_packet_in_print(ndo, cp, len);
2186 return;
2187
2188 /* a. OpenFlow header. */
2189 /* b. OpenFlow header and one of the fixed-size message bodies. */
2190 /* c. OpenFlow header, fixed-size message body and variable-size data. */
2191 case OFPT_STATS_REQUEST:
2192 if (len < OF_STATS_REQUEST_MINLEN - OF_HEADER_FIXLEN)
2193 goto invalid;
2194 if (ndo->ndo_vflag < 1)
2195 break;
2196 of10_stats_request_print(ndo, cp, len);
2197 return;
2198
2199 /* a. OpenFlow header and fixed-size message body. */
2200 /* b. OpenFlow header and n * fixed-size data units. */
2201 /* c. OpenFlow header and n * variable-size data units. */
2202 /* d. OpenFlow header, fixed-size message body and variable-size data. */
2203 case OFPT_STATS_REPLY:
2204 if (len < OF_STATS_REPLY_MINLEN - OF_HEADER_FIXLEN)
2205 goto invalid;
2206 if (ndo->ndo_vflag < 1)
2207 break;
2208 of10_stats_reply_print(ndo, cp, len);
2209 return;
2210
2211 /* OpenFlow header and n * variable-size data units and variable-size data. */
2212 case OFPT_PACKET_OUT:
2213 if (len < OF_PACKET_OUT_MINLEN - OF_HEADER_FIXLEN)
2214 goto invalid;
2215 if (ndo->ndo_vflag < 1)
2216 break;
2217 of10_packet_out_print(ndo, cp, len);
2218 return;
2219
2220 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2221 case OFPT_FLOW_MOD:
2222 if (len < OF_FLOW_MOD_MINLEN - OF_HEADER_FIXLEN)
2223 goto invalid;
2224 if (ndo->ndo_vflag < 1)
2225 break;
2226 of10_flow_mod_print(ndo, cp, len);
2227 return;
2228
2229 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2230 case OFPT_QUEUE_GET_CONFIG_REPLY: /* [OF10] Section 5.3.4 */
2231 if (len < OF_QUEUE_GET_CONFIG_REPLY_MINLEN - OF_HEADER_FIXLEN)
2232 goto invalid;
2233 if (ndo->ndo_vflag < 1)
2234 break;
2235 /* port */
2236 ND_PRINT("\n\t port %s",
2237 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
2238 OF_FWD(2);
2239 /* pad */
2240 /* Sometimes the last field, check bounds. */
2241 OF_CHK_FWD(6);
2242 /* queues */
2243 of10_queues_print(ndo, cp, len);
2244 return;
2245 } /* switch (type) */
2246 /*
2247 * Not a recognised type or did not print the details, fall back to
2248 * a bounds check.
2249 */
2250 ND_TCHECK_LEN(cp, len);
2251 return;
2252
2253 invalid: /* skip the message body */
2254 nd_print_invalid(ndo);
2255 ND_TCHECK_LEN(cp, len);
2256 }