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