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