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