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