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