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