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