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