]> The Tcpdump Group git mirrors - tcpdump/blob - print-openflow-1.0.c
Update ND_PRINT() as a variadic macro
[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 /* \summary: OpenFlow protocol version 1.0 printer */
60
61 #ifdef HAVE_CONFIG_H
62 #include "config.h"
63 #endif
64
65 #include <netdissect-stdinc.h>
66
67 #include "netdissect.h"
68 #include "extract.h"
69 #include "addrtoname.h"
70 #include "ethertype.h"
71 #include "ipproto.h"
72 #include "oui.h"
73 #include "openflow.h"
74
75 static const char tstr[] = " [|openflow]";
76
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 (1U <<0)
126 #define OFPPC_NO_STP (1U <<1)
127 #define OFPPC_NO_RECV (1U <<2)
128 #define OFPPC_NO_RECV_STP (1U <<3)
129 #define OFPPC_NO_FLOOD (1U <<4)
130 #define OFPPC_NO_FWD (1U <<5)
131 #define OFPPC_NO_PACKET_IN (1U <<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 (1U << 0)
147 #define OFPPS_STP_LISTEN (0U << 8)
148 #define OFPPS_STP_LEARN (1U << 8)
149 #define OFPPS_STP_FORWARD (2U << 8)
150 #define OFPPS_STP_BLOCK (3U << 8)
151 #define OFPPS_STP_MASK (3U << 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 0xff00U
164 #define OFPP_IN_PORT 0xfff8U
165 #define OFPP_TABLE 0xfff9U
166 #define OFPP_NORMAL 0xfffaU
167 #define OFPP_FLOOD 0xfffbU
168 #define OFPP_ALL 0xfffcU
169 #define OFPP_CONTROLLER 0xfffdU
170 #define OFPP_LOCAL 0xfffeU
171 #define OFPP_NONE 0xffffU
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 (1U << 0)
186 #define OFPPF_10MB_FD (1U << 1)
187 #define OFPPF_100MB_HD (1U << 2)
188 #define OFPPF_100MB_FD (1U << 3)
189 #define OFPPF_1GB_HD (1U << 4)
190 #define OFPPF_1GB_FD (1U << 5)
191 #define OFPPF_10GB_FD (1U << 6)
192 #define OFPPF_COPPER (1U << 7)
193 #define OFPPF_FIBER (1U << 8)
194 #define OFPPF_AUTONEG (1U << 9)
195 #define OFPPF_PAUSE (1U <<10)
196 #define OFPPF_PAUSE_ASYM (1U <<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 (1U <<0)
226 #define OFPFW_DL_VLAN (1U <<1)
227 #define OFPFW_DL_SRC (1U <<2)
228 #define OFPFW_DL_DST (1U <<3)
229 #define OFPFW_DL_TYPE (1U <<4)
230 #define OFPFW_NW_PROTO (1U <<5)
231 #define OFPFW_TP_SRC (1U <<6)
232 #define OFPFW_TP_DST (1U <<7)
233 #define OFPFW_NW_SRC_SHIFT 8
234 #define OFPFW_NW_SRC_BITS 6
235 #define OFPFW_NW_SRC_MASK (((1U <<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 (((1U <<OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT)
239 #define OFPFW_DL_VLAN_PCP (1U <<20)
240 #define OFPFW_NW_TOS (1U <<21)
241 #define OFPFW_ALL ((1U <<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 0x0000U
262 #define OFPAT_SET_VLAN_VID 0x0001U
263 #define OFPAT_SET_VLAN_PCP 0x0002U
264 #define OFPAT_STRIP_VLAN 0x0003U
265 #define OFPAT_SET_DL_SRC 0x0004U
266 #define OFPAT_SET_DL_DST 0x0005U
267 #define OFPAT_SET_NW_SRC 0x0006U
268 #define OFPAT_SET_NW_DST 0x0007U
269 #define OFPAT_SET_NW_TOS 0x0008U
270 #define OFPAT_SET_TP_SRC 0x0009U
271 #define OFPAT_SET_TP_DST 0x000aU
272 #define OFPAT_ENQUEUE 0x000bU
273 #define OFPAT_VENDOR 0xffffU
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 { 1U <<OFPAT_OUTPUT, "OUTPUT" },
294 { 1U <<OFPAT_SET_VLAN_VID, "SET_VLAN_VID" },
295 { 1U <<OFPAT_SET_VLAN_PCP, "SET_VLAN_PCP" },
296 { 1U <<OFPAT_STRIP_VLAN, "STRIP_VLAN" },
297 { 1U <<OFPAT_SET_DL_SRC, "SET_DL_SRC" },
298 { 1U <<OFPAT_SET_DL_DST, "SET_DL_DST" },
299 { 1U <<OFPAT_SET_NW_SRC, "SET_NW_SRC" },
300 { 1U <<OFPAT_SET_NW_DST, "SET_NW_DST" },
301 { 1U <<OFPAT_SET_NW_TOS, "SET_NW_TOS" },
302 { 1U <<OFPAT_SET_TP_SRC, "SET_TP_SRC" },
303 { 1U <<OFPAT_SET_TP_DST, "SET_TP_DST" },
304 { 1U <<OFPAT_ENQUEUE, "ENQUEUE" },
305 { 0, NULL }
306 };
307 #define OFPAT_U (~(1U <<OFPAT_OUTPUT | 1U <<OFPAT_SET_VLAN_VID | \
308 1U <<OFPAT_SET_VLAN_PCP | 1U <<OFPAT_STRIP_VLAN | \
309 1U <<OFPAT_SET_DL_SRC | 1U <<OFPAT_SET_DL_DST | \
310 1U <<OFPAT_SET_NW_SRC | 1U <<OFPAT_SET_NW_DST | \
311 1U <<OFPAT_SET_NW_TOS | 1U <<OFPAT_SET_TP_SRC | \
312 1U <<OFPAT_SET_TP_DST | 1U <<OFPAT_ENQUEUE))
313
314 #define OFPC_FLOW_STATS (1U <<0)
315 #define OFPC_TABLE_STATS (1U <<1)
316 #define OFPC_PORT_STATS (1U <<2)
317 #define OFPC_STP (1U <<3)
318 #define OFPC_RESERVED (1U <<4)
319 #define OFPC_IP_REASM (1U <<5)
320 #define OFPC_QUEUE_STATS (1U <<6)
321 #define OFPC_ARP_MATCH_IP (1U <<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 0x0000U
338 #define OFPC_FRAG_DROP 0x0001U
339 #define OFPC_FRAG_REASM 0x0002U
340 #define OFPC_FRAG_MASK 0x0003U
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 0x0000U
349 #define OFPFC_MODIFY 0x0001U
350 #define OFPFC_MODIFY_STRICT 0x0002U
351 #define OFPFC_DELETE 0x0003U
352 #define OFPFC_DELETE_STRICT 0x0004U
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 (1U <<0)
368 #define OFPFF_CHECK_OVERLAP (1U <<1)
369 #define OFPFF_EMERG (1U <<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 0x0000U
379 #define OFPST_FLOW 0x0001U
380 #define OFPST_AGGREGATE 0x0002U
381 #define OFPST_TABLE 0x0003U
382 #define OFPST_PORT 0x0004U
383 #define OFPST_QUEUE 0x0005U
384 #define OFPST_VENDOR 0xffffU
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 { 0xfeU, "EMERG" },
398 { 0xffU, "ALL" },
399 { 0, NULL }
400 };
401
402 #define OFPQ_ALL 0xffffffffU
403 static const struct tok ofpq_str[] = {
404 { OFPQ_ALL, "ALL" },
405 { 0, NULL }
406 };
407
408 #define OFPSF_REPLY_MORE 0x0001U
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 0x00U
416 #define OFPR_ACTION 0x01U
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 0x00U
424 #define OFPRR_HARD_TIMEOUT 0x01U
425 #define OFPRR_DELETE 0x02U
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 0x00U
434 #define OFPPR_DELETE 0x01U
435 #define OFPPR_MODIFY 0x02U
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 0x0000U
444 #define OFPET_BAD_REQUEST 0x0001U
445 #define OFPET_BAD_ACTION 0x0002U
446 #define OFPET_FLOW_MOD_FAILED 0x0003U
447 #define OFPET_PORT_MOD_FAILED 0x0004U
448 #define OFPET_QUEUE_OP_FAILED 0x0005U
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 0x0000U
460 #define OFPHFC_EPERM 0x0001U
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 0x0000U
468 #define OFPBRC_BAD_TYPE 0x0001U
469 #define OFPBRC_BAD_STAT 0x0002U
470 #define OFPBRC_BAD_VENDOR 0x0003U
471 #define OFPBRC_BAD_SUBTYPE 0x0004U
472 #define OFPBRC_EPERM 0x0005U
473 #define OFPBRC_BAD_LEN 0x0006U
474 #define OFPBRC_BUFFER_EMPTY 0x0007U
475 #define OFPBRC_BUFFER_UNKNOWN 0x0008U
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 0x0000U
490 #define OFPBAC_BAD_LEN 0x0001U
491 #define OFPBAC_BAD_VENDOR 0x0002U
492 #define OFPBAC_BAD_VENDOR_TYPE 0x0003U
493 #define OFPBAC_BAD_OUT_PORT 0x0004U
494 #define OFPBAC_BAD_ARGUMENT 0x0005U
495 #define OFPBAC_EPERM 0x0006U
496 #define OFPBAC_TOO_MANY 0x0007U
497 #define OFPBAC_BAD_QUEUE 0x0008U
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 0x0000U
512 #define OFPFMFC_OVERLAP 0x0001U
513 #define OFPFMFC_EPERM 0x0002U
514 #define OFPFMFC_BAD_EMERG_TIMEOUT 0x0003U
515 #define OFPFMFC_BAD_COMMAND 0x0004U
516 #define OFPFMFC_UNSUPPORTED 0x0005U
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 0x0000U
528 #define OFPPMFC_BAD_HW_ADDR 0x0001U
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 0x0000U
536 #define OFPQOFC_BAD_QUEUE 0x0001U
537 #define OFPQOFC_EPERM 0x0002U
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 0xffffU
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("%s%s", sep, t->s);
730 sep = ", ";
731 }
732 /* unassigned bits? */
733 ND_PRINT(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("\n\t data (%u octets)", len);
744 ND_TCHECK_LEN(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("%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_TCHECK_4(cp);
765 subtype = EXTRACT_BE_U_4(cp);
766 cp += 4;
767 ND_PRINT("\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_TCHECK_1(cp);
786 ND_PRINT(", index %u", EXTRACT_U_1(cp));
787 cp += 1;
788 /* pad */
789 ND_TCHECK_7(cp);
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_TCHECK_1(cp);
810 ND_PRINT(", index %u", EXTRACT_U_1(cp));
811 cp += 1;
812 /* pad */
813 ND_TCHECK_3(cp);
814 cp += 3;
815 /* mask */
816 ND_TCHECK_4(cp);
817 ND_PRINT(", 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_TCHECK_1(cp);
837 ND_PRINT(", report_mirror_ports %s", tok2str(bsn_onoff_str, "bogus (%u)", EXTRACT_U_1(cp)));
838 cp += 1;
839 /* pad */
840 ND_TCHECK_3(cp);
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_TCHECK_4(cp);
874 ND_PRINT(", vport_no %u", EXTRACT_BE_U_4(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_TCHECK_4(cp);
894 ND_PRINT(", service %u", EXTRACT_BE_U_4(cp));
895 cp += 4;
896 /* data */
897 ND_PRINT(", data '");
898 if (fn_printn(ndo, cp, len - 8, ep)) {
899 ND_PRINT("'");
900 goto trunc;
901 }
902 ND_PRINT("'");
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(", data '");
919 if (fn_printn(ndo, cp, len - 4, ep)) {
920 ND_PRINT("'");
921 goto trunc;
922 }
923 ND_PRINT("'");
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_TCHECK_4(cp);
941 ND_PRINT(", status 0x%08x", EXTRACT_BE_U_4(cp));
942 cp += 4;
943 break;
944 default:
945 ND_TCHECK_LEN(cp, len - 4);
946 cp += len - 4;
947 }
948 return cp;
949
950 invalid: /* skip the undersized data */
951 ND_PRINT("%s", istr);
952 ND_TCHECK_LEN(cp0, len);
953 return cp0 + len;
954 trunc:
955 ND_PRINT("%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_TCHECK_4(cp);
970 subtype = EXTRACT_BE_U_4(cp);
971 cp += 4;
972 ND_PRINT("\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_TCHECK_4(cp);
993 ND_PRINT(", dest_port %u", EXTRACT_BE_U_4(cp));
994 cp += 4;
995 /* vlan_tag */
996 ND_TCHECK_4(cp);
997 vlan_tag = EXTRACT_BE_U_4(cp);
998 cp += 4;
999 switch (vlan_tag >> 16) {
1000 case 0:
1001 ND_PRINT(", vlan_tag none");
1002 break;
1003 case ETHERTYPE_8021Q:
1004 ND_PRINT(", vlan_tag 802.1Q (%s)", ieee8021q_tci_string(vlan_tag & 0xffff));
1005 break;
1006 default:
1007 ND_PRINT(", vlan_tag unknown (0x%04x)", vlan_tag >> 16);
1008 }
1009 /* copy_stage */
1010 ND_TCHECK_1(cp);
1011 ND_PRINT(", copy_stage %s", tok2str(bsn_mirror_copy_stage_str, "unknown (%u)", EXTRACT_U_1(cp)));
1012 cp += 1;
1013 /* pad */
1014 ND_TCHECK_3(cp);
1015 cp += 3;
1016 break;
1017 default:
1018 ND_TCHECK_LEN(cp, len - 4);
1019 cp += len - 4;
1020 }
1021
1022 return cp;
1023
1024 invalid:
1025 ND_PRINT("%s", istr);
1026 ND_TCHECK_LEN(cp0, len);
1027 return cp0 + len;
1028 trunc:
1029 ND_PRINT("%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_TCHECK_4(cp);
1044 vendor = EXTRACT_BE_U_4(cp);
1045 cp += 4;
1046 ND_PRINT(", 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("%s", istr);
1055 ND_TCHECK_LEN(cp, len);
1056 return cp + len;
1057 trunc:
1058 ND_PRINT("%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_TCHECK_4(cp);
1073 vendor = EXTRACT_BE_U_4(cp);
1074 cp += 4;
1075 ND_PRINT(", 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("%s", istr);
1084 ND_TCHECK_LEN(cp, len);
1085 return cp + len;
1086 trunc:
1087 ND_PRINT("%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_TCHECK_4(cp);
1102 vendor = EXTRACT_BE_U_4(cp);
1103 cp += 4;
1104 ND_PRINT(", 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("%s", istr);
1110 ND_TCHECK_LEN(cp, len);
1111 return cp + len;
1112 trunc:
1113 ND_PRINT("%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("\n\t data (%u octets)", len);
1125 if (ndo->ndo_vflag < 3)
1126 return cp + len;
1127 ND_TCHECK_LEN(cp, len);
1128 ndo->ndo_vflag -= 3;
1129 ND_PRINT(", 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("%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_TCHECK_2(cp);
1152 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
1153 cp += 2;
1154 /* hw_addr */
1155 ND_TCHECK_LEN(cp, MAC_ADDR_LEN);
1156 ND_PRINT(", hw_addr %s", etheraddr_string(ndo, cp));
1157 cp += MAC_ADDR_LEN;
1158 /* name */
1159 ND_TCHECK_LEN(cp, OFP_MAX_PORT_NAME_LEN);
1160 ND_PRINT(", name '");
1161 fn_print(ndo, cp, cp + OFP_MAX_PORT_NAME_LEN);
1162 ND_PRINT("'");
1163 cp += OFP_MAX_PORT_NAME_LEN;
1164
1165 if (ndo->ndo_vflag < 2) {
1166 ND_TCHECK_LEN(cp, 24);
1167 cp += 24;
1168 goto next_port;
1169 }
1170 /* config */
1171 ND_TCHECK_4(cp);
1172 ND_PRINT("\n\t config 0x%08x", EXTRACT_BE_U_4(cp));
1173 of10_bitmap_print(ndo, ofppc_bm, EXTRACT_BE_U_4(cp),
1174 OFPPC_U);
1175 cp += 4;
1176 /* state */
1177 ND_TCHECK_4(cp);
1178 ND_PRINT("\n\t state 0x%08x", EXTRACT_BE_U_4(cp));
1179 of10_bitmap_print(ndo, ofpps_bm, EXTRACT_BE_U_4(cp),
1180 OFPPS_U);
1181 cp += 4;
1182 /* curr */
1183 ND_TCHECK_4(cp);
1184 ND_PRINT("\n\t curr 0x%08x", EXTRACT_BE_U_4(cp));
1185 of10_bitmap_print(ndo, ofppf_bm, EXTRACT_BE_U_4(cp),
1186 OFPPF_U);
1187 cp += 4;
1188 /* advertised */
1189 ND_TCHECK_4(cp);
1190 ND_PRINT("\n\t advertised 0x%08x", EXTRACT_BE_U_4(cp));
1191 of10_bitmap_print(ndo, ofppf_bm, EXTRACT_BE_U_4(cp),
1192 OFPPF_U);
1193 cp += 4;
1194 /* supported */
1195 ND_TCHECK_4(cp);
1196 ND_PRINT("\n\t supported 0x%08x", EXTRACT_BE_U_4(cp));
1197 of10_bitmap_print(ndo, ofppf_bm, EXTRACT_BE_U_4(cp),
1198 OFPPF_U);
1199 cp += 4;
1200 /* peer */
1201 ND_TCHECK_4(cp);
1202 ND_PRINT("\n\t peer 0x%08x", EXTRACT_BE_U_4(cp));
1203 of10_bitmap_print(ndo, ofppf_bm, EXTRACT_BE_U_4(cp),
1204 OFPPF_U);
1205 cp += 4;
1206 next_port:
1207 len -= OF_PHY_PORT_LEN;
1208 } /* while */
1209 return cp;
1210
1211 invalid: /* skip the undersized trailing data */
1212 ND_PRINT("%s", istr);
1213 ND_TCHECK_LEN(cp0, len0);
1214 return cp0 + len0;
1215 trunc:
1216 ND_PRINT("%s", tstr);
1217 return ep;
1218 }
1219
1220 /* [OF10] Section 5.2.2 */
1221 static const u_char *
1222 of10_queue_props_print(netdissect_options *ndo,
1223 const u_char *cp, const u_char *ep, u_int len)
1224 {
1225 const u_char *cp0 = cp;
1226 const u_int len0 = len;
1227 uint16_t property, plen, rate;
1228
1229 while (len) {
1230 u_char plen_bogus = 0, skip = 0;
1231
1232 if (len < OF_QUEUE_PROP_HEADER_LEN)
1233 goto invalid;
1234 /* property */
1235 ND_TCHECK_2(cp);
1236 property = EXTRACT_BE_U_2(cp);
1237 cp += 2;
1238 ND_PRINT("\n\t property %s", tok2str(ofpqt_str, "invalid (0x%04x)", property));
1239 /* len */
1240 ND_TCHECK_2(cp);
1241 plen = EXTRACT_BE_U_2(cp);
1242 cp += 2;
1243 ND_PRINT(", len %u", plen);
1244 if (plen < OF_QUEUE_PROP_HEADER_LEN || plen > len)
1245 goto invalid;
1246 /* pad */
1247 ND_TCHECK_4(cp);
1248 cp += 4;
1249 /* property-specific constraints and decoding */
1250 switch (property) {
1251 case OFPQT_NONE:
1252 plen_bogus = plen != OF_QUEUE_PROP_HEADER_LEN;
1253 break;
1254 case OFPQT_MIN_RATE:
1255 plen_bogus = plen != OF_QUEUE_PROP_MIN_RATE_LEN;
1256 break;
1257 default:
1258 skip = 1;
1259 }
1260 if (plen_bogus) {
1261 ND_PRINT(" (bogus)");
1262 skip = 1;
1263 }
1264 if (skip) {
1265 ND_TCHECK_LEN(cp, plen - 4);
1266 cp += plen - 4;
1267 goto next_property;
1268 }
1269 if (property == OFPQT_MIN_RATE) { /* the only case of property decoding */
1270 /* rate */
1271 ND_TCHECK_2(cp);
1272 rate = EXTRACT_BE_U_2(cp);
1273 cp += 2;
1274 if (rate > 1000)
1275 ND_PRINT(", rate disabled");
1276 else
1277 ND_PRINT(", rate %u.%u%%", rate / 10, rate % 10);
1278 /* pad */
1279 ND_TCHECK_6(cp);
1280 cp += 6;
1281 }
1282 next_property:
1283 len -= plen;
1284 } /* while */
1285 return cp;
1286
1287 invalid: /* skip the rest of queue properties */
1288 ND_PRINT("%s", istr);
1289 ND_TCHECK_LEN(cp0, len0);
1290 return cp0 + len0;
1291 trunc:
1292 ND_PRINT("%s", tstr);
1293 return ep;
1294 }
1295
1296 /* ibid */
1297 static const u_char *
1298 of10_queues_print(netdissect_options *ndo,
1299 const u_char *cp, const u_char *ep, u_int len)
1300 {
1301 const u_char *cp0 = cp;
1302 const u_int len0 = len;
1303 uint16_t desclen;
1304
1305 while (len) {
1306 if (len < OF_PACKET_QUEUE_LEN)
1307 goto invalid;
1308 /* queue_id */
1309 ND_TCHECK_4(cp);
1310 ND_PRINT("\n\t queue_id %u", EXTRACT_BE_U_4(cp));
1311 cp += 4;
1312 /* len */
1313 ND_TCHECK_2(cp);
1314 desclen = EXTRACT_BE_U_2(cp);
1315 cp += 2;
1316 ND_PRINT(", len %u", desclen);
1317 if (desclen < OF_PACKET_QUEUE_LEN || desclen > len)
1318 goto invalid;
1319 /* pad */
1320 ND_TCHECK_2(cp);
1321 cp += 2;
1322 /* properties */
1323 if (ndo->ndo_vflag < 2) {
1324 ND_TCHECK_LEN(cp, desclen - OF_PACKET_QUEUE_LEN);
1325 cp += desclen - OF_PACKET_QUEUE_LEN;
1326 goto next_queue;
1327 }
1328 if (ep == (cp = of10_queue_props_print(ndo, cp, ep, desclen - OF_PACKET_QUEUE_LEN)))
1329 return ep; /* end of snapshot */
1330 next_queue:
1331 len -= desclen;
1332 } /* while */
1333 return cp;
1334
1335 invalid: /* skip the rest of queues */
1336 ND_PRINT("%s", istr);
1337 ND_TCHECK_LEN(cp0, len0);
1338 return cp0 + len0;
1339 trunc:
1340 ND_PRINT("%s", tstr);
1341 return ep;
1342 }
1343
1344 /* [OF10] Section 5.2.3 */
1345 static const u_char *
1346 of10_match_print(netdissect_options *ndo,
1347 const char *pfx, const u_char *cp, const u_char *ep)
1348 {
1349 uint32_t wildcards;
1350 uint16_t dl_type;
1351 uint8_t nw_proto;
1352 u_char nw_bits;
1353 const char *field_name;
1354
1355 /* wildcards */
1356 ND_TCHECK_4(cp);
1357 wildcards = EXTRACT_BE_U_4(cp);
1358 if (wildcards & OFPFW_U)
1359 ND_PRINT("%swildcards 0x%08x (bogus)", pfx, wildcards);
1360 cp += 4;
1361 /* in_port */
1362 ND_TCHECK_2(cp);
1363 if (! (wildcards & OFPFW_IN_PORT))
1364 ND_PRINT("%smatch in_port %s", pfx, tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
1365 cp += 2;
1366 /* dl_src */
1367 ND_TCHECK_LEN(cp, MAC_ADDR_LEN);
1368 if (! (wildcards & OFPFW_DL_SRC))
1369 ND_PRINT("%smatch dl_src %s", pfx, etheraddr_string(ndo, cp));
1370 cp += MAC_ADDR_LEN;
1371 /* dl_dst */
1372 ND_TCHECK_LEN(cp, MAC_ADDR_LEN);
1373 if (! (wildcards & OFPFW_DL_DST))
1374 ND_PRINT("%smatch dl_dst %s", pfx, etheraddr_string(ndo, cp));
1375 cp += MAC_ADDR_LEN;
1376 /* dl_vlan */
1377 ND_TCHECK_2(cp);
1378 if (! (wildcards & OFPFW_DL_VLAN))
1379 ND_PRINT("%smatch dl_vlan %s", pfx, vlan_str(EXTRACT_BE_U_2(cp)));
1380 cp += 2;
1381 /* dl_vlan_pcp */
1382 ND_TCHECK_1(cp);
1383 if (! (wildcards & OFPFW_DL_VLAN_PCP))
1384 ND_PRINT("%smatch dl_vlan_pcp %s", pfx, pcp_str(EXTRACT_U_1(cp)));
1385 cp += 1;
1386 /* pad1 */
1387 ND_TCHECK_1(cp);
1388 cp += 1;
1389 /* dl_type */
1390 ND_TCHECK_2(cp);
1391 dl_type = EXTRACT_BE_U_2(cp);
1392 cp += 2;
1393 if (! (wildcards & OFPFW_DL_TYPE))
1394 ND_PRINT("%smatch dl_type 0x%04x", pfx, dl_type);
1395 /* nw_tos */
1396 ND_TCHECK_1(cp);
1397 if (! (wildcards & OFPFW_NW_TOS))
1398 ND_PRINT("%smatch nw_tos 0x%02x", pfx, EXTRACT_U_1(cp));
1399 cp += 1;
1400 /* nw_proto */
1401 ND_TCHECK_1(cp);
1402 nw_proto = EXTRACT_U_1(cp);
1403 cp += 1;
1404 if (! (wildcards & OFPFW_NW_PROTO)) {
1405 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_ARP
1406 ? "arp_opcode" : "nw_proto";
1407 ND_PRINT("%smatch %s %u", pfx, field_name, nw_proto);
1408 }
1409 /* pad2 */
1410 ND_TCHECK_2(cp);
1411 cp += 2;
1412 /* nw_src */
1413 ND_TCHECK_4(cp);
1414 nw_bits = (wildcards & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT;
1415 if (nw_bits < 32)
1416 ND_PRINT("%smatch nw_src %s/%u", pfx, ipaddr_string(ndo, cp), 32 - nw_bits);
1417 cp += 4;
1418 /* nw_dst */
1419 ND_TCHECK_4(cp);
1420 nw_bits = (wildcards & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT;
1421 if (nw_bits < 32)
1422 ND_PRINT("%smatch nw_dst %s/%u", pfx, ipaddr_string(ndo, cp), 32 - nw_bits);
1423 cp += 4;
1424 /* tp_src */
1425 ND_TCHECK_2(cp);
1426 if (! (wildcards & OFPFW_TP_SRC)) {
1427 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_IP
1428 && ! (wildcards & OFPFW_NW_PROTO) && nw_proto == IPPROTO_ICMP
1429 ? "icmp_type" : "tp_src";
1430 ND_PRINT("%smatch %s %u", pfx, field_name, EXTRACT_BE_U_2(cp));
1431 }
1432 cp += 2;
1433 /* tp_dst */
1434 ND_TCHECK_2(cp);
1435 if (! (wildcards & OFPFW_TP_DST)) {
1436 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_IP
1437 && ! (wildcards & OFPFW_NW_PROTO) && nw_proto == IPPROTO_ICMP
1438 ? "icmp_code" : "tp_dst";
1439 ND_PRINT("%smatch %s %u", pfx, field_name, EXTRACT_BE_U_2(cp));
1440 }
1441 return cp + 2;
1442
1443 trunc:
1444 ND_PRINT("%s", tstr);
1445 return ep;
1446 }
1447
1448 /* [OF10] Section 5.2.4 */
1449 static const u_char *
1450 of10_actions_print(netdissect_options *ndo,
1451 const char *pfx, const u_char *cp, const u_char *ep,
1452 u_int len)
1453 {
1454 const u_char *cp0 = cp;
1455 const u_int len0 = len;
1456 uint16_t type, alen, output_port;
1457
1458 while (len) {
1459 u_char alen_bogus = 0, skip = 0;
1460
1461 if (len < OF_ACTION_HEADER_LEN)
1462 goto invalid;
1463 /* type */
1464 ND_TCHECK_2(cp);
1465 type = EXTRACT_BE_U_2(cp);
1466 cp += 2;
1467 ND_PRINT("%saction type %s", pfx, tok2str(ofpat_str, "invalid (0x%04x)", type));
1468 /* length */
1469 ND_TCHECK_2(cp);
1470 alen = EXTRACT_BE_U_2(cp);
1471 cp += 2;
1472 ND_PRINT(", len %u", alen);
1473 /* On action size underrun/overrun skip the rest of the action list. */
1474 if (alen < OF_ACTION_HEADER_LEN || alen > len)
1475 goto invalid;
1476 /* On action size inappropriate for the given type or invalid type just skip
1477 * the current action, as the basic length constraint has been met. */
1478 switch (type) {
1479 case OFPAT_OUTPUT:
1480 case OFPAT_SET_VLAN_VID:
1481 case OFPAT_SET_VLAN_PCP:
1482 case OFPAT_STRIP_VLAN:
1483 case OFPAT_SET_NW_SRC:
1484 case OFPAT_SET_NW_DST:
1485 case OFPAT_SET_NW_TOS:
1486 case OFPAT_SET_TP_SRC:
1487 case OFPAT_SET_TP_DST:
1488 alen_bogus = alen != 8;
1489 break;
1490 case OFPAT_SET_DL_SRC:
1491 case OFPAT_SET_DL_DST:
1492 case OFPAT_ENQUEUE:
1493 alen_bogus = alen != 16;
1494 break;
1495 case OFPAT_VENDOR:
1496 alen_bogus = alen % 8 != 0; /* already >= 8 so far */
1497 break;
1498 default:
1499 skip = 1;
1500 }
1501 if (alen_bogus) {
1502 ND_PRINT(" (bogus)");
1503 skip = 1;
1504 }
1505 if (skip) {
1506 ND_TCHECK_LEN(cp, alen - 4);
1507 cp += alen - 4;
1508 goto next_action;
1509 }
1510 /* OK to decode the rest of the action structure */
1511 switch (type) {
1512 case OFPAT_OUTPUT:
1513 /* port */
1514 ND_TCHECK_2(cp);
1515 output_port = EXTRACT_BE_U_2(cp);
1516 cp += 2;
1517 ND_PRINT(", port %s", tok2str(ofpp_str, "%u", output_port));
1518 /* max_len */
1519 ND_TCHECK_2(cp);
1520 if (output_port == OFPP_CONTROLLER)
1521 ND_PRINT(", max_len %u", EXTRACT_BE_U_2(cp));
1522 cp += 2;
1523 break;
1524 case OFPAT_SET_VLAN_VID:
1525 /* vlan_vid */
1526 ND_TCHECK_2(cp);
1527 ND_PRINT(", vlan_vid %s", vlan_str(EXTRACT_BE_U_2(cp)));
1528 cp += 2;
1529 /* pad */
1530 ND_TCHECK_2(cp);
1531 cp += 2;
1532 break;
1533 case OFPAT_SET_VLAN_PCP:
1534 /* vlan_pcp */
1535 ND_TCHECK_1(cp);
1536 ND_PRINT(", vlan_pcp %s", pcp_str(EXTRACT_U_1(cp)));
1537 cp += 1;
1538 /* pad */
1539 ND_TCHECK_3(cp);
1540 cp += 3;
1541 break;
1542 case OFPAT_SET_DL_SRC:
1543 case OFPAT_SET_DL_DST:
1544 /* dl_addr */
1545 ND_TCHECK_LEN(cp, MAC_ADDR_LEN);
1546 ND_PRINT(", dl_addr %s", etheraddr_string(ndo, cp));
1547 cp += MAC_ADDR_LEN;
1548 /* pad */
1549 ND_TCHECK_6(cp);
1550 cp += 6;
1551 break;
1552 case OFPAT_SET_NW_SRC:
1553 case OFPAT_SET_NW_DST:
1554 /* nw_addr */
1555 ND_TCHECK_4(cp);
1556 ND_PRINT(", nw_addr %s", ipaddr_string(ndo, cp));
1557 cp += 4;
1558 break;
1559 case OFPAT_SET_NW_TOS:
1560 /* nw_tos */
1561 ND_TCHECK_1(cp);
1562 ND_PRINT(", nw_tos 0x%02x", EXTRACT_U_1(cp));
1563 cp += 1;
1564 /* pad */
1565 ND_TCHECK_3(cp);
1566 cp += 3;
1567 break;
1568 case OFPAT_SET_TP_SRC:
1569 case OFPAT_SET_TP_DST:
1570 /* nw_tos */
1571 ND_TCHECK_2(cp);
1572 ND_PRINT(", tp_port %u", EXTRACT_BE_U_2(cp));
1573 cp += 2;
1574 /* pad */
1575 ND_TCHECK_2(cp);
1576 cp += 2;
1577 break;
1578 case OFPAT_ENQUEUE:
1579 /* port */
1580 ND_TCHECK_2(cp);
1581 ND_PRINT(", port %s", tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
1582 cp += 2;
1583 /* pad */
1584 ND_TCHECK_6(cp);
1585 cp += 6;
1586 /* queue_id */
1587 ND_TCHECK_4(cp);
1588 ND_PRINT(", queue_id %s", tok2str(ofpq_str, "%u", EXTRACT_BE_U_4(cp)));
1589 cp += 4;
1590 break;
1591 case OFPAT_VENDOR:
1592 if (ep == (cp = of10_vendor_action_print(ndo, cp, ep, alen - 4)))
1593 return ep; /* end of snapshot */
1594 break;
1595 case OFPAT_STRIP_VLAN:
1596 /* pad */
1597 ND_TCHECK_4(cp);
1598 cp += 4;
1599 break;
1600 } /* switch */
1601 next_action:
1602 len -= alen;
1603 } /* while */
1604 return cp;
1605
1606 invalid: /* skip the rest of actions */
1607 ND_PRINT("%s", istr);
1608 ND_TCHECK_LEN(cp0, len0);
1609 return cp0 + len0;
1610 trunc:
1611 ND_PRINT("%s", tstr);
1612 return ep;
1613 }
1614
1615 /* [OF10] Section 5.3.1 */
1616 static const u_char *
1617 of10_features_reply_print(netdissect_options *ndo,
1618 const u_char *cp, const u_char *ep, const u_int len)
1619 {
1620 /* datapath_id */
1621 ND_TCHECK_8(cp);
1622 ND_PRINT("\n\t dpid 0x%016" PRIx64, EXTRACT_BE_U_8(cp));
1623 cp += 8;
1624 /* n_buffers */
1625 ND_TCHECK_4(cp);
1626 ND_PRINT(", n_buffers %u", EXTRACT_BE_U_4(cp));
1627 cp += 4;
1628 /* n_tables */
1629 ND_TCHECK_1(cp);
1630 ND_PRINT(", n_tables %u", EXTRACT_U_1(cp));
1631 cp += 1;
1632 /* pad */
1633 ND_TCHECK_3(cp);
1634 cp += 3;
1635 /* capabilities */
1636 ND_TCHECK_4(cp);
1637 ND_PRINT("\n\t capabilities 0x%08x", EXTRACT_BE_U_4(cp));
1638 of10_bitmap_print(ndo, ofp_capabilities_bm, EXTRACT_BE_U_4(cp),
1639 OFPCAP_U);
1640 cp += 4;
1641 /* actions */
1642 ND_TCHECK_4(cp);
1643 ND_PRINT("\n\t actions 0x%08x", EXTRACT_BE_U_4(cp));
1644 of10_bitmap_print(ndo, ofpat_bm, EXTRACT_BE_U_4(cp), OFPAT_U);
1645 cp += 4;
1646 /* ports */
1647 return of10_phy_ports_print(ndo, cp, ep, len - OF_SWITCH_FEATURES_LEN);
1648
1649 trunc:
1650 ND_PRINT("%s", tstr);
1651 return ep;
1652 }
1653
1654 /* [OF10] Section 5.3.3 */
1655 static const u_char *
1656 of10_flow_mod_print(netdissect_options *ndo,
1657 const u_char *cp, const u_char *ep, const u_int len)
1658 {
1659 uint16_t command;
1660
1661 /* match */
1662 if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
1663 return ep; /* end of snapshot */
1664 /* cookie */
1665 ND_TCHECK_8(cp);
1666 ND_PRINT("\n\t cookie 0x%016" PRIx64, EXTRACT_BE_U_8(cp));
1667 cp += 8;
1668 /* command */
1669 ND_TCHECK_2(cp);
1670 command = EXTRACT_BE_U_2(cp);
1671 ND_PRINT(", command %s", tok2str(ofpfc_str, "invalid (0x%04x)", command));
1672 cp += 2;
1673 /* idle_timeout */
1674 ND_TCHECK_2(cp);
1675 if (EXTRACT_BE_U_2(cp))
1676 ND_PRINT(", idle_timeout %u", EXTRACT_BE_U_2(cp));
1677 cp += 2;
1678 /* hard_timeout */
1679 ND_TCHECK_2(cp);
1680 if (EXTRACT_BE_U_2(cp))
1681 ND_PRINT(", hard_timeout %u", EXTRACT_BE_U_2(cp));
1682 cp += 2;
1683 /* priority */
1684 ND_TCHECK_2(cp);
1685 if (EXTRACT_BE_U_2(cp))
1686 ND_PRINT(", priority %u", EXTRACT_BE_U_2(cp));
1687 cp += 2;
1688 /* buffer_id */
1689 ND_TCHECK_4(cp);
1690 if (command == OFPFC_ADD || command == OFPFC_MODIFY ||
1691 command == OFPFC_MODIFY_STRICT)
1692 ND_PRINT(", buffer_id %s", tok2str(bufferid_str, "0x%08x", EXTRACT_BE_U_4(cp)));
1693 cp += 4;
1694 /* out_port */
1695 ND_TCHECK_2(cp);
1696 if (command == OFPFC_DELETE || command == OFPFC_DELETE_STRICT)
1697 ND_PRINT(", out_port %s", tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
1698 cp += 2;
1699 /* flags */
1700 ND_TCHECK_2(cp);
1701 ND_PRINT(", flags 0x%04x", EXTRACT_BE_U_2(cp));
1702 of10_bitmap_print(ndo, ofpff_bm, EXTRACT_BE_U_2(cp), OFPFF_U);
1703 cp += 2;
1704 /* actions */
1705 return of10_actions_print(ndo, "\n\t ", cp, ep, len - OF_FLOW_MOD_LEN);
1706
1707 trunc:
1708 ND_PRINT("%s", tstr);
1709 return ep;
1710 }
1711
1712 /* ibid */
1713 static const u_char *
1714 of10_port_mod_print(netdissect_options *ndo,
1715 const u_char *cp, const u_char *ep)
1716 {
1717 /* port_no */
1718 ND_TCHECK_2(cp);
1719 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
1720 cp += 2;
1721 /* hw_addr */
1722 ND_TCHECK_LEN(cp, MAC_ADDR_LEN);
1723 ND_PRINT(", hw_addr %s", etheraddr_string(ndo, cp));
1724 cp += MAC_ADDR_LEN;
1725 /* config */
1726 ND_TCHECK_4(cp);
1727 ND_PRINT("\n\t config 0x%08x", EXTRACT_BE_U_4(cp));
1728 of10_bitmap_print(ndo, ofppc_bm, EXTRACT_BE_U_4(cp), OFPPC_U);
1729 cp += 4;
1730 /* mask */
1731 ND_TCHECK_4(cp);
1732 ND_PRINT("\n\t mask 0x%08x", EXTRACT_BE_U_4(cp));
1733 of10_bitmap_print(ndo, ofppc_bm, EXTRACT_BE_U_4(cp), OFPPC_U);
1734 cp += 4;
1735 /* advertise */
1736 ND_TCHECK_4(cp);
1737 ND_PRINT("\n\t advertise 0x%08x", EXTRACT_BE_U_4(cp));
1738 of10_bitmap_print(ndo, ofppf_bm, EXTRACT_BE_U_4(cp), OFPPF_U);
1739 cp += 4;
1740 /* pad */
1741 ND_TCHECK_4(cp);
1742 return cp + 4;
1743
1744 trunc:
1745 ND_PRINT("%s", tstr);
1746 return ep;
1747 }
1748
1749 /* [OF10] Section 5.3.5 */
1750 static const u_char *
1751 of10_stats_request_print(netdissect_options *ndo,
1752 const u_char *cp, const u_char *ep, u_int len)
1753 {
1754 const u_char *cp0 = cp;
1755 const u_int len0 = len;
1756 uint16_t type;
1757
1758 /* type */
1759 ND_TCHECK_2(cp);
1760 type = EXTRACT_BE_U_2(cp);
1761 cp += 2;
1762 ND_PRINT("\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type));
1763 /* flags */
1764 ND_TCHECK_2(cp);
1765 ND_PRINT(", flags 0x%04x", EXTRACT_BE_U_2(cp));
1766 if (EXTRACT_BE_U_2(cp))
1767 ND_PRINT(" (bogus)");
1768 cp += 2;
1769 /* type-specific body of one of fixed lengths */
1770 len -= OF_STATS_REQUEST_LEN;
1771 switch(type) {
1772 case OFPST_DESC:
1773 case OFPST_TABLE:
1774 if (len)
1775 goto invalid;
1776 return cp;
1777 case OFPST_FLOW:
1778 case OFPST_AGGREGATE:
1779 if (len != OF_FLOW_STATS_REQUEST_LEN)
1780 goto invalid;
1781 /* match */
1782 if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
1783 return ep; /* end of snapshot */
1784 /* table_id */
1785 ND_TCHECK_1(cp);
1786 ND_PRINT("\n\t table_id %s", tok2str(tableid_str, "%u", EXTRACT_U_1(cp)));
1787 cp += 1;
1788 /* pad */
1789 ND_TCHECK_1(cp);
1790 cp += 1;
1791 /* out_port */
1792 ND_TCHECK_2(cp);
1793 ND_PRINT(", out_port %s", tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
1794 return cp + 2;
1795 case OFPST_PORT:
1796 if (len != OF_PORT_STATS_REQUEST_LEN)
1797 goto invalid;
1798 /* port_no */
1799 ND_TCHECK_2(cp);
1800 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
1801 cp += 2;
1802 /* pad */
1803 ND_TCHECK_6(cp);
1804 return cp + 6;
1805 case OFPST_QUEUE:
1806 if (len != OF_QUEUE_STATS_REQUEST_LEN)
1807 goto invalid;
1808 /* port_no */
1809 ND_TCHECK_2(cp);
1810 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
1811 cp += 2;
1812 /* pad */
1813 ND_TCHECK_2(cp);
1814 cp += 2;
1815 /* queue_id */
1816 ND_TCHECK_4(cp);
1817 ND_PRINT(", queue_id %s", tok2str(ofpq_str, "%u", EXTRACT_BE_U_4(cp)));
1818 return cp + 4;
1819 case OFPST_VENDOR:
1820 return of10_vendor_data_print(ndo, cp, ep, len);
1821 }
1822 return cp;
1823
1824 invalid: /* skip the message body */
1825 ND_PRINT("%s", istr);
1826 ND_TCHECK_LEN(cp0, len0);
1827 return cp0 + len0;
1828 trunc:
1829 ND_PRINT("%s", tstr);
1830 return ep;
1831 }
1832
1833 /* ibid */
1834 static const u_char *
1835 of10_desc_stats_reply_print(netdissect_options *ndo,
1836 const u_char *cp, const u_char *ep, const u_int len)
1837 {
1838 if (len != OF_DESC_STATS_LEN)
1839 goto invalid;
1840 /* mfr_desc */
1841 ND_TCHECK_LEN(cp, DESC_STR_LEN);
1842 ND_PRINT("\n\t mfr_desc '");
1843 fn_print(ndo, cp, cp + DESC_STR_LEN);
1844 ND_PRINT("'");
1845 cp += DESC_STR_LEN;
1846 /* hw_desc */
1847 ND_TCHECK_LEN(cp, DESC_STR_LEN);
1848 ND_PRINT("\n\t hw_desc '");
1849 fn_print(ndo, cp, cp + DESC_STR_LEN);
1850 ND_PRINT("'");
1851 cp += DESC_STR_LEN;
1852 /* sw_desc */
1853 ND_TCHECK_LEN(cp, DESC_STR_LEN);
1854 ND_PRINT("\n\t sw_desc '");
1855 fn_print(ndo, cp, cp + DESC_STR_LEN);
1856 ND_PRINT("'");
1857 cp += DESC_STR_LEN;
1858 /* serial_num */
1859 ND_TCHECK_LEN(cp, SERIAL_NUM_LEN);
1860 ND_PRINT("\n\t serial_num '");
1861 fn_print(ndo, cp, cp + SERIAL_NUM_LEN);
1862 ND_PRINT("'");
1863 cp += SERIAL_NUM_LEN;
1864 /* dp_desc */
1865 ND_TCHECK_LEN(cp, DESC_STR_LEN);
1866 ND_PRINT("\n\t dp_desc '");
1867 fn_print(ndo, cp, cp + DESC_STR_LEN);
1868 ND_PRINT("'");
1869 return cp + DESC_STR_LEN;
1870
1871 invalid: /* skip the message body */
1872 ND_PRINT("%s", istr);
1873 ND_TCHECK_LEN(cp, len);
1874 return cp + len;
1875 trunc:
1876 ND_PRINT("%s", tstr);
1877 return ep;
1878 }
1879
1880 /* ibid */
1881 static const u_char *
1882 of10_flow_stats_reply_print(netdissect_options *ndo,
1883 const u_char *cp, const u_char *ep, u_int len)
1884 {
1885 const u_char *cp0 = cp;
1886 const u_int len0 = len;
1887 uint16_t entry_len;
1888
1889 while (len) {
1890 if (len < OF_FLOW_STATS_LEN)
1891 goto invalid;
1892 /* length */
1893 ND_TCHECK_2(cp);
1894 entry_len = EXTRACT_BE_U_2(cp);
1895 ND_PRINT("\n\t length %u", entry_len);
1896 if (entry_len < OF_FLOW_STATS_LEN || entry_len > len)
1897 goto invalid;
1898 cp += 2;
1899 /* table_id */
1900 ND_TCHECK_1(cp);
1901 ND_PRINT(", table_id %s", tok2str(tableid_str, "%u", EXTRACT_U_1(cp)));
1902 cp += 1;
1903 /* pad */
1904 ND_TCHECK_1(cp);
1905 cp += 1;
1906 /* match */
1907 if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
1908 return ep; /* end of snapshot */
1909 /* duration_sec */
1910 ND_TCHECK_4(cp);
1911 ND_PRINT("\n\t duration_sec %u", EXTRACT_BE_U_4(cp));
1912 cp += 4;
1913 /* duration_nsec */
1914 ND_TCHECK_4(cp);
1915 ND_PRINT(", duration_nsec %u", EXTRACT_BE_U_4(cp));
1916 cp += 4;
1917 /* priority */
1918 ND_TCHECK_2(cp);
1919 ND_PRINT(", priority %u", EXTRACT_BE_U_2(cp));
1920 cp += 2;
1921 /* idle_timeout */
1922 ND_TCHECK_2(cp);
1923 ND_PRINT(", idle_timeout %u", EXTRACT_BE_U_2(cp));
1924 cp += 2;
1925 /* hard_timeout */
1926 ND_TCHECK_2(cp);
1927 ND_PRINT(", hard_timeout %u", EXTRACT_BE_U_2(cp));
1928 cp += 2;
1929 /* pad2 */
1930 ND_TCHECK_6(cp);
1931 cp += 6;
1932 /* cookie */
1933 ND_TCHECK_8(cp);
1934 ND_PRINT(", cookie 0x%016" PRIx64, EXTRACT_BE_U_8(cp));
1935 cp += 8;
1936 /* packet_count */
1937 ND_TCHECK_8(cp);
1938 ND_PRINT(", packet_count %" PRIu64, EXTRACT_BE_U_8(cp));
1939 cp += 8;
1940 /* byte_count */
1941 ND_TCHECK_8(cp);
1942 ND_PRINT(", byte_count %" PRIu64, EXTRACT_BE_U_8(cp));
1943 cp += 8;
1944 /* actions */
1945 if (ep == (cp = of10_actions_print(ndo, "\n\t ", cp, ep, entry_len - OF_FLOW_STATS_LEN)))
1946 return ep; /* end of snapshot */
1947
1948 len -= entry_len;
1949 } /* while */
1950 return cp;
1951
1952 invalid: /* skip the rest of flow statistics entries */
1953 ND_PRINT("%s", istr);
1954 ND_TCHECK_LEN(cp0, len0);
1955 return cp0 + len0;
1956 trunc:
1957 ND_PRINT("%s", tstr);
1958 return ep;
1959 }
1960
1961 /* ibid */
1962 static const u_char *
1963 of10_aggregate_stats_reply_print(netdissect_options *ndo,
1964 const u_char *cp, const u_char *ep,
1965 const u_int len)
1966 {
1967 if (len != OF_AGGREGATE_STATS_REPLY_LEN)
1968 goto invalid;
1969 /* packet_count */
1970 ND_TCHECK_8(cp);
1971 ND_PRINT("\n\t packet_count %" PRIu64, EXTRACT_BE_U_8(cp));
1972 cp += 8;
1973 /* byte_count */
1974 ND_TCHECK_8(cp);
1975 ND_PRINT(", byte_count %" PRIu64, EXTRACT_BE_U_8(cp));
1976 cp += 8;
1977 /* flow_count */
1978 ND_TCHECK_4(cp);
1979 ND_PRINT(", flow_count %u", EXTRACT_BE_U_4(cp));
1980 cp += 4;
1981 /* pad */
1982 ND_TCHECK_4(cp);
1983 return cp + 4;
1984
1985 invalid: /* skip the message body */
1986 ND_PRINT("%s", istr);
1987 ND_TCHECK_LEN(cp, len);
1988 return cp + len;
1989 trunc:
1990 ND_PRINT("%s", tstr);
1991 return ep;
1992 }
1993
1994 /* ibid */
1995 static const u_char *
1996 of10_table_stats_reply_print(netdissect_options *ndo,
1997 const u_char *cp, const u_char *ep, u_int len)
1998 {
1999 const u_char *cp0 = cp;
2000 const u_int len0 = len;
2001
2002 while (len) {
2003 if (len < OF_TABLE_STATS_LEN)
2004 goto invalid;
2005 /* table_id */
2006 ND_TCHECK_1(cp);
2007 ND_PRINT("\n\t table_id %s", tok2str(tableid_str, "%u", EXTRACT_U_1(cp)));
2008 cp += 1;
2009 /* pad */
2010 ND_TCHECK_3(cp);
2011 cp += 3;
2012 /* name */
2013 ND_TCHECK_LEN(cp, OFP_MAX_TABLE_NAME_LEN);
2014 ND_PRINT(", name '");
2015 fn_print(ndo, cp, cp + OFP_MAX_TABLE_NAME_LEN);
2016 ND_PRINT("'");
2017 cp += OFP_MAX_TABLE_NAME_LEN;
2018 /* wildcards */
2019 ND_TCHECK_4(cp);
2020 ND_PRINT("\n\t wildcards 0x%08x", EXTRACT_BE_U_4(cp));
2021 of10_bitmap_print(ndo, ofpfw_bm, EXTRACT_BE_U_4(cp),
2022 OFPFW_U);
2023 cp += 4;
2024 /* max_entries */
2025 ND_TCHECK_4(cp);
2026 ND_PRINT("\n\t max_entries %u", EXTRACT_BE_U_4(cp));
2027 cp += 4;
2028 /* active_count */
2029 ND_TCHECK_4(cp);
2030 ND_PRINT(", active_count %u", EXTRACT_BE_U_4(cp));
2031 cp += 4;
2032 /* lookup_count */
2033 ND_TCHECK_8(cp);
2034 ND_PRINT(", lookup_count %" PRIu64, EXTRACT_BE_U_8(cp));
2035 cp += 8;
2036 /* matched_count */
2037 ND_TCHECK_8(cp);
2038 ND_PRINT(", matched_count %" PRIu64, EXTRACT_BE_U_8(cp));
2039 cp += 8;
2040
2041 len -= OF_TABLE_STATS_LEN;
2042 } /* while */
2043 return cp;
2044
2045 invalid: /* skip the undersized trailing data */
2046 ND_PRINT("%s", istr);
2047 ND_TCHECK_LEN(cp0, len0);
2048 return cp0 + len0;
2049 trunc:
2050 ND_PRINT("%s", tstr);
2051 return ep;
2052 }
2053
2054 /* ibid */
2055 static const u_char *
2056 of10_port_stats_reply_print(netdissect_options *ndo,
2057 const u_char *cp, const u_char *ep, u_int len)
2058 {
2059 const u_char *cp0 = cp;
2060 const u_int len0 = len;
2061
2062 while (len) {
2063 if (len < OF_PORT_STATS_LEN)
2064 goto invalid;
2065 /* port_no */
2066 ND_TCHECK_2(cp);
2067 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
2068 cp += 2;
2069 if (ndo->ndo_vflag < 2) {
2070 ND_TCHECK_LEN(cp, OF_PORT_STATS_LEN - 2);
2071 cp += OF_PORT_STATS_LEN - 2;
2072 goto next_port;
2073 }
2074 /* pad */
2075 ND_TCHECK_6(cp);
2076 cp += 6;
2077 /* rx_packets */
2078 ND_TCHECK_8(cp);
2079 ND_PRINT(", rx_packets %" PRIu64, EXTRACT_BE_U_8(cp));
2080 cp += 8;
2081 /* tx_packets */
2082 ND_TCHECK_8(cp);
2083 ND_PRINT(", tx_packets %" PRIu64, EXTRACT_BE_U_8(cp));
2084 cp += 8;
2085 /* rx_bytes */
2086 ND_TCHECK_8(cp);
2087 ND_PRINT(", rx_bytes %" PRIu64, EXTRACT_BE_U_8(cp));
2088 cp += 8;
2089 /* tx_bytes */
2090 ND_TCHECK_8(cp);
2091 ND_PRINT(", tx_bytes %" PRIu64, EXTRACT_BE_U_8(cp));
2092 cp += 8;
2093 /* rx_dropped */
2094 ND_TCHECK_8(cp);
2095 ND_PRINT(", rx_dropped %" PRIu64, EXTRACT_BE_U_8(cp));
2096 cp += 8;
2097 /* tx_dropped */
2098 ND_TCHECK_8(cp);
2099 ND_PRINT(", tx_dropped %" PRIu64, EXTRACT_BE_U_8(cp));
2100 cp += 8;
2101 /* rx_errors */
2102 ND_TCHECK_8(cp);
2103 ND_PRINT(", rx_errors %" PRIu64, EXTRACT_BE_U_8(cp));
2104 cp += 8;
2105 /* tx_errors */
2106 ND_TCHECK_8(cp);
2107 ND_PRINT(", tx_errors %" PRIu64, EXTRACT_BE_U_8(cp));
2108 cp += 8;
2109 /* rx_frame_err */
2110 ND_TCHECK_8(cp);
2111 ND_PRINT(", rx_frame_err %" PRIu64, EXTRACT_BE_U_8(cp));
2112 cp += 8;
2113 /* rx_over_err */
2114 ND_TCHECK_8(cp);
2115 ND_PRINT(", rx_over_err %" PRIu64, EXTRACT_BE_U_8(cp));
2116 cp += 8;
2117 /* rx_crc_err */
2118 ND_TCHECK_8(cp);
2119 ND_PRINT(", rx_crc_err %" PRIu64, EXTRACT_BE_U_8(cp));
2120 cp += 8;
2121 /* collisions */
2122 ND_TCHECK_8(cp);
2123 ND_PRINT(", collisions %" PRIu64, EXTRACT_BE_U_8(cp));
2124 cp += 8;
2125 next_port:
2126 len -= OF_PORT_STATS_LEN;
2127 } /* while */
2128 return cp;
2129
2130 invalid: /* skip the undersized trailing data */
2131 ND_PRINT("%s", istr);
2132 ND_TCHECK_LEN(cp0, len0);
2133 return cp0 + len0;
2134 trunc:
2135 ND_PRINT("%s", tstr);
2136 return ep;
2137 }
2138
2139 /* ibid */
2140 static const u_char *
2141 of10_queue_stats_reply_print(netdissect_options *ndo,
2142 const u_char *cp, const u_char *ep, u_int len)
2143 {
2144 const u_char *cp0 = cp;
2145 const u_int len0 = len;
2146
2147 while (len) {
2148 if (len < OF_QUEUE_STATS_LEN)
2149 goto invalid;
2150 /* port_no */
2151 ND_TCHECK_2(cp);
2152 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
2153 cp += 2;
2154 /* pad */
2155 ND_TCHECK_2(cp);
2156 cp += 2;
2157 /* queue_id */
2158 ND_TCHECK_4(cp);
2159 ND_PRINT(", queue_id %u", EXTRACT_BE_U_4(cp));
2160 cp += 4;
2161 /* tx_bytes */
2162 ND_TCHECK_8(cp);
2163 ND_PRINT(", tx_bytes %" PRIu64, EXTRACT_BE_U_8(cp));
2164 cp += 8;
2165 /* tx_packets */
2166 ND_TCHECK_8(cp);
2167 ND_PRINT(", tx_packets %" PRIu64, EXTRACT_BE_U_8(cp));
2168 cp += 8;
2169 /* tx_errors */
2170 ND_TCHECK_8(cp);
2171 ND_PRINT(", tx_errors %" PRIu64, EXTRACT_BE_U_8(cp));
2172 cp += 8;
2173
2174 len -= OF_QUEUE_STATS_LEN;
2175 } /* while */
2176 return cp;
2177
2178 invalid: /* skip the undersized trailing data */
2179 ND_PRINT("%s", istr);
2180 ND_TCHECK_LEN(cp0, len0);
2181 return cp0 + len0;
2182 trunc:
2183 ND_PRINT("%s", tstr);
2184 return ep;
2185 }
2186
2187 /* ibid */
2188 static const u_char *
2189 of10_stats_reply_print(netdissect_options *ndo,
2190 const u_char *cp, const u_char *ep, const u_int len)
2191 {
2192 const u_char *cp0 = cp;
2193 uint16_t type;
2194
2195 /* type */
2196 ND_TCHECK_2(cp);
2197 type = EXTRACT_BE_U_2(cp);
2198 ND_PRINT("\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type));
2199 cp += 2;
2200 /* flags */
2201 ND_TCHECK_2(cp);
2202 ND_PRINT(", flags 0x%04x", EXTRACT_BE_U_2(cp));
2203 of10_bitmap_print(ndo, ofpsf_reply_bm, EXTRACT_BE_U_2(cp),
2204 OFPSF_REPLY_U);
2205 cp += 2;
2206
2207 if (ndo->ndo_vflag > 0) {
2208 const u_char *(*decoder)(netdissect_options *, const u_char *, const u_char *, u_int) =
2209 type == OFPST_DESC ? of10_desc_stats_reply_print :
2210 type == OFPST_FLOW ? of10_flow_stats_reply_print :
2211 type == OFPST_AGGREGATE ? of10_aggregate_stats_reply_print :
2212 type == OFPST_TABLE ? of10_table_stats_reply_print :
2213 type == OFPST_PORT ? of10_port_stats_reply_print :
2214 type == OFPST_QUEUE ? of10_queue_stats_reply_print :
2215 type == OFPST_VENDOR ? of10_vendor_data_print :
2216 NULL;
2217 if (decoder != NULL)
2218 return decoder(ndo, cp, ep, len - OF_STATS_REPLY_LEN);
2219 }
2220 ND_TCHECK_LEN(cp0, len);
2221 return cp0 + len;
2222
2223 trunc:
2224 ND_PRINT("%s", tstr);
2225 return ep;
2226 }
2227
2228 /* [OF10] Section 5.3.6 */
2229 static const u_char *
2230 of10_packet_out_print(netdissect_options *ndo,
2231 const u_char *cp, const u_char *ep, const u_int len)
2232 {
2233 const u_char *cp0 = cp;
2234 const u_int len0 = len;
2235 uint16_t actions_len;
2236
2237 /* buffer_id */
2238 ND_TCHECK_4(cp);
2239 ND_PRINT("\n\t buffer_id 0x%08x", EXTRACT_BE_U_4(cp));
2240 cp += 4;
2241 /* in_port */
2242 ND_TCHECK_2(cp);
2243 ND_PRINT(", in_port %s", tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
2244 cp += 2;
2245 /* actions_len */
2246 ND_TCHECK_2(cp);
2247 actions_len = EXTRACT_BE_U_2(cp);
2248 cp += 2;
2249 if (actions_len > len - OF_PACKET_OUT_LEN)
2250 goto invalid;
2251 /* actions */
2252 if (ep == (cp = of10_actions_print(ndo, "\n\t ", cp, ep, actions_len)))
2253 return ep; /* end of snapshot */
2254 /* data */
2255 return of10_packet_data_print(ndo, cp, ep, len - OF_PACKET_OUT_LEN - actions_len);
2256
2257 invalid: /* skip the rest of the message body */
2258 ND_PRINT("%s", istr);
2259 ND_TCHECK_LEN(cp0, len0);
2260 return cp0 + len0;
2261 trunc:
2262 ND_PRINT("%s", tstr);
2263 return ep;
2264 }
2265
2266 /* [OF10] Section 5.4.1 */
2267 static const u_char *
2268 of10_packet_in_print(netdissect_options *ndo,
2269 const u_char *cp, const u_char *ep, const u_int len)
2270 {
2271 /* buffer_id */
2272 ND_TCHECK_4(cp);
2273 ND_PRINT("\n\t buffer_id %s", tok2str(bufferid_str, "0x%08x", EXTRACT_BE_U_4(cp)));
2274 cp += 4;
2275 /* total_len */
2276 ND_TCHECK_2(cp);
2277 ND_PRINT(", total_len %u", EXTRACT_BE_U_2(cp));
2278 cp += 2;
2279 /* in_port */
2280 ND_TCHECK_2(cp);
2281 ND_PRINT(", in_port %s", tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
2282 cp += 2;
2283 /* reason */
2284 ND_TCHECK_1(cp);
2285 ND_PRINT(", reason %s", tok2str(ofpr_str, "invalid (0x%02x)", EXTRACT_U_1(cp)));
2286 cp += 1;
2287 /* pad */
2288 ND_TCHECK_1(cp);
2289 cp += 1;
2290 /* data */
2291 /* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
2292 return of10_packet_data_print(ndo, cp, ep, len - (OF_PACKET_IN_LEN - 2));
2293
2294 trunc:
2295 ND_PRINT("%s", tstr);
2296 return ep;
2297 }
2298
2299 /* [OF10] Section 5.4.2 */
2300 static const u_char *
2301 of10_flow_removed_print(netdissect_options *ndo,
2302 const u_char *cp, const u_char *ep)
2303 {
2304 /* match */
2305 if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
2306 return ep; /* end of snapshot */
2307 /* cookie */
2308 ND_TCHECK_8(cp);
2309 ND_PRINT("\n\t cookie 0x%016" PRIx64, EXTRACT_BE_U_8(cp));
2310 cp += 8;
2311 /* priority */
2312 ND_TCHECK_2(cp);
2313 if (EXTRACT_BE_U_2(cp))
2314 ND_PRINT(", priority %u", EXTRACT_BE_U_2(cp));
2315 cp += 2;
2316 /* reason */
2317 ND_TCHECK_1(cp);
2318 ND_PRINT(", reason %s", tok2str(ofprr_str, "unknown (0x%02x)", EXTRACT_U_1(cp)));
2319 cp += 1;
2320 /* pad */
2321 ND_TCHECK_1(cp);
2322 cp += 1;
2323 /* duration_sec */
2324 ND_TCHECK_4(cp);
2325 ND_PRINT(", duration_sec %u", EXTRACT_BE_U_4(cp));
2326 cp += 4;
2327 /* duration_nsec */
2328 ND_TCHECK_4(cp);
2329 ND_PRINT(", duration_nsec %u", EXTRACT_BE_U_4(cp));
2330 cp += 4;
2331 /* idle_timeout */
2332 ND_TCHECK_2(cp);
2333 if (EXTRACT_BE_U_2(cp))
2334 ND_PRINT(", idle_timeout %u", EXTRACT_BE_U_2(cp));
2335 cp += 2;
2336 /* pad2 */
2337 ND_TCHECK_2(cp);
2338 cp += 2;
2339 /* packet_count */
2340 ND_TCHECK_8(cp);
2341 ND_PRINT(", packet_count %" PRIu64, EXTRACT_BE_U_8(cp));
2342 cp += 8;
2343 /* byte_count */
2344 ND_TCHECK_8(cp);
2345 ND_PRINT(", byte_count %" PRIu64, EXTRACT_BE_U_8(cp));
2346 return cp + 8;
2347
2348 trunc:
2349 ND_PRINT("%s", tstr);
2350 return ep;
2351 }
2352
2353 /* [OF10] Section 5.4.4 */
2354 static const u_char *
2355 of10_error_print(netdissect_options *ndo,
2356 const u_char *cp, const u_char *ep, const u_int len)
2357 {
2358 uint16_t type;
2359 const struct tok *code_str;
2360
2361 /* type */
2362 ND_TCHECK_2(cp);
2363 type = EXTRACT_BE_U_2(cp);
2364 cp += 2;
2365 ND_PRINT("\n\t type %s", tok2str(ofpet_str, "invalid (0x%04x)", type));
2366 /* code */
2367 ND_TCHECK_2(cp);
2368 code_str =
2369 type == OFPET_HELLO_FAILED ? ofphfc_str :
2370 type == OFPET_BAD_REQUEST ? ofpbrc_str :
2371 type == OFPET_BAD_ACTION ? ofpbac_str :
2372 type == OFPET_FLOW_MOD_FAILED ? ofpfmfc_str :
2373 type == OFPET_PORT_MOD_FAILED ? ofppmfc_str :
2374 type == OFPET_QUEUE_OP_FAILED ? ofpqofc_str :
2375 empty_str;
2376 ND_PRINT(", code %s", tok2str(code_str, "invalid (0x%04x)", EXTRACT_BE_U_2(cp)));
2377 cp += 2;
2378 /* data */
2379 return of10_data_print(ndo, cp, ep, len - OF_ERROR_MSG_LEN);
2380
2381 trunc:
2382 ND_PRINT("%s", tstr);
2383 return ep;
2384 }
2385
2386 const u_char *
2387 of10_header_body_print(netdissect_options *ndo,
2388 const u_char *cp, const u_char *ep, const uint8_t type,
2389 const uint16_t len, const uint32_t xid)
2390 {
2391 const u_char *cp0 = cp;
2392 const u_int len0 = len;
2393 /* Thus far message length is not less than the basic header size, but most
2394 * message types have additional assorted constraints on the length. Wherever
2395 * possible, check that message length meets the constraint, in remaining
2396 * cases check that the length is OK to begin decoding and leave any final
2397 * verification up to a lower-layer function. When the current message is
2398 * invalid, proceed to the next message. */
2399
2400 /* [OF10] Section 5.1 */
2401 ND_PRINT("\n\tversion 1.0, type %s, length %u, xid 0x%08x",
2402 tok2str(ofpt_str, "invalid (0x%02x)", type), len, xid);
2403 switch (type) {
2404 /* OpenFlow header only. */
2405 case OFPT_FEATURES_REQUEST: /* [OF10] Section 5.3.1 */
2406 case OFPT_GET_CONFIG_REQUEST: /* [OF10] Section 5.3.2 */
2407 case OFPT_BARRIER_REQUEST: /* [OF10] Section 5.3.7 */
2408 case OFPT_BARRIER_REPLY: /* ibid */
2409 if (len != OF_HEADER_LEN)
2410 goto invalid;
2411 break;
2412
2413 /* OpenFlow header and fixed-size message body. */
2414 case OFPT_SET_CONFIG: /* [OF10] Section 5.3.2 */
2415 case OFPT_GET_CONFIG_REPLY: /* ibid */
2416 if (len != OF_SWITCH_CONFIG_LEN)
2417 goto invalid;
2418 if (ndo->ndo_vflag < 1)
2419 goto next_message;
2420 /* flags */
2421 ND_TCHECK_2(cp);
2422 ND_PRINT("\n\t flags %s", tok2str(ofp_config_str, "invalid (0x%04x)", EXTRACT_BE_U_2(cp)));
2423 cp += 2;
2424 /* miss_send_len */
2425 ND_TCHECK_2(cp);
2426 ND_PRINT(", miss_send_len %u", EXTRACT_BE_U_2(cp));
2427 return cp + 2;
2428 case OFPT_PORT_MOD:
2429 if (len != OF_PORT_MOD_LEN)
2430 goto invalid;
2431 if (ndo->ndo_vflag < 1)
2432 goto next_message;
2433 return of10_port_mod_print(ndo, cp, ep);
2434 case OFPT_QUEUE_GET_CONFIG_REQUEST: /* [OF10] Section 5.3.4 */
2435 if (len != OF_QUEUE_GET_CONFIG_REQUEST_LEN)
2436 goto invalid;
2437 if (ndo->ndo_vflag < 1)
2438 goto next_message;
2439 /* port */
2440 ND_TCHECK_2(cp);
2441 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
2442 cp += 2;
2443 /* pad */
2444 ND_TCHECK_2(cp);
2445 return cp + 2;
2446 case OFPT_FLOW_REMOVED:
2447 if (len != OF_FLOW_REMOVED_LEN)
2448 goto invalid;
2449 if (ndo->ndo_vflag < 1)
2450 goto next_message;
2451 return of10_flow_removed_print(ndo, cp, ep);
2452 case OFPT_PORT_STATUS: /* [OF10] Section 5.4.3 */
2453 if (len != OF_PORT_STATUS_LEN)
2454 goto invalid;
2455 if (ndo->ndo_vflag < 1)
2456 goto next_message;
2457 /* reason */
2458 ND_TCHECK_1(cp);
2459 ND_PRINT("\n\t reason %s", tok2str(ofppr_str, "invalid (0x%02x)", EXTRACT_U_1(cp)));
2460 cp += 1;
2461 /* pad */
2462 ND_TCHECK_7(cp);
2463 cp += 7;
2464 /* desc */
2465 return of10_phy_ports_print(ndo, cp, ep, OF_PHY_PORT_LEN);
2466
2467 /* OpenFlow header, fixed-size message body and n * fixed-size data units. */
2468 case OFPT_FEATURES_REPLY:
2469 if (len < OF_SWITCH_FEATURES_LEN)
2470 goto invalid;
2471 if (ndo->ndo_vflag < 1)
2472 goto next_message;
2473 return of10_features_reply_print(ndo, cp, ep, len);
2474
2475 /* OpenFlow header and variable-size data. */
2476 case OFPT_HELLO: /* [OF10] Section 5.5.1 */
2477 case OFPT_ECHO_REQUEST: /* [OF10] Section 5.5.2 */
2478 case OFPT_ECHO_REPLY: /* [OF10] Section 5.5.3 */
2479 if (ndo->ndo_vflag < 1)
2480 goto next_message;
2481 return of10_data_print(ndo, cp, ep, len - OF_HEADER_LEN);
2482
2483 /* OpenFlow header, fixed-size message body and variable-size data. */
2484 case OFPT_ERROR:
2485 if (len < OF_ERROR_MSG_LEN)
2486 goto invalid;
2487 if (ndo->ndo_vflag < 1)
2488 goto next_message;
2489 return of10_error_print(ndo, cp, ep, len);
2490 case OFPT_VENDOR:
2491 /* [OF10] Section 5.5.4 */
2492 if (len < OF_VENDOR_HEADER_LEN)
2493 goto invalid;
2494 if (ndo->ndo_vflag < 1)
2495 goto next_message;
2496 return of10_vendor_message_print(ndo, cp, ep, len - OF_HEADER_LEN);
2497 case OFPT_PACKET_IN:
2498 /* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
2499 if (len < OF_PACKET_IN_LEN - 2)
2500 goto invalid;
2501 if (ndo->ndo_vflag < 1)
2502 goto next_message;
2503 return of10_packet_in_print(ndo, cp, ep, len);
2504
2505 /* a. OpenFlow header. */
2506 /* b. OpenFlow header and one of the fixed-size message bodies. */
2507 /* c. OpenFlow header, fixed-size message body and variable-size data. */
2508 case OFPT_STATS_REQUEST:
2509 if (len < OF_STATS_REQUEST_LEN)
2510 goto invalid;
2511 if (ndo->ndo_vflag < 1)
2512 goto next_message;
2513 return of10_stats_request_print(ndo, cp, ep, len);
2514
2515 /* a. OpenFlow header and fixed-size message body. */
2516 /* b. OpenFlow header and n * fixed-size data units. */
2517 /* c. OpenFlow header and n * variable-size data units. */
2518 /* d. OpenFlow header, fixed-size message body and variable-size data. */
2519 case OFPT_STATS_REPLY:
2520 if (len < OF_STATS_REPLY_LEN)
2521 goto invalid;
2522 if (ndo->ndo_vflag < 1)
2523 goto next_message;
2524 return of10_stats_reply_print(ndo, cp, ep, len);
2525
2526 /* OpenFlow header and n * variable-size data units and variable-size data. */
2527 case OFPT_PACKET_OUT:
2528 if (len < OF_PACKET_OUT_LEN)
2529 goto invalid;
2530 if (ndo->ndo_vflag < 1)
2531 goto next_message;
2532 return of10_packet_out_print(ndo, cp, ep, len);
2533
2534 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2535 case OFPT_FLOW_MOD:
2536 if (len < OF_FLOW_MOD_LEN)
2537 goto invalid;
2538 if (ndo->ndo_vflag < 1)
2539 goto next_message;
2540 return of10_flow_mod_print(ndo, cp, ep, len);
2541
2542 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2543 case OFPT_QUEUE_GET_CONFIG_REPLY: /* [OF10] Section 5.3.4 */
2544 if (len < OF_QUEUE_GET_CONFIG_REPLY_LEN)
2545 goto invalid;
2546 if (ndo->ndo_vflag < 1)
2547 goto next_message;
2548 /* port */
2549 ND_TCHECK_2(cp);
2550 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_BE_U_2(cp)));
2551 cp += 2;
2552 /* pad */
2553 ND_TCHECK_6(cp);
2554 cp += 6;
2555 /* queues */
2556 return of10_queues_print(ndo, cp, ep, len - OF_QUEUE_GET_CONFIG_REPLY_LEN);
2557 } /* switch (type) */
2558 goto next_message;
2559
2560 invalid: /* skip the message body */
2561 ND_PRINT("%s", istr);
2562 next_message:
2563 ND_TCHECK_LEN(cp0, len0 - OF_HEADER_LEN);
2564 return cp0 + len0 - OF_HEADER_LEN;
2565 trunc:
2566 ND_PRINT("%s", tstr);
2567 return ep;
2568 }