]> The Tcpdump Group git mirrors - tcpdump/blob - print-openflow-1.0.c
OpenFlow: handle 5 more BSN subtypes
[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 case BSN_GET_L2_TABLE_REQUEST:
804 case BSN_BW_ENABLE_GET_REQUEST:
805 case BSN_BW_CLEAR_DATA_REQUEST:
806 case BSN_HYBRID_GET_REQUEST:
807 /*
808 * 0 1 2 3
809 * 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
810 * +---------------+---------------+---------------+---------------+
811 * | subtype |
812 * +---------------+---------------+---------------+---------------+
813 *
814 */
815 if (len != 4)
816 goto corrupt;
817 break;
818 case BSN_VIRTUAL_PORT_REMOVE_REQUEST:
819 /*
820 * 0 1 2 3
821 * 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
822 * +---------------+---------------+---------------+---------------+
823 * | subtype |
824 * +---------------+---------------+---------------+---------------+
825 * | vport_no |
826 * +---------------+---------------+---------------+---------------+
827 *
828 */
829 if (len != 8)
830 goto corrupt;
831 /* vport_no */
832 ND_TCHECK2(*cp, 4);
833 ND_PRINT((ndo, ", vport_no %u", EXTRACT_32BITS(cp)));
834 cp += 4;
835 break;
836 default:
837 ND_TCHECK2(*cp, len - 4);
838 cp += len - 4;
839 }
840 return cp;
841
842 corrupt: /* skip the undersized data */
843 ND_PRINT((ndo, "%s", cstr));
844 ND_TCHECK2(*cp0, len);
845 return cp0 + len;
846 trunc:
847 ND_PRINT((ndo, "%s", tstr));
848 return ep;
849 }
850
851 static const u_char *
852 of10_vendor_message_print(netdissect_options *ndo,
853 const u_char *cp, const u_char *ep, const u_int len) {
854 uint32_t vendor;
855 const u_char *(*decoder)(netdissect_options *, const u_char *, const u_char *, u_int);
856
857 if (len < 4)
858 goto corrupt;
859 /* vendor */
860 ND_TCHECK2(*cp, 4);
861 vendor = EXTRACT_32BITS(cp);
862 cp += 4;
863 ND_PRINT((ndo, ", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor)));
864 /* data */
865 decoder =
866 vendor == OUI_BSN ? of10_bsn_message_print :
867 of10_data_print;
868 return decoder(ndo, cp, ep, len - 4);
869
870 corrupt: /* skip the undersized data */
871 ND_PRINT((ndo, "%s", cstr));
872 ND_TCHECK2(*cp, len);
873 return cp + len;
874 trunc:
875 ND_PRINT((ndo, "%s", tstr));
876 return ep;
877 }
878
879 /* Vendor ID is mandatory, data is optional. */
880 static const u_char *
881 of10_vendor_data_print(netdissect_options *ndo,
882 const u_char *cp, const u_char *ep, const u_int len) {
883 uint32_t vendor;
884
885 if (len < 4)
886 goto corrupt;
887 /* vendor */
888 ND_TCHECK2(*cp, 4);
889 vendor = EXTRACT_32BITS(cp);
890 cp += 4;
891 ND_PRINT((ndo, ", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor)));
892 /* data */
893 return of10_data_print(ndo, cp, ep, len - 4);
894
895 corrupt: /* skip the undersized data */
896 ND_PRINT((ndo, "%s", cstr));
897 ND_TCHECK2(*cp, len);
898 return cp + len;
899 trunc:
900 ND_PRINT((ndo, "%s", tstr));
901 return ep;
902 }
903
904 static const u_char *
905 of10_packet_data_print(netdissect_options *ndo,
906 const u_char *cp, const u_char *ep, const u_int len) {
907 if (len == 0)
908 return cp;
909 /* data */
910 ND_PRINT((ndo, "\n\t data (%u octets)", len));
911 if (ndo->ndo_vflag < 3)
912 return cp + len;
913 ND_TCHECK2(*cp, len);
914 ndo->ndo_vflag -= 3;
915 ND_PRINT((ndo, ", frame decoding below\n"));
916 ether_print(ndo, cp, len, ndo->ndo_snapend - cp, NULL, NULL);
917 ndo->ndo_vflag += 3;
918 return cp + len;
919
920 trunc:
921 ND_PRINT((ndo, "%s", tstr));
922 return ep;
923 }
924
925 /* [OF10] Section 5.2.1 */
926 static const u_char *
927 of10_phy_ports_print(netdissect_options *ndo,
928 const u_char *cp, const u_char *ep, u_int len) {
929 const u_char *cp0 = cp;
930 const u_int len0 = len;
931
932 while (len) {
933 if (len < OF_PHY_PORT_LEN)
934 goto corrupt;
935 /* port_no */
936 ND_TCHECK2(*cp, 2);
937 ND_PRINT((ndo, "\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
938 cp += 2;
939 /* hw_addr */
940 ND_TCHECK2(*cp, ETHER_ADDR_LEN);
941 ND_PRINT((ndo, ", hw_addr %s", etheraddr_string(ndo, cp)));
942 cp += ETHER_ADDR_LEN;
943 /* name */
944 ND_TCHECK2(*cp, OFP_MAX_PORT_NAME_LEN);
945 ND_PRINT((ndo, ", name '"));
946 fn_print(ndo, cp, cp + OFP_MAX_PORT_NAME_LEN);
947 ND_PRINT((ndo, "'"));
948 cp += OFP_MAX_PORT_NAME_LEN;
949
950 if (ndo->ndo_vflag < 2) {
951 ND_TCHECK2(*cp, 24);
952 cp += 24;
953 goto next_port;
954 }
955 /* config */
956 ND_TCHECK2(*cp, 4);
957 ND_PRINT((ndo, "\n\t config 0x%08x", EXTRACT_32BITS(cp)));
958 of10_bitmap_print(ndo, ofppc_bm, EXTRACT_32BITS(cp), OFPPC_U);
959 cp += 4;
960 /* state */
961 ND_TCHECK2(*cp, 4);
962 ND_PRINT((ndo, "\n\t state 0x%08x", EXTRACT_32BITS(cp)));
963 of10_bitmap_print(ndo, ofpps_bm, EXTRACT_32BITS(cp), OFPPS_U);
964 cp += 4;
965 /* curr */
966 ND_TCHECK2(*cp, 4);
967 ND_PRINT((ndo, "\n\t curr 0x%08x", EXTRACT_32BITS(cp)));
968 of10_bitmap_print(ndo, ofppf_bm, EXTRACT_32BITS(cp), OFPPF_U);
969 cp += 4;
970 /* advertised */
971 ND_TCHECK2(*cp, 4);
972 ND_PRINT((ndo, "\n\t advertised 0x%08x", EXTRACT_32BITS(cp)));
973 of10_bitmap_print(ndo, ofppf_bm, EXTRACT_32BITS(cp), OFPPF_U);
974 cp += 4;
975 /* supported */
976 ND_TCHECK2(*cp, 4);
977 ND_PRINT((ndo, "\n\t supported 0x%08x", EXTRACT_32BITS(cp)));
978 of10_bitmap_print(ndo, ofppf_bm, EXTRACT_32BITS(cp), OFPPF_U);
979 cp += 4;
980 /* peer */
981 ND_TCHECK2(*cp, 4);
982 ND_PRINT((ndo, "\n\t peer 0x%08x", EXTRACT_32BITS(cp)));
983 of10_bitmap_print(ndo, ofppf_bm, EXTRACT_32BITS(cp), OFPPF_U);
984 cp += 4;
985 next_port:
986 len -= OF_PHY_PORT_LEN;
987 } /* while */
988 return cp;
989
990 corrupt: /* skip the undersized trailing data */
991 ND_PRINT((ndo, "%s", cstr));
992 ND_TCHECK2(*cp0, len0);
993 return cp0 + len0;
994 trunc:
995 ND_PRINT((ndo, "%s", tstr));
996 return ep;
997 }
998
999 /* [OF10] Section 5.2.2 */
1000 static const u_char *
1001 of10_queue_props_print(netdissect_options *ndo,
1002 const u_char *cp, const u_char *ep, u_int len) {
1003 const u_char *cp0 = cp;
1004 const u_int len0 = len;
1005 uint16_t property, plen, rate;
1006
1007 while (len) {
1008 u_char plen_bogus = 0, skip = 0;
1009
1010 if (len < OF_QUEUE_PROP_HEADER_LEN)
1011 goto corrupt;
1012 /* property */
1013 ND_TCHECK2(*cp, 2);
1014 property = EXTRACT_16BITS(cp);
1015 cp += 2;
1016 ND_PRINT((ndo, "\n\t property %s", tok2str(ofpqt_str, "invalid (0x%04x)", property)));
1017 /* len */
1018 ND_TCHECK2(*cp, 2);
1019 plen = EXTRACT_16BITS(cp);
1020 cp += 2;
1021 ND_PRINT((ndo, ", len %u", plen));
1022 if (plen < OF_QUEUE_PROP_HEADER_LEN || plen > len)
1023 goto corrupt;
1024 /* pad */
1025 ND_TCHECK2(*cp, 4);
1026 cp += 4;
1027 /* property-specific constraints and decoding */
1028 switch (property) {
1029 case OFPQT_NONE:
1030 plen_bogus = plen != OF_QUEUE_PROP_HEADER_LEN;
1031 break;
1032 case OFPQT_MIN_RATE:
1033 plen_bogus = plen != OF_QUEUE_PROP_MIN_RATE_LEN;
1034 break;
1035 default:
1036 skip = 1;
1037 }
1038 if (plen_bogus) {
1039 ND_PRINT((ndo, " (bogus)"));
1040 skip = 1;
1041 }
1042 if (skip) {
1043 ND_TCHECK2(*cp, plen - 4);
1044 cp += plen - 4;
1045 goto next_property;
1046 }
1047 if (property == OFPQT_MIN_RATE) { /* the only case of property decoding */
1048 /* rate */
1049 ND_TCHECK2(*cp, 2);
1050 rate = EXTRACT_16BITS(cp);
1051 cp += 2;
1052 if (rate > 1000)
1053 ND_PRINT((ndo, ", rate disabled"));
1054 else
1055 ND_PRINT((ndo, ", rate %u.%u%%", rate / 10, rate % 10));
1056 /* pad */
1057 ND_TCHECK2(*cp, 6);
1058 cp += 6;
1059 }
1060 next_property:
1061 len -= plen;
1062 } /* while */
1063 return cp;
1064
1065 corrupt: /* skip the rest of queue properties */
1066 ND_PRINT((ndo, "%s", cstr));
1067 ND_TCHECK2(*cp0, len0);
1068 return cp0 + len0;
1069 trunc:
1070 ND_PRINT((ndo, "%s", tstr));
1071 return ep;
1072 }
1073
1074 /* ibid */
1075 static const u_char *
1076 of10_queues_print(netdissect_options *ndo,
1077 const u_char *cp, const u_char *ep, u_int len) {
1078 const u_char *cp0 = cp;
1079 const u_int len0 = len;
1080 uint16_t desclen;
1081
1082 while (len) {
1083 if (len < OF_PACKET_QUEUE_LEN)
1084 goto corrupt;
1085 /* queue_id */
1086 ND_TCHECK2(*cp, 4);
1087 ND_PRINT((ndo, "\n\t queue_id %u", EXTRACT_32BITS(cp)));
1088 cp += 4;
1089 /* len */
1090 ND_TCHECK2(*cp, 2);
1091 desclen = EXTRACT_16BITS(cp);
1092 cp += 2;
1093 ND_PRINT((ndo, ", len %u", desclen));
1094 if (desclen < OF_PACKET_QUEUE_LEN || desclen > len)
1095 goto corrupt;
1096 /* pad */
1097 ND_TCHECK2(*cp, 2);
1098 cp += 2;
1099 /* properties */
1100 if (ndo->ndo_vflag < 2) {
1101 ND_TCHECK2(*cp, desclen - OF_PACKET_QUEUE_LEN);
1102 cp += desclen - OF_PACKET_QUEUE_LEN;
1103 goto next_queue;
1104 }
1105 if (ep == (cp = of10_queue_props_print(ndo, cp, ep, desclen - OF_PACKET_QUEUE_LEN)))
1106 return ep; /* end of snapshot */
1107 next_queue:
1108 len -= desclen;
1109 } /* while */
1110 return cp;
1111
1112 corrupt: /* skip the rest of queues */
1113 ND_PRINT((ndo, "%s", cstr));
1114 ND_TCHECK2(*cp0, len0);
1115 return cp0 + len0;
1116 trunc:
1117 ND_PRINT((ndo, "%s", tstr));
1118 return ep;
1119 }
1120
1121 /* [OF10] Section 5.2.3 */
1122 static const u_char *
1123 of10_match_print(netdissect_options *ndo,
1124 const char *pfx, const u_char *cp, const u_char *ep) {
1125 uint32_t wildcards;
1126 uint16_t dl_type;
1127 uint8_t nw_proto;
1128 u_char nw_bits;
1129 const char *field_name;
1130
1131 /* wildcards */
1132 ND_TCHECK2(*cp, 4);
1133 wildcards = EXTRACT_32BITS(cp);
1134 if (wildcards & OFPFW_U)
1135 ND_PRINT((ndo, "%swildcards 0x%08x (bogus)", pfx, wildcards));
1136 cp += 4;
1137 /* in_port */
1138 ND_TCHECK2(*cp, 2);
1139 if (! (wildcards & OFPFW_IN_PORT))
1140 ND_PRINT((ndo, "%smatch in_port %s", pfx, tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1141 cp += 2;
1142 /* dl_src */
1143 ND_TCHECK2(*cp, ETHER_ADDR_LEN);
1144 if (! (wildcards & OFPFW_DL_SRC))
1145 ND_PRINT((ndo, "%smatch dl_src %s", pfx, etheraddr_string(ndo, cp)));
1146 cp += ETHER_ADDR_LEN;
1147 /* dl_dst */
1148 ND_TCHECK2(*cp, ETHER_ADDR_LEN);
1149 if (! (wildcards & OFPFW_DL_DST))
1150 ND_PRINT((ndo, "%smatch dl_dst %s", pfx, etheraddr_string(ndo, cp)));
1151 cp += ETHER_ADDR_LEN;
1152 /* dl_vlan */
1153 ND_TCHECK2(*cp, 2);
1154 if (! (wildcards & OFPFW_DL_VLAN))
1155 ND_PRINT((ndo, "%smatch dl_vlan %s", pfx, vlan_str(EXTRACT_16BITS(cp))));
1156 cp += 2;
1157 /* dl_vlan_pcp */
1158 ND_TCHECK2(*cp, 1);
1159 if (! (wildcards & OFPFW_DL_VLAN_PCP))
1160 ND_PRINT((ndo, "%smatch dl_vlan_pcp %s", pfx, pcp_str(*cp)));
1161 cp += 1;
1162 /* pad1 */
1163 ND_TCHECK2(*cp, 1);
1164 cp += 1;
1165 /* dl_type */
1166 ND_TCHECK2(*cp, 2);
1167 dl_type = EXTRACT_16BITS(cp);
1168 cp += 2;
1169 if (! (wildcards & OFPFW_DL_TYPE))
1170 ND_PRINT((ndo, "%smatch dl_type 0x%04x", pfx, dl_type));
1171 /* nw_tos */
1172 ND_TCHECK2(*cp, 1);
1173 if (! (wildcards & OFPFW_NW_TOS))
1174 ND_PRINT((ndo, "%smatch nw_tos 0x%02x", pfx, *cp));
1175 cp += 1;
1176 /* nw_proto */
1177 ND_TCHECK2(*cp, 1);
1178 nw_proto = *cp;
1179 cp += 1;
1180 if (! (wildcards & OFPFW_NW_PROTO)) {
1181 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_ARP
1182 ? "arp_opcode" : "nw_proto";
1183 ND_PRINT((ndo, "%smatch %s %u", pfx, field_name, nw_proto));
1184 }
1185 /* pad2 */
1186 ND_TCHECK2(*cp, 2);
1187 cp += 2;
1188 /* nw_src */
1189 ND_TCHECK2(*cp, 4);
1190 nw_bits = (wildcards & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT;
1191 if (nw_bits < 32)
1192 ND_PRINT((ndo, "%smatch nw_src %s/%u", pfx, ipaddr_string(ndo, cp), 32 - nw_bits));
1193 cp += 4;
1194 /* nw_dst */
1195 ND_TCHECK2(*cp, 4);
1196 nw_bits = (wildcards & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT;
1197 if (nw_bits < 32)
1198 ND_PRINT((ndo, "%smatch nw_dst %s/%u", pfx, ipaddr_string(ndo, cp), 32 - nw_bits));
1199 cp += 4;
1200 /* tp_src */
1201 ND_TCHECK2(*cp, 2);
1202 if (! (wildcards & OFPFW_TP_SRC)) {
1203 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_IP
1204 && ! (wildcards & OFPFW_NW_PROTO) && nw_proto == IPPROTO_ICMP
1205 ? "icmp_type" : "tp_src";
1206 ND_PRINT((ndo, "%smatch %s %u", pfx, field_name, EXTRACT_16BITS(cp)));
1207 }
1208 cp += 2;
1209 /* tp_dst */
1210 ND_TCHECK2(*cp, 2);
1211 if (! (wildcards & OFPFW_TP_DST)) {
1212 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_IP
1213 && ! (wildcards & OFPFW_NW_PROTO) && nw_proto == IPPROTO_ICMP
1214 ? "icmp_code" : "tp_dst";
1215 ND_PRINT((ndo, "%smatch %s %u", pfx, field_name, EXTRACT_16BITS(cp)));
1216 }
1217 return cp + 2;
1218
1219 trunc:
1220 ND_PRINT((ndo, "%s", tstr));
1221 return ep;
1222 }
1223
1224 /* [OF10] Section 5.2.4 */
1225 static const u_char *
1226 of10_actions_print(netdissect_options *ndo,
1227 const char *pfx, const u_char *cp, const u_char *ep,
1228 u_int len) {
1229 const u_char *cp0 = cp;
1230 const u_int len0 = len;
1231 uint16_t type, alen, output_port;
1232
1233 while (len) {
1234 u_char alen_bogus = 0, skip = 0;
1235
1236 if (len < OF_ACTION_HEADER_LEN)
1237 goto corrupt;
1238 /* type */
1239 ND_TCHECK2(*cp, 2);
1240 type = EXTRACT_16BITS(cp);
1241 cp += 2;
1242 ND_PRINT((ndo, "%saction type %s", pfx, tok2str(ofpat_str, "invalid (0x%04x)", type)));
1243 /* length */
1244 ND_TCHECK2(*cp, 2);
1245 alen = EXTRACT_16BITS(cp);
1246 cp += 2;
1247 ND_PRINT((ndo, ", len %u", alen));
1248 /* On action size underrun/overrun skip the rest of the action list. */
1249 if (alen < OF_ACTION_HEADER_LEN || alen > len)
1250 goto corrupt;
1251 /* On action size inappropriate for the given type or invalid type just skip
1252 * the current action, as the basic length constraint has been met. */
1253 switch (type) {
1254 case OFPAT_OUTPUT:
1255 case OFPAT_SET_VLAN_VID:
1256 case OFPAT_SET_VLAN_PCP:
1257 case OFPAT_STRIP_VLAN:
1258 case OFPAT_SET_NW_SRC:
1259 case OFPAT_SET_NW_DST:
1260 case OFPAT_SET_NW_TOS:
1261 case OFPAT_SET_TP_SRC:
1262 case OFPAT_SET_TP_DST:
1263 alen_bogus = alen != 8;
1264 break;
1265 case OFPAT_SET_DL_SRC:
1266 case OFPAT_SET_DL_DST:
1267 case OFPAT_ENQUEUE:
1268 alen_bogus = alen != 16;
1269 break;
1270 case OFPAT_VENDOR:
1271 alen_bogus = alen % 8 != 0; /* already >= 8 so far */
1272 break;
1273 default:
1274 skip = 1;
1275 }
1276 if (alen_bogus) {
1277 ND_PRINT((ndo, " (bogus)"));
1278 skip = 1;
1279 }
1280 if (skip) {
1281 ND_TCHECK2(*cp, alen - 4);
1282 cp += alen - 4;
1283 goto next_action;
1284 }
1285 /* OK to decode the rest of the action structure */
1286 switch (type) {
1287 case OFPAT_OUTPUT:
1288 /* port */
1289 ND_TCHECK2(*cp, 2);
1290 output_port = EXTRACT_16BITS(cp);
1291 cp += 2;
1292 ND_PRINT((ndo, ", port %s", tok2str(ofpp_str, "%u", output_port)));
1293 /* max_len */
1294 ND_TCHECK2(*cp, 2);
1295 if (output_port == OFPP_CONTROLLER)
1296 ND_PRINT((ndo, ", max_len %u", EXTRACT_16BITS(cp)));
1297 cp += 2;
1298 break;
1299 case OFPAT_SET_VLAN_VID:
1300 /* vlan_vid */
1301 ND_TCHECK2(*cp, 2);
1302 ND_PRINT((ndo, ", vlan_vid %s", vlan_str(EXTRACT_16BITS(cp))));
1303 cp += 2;
1304 /* pad */
1305 ND_TCHECK2(*cp, 2);
1306 cp += 2;
1307 break;
1308 case OFPAT_SET_VLAN_PCP:
1309 /* vlan_pcp */
1310 ND_TCHECK2(*cp, 1);
1311 ND_PRINT((ndo, ", vlan_pcp %s", pcp_str(*cp)));
1312 cp += 1;
1313 /* pad */
1314 ND_TCHECK2(*cp, 3);
1315 cp += 3;
1316 break;
1317 case OFPAT_SET_DL_SRC:
1318 case OFPAT_SET_DL_DST:
1319 /* dl_addr */
1320 ND_TCHECK2(*cp, ETHER_ADDR_LEN);
1321 ND_PRINT((ndo, ", dl_addr %s", etheraddr_string(ndo, cp)));
1322 cp += ETHER_ADDR_LEN;
1323 /* pad */
1324 ND_TCHECK2(*cp, 6);
1325 cp += 6;
1326 break;
1327 case OFPAT_SET_NW_SRC:
1328 case OFPAT_SET_NW_DST:
1329 /* nw_addr */
1330 ND_TCHECK2(*cp, 4);
1331 ND_PRINT((ndo, ", nw_addr %s", ipaddr_string(ndo, cp)));
1332 cp += 4;
1333 break;
1334 case OFPAT_SET_NW_TOS:
1335 /* nw_tos */
1336 ND_TCHECK2(*cp, 1);
1337 ND_PRINT((ndo, ", nw_tos 0x%02x", *cp));
1338 cp += 1;
1339 /* pad */
1340 ND_TCHECK2(*cp, 3);
1341 cp += 3;
1342 break;
1343 case OFPAT_SET_TP_SRC:
1344 case OFPAT_SET_TP_DST:
1345 /* nw_tos */
1346 ND_TCHECK2(*cp, 2);
1347 ND_PRINT((ndo, ", tp_port %u", EXTRACT_16BITS(cp)));
1348 cp += 2;
1349 /* pad */
1350 ND_TCHECK2(*cp, 2);
1351 cp += 2;
1352 break;
1353 case OFPAT_ENQUEUE:
1354 /* port */
1355 ND_TCHECK2(*cp, 2);
1356 ND_PRINT((ndo, ", port %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1357 cp += 2;
1358 /* pad */
1359 ND_TCHECK2(*cp, 6);
1360 cp += 6;
1361 /* queue_id */
1362 ND_TCHECK2(*cp, 4);
1363 ND_PRINT((ndo, ", queue_id %s", tok2str(ofpq_str, "%u", EXTRACT_32BITS(cp))));
1364 cp += 4;
1365 break;
1366 case OFPAT_VENDOR:
1367 if (ep == (cp = of10_vendor_data_print(ndo, cp, ep, alen - 4)))
1368 return ep; /* end of snapshot */
1369 break;
1370 case OFPAT_STRIP_VLAN:
1371 /* pad */
1372 ND_TCHECK2(*cp, 4);
1373 cp += 4;
1374 break;
1375 } /* switch */
1376 next_action:
1377 len -= alen;
1378 } /* while */
1379 return cp;
1380
1381 corrupt: /* skip the rest of actions */
1382 ND_PRINT((ndo, "%s", cstr));
1383 ND_TCHECK2(*cp0, len0);
1384 return cp0 + len0;
1385 trunc:
1386 ND_PRINT((ndo, "%s", tstr));
1387 return ep;
1388 }
1389
1390 /* [OF10] Section 5.3.1 */
1391 static const u_char *
1392 of10_features_reply_print(netdissect_options *ndo,
1393 const u_char *cp, const u_char *ep, const u_int len) {
1394 /* datapath_id */
1395 ND_TCHECK2(*cp, 8);
1396 ND_PRINT((ndo, "\n\t dpid 0x%016" PRIx64, EXTRACT_64BITS(cp)));
1397 cp += 8;
1398 /* n_buffers */
1399 ND_TCHECK2(*cp, 4);
1400 ND_PRINT((ndo, ", n_buffers %u", EXTRACT_32BITS(cp)));
1401 cp += 4;
1402 /* n_tables */
1403 ND_TCHECK2(*cp, 1);
1404 ND_PRINT((ndo, ", n_tables %u", *cp));
1405 cp += 1;
1406 /* pad */
1407 ND_TCHECK2(*cp, 3);
1408 cp += 3;
1409 /* capabilities */
1410 ND_TCHECK2(*cp, 4);
1411 ND_PRINT((ndo, "\n\t capabilities 0x%08x", EXTRACT_32BITS(cp)));
1412 of10_bitmap_print(ndo, ofp_capabilities_bm, EXTRACT_32BITS(cp), OFPCAP_U);
1413 cp += 4;
1414 /* actions */
1415 ND_TCHECK2(*cp, 4);
1416 ND_PRINT((ndo, "\n\t actions 0x%08x", EXTRACT_32BITS(cp)));
1417 of10_bitmap_print(ndo, ofpat_bm, EXTRACT_32BITS(cp), OFPAT_U);
1418 cp += 4;
1419 /* ports */
1420 return of10_phy_ports_print(ndo, cp, ep, len - OF_SWITCH_FEATURES_LEN);
1421
1422 trunc:
1423 ND_PRINT((ndo, "%s", tstr));
1424 return ep;
1425 }
1426
1427 /* [OF10] Section 5.3.3 */
1428 static const u_char *
1429 of10_flow_mod_print(netdissect_options *ndo,
1430 const u_char *cp, const u_char *ep, const u_int len) {
1431 uint16_t command;
1432
1433 /* match */
1434 if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
1435 return ep; /* end of snapshot */
1436 /* cookie */
1437 ND_TCHECK2(*cp, 8);
1438 ND_PRINT((ndo, "\n\t cookie 0x%016" PRIx64, EXTRACT_64BITS(cp)));
1439 cp += 8;
1440 /* command */
1441 ND_TCHECK2(*cp, 2);
1442 command = EXTRACT_16BITS(cp);
1443 ND_PRINT((ndo, ", command %s", tok2str(ofpfc_str, "invalid (0x%04x)", command)));
1444 cp += 2;
1445 /* idle_timeout */
1446 ND_TCHECK2(*cp, 2);
1447 if (EXTRACT_16BITS(cp))
1448 ND_PRINT((ndo, ", idle_timeout %u", EXTRACT_16BITS(cp)));
1449 cp += 2;
1450 /* hard_timeout */
1451 ND_TCHECK2(*cp, 2);
1452 if (EXTRACT_16BITS(cp))
1453 ND_PRINT((ndo, ", hard_timeout %u", EXTRACT_16BITS(cp)));
1454 cp += 2;
1455 /* priority */
1456 ND_TCHECK2(*cp, 2);
1457 if (EXTRACT_16BITS(cp))
1458 ND_PRINT((ndo, ", priority %u", EXTRACT_16BITS(cp)));
1459 cp += 2;
1460 /* buffer_id */
1461 ND_TCHECK2(*cp, 4);
1462 if (command == OFPFC_ADD || command == OFPFC_MODIFY ||
1463 command == OFPFC_MODIFY_STRICT)
1464 ND_PRINT((ndo, ", buffer_id %s", tok2str(bufferid_str, "0x%08x", EXTRACT_32BITS(cp))));
1465 cp += 4;
1466 /* out_port */
1467 ND_TCHECK2(*cp, 2);
1468 if (command == OFPFC_DELETE || command == OFPFC_DELETE_STRICT)
1469 ND_PRINT((ndo, ", out_port %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1470 cp += 2;
1471 /* flags */
1472 ND_TCHECK2(*cp, 2);
1473 ND_PRINT((ndo, ", flags 0x%04x", EXTRACT_16BITS(cp)));
1474 of10_bitmap_print(ndo, ofpff_bm, EXTRACT_16BITS(cp), OFPFF_U);
1475 cp += 2;
1476 /* actions */
1477 return of10_actions_print(ndo, "\n\t ", cp, ep, len - OF_FLOW_MOD_LEN);
1478
1479 trunc:
1480 ND_PRINT((ndo, "%s", tstr));
1481 return ep;
1482 }
1483
1484 /* ibid */
1485 static const u_char *
1486 of10_port_mod_print(netdissect_options *ndo,
1487 const u_char *cp, const u_char *ep) {
1488 /* port_no */
1489 ND_TCHECK2(*cp, 2);
1490 ND_PRINT((ndo, "\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1491 cp += 2;
1492 /* hw_addr */
1493 ND_TCHECK2(*cp, ETHER_ADDR_LEN);
1494 ND_PRINT((ndo, ", hw_addr %s", etheraddr_string(ndo, cp)));
1495 cp += ETHER_ADDR_LEN;
1496 /* config */
1497 ND_TCHECK2(*cp, 4);
1498 ND_PRINT((ndo, "\n\t config 0x%08x", EXTRACT_32BITS(cp)));
1499 of10_bitmap_print(ndo, ofppc_bm, EXTRACT_32BITS(cp), OFPPC_U);
1500 cp += 4;
1501 /* mask */
1502 ND_TCHECK2(*cp, 4);
1503 ND_PRINT((ndo, "\n\t mask 0x%08x", EXTRACT_32BITS(cp)));
1504 of10_bitmap_print(ndo, ofppc_bm, EXTRACT_32BITS(cp), OFPPC_U);
1505 cp += 4;
1506 /* advertise */
1507 ND_TCHECK2(*cp, 4);
1508 ND_PRINT((ndo, "\n\t advertise 0x%08x", EXTRACT_32BITS(cp)));
1509 of10_bitmap_print(ndo, ofppf_bm, EXTRACT_32BITS(cp), OFPPF_U);
1510 cp += 4;
1511 /* pad */
1512 ND_TCHECK2(*cp, 4);
1513 return cp + 4;
1514
1515 trunc:
1516 ND_PRINT((ndo, "%s", tstr));
1517 return ep;
1518 }
1519
1520 /* [OF10] Section 5.3.5 */
1521 static const u_char *
1522 of10_stats_request_print(netdissect_options *ndo,
1523 const u_char *cp, const u_char *ep, u_int len) {
1524 const u_char *cp0 = cp;
1525 const u_int len0 = len;
1526 uint16_t type;
1527
1528 /* type */
1529 ND_TCHECK2(*cp, 2);
1530 type = EXTRACT_16BITS(cp);
1531 cp += 2;
1532 ND_PRINT((ndo, "\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type)));
1533 /* flags */
1534 ND_TCHECK2(*cp, 2);
1535 ND_PRINT((ndo, ", flags 0x%04x", EXTRACT_16BITS(cp)));
1536 if (EXTRACT_16BITS(cp))
1537 ND_PRINT((ndo, " (bogus)"));
1538 cp += 2;
1539 /* type-specific body of one of fixed lengths */
1540 len -= OF_STATS_REQUEST_LEN;
1541 switch(type) {
1542 case OFPST_DESC:
1543 case OFPST_TABLE:
1544 if (len)
1545 goto corrupt;
1546 return cp;
1547 case OFPST_FLOW:
1548 case OFPST_AGGREGATE:
1549 if (len != OF_FLOW_STATS_REQUEST_LEN)
1550 goto corrupt;
1551 /* match */
1552 if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
1553 return ep; /* end of snapshot */
1554 /* table_id */
1555 ND_TCHECK2(*cp, 1);
1556 ND_PRINT((ndo, "\n\t table_id %s", tok2str(tableid_str, "%u", *cp)));
1557 cp += 1;
1558 /* pad */
1559 ND_TCHECK2(*cp, 1);
1560 cp += 1;
1561 /* out_port */
1562 ND_TCHECK2(*cp, 2);
1563 ND_PRINT((ndo, ", out_port %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1564 return cp + 2;
1565 case OFPST_PORT:
1566 if (len != OF_PORT_STATS_REQUEST_LEN)
1567 goto corrupt;
1568 /* port_no */
1569 ND_TCHECK2(*cp, 2);
1570 ND_PRINT((ndo, "\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1571 cp += 2;
1572 /* pad */
1573 ND_TCHECK2(*cp, 6);
1574 return cp + 6;
1575 case OFPST_QUEUE:
1576 if (len != OF_QUEUE_STATS_REQUEST_LEN)
1577 goto corrupt;
1578 /* port_no */
1579 ND_TCHECK2(*cp, 2);
1580 ND_PRINT((ndo, "\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1581 cp += 2;
1582 /* pad */
1583 ND_TCHECK2(*cp, 2);
1584 cp += 2;
1585 /* queue_id */
1586 ND_TCHECK2(*cp, 4);
1587 ND_PRINT((ndo, ", queue_id %s", tok2str(ofpq_str, "%u", EXTRACT_32BITS(cp))));
1588 return cp + 4;
1589 case OFPST_VENDOR:
1590 return of10_vendor_data_print(ndo, cp, ep, len);
1591 }
1592 return cp;
1593
1594 corrupt: /* skip the message body */
1595 ND_PRINT((ndo, "%s", cstr));
1596 ND_TCHECK2(*cp0, len0);
1597 return cp0 + len0;
1598 trunc:
1599 ND_PRINT((ndo, "%s", tstr));
1600 return ep;
1601 }
1602
1603 /* ibid */
1604 static const u_char *
1605 of10_desc_stats_reply_print(netdissect_options *ndo,
1606 const u_char *cp, const u_char *ep, const u_int len) {
1607 if (len != OF_DESC_STATS_LEN)
1608 goto corrupt;
1609 /* mfr_desc */
1610 ND_TCHECK2(*cp, DESC_STR_LEN);
1611 ND_PRINT((ndo, "\n\t mfr_desc '"));
1612 fn_print(ndo, cp, cp + DESC_STR_LEN);
1613 ND_PRINT((ndo, "'"));
1614 cp += DESC_STR_LEN;
1615 /* hw_desc */
1616 ND_TCHECK2(*cp, DESC_STR_LEN);
1617 ND_PRINT((ndo, "\n\t hw_desc '"));
1618 fn_print(ndo, cp, cp + DESC_STR_LEN);
1619 ND_PRINT((ndo, "'"));
1620 cp += DESC_STR_LEN;
1621 /* sw_desc */
1622 ND_TCHECK2(*cp, DESC_STR_LEN);
1623 ND_PRINT((ndo, "\n\t sw_desc '"));
1624 fn_print(ndo, cp, cp + DESC_STR_LEN);
1625 ND_PRINT((ndo, "'"));
1626 cp += DESC_STR_LEN;
1627 /* serial_num */
1628 ND_TCHECK2(*cp, SERIAL_NUM_LEN);
1629 ND_PRINT((ndo, "\n\t serial_num '"));
1630 fn_print(ndo, cp, cp + SERIAL_NUM_LEN);
1631 ND_PRINT((ndo, "'"));
1632 cp += SERIAL_NUM_LEN;
1633 /* dp_desc */
1634 ND_TCHECK2(*cp, DESC_STR_LEN);
1635 ND_PRINT((ndo, "\n\t dp_desc '"));
1636 fn_print(ndo, cp, cp + DESC_STR_LEN);
1637 ND_PRINT((ndo, "'"));
1638 return cp + DESC_STR_LEN;
1639
1640 corrupt: /* skip the message body */
1641 ND_PRINT((ndo, "%s", cstr));
1642 ND_TCHECK2(*cp, len);
1643 return cp + len;
1644 trunc:
1645 ND_PRINT((ndo, "%s", tstr));
1646 return ep;
1647 }
1648
1649 /* ibid */
1650 static const u_char *
1651 of10_flow_stats_reply_print(netdissect_options *ndo,
1652 const u_char *cp, const u_char *ep, u_int len) {
1653 const u_char *cp0 = cp;
1654 const u_int len0 = len;
1655 uint16_t entry_len;
1656
1657 while (len) {
1658 if (len < OF_FLOW_STATS_LEN)
1659 goto corrupt;
1660 /* length */
1661 ND_TCHECK2(*cp, 2);
1662 entry_len = EXTRACT_16BITS(cp);
1663 ND_PRINT((ndo, "\n\t length %u", entry_len));
1664 if (entry_len < OF_FLOW_STATS_LEN || entry_len > len)
1665 goto corrupt;
1666 cp += 2;
1667 /* table_id */
1668 ND_TCHECK2(*cp, 1);
1669 ND_PRINT((ndo, ", table_id %s", tok2str(tableid_str, "%u", *cp)));
1670 cp += 1;
1671 /* pad */
1672 ND_TCHECK2(*cp, 1);
1673 cp += 1;
1674 /* match */
1675 if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
1676 return ep; /* end of snapshot */
1677 /* duration_sec */
1678 ND_TCHECK2(*cp, 4);
1679 ND_PRINT((ndo, "\n\t duration_sec %u", EXTRACT_32BITS(cp)));
1680 cp += 4;
1681 /* duration_nsec */
1682 ND_TCHECK2(*cp, 4);
1683 ND_PRINT((ndo, ", duration_nsec %u", EXTRACT_32BITS(cp)));
1684 cp += 4;
1685 /* priority */
1686 ND_TCHECK2(*cp, 2);
1687 ND_PRINT((ndo, ", priority %u", EXTRACT_16BITS(cp)));
1688 cp += 2;
1689 /* idle_timeout */
1690 ND_TCHECK2(*cp, 2);
1691 ND_PRINT((ndo, ", idle_timeout %u", EXTRACT_16BITS(cp)));
1692 cp += 2;
1693 /* hard_timeout */
1694 ND_TCHECK2(*cp, 2);
1695 ND_PRINT((ndo, ", hard_timeout %u", EXTRACT_16BITS(cp)));
1696 cp += 2;
1697 /* pad2 */
1698 ND_TCHECK2(*cp, 6);
1699 cp += 6;
1700 /* cookie */
1701 ND_TCHECK2(*cp, 8);
1702 ND_PRINT((ndo, ", cookie 0x%016" PRIx64, EXTRACT_64BITS(cp)));
1703 cp += 8;
1704 /* packet_count */
1705 ND_TCHECK2(*cp, 8);
1706 ND_PRINT((ndo, ", packet_count %" PRIu64, EXTRACT_64BITS(cp)));
1707 cp += 8;
1708 /* byte_count */
1709 ND_TCHECK2(*cp, 8);
1710 ND_PRINT((ndo, ", byte_count %" PRIu64, EXTRACT_64BITS(cp)));
1711 cp += 8;
1712 /* actions */
1713 if (ep == (cp = of10_actions_print(ndo, "\n\t ", cp, ep, entry_len - OF_FLOW_STATS_LEN)))
1714 return ep; /* end of snapshot */
1715
1716 len -= entry_len;
1717 } /* while */
1718 return cp;
1719
1720 corrupt: /* skip the rest of flow statistics entries */
1721 ND_PRINT((ndo, "%s", cstr));
1722 ND_TCHECK2(*cp0, len0);
1723 return cp0 + len0;
1724 trunc:
1725 ND_PRINT((ndo, "%s", tstr));
1726 return ep;
1727 }
1728
1729 /* ibid */
1730 static const u_char *
1731 of10_aggregate_stats_reply_print(netdissect_options *ndo,
1732 const u_char *cp, const u_char *ep,
1733 const u_int len) {
1734 if (len != OF_AGGREGATE_STATS_REPLY_LEN)
1735 goto corrupt;
1736 /* packet_count */
1737 ND_TCHECK2(*cp, 8);
1738 ND_PRINT((ndo, "\n\t packet_count %" PRIu64, EXTRACT_64BITS(cp)));
1739 cp += 8;
1740 /* byte_count */
1741 ND_TCHECK2(*cp, 8);
1742 ND_PRINT((ndo, ", byte_count %" PRIu64, EXTRACT_64BITS(cp)));
1743 cp += 8;
1744 /* flow_count */
1745 ND_TCHECK2(*cp, 4);
1746 ND_PRINT((ndo, ", flow_count %u", EXTRACT_32BITS(cp)));
1747 cp += 4;
1748 /* pad */
1749 ND_TCHECK2(*cp, 4);
1750 return cp + 4;
1751
1752 corrupt: /* skip the message body */
1753 ND_PRINT((ndo, "%s", cstr));
1754 ND_TCHECK2(*cp, len);
1755 return cp + len;
1756 trunc:
1757 ND_PRINT((ndo, "%s", tstr));
1758 return ep;
1759 }
1760
1761 /* ibid */
1762 static const u_char *
1763 of10_table_stats_reply_print(netdissect_options *ndo,
1764 const u_char *cp, const u_char *ep, u_int len) {
1765 const u_char *cp0 = cp;
1766 const u_int len0 = len;
1767
1768 while (len) {
1769 if (len < OF_TABLE_STATS_LEN)
1770 goto corrupt;
1771 /* table_id */
1772 ND_TCHECK2(*cp, 1);
1773 ND_PRINT((ndo, "\n\t table_id %s", tok2str(tableid_str, "%u", *cp)));
1774 cp += 1;
1775 /* pad */
1776 ND_TCHECK2(*cp, 3);
1777 cp += 3;
1778 /* name */
1779 ND_TCHECK2(*cp, OFP_MAX_TABLE_NAME_LEN);
1780 ND_PRINT((ndo, ", name '"));
1781 fn_print(ndo, cp, cp + OFP_MAX_TABLE_NAME_LEN);
1782 ND_PRINT((ndo, "'"));
1783 cp += OFP_MAX_TABLE_NAME_LEN;
1784 /* wildcards */
1785 ND_TCHECK2(*cp, 4);
1786 ND_PRINT((ndo, "\n\t wildcards 0x%08x", EXTRACT_32BITS(cp)));
1787 of10_bitmap_print(ndo, ofpfw_bm, EXTRACT_32BITS(cp), OFPFW_U);
1788 cp += 4;
1789 /* max_entries */
1790 ND_TCHECK2(*cp, 4);
1791 ND_PRINT((ndo, "\n\t max_entries %u", EXTRACT_32BITS(cp)));
1792 cp += 4;
1793 /* active_count */
1794 ND_TCHECK2(*cp, 4);
1795 ND_PRINT((ndo, ", active_count %u", EXTRACT_32BITS(cp)));
1796 cp += 4;
1797 /* lookup_count */
1798 ND_TCHECK2(*cp, 8);
1799 ND_PRINT((ndo, ", lookup_count %" PRIu64, EXTRACT_64BITS(cp)));
1800 cp += 8;
1801 /* matched_count */
1802 ND_TCHECK2(*cp, 8);
1803 ND_PRINT((ndo, ", matched_count %" PRIu64, EXTRACT_64BITS(cp)));
1804 cp += 8;
1805
1806 len -= OF_TABLE_STATS_LEN;
1807 } /* while */
1808 return cp;
1809
1810 corrupt: /* skip the undersized trailing data */
1811 ND_PRINT((ndo, "%s", cstr));
1812 ND_TCHECK2(*cp0, len0);
1813 return cp0 + len0;
1814 trunc:
1815 ND_PRINT((ndo, "%s", tstr));
1816 return ep;
1817 }
1818
1819 /* ibid */
1820 static const u_char *
1821 of10_port_stats_reply_print(netdissect_options *ndo,
1822 const u_char *cp, const u_char *ep, u_int len) {
1823 const u_char *cp0 = cp;
1824 const u_int len0 = len;
1825
1826 while (len) {
1827 if (len < OF_PORT_STATS_LEN)
1828 goto corrupt;
1829 /* port_no */
1830 ND_TCHECK2(*cp, 2);
1831 ND_PRINT((ndo, "\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1832 cp += 2;
1833 if (ndo->ndo_vflag < 2) {
1834 ND_TCHECK2(*cp, OF_PORT_STATS_LEN - 2);
1835 cp += OF_PORT_STATS_LEN - 2;
1836 goto next_port;
1837 }
1838 /* pad */
1839 ND_TCHECK2(*cp, 6);
1840 cp += 6;
1841 /* rx_packets */
1842 ND_TCHECK2(*cp, 8);
1843 ND_PRINT((ndo, ", rx_packets %" PRIu64, EXTRACT_64BITS(cp)));
1844 cp += 8;
1845 /* tx_packets */
1846 ND_TCHECK2(*cp, 8);
1847 ND_PRINT((ndo, ", tx_packets %" PRIu64, EXTRACT_64BITS(cp)));
1848 cp += 8;
1849 /* rx_bytes */
1850 ND_TCHECK2(*cp, 8);
1851 ND_PRINT((ndo, ", rx_bytes %" PRIu64, EXTRACT_64BITS(cp)));
1852 cp += 8;
1853 /* tx_bytes */
1854 ND_TCHECK2(*cp, 8);
1855 ND_PRINT((ndo, ", tx_bytes %" PRIu64, EXTRACT_64BITS(cp)));
1856 cp += 8;
1857 /* rx_dropped */
1858 ND_TCHECK2(*cp, 8);
1859 ND_PRINT((ndo, ", rx_dropped %" PRIu64, EXTRACT_64BITS(cp)));
1860 cp += 8;
1861 /* tx_dropped */
1862 ND_TCHECK2(*cp, 8);
1863 ND_PRINT((ndo, ", tx_dropped %" PRIu64, EXTRACT_64BITS(cp)));
1864 cp += 8;
1865 /* rx_errors */
1866 ND_TCHECK2(*cp, 8);
1867 ND_PRINT((ndo, ", rx_errors %" PRIu64, EXTRACT_64BITS(cp)));
1868 cp += 8;
1869 /* tx_errors */
1870 ND_TCHECK2(*cp, 8);
1871 ND_PRINT((ndo, ", tx_errors %" PRIu64, EXTRACT_64BITS(cp)));
1872 cp += 8;
1873 /* rx_frame_err */
1874 ND_TCHECK2(*cp, 8);
1875 ND_PRINT((ndo, ", rx_frame_err %" PRIu64, EXTRACT_64BITS(cp)));
1876 cp += 8;
1877 /* rx_over_err */
1878 ND_TCHECK2(*cp, 8);
1879 ND_PRINT((ndo, ", rx_over_err %" PRIu64, EXTRACT_64BITS(cp)));
1880 cp += 8;
1881 /* rx_crc_err */
1882 ND_TCHECK2(*cp, 8);
1883 ND_PRINT((ndo, ", rx_crc_err %" PRIu64, EXTRACT_64BITS(cp)));
1884 cp += 8;
1885 /* collisions */
1886 ND_TCHECK2(*cp, 8);
1887 ND_PRINT((ndo, ", collisions %" PRIu64, EXTRACT_64BITS(cp)));
1888 cp += 8;
1889 next_port:
1890 len -= OF_PORT_STATS_LEN;
1891 } /* while */
1892 return cp;
1893
1894 corrupt: /* skip the undersized trailing data */
1895 ND_PRINT((ndo, "%s", cstr));
1896 ND_TCHECK2(*cp0, len0);
1897 return cp0 + len0;
1898 trunc:
1899 ND_PRINT((ndo, "%s", tstr));
1900 return ep;
1901 }
1902
1903 /* ibid */
1904 static const u_char *
1905 of10_queue_stats_reply_print(netdissect_options *ndo,
1906 const u_char *cp, const u_char *ep, u_int len) {
1907 const u_char *cp0 = cp;
1908 const u_int len0 = len;
1909
1910 while (len) {
1911 if (len < OF_QUEUE_STATS_LEN)
1912 goto corrupt;
1913 /* port_no */
1914 ND_TCHECK2(*cp, 2);
1915 ND_PRINT((ndo, "\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1916 cp += 2;
1917 /* pad */
1918 ND_TCHECK2(*cp, 2);
1919 cp += 2;
1920 /* queue_id */
1921 ND_TCHECK2(*cp, 4);
1922 ND_PRINT((ndo, ", queue_id %u", EXTRACT_32BITS(cp)));
1923 cp += 4;
1924 /* tx_bytes */
1925 ND_TCHECK2(*cp, 8);
1926 ND_PRINT((ndo, ", tx_bytes %" PRIu64, EXTRACT_64BITS(cp)));
1927 cp += 8;
1928 /* tx_packets */
1929 ND_TCHECK2(*cp, 8);
1930 ND_PRINT((ndo, ", tx_packets %" PRIu64, EXTRACT_64BITS(cp)));
1931 cp += 8;
1932 /* tx_errors */
1933 ND_TCHECK2(*cp, 8);
1934 ND_PRINT((ndo, ", tx_errors %" PRIu64, EXTRACT_64BITS(cp)));
1935 cp += 8;
1936
1937 len -= OF_QUEUE_STATS_LEN;
1938 } /* while */
1939 return cp;
1940
1941 corrupt: /* skip the undersized trailing data */
1942 ND_PRINT((ndo, "%s", cstr));
1943 ND_TCHECK2(*cp0, len0);
1944 return cp0 + len0;
1945 trunc:
1946 ND_PRINT((ndo, "%s", tstr));
1947 return ep;
1948 }
1949
1950 /* ibid */
1951 static const u_char *
1952 of10_stats_reply_print(netdissect_options *ndo,
1953 const u_char *cp, const u_char *ep, const u_int len) {
1954 const u_char *cp0 = cp;
1955 uint16_t type;
1956
1957 /* type */
1958 ND_TCHECK2(*cp, 2);
1959 type = EXTRACT_16BITS(cp);
1960 ND_PRINT((ndo, "\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type)));
1961 cp += 2;
1962 /* flags */
1963 ND_TCHECK2(*cp, 2);
1964 ND_PRINT((ndo, ", flags 0x%04x", EXTRACT_16BITS(cp)));
1965 of10_bitmap_print(ndo, ofpsf_reply_bm, EXTRACT_16BITS(cp), OFPSF_REPLY_U);
1966 cp += 2;
1967
1968 if (ndo->ndo_vflag > 0) {
1969 const u_char *(*decoder)(netdissect_options *, const u_char *, const u_char *, u_int) =
1970 type == OFPST_DESC ? of10_desc_stats_reply_print :
1971 type == OFPST_FLOW ? of10_flow_stats_reply_print :
1972 type == OFPST_AGGREGATE ? of10_aggregate_stats_reply_print :
1973 type == OFPST_TABLE ? of10_table_stats_reply_print :
1974 type == OFPST_PORT ? of10_port_stats_reply_print :
1975 type == OFPST_QUEUE ? of10_queue_stats_reply_print :
1976 type == OFPST_VENDOR ? of10_vendor_data_print :
1977 NULL;
1978 if (decoder != NULL)
1979 return decoder(ndo, cp, ep, len - OF_STATS_REPLY_LEN);
1980 }
1981 ND_TCHECK2(*cp0, len);
1982 return cp0 + len;
1983
1984 trunc:
1985 ND_PRINT((ndo, "%s", tstr));
1986 return ep;
1987 }
1988
1989 /* [OF10] Section 5.3.6 */
1990 static const u_char *
1991 of10_packet_out_print(netdissect_options *ndo,
1992 const u_char *cp, const u_char *ep, const u_int len) {
1993 const u_char *cp0 = cp;
1994 const u_int len0 = len;
1995 uint16_t actions_len;
1996
1997 /* buffer_id */
1998 ND_TCHECK2(*cp, 4);
1999 ND_PRINT((ndo, "\n\t buffer_id 0x%08x", EXTRACT_32BITS(cp)));
2000 cp += 4;
2001 /* in_port */
2002 ND_TCHECK2(*cp, 2);
2003 ND_PRINT((ndo, ", in_port %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
2004 cp += 2;
2005 /* actions_len */
2006 ND_TCHECK2(*cp, 2);
2007 actions_len = EXTRACT_16BITS(cp);
2008 cp += 2;
2009 if (actions_len > len - OF_PACKET_OUT_LEN)
2010 goto corrupt;
2011 /* actions */
2012 if (ep == (cp = of10_actions_print(ndo, "\n\t ", cp, ep, actions_len)))
2013 return ep; /* end of snapshot */
2014 /* data */
2015 return of10_packet_data_print(ndo, cp, ep, len - OF_PACKET_OUT_LEN - actions_len);
2016
2017 corrupt: /* skip the rest of the message body */
2018 ND_PRINT((ndo, "%s", cstr));
2019 ND_TCHECK2(*cp0, len0);
2020 return cp0 + len0;
2021 trunc:
2022 ND_PRINT((ndo, "%s", tstr));
2023 return ep;
2024 }
2025
2026 /* [OF10] Section 5.4.1 */
2027 static const u_char *
2028 of10_packet_in_print(netdissect_options *ndo,
2029 const u_char *cp, const u_char *ep, const u_int len) {
2030 /* buffer_id */
2031 ND_TCHECK2(*cp, 4);
2032 ND_PRINT((ndo, "\n\t buffer_id %s", tok2str(bufferid_str, "0x%08x", EXTRACT_32BITS(cp))));
2033 cp += 4;
2034 /* total_len */
2035 ND_TCHECK2(*cp, 2);
2036 ND_PRINT((ndo, ", total_len %u", EXTRACT_16BITS(cp)));
2037 cp += 2;
2038 /* in_port */
2039 ND_TCHECK2(*cp, 2);
2040 ND_PRINT((ndo, ", in_port %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
2041 cp += 2;
2042 /* reason */
2043 ND_TCHECK2(*cp, 1);
2044 ND_PRINT((ndo, ", reason %s", tok2str(ofpr_str, "invalid (0x%02x)", *cp)));
2045 cp += 1;
2046 /* pad */
2047 ND_TCHECK2(*cp, 1);
2048 cp += 1;
2049 /* data */
2050 /* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
2051 return of10_packet_data_print(ndo, cp, ep, len - (OF_PACKET_IN_LEN - 2));
2052
2053 trunc:
2054 ND_PRINT((ndo, "%s", tstr));
2055 return ep;
2056 }
2057
2058 /* [OF10] Section 5.4.2 */
2059 static const u_char *
2060 of10_flow_removed_print(netdissect_options *ndo,
2061 const u_char *cp, const u_char *ep) {
2062 /* match */
2063 if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
2064 return ep; /* end of snapshot */
2065 /* cookie */
2066 ND_TCHECK2(*cp, 8);
2067 ND_PRINT((ndo, "\n\t cookie 0x%016" PRIx64, EXTRACT_64BITS(cp)));
2068 cp += 8;
2069 /* priority */
2070 ND_TCHECK2(*cp, 2);
2071 if (EXTRACT_16BITS(cp))
2072 ND_PRINT((ndo, ", priority %u", EXTRACT_16BITS(cp)));
2073 cp += 2;
2074 /* reason */
2075 ND_TCHECK2(*cp, 1);
2076 ND_PRINT((ndo, ", reason %s", tok2str(ofprr_str, "unknown (0x%02x)", *cp)));
2077 cp += 1;
2078 /* pad */
2079 ND_TCHECK2(*cp, 1);
2080 cp += 1;
2081 /* duration_sec */
2082 ND_TCHECK2(*cp, 4);
2083 ND_PRINT((ndo, ", duration_sec %u", EXTRACT_32BITS(cp)));
2084 cp += 4;
2085 /* duration_nsec */
2086 ND_TCHECK2(*cp, 4);
2087 ND_PRINT((ndo, ", duration_nsec %u", EXTRACT_32BITS(cp)));
2088 cp += 4;
2089 /* idle_timeout */
2090 ND_TCHECK2(*cp, 2);
2091 if (EXTRACT_16BITS(cp))
2092 ND_PRINT((ndo, ", idle_timeout %u", EXTRACT_16BITS(cp)));
2093 cp += 2;
2094 /* pad2 */
2095 ND_TCHECK2(*cp, 2);
2096 cp += 2;
2097 /* packet_count */
2098 ND_TCHECK2(*cp, 8);
2099 ND_PRINT((ndo, ", packet_count %" PRIu64, EXTRACT_64BITS(cp)));
2100 cp += 8;
2101 /* byte_count */
2102 ND_TCHECK2(*cp, 8);
2103 ND_PRINT((ndo, ", byte_count %" PRIu64, EXTRACT_64BITS(cp)));
2104 return cp + 8;
2105
2106 trunc:
2107 ND_PRINT((ndo, "%s", tstr));
2108 return ep;
2109 }
2110
2111 /* [OF10] Section 5.4.4 */
2112 static const u_char *
2113 of10_error_print(netdissect_options *ndo,
2114 const u_char *cp, const u_char *ep, const u_int len) {
2115 uint16_t type;
2116 const struct tok *code_str;
2117
2118 /* type */
2119 ND_TCHECK2(*cp, 2);
2120 type = EXTRACT_16BITS(cp);
2121 cp += 2;
2122 ND_PRINT((ndo, "\n\t type %s", tok2str(ofpet_str, "invalid (0x%04x)", type)));
2123 /* code */
2124 ND_TCHECK2(*cp, 2);
2125 code_str =
2126 type == OFPET_HELLO_FAILED ? ofphfc_str :
2127 type == OFPET_BAD_REQUEST ? ofpbrc_str :
2128 type == OFPET_BAD_ACTION ? ofpbac_str :
2129 type == OFPET_FLOW_MOD_FAILED ? ofpfmfc_str :
2130 type == OFPET_PORT_MOD_FAILED ? ofppmfc_str :
2131 type == OFPET_QUEUE_OP_FAILED ? ofpqofc_str :
2132 empty_str;
2133 ND_PRINT((ndo, ", code %s", tok2str(code_str, "invalid (0x%04x)", EXTRACT_16BITS(cp))));
2134 cp += 2;
2135 /* data */
2136 return of10_data_print(ndo, cp, ep, len - OF_ERROR_MSG_LEN);
2137
2138 trunc:
2139 ND_PRINT((ndo, "%s", tstr));
2140 return ep;
2141 }
2142
2143 const u_char *
2144 of10_header_body_print(netdissect_options *ndo,
2145 const u_char *cp, const u_char *ep, const uint8_t type,
2146 const uint16_t len, const uint32_t xid) {
2147 const u_char *cp0 = cp;
2148 const u_int len0 = len;
2149 /* Thus far message length is not less than the basic header size, but most
2150 * message types have additional assorted constraints on the length. Wherever
2151 * possible, check that message length meets the constraint, in remaining
2152 * cases check that the length is OK to begin decoding and leave any final
2153 * verification up to a lower-layer function. When the current message is
2154 * corrupt, proceed to the next message. */
2155
2156 /* [OF10] Section 5.1 */
2157 ND_PRINT((ndo, "\n\tversion 1.0, type %s, length %u, xid 0x%08x",
2158 tok2str(ofpt_str, "invalid (0x%02x)", type), len, xid));
2159 switch (type) {
2160 /* OpenFlow header only. */
2161 case OFPT_FEATURES_REQUEST: /* [OF10] Section 5.3.1 */
2162 case OFPT_GET_CONFIG_REQUEST: /* [OF10] Section 5.3.2 */
2163 case OFPT_BARRIER_REQUEST: /* [OF10] Section 5.3.7 */
2164 case OFPT_BARRIER_REPLY: /* ibid */
2165 if (len != OF_HEADER_LEN)
2166 goto corrupt;
2167 break;
2168
2169 /* OpenFlow header and fixed-size message body. */
2170 case OFPT_SET_CONFIG: /* [OF10] Section 5.3.2 */
2171 case OFPT_GET_CONFIG_REPLY: /* ibid */
2172 if (len != OF_SWITCH_CONFIG_LEN)
2173 goto corrupt;
2174 if (ndo->ndo_vflag < 1)
2175 goto next_message;
2176 /* flags */
2177 ND_TCHECK2(*cp, 2);
2178 ND_PRINT((ndo, "\n\t flags %s", tok2str(ofp_config_str, "invalid (0x%04x)", EXTRACT_16BITS(cp))));
2179 cp += 2;
2180 /* miss_send_len */
2181 ND_TCHECK2(*cp, 2);
2182 ND_PRINT((ndo, ", miss_send_len %u", EXTRACT_16BITS(cp)));
2183 return cp + 2;
2184 case OFPT_PORT_MOD:
2185 if (len != OF_PORT_MOD_LEN)
2186 goto corrupt;
2187 if (ndo->ndo_vflag < 1)
2188 goto next_message;
2189 return of10_port_mod_print(ndo, cp, ep);
2190 case OFPT_QUEUE_GET_CONFIG_REQUEST: /* [OF10] Section 5.3.4 */
2191 if (len != OF_QUEUE_GET_CONFIG_REQUEST_LEN)
2192 goto corrupt;
2193 if (ndo->ndo_vflag < 1)
2194 goto next_message;
2195 /* port */
2196 ND_TCHECK2(*cp, 2);
2197 ND_PRINT((ndo, "\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
2198 cp += 2;
2199 /* pad */
2200 ND_TCHECK2(*cp, 2);
2201 return cp + 2;
2202 case OFPT_FLOW_REMOVED:
2203 if (len != OF_FLOW_REMOVED_LEN)
2204 goto corrupt;
2205 if (ndo->ndo_vflag < 1)
2206 goto next_message;
2207 return of10_flow_removed_print(ndo, cp, ep);
2208 case OFPT_PORT_STATUS: /* [OF10] Section 5.4.3 */
2209 if (len != OF_PORT_STATUS_LEN)
2210 goto corrupt;
2211 if (ndo->ndo_vflag < 1)
2212 goto next_message;
2213 /* reason */
2214 ND_TCHECK2(*cp, 1);
2215 ND_PRINT((ndo, "\n\t reason %s", tok2str(ofppr_str, "invalid (0x%02x)", *cp)));
2216 cp += 1;
2217 /* pad */
2218 ND_TCHECK2(*cp, 7);
2219 cp += 7;
2220 /* desc */
2221 return of10_phy_ports_print(ndo, cp, ep, OF_PHY_PORT_LEN);
2222
2223 /* OpenFlow header, fixed-size message body and n * fixed-size data units. */
2224 case OFPT_FEATURES_REPLY:
2225 if (len < OF_SWITCH_FEATURES_LEN)
2226 goto corrupt;
2227 if (ndo->ndo_vflag < 1)
2228 goto next_message;
2229 return of10_features_reply_print(ndo, cp, ep, len);
2230
2231 /* OpenFlow header and variable-size data. */
2232 case OFPT_HELLO: /* [OF10] Section 5.5.1 */
2233 case OFPT_ECHO_REQUEST: /* [OF10] Section 5.5.2 */
2234 case OFPT_ECHO_REPLY: /* [OF10] Section 5.5.3 */
2235 if (ndo->ndo_vflag < 1)
2236 goto next_message;
2237 return of10_data_print(ndo, cp, ep, len - OF_HEADER_LEN);
2238
2239 /* OpenFlow header, fixed-size message body and variable-size data. */
2240 case OFPT_ERROR:
2241 if (len < OF_ERROR_MSG_LEN)
2242 goto corrupt;
2243 if (ndo->ndo_vflag < 1)
2244 goto next_message;
2245 return of10_error_print(ndo, cp, ep, len);
2246 case OFPT_VENDOR:
2247 /* [OF10] Section 5.5.4 */
2248 if (len < OF_VENDOR_HEADER_LEN)
2249 goto corrupt;
2250 if (ndo->ndo_vflag < 1)
2251 goto next_message;
2252 return of10_vendor_message_print(ndo, cp, ep, len - OF_HEADER_LEN);
2253 case OFPT_PACKET_IN:
2254 /* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
2255 if (len < OF_PACKET_IN_LEN - 2)
2256 goto corrupt;
2257 if (ndo->ndo_vflag < 1)
2258 goto next_message;
2259 return of10_packet_in_print(ndo, cp, ep, len);
2260
2261 /* a. OpenFlow header. */
2262 /* b. OpenFlow header and one of the fixed-size message bodies. */
2263 /* c. OpenFlow header, fixed-size message body and variable-size data. */
2264 case OFPT_STATS_REQUEST:
2265 if (len < OF_STATS_REQUEST_LEN)
2266 goto corrupt;
2267 if (ndo->ndo_vflag < 1)
2268 goto next_message;
2269 return of10_stats_request_print(ndo, cp, ep, len);
2270
2271 /* a. OpenFlow header and fixed-size message body. */
2272 /* b. OpenFlow header and n * fixed-size data units. */
2273 /* c. OpenFlow header and n * variable-size data units. */
2274 /* d. OpenFlow header, fixed-size message body and variable-size data. */
2275 case OFPT_STATS_REPLY:
2276 if (len < OF_STATS_REPLY_LEN)
2277 goto corrupt;
2278 if (ndo->ndo_vflag < 1)
2279 goto next_message;
2280 return of10_stats_reply_print(ndo, cp, ep, len);
2281
2282 /* OpenFlow header and n * variable-size data units and variable-size data. */
2283 case OFPT_PACKET_OUT:
2284 if (len < OF_PACKET_OUT_LEN)
2285 goto corrupt;
2286 if (ndo->ndo_vflag < 1)
2287 goto next_message;
2288 return of10_packet_out_print(ndo, cp, ep, len);
2289
2290 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2291 case OFPT_FLOW_MOD:
2292 if (len < OF_FLOW_MOD_LEN)
2293 goto corrupt;
2294 if (ndo->ndo_vflag < 1)
2295 goto next_message;
2296 return of10_flow_mod_print(ndo, cp, ep, len);
2297
2298 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2299 case OFPT_QUEUE_GET_CONFIG_REPLY: /* [OF10] Section 5.3.4 */
2300 if (len < OF_QUEUE_GET_CONFIG_REPLY_LEN)
2301 goto corrupt;
2302 if (ndo->ndo_vflag < 1)
2303 goto next_message;
2304 /* port */
2305 ND_TCHECK2(*cp, 2);
2306 ND_PRINT((ndo, "\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
2307 cp += 2;
2308 /* pad */
2309 ND_TCHECK2(*cp, 6);
2310 cp += 6;
2311 /* queues */
2312 return of10_queues_print(ndo, cp, ep, len - OF_QUEUE_GET_CONFIG_REPLY_LEN);
2313 } /* switch (type) */
2314 goto next_message;
2315
2316 corrupt: /* skip the message body */
2317 ND_PRINT((ndo, "%s", cstr));
2318 next_message:
2319 ND_TCHECK2(*cp0, len0 - OF_HEADER_LEN);
2320 return cp0 + len0 - OF_HEADER_LEN;
2321 trunc:
2322 ND_PRINT((ndo, "%s", tstr));
2323 return ep;
2324 }