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