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