]> The Tcpdump Group git mirrors - tcpdump/blob - print-openflow-1.0.c
b2eb27d85432d5f6e0a92b4293874c89c4df377f
[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 subtype = GET_BE_U_4(cp);
764 cp += 4;
765 ND_PRINT("\n\t subtype %s", tok2str(bsn_subtype_str, "unknown (0x%08x)", subtype));
766 switch (subtype) {
767 case BSN_GET_IP_MASK_REQUEST:
768 /*
769 * 0 1 2 3
770 * 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
771 * +---------------+---------------+---------------+---------------+
772 * | subtype |
773 * +---------------+---------------+---------------+---------------+
774 * | index | pad |
775 * +---------------+---------------+---------------+---------------+
776 * | pad |
777 * +---------------+---------------+---------------+---------------+
778 *
779 */
780 if (len != 12)
781 goto invalid;
782 /* index */
783 ND_PRINT(", index %u", GET_U_1(cp));
784 cp += 1;
785 /* pad */
786 ND_TCHECK_7(cp);
787 cp += 7;
788 break;
789 case BSN_SET_IP_MASK:
790 case BSN_GET_IP_MASK_REPLY:
791 /*
792 * 0 1 2 3
793 * 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
794 * +---------------+---------------+---------------+---------------+
795 * | subtype |
796 * +---------------+---------------+---------------+---------------+
797 * | index | pad |
798 * +---------------+---------------+---------------+---------------+
799 * | mask |
800 * +---------------+---------------+---------------+---------------+
801 *
802 */
803 if (len != 12)
804 goto invalid;
805 /* index */
806 ND_PRINT(", index %u", GET_U_1(cp));
807 cp += 1;
808 /* pad */
809 ND_TCHECK_3(cp);
810 cp += 3;
811 /* mask */
812 ND_TCHECK_4(cp);
813 ND_PRINT(", mask %s", GET_IPADDR_STRING(cp));
814 cp += 4;
815 break;
816 case BSN_SET_MIRRORING:
817 case BSN_GET_MIRRORING_REQUEST:
818 case BSN_GET_MIRRORING_REPLY:
819 /*
820 * 0 1 2 3
821 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
822 * +---------------+---------------+---------------+---------------+
823 * | subtype |
824 * +---------------+---------------+---------------+---------------+
825 * | report m. p. | pad |
826 * +---------------+---------------+---------------+---------------+
827 *
828 */
829 if (len != 8)
830 goto invalid;
831 /* report_mirror_ports */
832 ND_PRINT(", report_mirror_ports %s",
833 tok2str(bsn_onoff_str, "bogus (%u)", GET_U_1(cp)));
834 cp += 1;
835 /* pad */
836 ND_TCHECK_3(cp);
837 cp += 3;
838 break;
839 case BSN_GET_INTERFACES_REQUEST:
840 case BSN_GET_L2_TABLE_REQUEST:
841 case BSN_BW_ENABLE_GET_REQUEST:
842 case BSN_BW_CLEAR_DATA_REQUEST:
843 case BSN_HYBRID_GET_REQUEST:
844 /*
845 * 0 1 2 3
846 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
847 * +---------------+---------------+---------------+---------------+
848 * | subtype |
849 * +---------------+---------------+---------------+---------------+
850 *
851 */
852 if (len != 4)
853 goto invalid;
854 break;
855 case BSN_VIRTUAL_PORT_REMOVE_REQUEST:
856 /*
857 * 0 1 2 3
858 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
859 * +---------------+---------------+---------------+---------------+
860 * | subtype |
861 * +---------------+---------------+---------------+---------------+
862 * | vport_no |
863 * +---------------+---------------+---------------+---------------+
864 *
865 */
866 if (len != 8)
867 goto invalid;
868 /* vport_no */
869 ND_PRINT(", vport_no %u", GET_BE_U_4(cp));
870 cp += 4;
871 break;
872 case BSN_SHELL_COMMAND:
873 /*
874 * 0 1 2 3
875 * 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
876 * +---------------+---------------+---------------+---------------+
877 * | subtype |
878 * +---------------+---------------+---------------+---------------+
879 * | service |
880 * +---------------+---------------+---------------+---------------+
881 * | data ...
882 * +---------------+---------------+--------
883 *
884 */
885 if (len < 8)
886 goto invalid;
887 /* service */
888 ND_PRINT(", service %u", GET_BE_U_4(cp));
889 cp += 4;
890 /* data */
891 ND_PRINT(", data '");
892 if (nd_printn(ndo, cp, len - 8, ep)) {
893 ND_PRINT("'");
894 goto trunc;
895 }
896 ND_PRINT("'");
897 cp += len - 8;
898 break;
899 case BSN_SHELL_OUTPUT:
900 /*
901 * 0 1 2 3
902 * 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
903 * +---------------+---------------+---------------+---------------+
904 * | subtype |
905 * +---------------+---------------+---------------+---------------+
906 * | data ...
907 * +---------------+---------------+--------
908 *
909 */
910 /* already checked that len >= 4 */
911 /* data */
912 ND_PRINT(", data '");
913 if (nd_printn(ndo, cp, len - 4, ep)) {
914 ND_PRINT("'");
915 goto trunc;
916 }
917 ND_PRINT("'");
918 cp += len - 4;
919 break;
920 case BSN_SHELL_STATUS:
921 /*
922 * 0 1 2 3
923 * 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
924 * +---------------+---------------+---------------+---------------+
925 * | subtype |
926 * +---------------+---------------+---------------+---------------+
927 * | status |
928 * +---------------+---------------+---------------+---------------+
929 *
930 */
931 if (len != 8)
932 goto invalid;
933 /* status */
934 ND_PRINT(", status 0x%08x", GET_BE_U_4(cp));
935 cp += 4;
936 break;
937 default:
938 ND_TCHECK_LEN(cp, len - 4);
939 cp += len - 4;
940 }
941 return cp;
942
943 invalid: /* skip the undersized data */
944 nd_print_invalid(ndo);
945 ND_TCHECK_LEN(cp0, len);
946 return cp0 + len;
947 trunc:
948 nd_print_trunc(ndo);
949 return ep;
950 }
951
952 static const u_char *
953 of10_bsn_actions_print(netdissect_options *ndo,
954 const u_char *cp, const u_char *ep, const u_int len)
955 {
956 const u_char *cp0 = cp;
957 uint32_t subtype, vlan_tag;
958
959 if (len < 4)
960 goto invalid;
961 /* subtype */
962 subtype = GET_BE_U_4(cp);
963 cp += 4;
964 ND_PRINT("\n\t subtype %s", tok2str(bsn_action_subtype_str, "unknown (0x%08x)", subtype));
965 switch (subtype) {
966 case BSN_ACTION_MIRROR:
967 /*
968 * 0 1 2 3
969 * 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
970 * +---------------+---------------+---------------+---------------+
971 * | subtype |
972 * +---------------+---------------+---------------+---------------+
973 * | dest_port |
974 * +---------------+---------------+---------------+---------------+
975 * | vlan_tag |
976 * +---------------+---------------+---------------+---------------+
977 * | copy_stage | pad |
978 * +---------------+---------------+---------------+---------------+
979 *
980 */
981 if (len != 16)
982 goto invalid;
983 /* dest_port */
984 ND_PRINT(", dest_port %u", GET_BE_U_4(cp));
985 cp += 4;
986 /* vlan_tag */
987 vlan_tag = GET_BE_U_4(cp);
988 cp += 4;
989 switch (vlan_tag >> 16) {
990 case 0:
991 ND_PRINT(", vlan_tag none");
992 break;
993 case ETHERTYPE_8021Q:
994 ND_PRINT(", vlan_tag 802.1Q (%s)", ieee8021q_tci_string(vlan_tag & 0xffff));
995 break;
996 default:
997 ND_PRINT(", vlan_tag unknown (0x%04x)", vlan_tag >> 16);
998 }
999 /* copy_stage */
1000 ND_PRINT(", copy_stage %s",
1001 tok2str(bsn_mirror_copy_stage_str, "unknown (%u)", GET_U_1(cp)));
1002 cp += 1;
1003 /* pad */
1004 ND_TCHECK_3(cp);
1005 cp += 3;
1006 break;
1007 default:
1008 ND_TCHECK_LEN(cp, len - 4);
1009 cp += len - 4;
1010 }
1011
1012 return cp;
1013
1014 invalid:
1015 nd_print_invalid(ndo);
1016 ND_TCHECK_LEN(cp0, len);
1017 return cp0 + len;
1018 trunc:
1019 nd_print_trunc(ndo);
1020 return ep;
1021 }
1022
1023 static const u_char *
1024 of10_vendor_action_print(netdissect_options *ndo,
1025 const u_char *cp, const u_char *ep, const u_int len)
1026 {
1027 uint32_t vendor;
1028 const u_char *(*decoder)(netdissect_options *, const u_char *, const u_char *, const u_int);
1029
1030 if (len < 4)
1031 goto invalid;
1032 /* vendor */
1033 vendor = GET_BE_U_4(cp);
1034 cp += 4;
1035 ND_PRINT(", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor));
1036 /* data */
1037 decoder =
1038 vendor == OUI_BSN ? of10_bsn_actions_print :
1039 of10_data_print;
1040 return decoder(ndo, cp, ep, len - 4);
1041
1042 invalid: /* skip the undersized data */
1043 nd_print_invalid(ndo);
1044 ND_TCHECK_LEN(cp, len);
1045 return cp + len;
1046 trunc:
1047 nd_print_trunc(ndo);
1048 return ep;
1049 }
1050
1051 static const u_char *
1052 of10_vendor_message_print(netdissect_options *ndo,
1053 const u_char *cp, const u_char *ep, const u_int len)
1054 {
1055 uint32_t vendor;
1056 const u_char *(*decoder)(netdissect_options *, const u_char *, const u_char *, u_int);
1057
1058 if (len < 4)
1059 goto invalid;
1060 /* vendor */
1061 vendor = GET_BE_U_4(cp);
1062 cp += 4;
1063 ND_PRINT(", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor));
1064 /* data */
1065 decoder =
1066 vendor == OUI_BSN ? of10_bsn_message_print :
1067 of10_data_print;
1068 return decoder(ndo, cp, ep, len - 4);
1069
1070 invalid: /* skip the undersized data */
1071 nd_print_invalid(ndo);
1072 ND_TCHECK_LEN(cp, len);
1073 return cp + len;
1074 trunc:
1075 nd_print_trunc(ndo);
1076 return ep;
1077 }
1078
1079 /* Vendor ID is mandatory, data is optional. */
1080 static const u_char *
1081 of10_vendor_data_print(netdissect_options *ndo,
1082 const u_char *cp, const u_char *ep, const u_int len)
1083 {
1084 uint32_t vendor;
1085
1086 if (len < 4)
1087 goto invalid;
1088 /* vendor */
1089 vendor = GET_BE_U_4(cp);
1090 cp += 4;
1091 ND_PRINT(", vendor 0x%08x (%s)", vendor, of_vendor_name(vendor));
1092 /* data */
1093 return of10_data_print(ndo, cp, ep, len - 4);
1094
1095 invalid: /* skip the undersized data */
1096 nd_print_invalid(ndo);
1097 ND_TCHECK_LEN(cp, len);
1098 return cp + len;
1099 trunc:
1100 nd_print_trunc(ndo);
1101 return ep;
1102 }
1103
1104 static const u_char *
1105 of10_packet_data_print(netdissect_options *ndo,
1106 const u_char *cp, const u_char *ep, const u_int len)
1107 {
1108 if (len == 0)
1109 return cp;
1110 /* data */
1111 ND_PRINT("\n\t data (%u octets)", len);
1112 if (ndo->ndo_vflag < 3)
1113 return cp + len;
1114 ND_TCHECK_LEN(cp, len);
1115 ndo->ndo_vflag -= 3;
1116 ND_PRINT(", frame decoding below\n");
1117 ether_print(ndo, cp, len, ND_BYTES_AVAILABLE_AFTER(cp), NULL, NULL);
1118 ndo->ndo_vflag += 3;
1119 return cp + len;
1120
1121 trunc:
1122 nd_print_trunc(ndo);
1123 return ep;
1124 }
1125
1126 /* [OF10] Section 5.2.1 */
1127 static const u_char *
1128 of10_phy_ports_print(netdissect_options *ndo,
1129 const u_char *cp, const u_char *ep, u_int len)
1130 {
1131 const u_char *cp0 = cp;
1132 const u_int len0 = len;
1133
1134 while (len) {
1135 if (len < OF_PHY_PORT_LEN)
1136 goto invalid;
1137 /* port_no */
1138 ND_PRINT("\n\t port_no %s",
1139 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1140 cp += 2;
1141 /* hw_addr */
1142 ND_TCHECK_LEN(cp, MAC_ADDR_LEN);
1143 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp));
1144 cp += MAC_ADDR_LEN;
1145 /* name */
1146 ND_TCHECK_LEN(cp, OFP_MAX_PORT_NAME_LEN);
1147 ND_PRINT(", name '");
1148 nd_print(ndo, cp, cp + OFP_MAX_PORT_NAME_LEN);
1149 ND_PRINT("'");
1150 cp += OFP_MAX_PORT_NAME_LEN;
1151
1152 if (ndo->ndo_vflag < 2) {
1153 ND_TCHECK_LEN(cp, 24);
1154 cp += 24;
1155 goto next_port;
1156 }
1157 /* config */
1158 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp));
1159 of10_bitmap_print(ndo, ofppc_bm, GET_BE_U_4(cp),
1160 OFPPC_U);
1161 cp += 4;
1162 /* state */
1163 ND_PRINT("\n\t state 0x%08x", GET_BE_U_4(cp));
1164 of10_bitmap_print(ndo, ofpps_bm, GET_BE_U_4(cp),
1165 OFPPS_U);
1166 cp += 4;
1167 /* curr */
1168 ND_PRINT("\n\t curr 0x%08x", GET_BE_U_4(cp));
1169 of10_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp),
1170 OFPPF_U);
1171 cp += 4;
1172 /* advertised */
1173 ND_PRINT("\n\t advertised 0x%08x", GET_BE_U_4(cp));
1174 of10_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp),
1175 OFPPF_U);
1176 cp += 4;
1177 /* supported */
1178 ND_PRINT("\n\t supported 0x%08x", GET_BE_U_4(cp));
1179 of10_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp),
1180 OFPPF_U);
1181 cp += 4;
1182 /* peer */
1183 ND_PRINT("\n\t peer 0x%08x", GET_BE_U_4(cp));
1184 of10_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp),
1185 OFPPF_U);
1186 cp += 4;
1187 next_port:
1188 len -= OF_PHY_PORT_LEN;
1189 } /* while */
1190 return cp;
1191
1192 invalid: /* skip the undersized trailing data */
1193 nd_print_invalid(ndo);
1194 ND_TCHECK_LEN(cp0, len0);
1195 return cp0 + len0;
1196 trunc:
1197 nd_print_trunc(ndo);
1198 return ep;
1199 }
1200
1201 /* [OF10] Section 5.2.2 */
1202 static const u_char *
1203 of10_queue_props_print(netdissect_options *ndo,
1204 const u_char *cp, const u_char *ep, u_int len)
1205 {
1206 const u_char *cp0 = cp;
1207 const u_int len0 = len;
1208 uint16_t property, plen, rate;
1209
1210 while (len) {
1211 u_char plen_bogus = 0, skip = 0;
1212
1213 if (len < OF_QUEUE_PROP_HEADER_LEN)
1214 goto invalid;
1215 /* property */
1216 property = GET_BE_U_2(cp);
1217 cp += 2;
1218 ND_PRINT("\n\t property %s", tok2str(ofpqt_str, "invalid (0x%04x)", property));
1219 /* len */
1220 plen = GET_BE_U_2(cp);
1221 cp += 2;
1222 ND_PRINT(", len %u", plen);
1223 if (plen < OF_QUEUE_PROP_HEADER_LEN || plen > len)
1224 goto invalid;
1225 /* pad */
1226 ND_TCHECK_4(cp);
1227 cp += 4;
1228 /* property-specific constraints and decoding */
1229 switch (property) {
1230 case OFPQT_NONE:
1231 plen_bogus = plen != OF_QUEUE_PROP_HEADER_LEN;
1232 break;
1233 case OFPQT_MIN_RATE:
1234 plen_bogus = plen != OF_QUEUE_PROP_MIN_RATE_LEN;
1235 break;
1236 default:
1237 skip = 1;
1238 }
1239 if (plen_bogus) {
1240 ND_PRINT(" (bogus)");
1241 skip = 1;
1242 }
1243 if (skip) {
1244 ND_TCHECK_LEN(cp, plen - 4);
1245 cp += plen - 4;
1246 goto next_property;
1247 }
1248 if (property == OFPQT_MIN_RATE) { /* the only case of property decoding */
1249 /* rate */
1250 rate = GET_BE_U_2(cp);
1251 cp += 2;
1252 if (rate > 1000)
1253 ND_PRINT(", rate disabled");
1254 else
1255 ND_PRINT(", rate %u.%u%%", rate / 10, rate % 10);
1256 /* pad */
1257 ND_TCHECK_6(cp);
1258 cp += 6;
1259 }
1260 next_property:
1261 len -= plen;
1262 } /* while */
1263 return cp;
1264
1265 invalid: /* skip the rest of queue properties */
1266 nd_print_invalid(ndo);
1267 ND_TCHECK_LEN(cp0, len0);
1268 return cp0 + len0;
1269 trunc:
1270 nd_print_trunc(ndo);
1271 return ep;
1272 }
1273
1274 /* ibid */
1275 static const u_char *
1276 of10_queues_print(netdissect_options *ndo,
1277 const u_char *cp, const u_char *ep, u_int len)
1278 {
1279 const u_char *cp0 = cp;
1280 const u_int len0 = len;
1281 uint16_t desclen;
1282
1283 while (len) {
1284 if (len < OF_PACKET_QUEUE_LEN)
1285 goto invalid;
1286 /* queue_id */
1287 ND_PRINT("\n\t queue_id %u", GET_BE_U_4(cp));
1288 cp += 4;
1289 /* len */
1290 desclen = GET_BE_U_2(cp);
1291 cp += 2;
1292 ND_PRINT(", len %u", desclen);
1293 if (desclen < OF_PACKET_QUEUE_LEN || desclen > len)
1294 goto invalid;
1295 /* pad */
1296 ND_TCHECK_2(cp);
1297 cp += 2;
1298 /* properties */
1299 if (ndo->ndo_vflag < 2) {
1300 ND_TCHECK_LEN(cp, desclen - OF_PACKET_QUEUE_LEN);
1301 cp += desclen - OF_PACKET_QUEUE_LEN;
1302 goto next_queue;
1303 }
1304 if (ep == (cp = of10_queue_props_print(ndo, cp, ep, desclen - OF_PACKET_QUEUE_LEN)))
1305 return ep; /* end of snapshot */
1306 next_queue:
1307 len -= desclen;
1308 } /* while */
1309 return cp;
1310
1311 invalid: /* skip the rest of queues */
1312 nd_print_invalid(ndo);
1313 ND_TCHECK_LEN(cp0, len0);
1314 return cp0 + len0;
1315 trunc:
1316 nd_print_trunc(ndo);
1317 return ep;
1318 }
1319
1320 /* [OF10] Section 5.2.3 */
1321 static const u_char *
1322 of10_match_print(netdissect_options *ndo,
1323 const char *pfx, const u_char *cp, const u_char *ep)
1324 {
1325 uint32_t wildcards;
1326 uint16_t dl_type;
1327 uint8_t nw_proto;
1328 u_int nw_bits;
1329 const char *field_name;
1330
1331 /* wildcards */
1332 wildcards = GET_BE_U_4(cp);
1333 if (wildcards & OFPFW_U)
1334 ND_PRINT("%swildcards 0x%08x (bogus)", pfx, wildcards);
1335 cp += 4;
1336 /* in_port */
1337 if (! (wildcards & OFPFW_IN_PORT))
1338 ND_PRINT("%smatch in_port %s", pfx,
1339 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1340 cp += 2;
1341 /* dl_src */
1342 ND_TCHECK_LEN(cp, MAC_ADDR_LEN);
1343 if (! (wildcards & OFPFW_DL_SRC))
1344 ND_PRINT("%smatch dl_src %s", pfx, GET_ETHERADDR_STRING(cp));
1345 cp += MAC_ADDR_LEN;
1346 /* dl_dst */
1347 ND_TCHECK_LEN(cp, MAC_ADDR_LEN);
1348 if (! (wildcards & OFPFW_DL_DST))
1349 ND_PRINT("%smatch dl_dst %s", pfx, GET_ETHERADDR_STRING(cp));
1350 cp += MAC_ADDR_LEN;
1351 /* dl_vlan */
1352 if (! (wildcards & OFPFW_DL_VLAN))
1353 ND_PRINT("%smatch dl_vlan %s", pfx, vlan_str(GET_BE_U_2(cp)));
1354 cp += 2;
1355 /* dl_vlan_pcp */
1356 if (! (wildcards & OFPFW_DL_VLAN_PCP))
1357 ND_PRINT("%smatch dl_vlan_pcp %s", pfx, pcp_str(GET_U_1(cp)));
1358 cp += 1;
1359 /* pad1 */
1360 ND_TCHECK_1(cp);
1361 cp += 1;
1362 /* dl_type */
1363 dl_type = GET_BE_U_2(cp);
1364 cp += 2;
1365 if (! (wildcards & OFPFW_DL_TYPE))
1366 ND_PRINT("%smatch dl_type 0x%04x", pfx, dl_type);
1367 /* nw_tos */
1368 if (! (wildcards & OFPFW_NW_TOS))
1369 ND_PRINT("%smatch nw_tos 0x%02x", pfx, GET_U_1(cp));
1370 cp += 1;
1371 /* nw_proto */
1372 nw_proto = GET_U_1(cp);
1373 cp += 1;
1374 if (! (wildcards & OFPFW_NW_PROTO)) {
1375 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_ARP
1376 ? "arp_opcode" : "nw_proto";
1377 ND_PRINT("%smatch %s %u", pfx, field_name, nw_proto);
1378 }
1379 /* pad2 */
1380 ND_TCHECK_2(cp);
1381 cp += 2;
1382 /* nw_src */
1383 ND_TCHECK_4(cp);
1384 nw_bits = (wildcards & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT;
1385 if (nw_bits < 32)
1386 ND_PRINT("%smatch nw_src %s/%u", pfx, GET_IPADDR_STRING(cp), 32 - nw_bits);
1387 cp += 4;
1388 /* nw_dst */
1389 ND_TCHECK_4(cp);
1390 nw_bits = (wildcards & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT;
1391 if (nw_bits < 32)
1392 ND_PRINT("%smatch nw_dst %s/%u", pfx, GET_IPADDR_STRING(cp), 32 - nw_bits);
1393 cp += 4;
1394 /* tp_src */
1395 ND_TCHECK_2(cp);
1396 if (! (wildcards & OFPFW_TP_SRC)) {
1397 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_IP
1398 && ! (wildcards & OFPFW_NW_PROTO) && nw_proto == IPPROTO_ICMP
1399 ? "icmp_type" : "tp_src";
1400 ND_PRINT("%smatch %s %u", pfx, field_name, GET_BE_U_2(cp));
1401 }
1402 cp += 2;
1403 /* tp_dst */
1404 ND_TCHECK_2(cp);
1405 if (! (wildcards & OFPFW_TP_DST)) {
1406 field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_IP
1407 && ! (wildcards & OFPFW_NW_PROTO) && nw_proto == IPPROTO_ICMP
1408 ? "icmp_code" : "tp_dst";
1409 ND_PRINT("%smatch %s %u", pfx, field_name, GET_BE_U_2(cp));
1410 }
1411 return cp + 2;
1412
1413 trunc:
1414 nd_print_trunc(ndo);
1415 return ep;
1416 }
1417
1418 /* [OF10] Section 5.2.4 */
1419 static const u_char *
1420 of10_actions_print(netdissect_options *ndo,
1421 const char *pfx, const u_char *cp, const u_char *ep,
1422 u_int len)
1423 {
1424 const u_char *cp0 = cp;
1425 const u_int len0 = len;
1426 uint16_t type, alen, output_port;
1427
1428 while (len) {
1429 u_char alen_bogus = 0, skip = 0;
1430
1431 if (len < OF_ACTION_HEADER_LEN)
1432 goto invalid;
1433 /* type */
1434 type = GET_BE_U_2(cp);
1435 cp += 2;
1436 ND_PRINT("%saction type %s", pfx, tok2str(ofpat_str, "invalid (0x%04x)", type));
1437 /* length */
1438 alen = GET_BE_U_2(cp);
1439 cp += 2;
1440 ND_PRINT(", len %u", alen);
1441 /* On action size underrun/overrun skip the rest of the action list. */
1442 if (alen < OF_ACTION_HEADER_LEN || alen > len)
1443 goto invalid;
1444 /* On action size inappropriate for the given type or invalid type just skip
1445 * the current action, as the basic length constraint has been met. */
1446 switch (type) {
1447 case OFPAT_OUTPUT:
1448 case OFPAT_SET_VLAN_VID:
1449 case OFPAT_SET_VLAN_PCP:
1450 case OFPAT_STRIP_VLAN:
1451 case OFPAT_SET_NW_SRC:
1452 case OFPAT_SET_NW_DST:
1453 case OFPAT_SET_NW_TOS:
1454 case OFPAT_SET_TP_SRC:
1455 case OFPAT_SET_TP_DST:
1456 alen_bogus = alen != 8;
1457 break;
1458 case OFPAT_SET_DL_SRC:
1459 case OFPAT_SET_DL_DST:
1460 case OFPAT_ENQUEUE:
1461 alen_bogus = alen != 16;
1462 break;
1463 case OFPAT_VENDOR:
1464 alen_bogus = alen % 8 != 0; /* already >= 8 so far */
1465 break;
1466 default:
1467 skip = 1;
1468 }
1469 if (alen_bogus) {
1470 ND_PRINT(" (bogus)");
1471 skip = 1;
1472 }
1473 if (skip) {
1474 ND_TCHECK_LEN(cp, alen - 4);
1475 cp += alen - 4;
1476 goto next_action;
1477 }
1478 /* OK to decode the rest of the action structure */
1479 switch (type) {
1480 case OFPAT_OUTPUT:
1481 /* port */
1482 output_port = GET_BE_U_2(cp);
1483 cp += 2;
1484 ND_PRINT(", port %s", tok2str(ofpp_str, "%u", output_port));
1485 /* max_len */
1486 if (output_port == OFPP_CONTROLLER)
1487 ND_PRINT(", max_len %u", GET_BE_U_2(cp));
1488 cp += 2;
1489 break;
1490 case OFPAT_SET_VLAN_VID:
1491 /* vlan_vid */
1492 ND_PRINT(", vlan_vid %s", vlan_str(GET_BE_U_2(cp)));
1493 cp += 2;
1494 /* pad */
1495 ND_TCHECK_2(cp);
1496 cp += 2;
1497 break;
1498 case OFPAT_SET_VLAN_PCP:
1499 /* vlan_pcp */
1500 ND_PRINT(", vlan_pcp %s", pcp_str(GET_U_1(cp)));
1501 cp += 1;
1502 /* pad */
1503 ND_TCHECK_3(cp);
1504 cp += 3;
1505 break;
1506 case OFPAT_SET_DL_SRC:
1507 case OFPAT_SET_DL_DST:
1508 /* dl_addr */
1509 ND_TCHECK_LEN(cp, MAC_ADDR_LEN);
1510 ND_PRINT(", dl_addr %s", GET_ETHERADDR_STRING(cp));
1511 cp += MAC_ADDR_LEN;
1512 /* pad */
1513 ND_TCHECK_6(cp);
1514 cp += 6;
1515 break;
1516 case OFPAT_SET_NW_SRC:
1517 case OFPAT_SET_NW_DST:
1518 /* nw_addr */
1519 ND_TCHECK_4(cp);
1520 ND_PRINT(", nw_addr %s", GET_IPADDR_STRING(cp));
1521 cp += 4;
1522 break;
1523 case OFPAT_SET_NW_TOS:
1524 /* nw_tos */
1525 ND_PRINT(", nw_tos 0x%02x", GET_U_1(cp));
1526 cp += 1;
1527 /* pad */
1528 ND_TCHECK_3(cp);
1529 cp += 3;
1530 break;
1531 case OFPAT_SET_TP_SRC:
1532 case OFPAT_SET_TP_DST:
1533 /* nw_tos */
1534 ND_PRINT(", tp_port %u", GET_BE_U_2(cp));
1535 cp += 2;
1536 /* pad */
1537 ND_TCHECK_2(cp);
1538 cp += 2;
1539 break;
1540 case OFPAT_ENQUEUE:
1541 /* port */
1542 ND_PRINT(", port %s",
1543 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1544 cp += 2;
1545 /* pad */
1546 ND_TCHECK_6(cp);
1547 cp += 6;
1548 /* queue_id */
1549 ND_PRINT(", queue_id %s",
1550 tok2str(ofpq_str, "%u", GET_BE_U_4(cp)));
1551 cp += 4;
1552 break;
1553 case OFPAT_VENDOR:
1554 if (ep == (cp = of10_vendor_action_print(ndo, cp, ep, alen - 4)))
1555 return ep; /* end of snapshot */
1556 break;
1557 case OFPAT_STRIP_VLAN:
1558 /* pad */
1559 ND_TCHECK_4(cp);
1560 cp += 4;
1561 break;
1562 } /* switch */
1563 next_action:
1564 len -= alen;
1565 } /* while */
1566 return cp;
1567
1568 invalid: /* skip the rest of actions */
1569 nd_print_invalid(ndo);
1570 ND_TCHECK_LEN(cp0, len0);
1571 return cp0 + len0;
1572 trunc:
1573 nd_print_trunc(ndo);
1574 return ep;
1575 }
1576
1577 /* [OF10] Section 5.3.1 */
1578 static const u_char *
1579 of10_features_reply_print(netdissect_options *ndo,
1580 const u_char *cp, const u_char *ep, const u_int len)
1581 {
1582 /* datapath_id */
1583 ND_PRINT("\n\t dpid 0x%016" PRIx64, GET_BE_U_8(cp));
1584 cp += 8;
1585 /* n_buffers */
1586 ND_PRINT(", n_buffers %u", GET_BE_U_4(cp));
1587 cp += 4;
1588 /* n_tables */
1589 ND_PRINT(", n_tables %u", GET_U_1(cp));
1590 cp += 1;
1591 /* pad */
1592 ND_TCHECK_3(cp);
1593 cp += 3;
1594 /* capabilities */
1595 ND_PRINT("\n\t capabilities 0x%08x", GET_BE_U_4(cp));
1596 of10_bitmap_print(ndo, ofp_capabilities_bm, GET_BE_U_4(cp),
1597 OFPCAP_U);
1598 cp += 4;
1599 /* actions */
1600 ND_PRINT("\n\t actions 0x%08x", GET_BE_U_4(cp));
1601 of10_bitmap_print(ndo, ofpat_bm, GET_BE_U_4(cp), OFPAT_U);
1602 cp += 4;
1603 /* ports */
1604 return of10_phy_ports_print(ndo, cp, ep, len - OF_SWITCH_FEATURES_LEN);
1605
1606 trunc:
1607 nd_print_trunc(ndo);
1608 return ep;
1609 }
1610
1611 /* [OF10] Section 5.3.3 */
1612 static const u_char *
1613 of10_flow_mod_print(netdissect_options *ndo,
1614 const u_char *cp, const u_char *ep, const u_int len)
1615 {
1616 uint16_t command;
1617
1618 /* match */
1619 if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
1620 return ep; /* end of snapshot */
1621 /* cookie */
1622 ND_PRINT("\n\t cookie 0x%016" PRIx64, GET_BE_U_8(cp));
1623 cp += 8;
1624 /* command */
1625 command = GET_BE_U_2(cp);
1626 ND_PRINT(", command %s", tok2str(ofpfc_str, "invalid (0x%04x)", command));
1627 cp += 2;
1628 /* idle_timeout */
1629 if (GET_BE_U_2(cp))
1630 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp));
1631 cp += 2;
1632 /* hard_timeout */
1633 if (GET_BE_U_2(cp))
1634 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp));
1635 cp += 2;
1636 /* priority */
1637 if (GET_BE_U_2(cp))
1638 ND_PRINT(", priority %u", GET_BE_U_2(cp));
1639 cp += 2;
1640 /* buffer_id */
1641 if (command == OFPFC_ADD || command == OFPFC_MODIFY ||
1642 command == OFPFC_MODIFY_STRICT)
1643 ND_PRINT(", buffer_id %s",
1644 tok2str(bufferid_str, "0x%08x", GET_BE_U_4(cp)));
1645 cp += 4;
1646 /* out_port */
1647 if (command == OFPFC_DELETE || command == OFPFC_DELETE_STRICT)
1648 ND_PRINT(", out_port %s",
1649 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1650 cp += 2;
1651 /* flags */
1652 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp));
1653 of10_bitmap_print(ndo, ofpff_bm, GET_BE_U_2(cp), OFPFF_U);
1654 cp += 2;
1655 /* actions */
1656 return of10_actions_print(ndo, "\n\t ", cp, ep, len - OF_FLOW_MOD_LEN);
1657 }
1658
1659 /* ibid */
1660 static const u_char *
1661 of10_port_mod_print(netdissect_options *ndo,
1662 const u_char *cp, const u_char *ep)
1663 {
1664 /* port_no */
1665 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1666 cp += 2;
1667 /* hw_addr */
1668 ND_TCHECK_LEN(cp, MAC_ADDR_LEN);
1669 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp));
1670 cp += MAC_ADDR_LEN;
1671 /* config */
1672 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp));
1673 of10_bitmap_print(ndo, ofppc_bm, GET_BE_U_4(cp), OFPPC_U);
1674 cp += 4;
1675 /* mask */
1676 ND_PRINT("\n\t mask 0x%08x", GET_BE_U_4(cp));
1677 of10_bitmap_print(ndo, ofppc_bm, GET_BE_U_4(cp), OFPPC_U);
1678 cp += 4;
1679 /* advertise */
1680 ND_PRINT("\n\t advertise 0x%08x", GET_BE_U_4(cp));
1681 of10_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
1682 cp += 4;
1683 /* pad */
1684 ND_TCHECK_4(cp);
1685 return cp + 4;
1686
1687 trunc:
1688 nd_print_trunc(ndo);
1689 return ep;
1690 }
1691
1692 /* [OF10] Section 5.3.5 */
1693 static const u_char *
1694 of10_stats_request_print(netdissect_options *ndo,
1695 const u_char *cp, const u_char *ep, u_int len)
1696 {
1697 const u_char *cp0 = cp;
1698 const u_int len0 = len;
1699 uint16_t type;
1700
1701 /* type */
1702 type = GET_BE_U_2(cp);
1703 cp += 2;
1704 ND_PRINT("\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type));
1705 /* flags */
1706 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp));
1707 if (GET_BE_U_2(cp))
1708 ND_PRINT(" (bogus)");
1709 cp += 2;
1710 /* type-specific body of one of fixed lengths */
1711 len -= OF_STATS_REQUEST_LEN;
1712 switch(type) {
1713 case OFPST_DESC:
1714 case OFPST_TABLE:
1715 if (len)
1716 goto invalid;
1717 return cp;
1718 case OFPST_FLOW:
1719 case OFPST_AGGREGATE:
1720 if (len != OF_FLOW_STATS_REQUEST_LEN)
1721 goto invalid;
1722 /* match */
1723 if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
1724 return ep; /* end of snapshot */
1725 /* table_id */
1726 ND_PRINT("\n\t table_id %s",
1727 tok2str(tableid_str, "%u", GET_U_1(cp)));
1728 cp += 1;
1729 /* pad */
1730 ND_TCHECK_1(cp);
1731 cp += 1;
1732 /* out_port */
1733 ND_PRINT(", out_port %s",
1734 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1735 return cp + 2;
1736 case OFPST_PORT:
1737 if (len != OF_PORT_STATS_REQUEST_LEN)
1738 goto invalid;
1739 /* port_no */
1740 ND_PRINT("\n\t port_no %s",
1741 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1742 cp += 2;
1743 /* pad */
1744 ND_TCHECK_6(cp);
1745 return cp + 6;
1746 case OFPST_QUEUE:
1747 if (len != OF_QUEUE_STATS_REQUEST_LEN)
1748 goto invalid;
1749 /* port_no */
1750 ND_PRINT("\n\t port_no %s",
1751 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1752 cp += 2;
1753 /* pad */
1754 ND_TCHECK_2(cp);
1755 cp += 2;
1756 /* queue_id */
1757 ND_PRINT(", queue_id %s",
1758 tok2str(ofpq_str, "%u", GET_BE_U_4(cp)));
1759 return cp + 4;
1760 case OFPST_VENDOR:
1761 return of10_vendor_data_print(ndo, cp, ep, len);
1762 }
1763 return cp;
1764
1765 invalid: /* skip the message body */
1766 nd_print_invalid(ndo);
1767 ND_TCHECK_LEN(cp0, len0);
1768 return cp0 + len0;
1769 trunc:
1770 nd_print_trunc(ndo);
1771 return ep;
1772 }
1773
1774 /* ibid */
1775 static const u_char *
1776 of10_desc_stats_reply_print(netdissect_options *ndo,
1777 const u_char *cp, const u_char *ep, const u_int len)
1778 {
1779 if (len != OF_DESC_STATS_LEN)
1780 goto invalid;
1781 /* mfr_desc */
1782 ND_TCHECK_LEN(cp, DESC_STR_LEN);
1783 ND_PRINT("\n\t mfr_desc '");
1784 nd_print(ndo, cp, cp + DESC_STR_LEN);
1785 ND_PRINT("'");
1786 cp += DESC_STR_LEN;
1787 /* hw_desc */
1788 ND_TCHECK_LEN(cp, DESC_STR_LEN);
1789 ND_PRINT("\n\t hw_desc '");
1790 nd_print(ndo, cp, cp + DESC_STR_LEN);
1791 ND_PRINT("'");
1792 cp += DESC_STR_LEN;
1793 /* sw_desc */
1794 ND_TCHECK_LEN(cp, DESC_STR_LEN);
1795 ND_PRINT("\n\t sw_desc '");
1796 nd_print(ndo, cp, cp + DESC_STR_LEN);
1797 ND_PRINT("'");
1798 cp += DESC_STR_LEN;
1799 /* serial_num */
1800 ND_TCHECK_LEN(cp, SERIAL_NUM_LEN);
1801 ND_PRINT("\n\t serial_num '");
1802 nd_print(ndo, cp, cp + SERIAL_NUM_LEN);
1803 ND_PRINT("'");
1804 cp += SERIAL_NUM_LEN;
1805 /* dp_desc */
1806 ND_TCHECK_LEN(cp, DESC_STR_LEN);
1807 ND_PRINT("\n\t dp_desc '");
1808 nd_print(ndo, cp, cp + DESC_STR_LEN);
1809 ND_PRINT("'");
1810 return cp + DESC_STR_LEN;
1811
1812 invalid: /* skip the message body */
1813 nd_print_invalid(ndo);
1814 ND_TCHECK_LEN(cp, len);
1815 return cp + len;
1816 trunc:
1817 nd_print_trunc(ndo);
1818 return ep;
1819 }
1820
1821 /* ibid */
1822 static const u_char *
1823 of10_flow_stats_reply_print(netdissect_options *ndo,
1824 const u_char *cp, const u_char *ep, u_int len)
1825 {
1826 const u_char *cp0 = cp;
1827 const u_int len0 = len;
1828 uint16_t entry_len;
1829
1830 while (len) {
1831 if (len < OF_FLOW_STATS_LEN)
1832 goto invalid;
1833 /* length */
1834 entry_len = GET_BE_U_2(cp);
1835 ND_PRINT("\n\t length %u", entry_len);
1836 if (entry_len < OF_FLOW_STATS_LEN || entry_len > len)
1837 goto invalid;
1838 cp += 2;
1839 /* table_id */
1840 ND_PRINT(", table_id %s",
1841 tok2str(tableid_str, "%u", GET_U_1(cp)));
1842 cp += 1;
1843 /* pad */
1844 ND_TCHECK_1(cp);
1845 cp += 1;
1846 /* match */
1847 if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
1848 return ep; /* end of snapshot */
1849 /* duration_sec */
1850 ND_PRINT("\n\t duration_sec %u", GET_BE_U_4(cp));
1851 cp += 4;
1852 /* duration_nsec */
1853 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp));
1854 cp += 4;
1855 /* priority */
1856 ND_PRINT(", priority %u", GET_BE_U_2(cp));
1857 cp += 2;
1858 /* idle_timeout */
1859 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp));
1860 cp += 2;
1861 /* hard_timeout */
1862 ND_PRINT(", hard_timeout %u", GET_BE_U_2(cp));
1863 cp += 2;
1864 /* pad2 */
1865 ND_TCHECK_6(cp);
1866 cp += 6;
1867 /* cookie */
1868 ND_PRINT(", cookie 0x%016" PRIx64, GET_BE_U_8(cp));
1869 cp += 8;
1870 /* packet_count */
1871 ND_PRINT(", packet_count %" PRIu64, GET_BE_U_8(cp));
1872 cp += 8;
1873 /* byte_count */
1874 ND_PRINT(", byte_count %" PRIu64, GET_BE_U_8(cp));
1875 cp += 8;
1876 /* actions */
1877 if (ep == (cp = of10_actions_print(ndo, "\n\t ", cp, ep, entry_len - OF_FLOW_STATS_LEN)))
1878 return ep; /* end of snapshot */
1879
1880 len -= entry_len;
1881 } /* while */
1882 return cp;
1883
1884 invalid: /* skip the rest of flow statistics entries */
1885 nd_print_invalid(ndo);
1886 ND_TCHECK_LEN(cp0, len0);
1887 return cp0 + len0;
1888 trunc:
1889 nd_print_trunc(ndo);
1890 return ep;
1891 }
1892
1893 /* ibid */
1894 static const u_char *
1895 of10_aggregate_stats_reply_print(netdissect_options *ndo,
1896 const u_char *cp, const u_char *ep,
1897 const u_int len)
1898 {
1899 if (len != OF_AGGREGATE_STATS_REPLY_LEN)
1900 goto invalid;
1901 /* packet_count */
1902 ND_PRINT("\n\t packet_count %" PRIu64, GET_BE_U_8(cp));
1903 cp += 8;
1904 /* byte_count */
1905 ND_PRINT(", byte_count %" PRIu64, GET_BE_U_8(cp));
1906 cp += 8;
1907 /* flow_count */
1908 ND_PRINT(", flow_count %u", GET_BE_U_4(cp));
1909 cp += 4;
1910 /* pad */
1911 ND_TCHECK_4(cp);
1912 return cp + 4;
1913
1914 invalid: /* skip the message body */
1915 nd_print_invalid(ndo);
1916 ND_TCHECK_LEN(cp, len);
1917 return cp + len;
1918 trunc:
1919 nd_print_trunc(ndo);
1920 return ep;
1921 }
1922
1923 /* ibid */
1924 static const u_char *
1925 of10_table_stats_reply_print(netdissect_options *ndo,
1926 const u_char *cp, const u_char *ep, u_int len)
1927 {
1928 const u_char *cp0 = cp;
1929 const u_int len0 = len;
1930
1931 while (len) {
1932 if (len < OF_TABLE_STATS_LEN)
1933 goto invalid;
1934 /* table_id */
1935 ND_PRINT("\n\t table_id %s",
1936 tok2str(tableid_str, "%u", GET_U_1(cp)));
1937 cp += 1;
1938 /* pad */
1939 ND_TCHECK_3(cp);
1940 cp += 3;
1941 /* name */
1942 ND_TCHECK_LEN(cp, OFP_MAX_TABLE_NAME_LEN);
1943 ND_PRINT(", name '");
1944 nd_print(ndo, cp, cp + OFP_MAX_TABLE_NAME_LEN);
1945 ND_PRINT("'");
1946 cp += OFP_MAX_TABLE_NAME_LEN;
1947 /* wildcards */
1948 ND_PRINT("\n\t wildcards 0x%08x", GET_BE_U_4(cp));
1949 of10_bitmap_print(ndo, ofpfw_bm, GET_BE_U_4(cp),
1950 OFPFW_U);
1951 cp += 4;
1952 /* max_entries */
1953 ND_PRINT("\n\t max_entries %u", GET_BE_U_4(cp));
1954 cp += 4;
1955 /* active_count */
1956 ND_PRINT(", active_count %u", GET_BE_U_4(cp));
1957 cp += 4;
1958 /* lookup_count */
1959 ND_PRINT(", lookup_count %" PRIu64, GET_BE_U_8(cp));
1960 cp += 8;
1961 /* matched_count */
1962 ND_PRINT(", matched_count %" PRIu64, GET_BE_U_8(cp));
1963 cp += 8;
1964
1965 len -= OF_TABLE_STATS_LEN;
1966 } /* while */
1967 return cp;
1968
1969 invalid: /* skip the undersized trailing data */
1970 nd_print_invalid(ndo);
1971 ND_TCHECK_LEN(cp0, len0);
1972 return cp0 + len0;
1973 trunc:
1974 nd_print_trunc(ndo);
1975 return ep;
1976 }
1977
1978 /* ibid */
1979 static const u_char *
1980 of10_port_stats_reply_print(netdissect_options *ndo,
1981 const u_char *cp, const u_char *ep, u_int len)
1982 {
1983 const u_char *cp0 = cp;
1984 const u_int len0 = len;
1985
1986 while (len) {
1987 if (len < OF_PORT_STATS_LEN)
1988 goto invalid;
1989 /* port_no */
1990 ND_PRINT("\n\t port_no %s",
1991 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
1992 cp += 2;
1993 if (ndo->ndo_vflag < 2) {
1994 ND_TCHECK_LEN(cp, OF_PORT_STATS_LEN - 2);
1995 cp += OF_PORT_STATS_LEN - 2;
1996 goto next_port;
1997 }
1998 /* pad */
1999 ND_TCHECK_6(cp);
2000 cp += 6;
2001 /* rx_packets */
2002 ND_PRINT(", rx_packets %" PRIu64, GET_BE_U_8(cp));
2003 cp += 8;
2004 /* tx_packets */
2005 ND_PRINT(", tx_packets %" PRIu64, GET_BE_U_8(cp));
2006 cp += 8;
2007 /* rx_bytes */
2008 ND_PRINT(", rx_bytes %" PRIu64, GET_BE_U_8(cp));
2009 cp += 8;
2010 /* tx_bytes */
2011 ND_PRINT(", tx_bytes %" PRIu64, GET_BE_U_8(cp));
2012 cp += 8;
2013 /* rx_dropped */
2014 ND_PRINT(", rx_dropped %" PRIu64, GET_BE_U_8(cp));
2015 cp += 8;
2016 /* tx_dropped */
2017 ND_PRINT(", tx_dropped %" PRIu64, GET_BE_U_8(cp));
2018 cp += 8;
2019 /* rx_errors */
2020 ND_PRINT(", rx_errors %" PRIu64, GET_BE_U_8(cp));
2021 cp += 8;
2022 /* tx_errors */
2023 ND_PRINT(", tx_errors %" PRIu64, GET_BE_U_8(cp));
2024 cp += 8;
2025 /* rx_frame_err */
2026 ND_PRINT(", rx_frame_err %" PRIu64, GET_BE_U_8(cp));
2027 cp += 8;
2028 /* rx_over_err */
2029 ND_PRINT(", rx_over_err %" PRIu64, GET_BE_U_8(cp));
2030 cp += 8;
2031 /* rx_crc_err */
2032 ND_PRINT(", rx_crc_err %" PRIu64, GET_BE_U_8(cp));
2033 cp += 8;
2034 /* collisions */
2035 ND_PRINT(", collisions %" PRIu64, GET_BE_U_8(cp));
2036 cp += 8;
2037 next_port:
2038 len -= OF_PORT_STATS_LEN;
2039 } /* while */
2040 return cp;
2041
2042 invalid: /* skip the undersized trailing data */
2043 nd_print_invalid(ndo);
2044 ND_TCHECK_LEN(cp0, len0);
2045 return cp0 + len0;
2046 trunc:
2047 nd_print_trunc(ndo);
2048 return ep;
2049 }
2050
2051 /* ibid */
2052 static const u_char *
2053 of10_queue_stats_reply_print(netdissect_options *ndo,
2054 const u_char *cp, const u_char *ep, u_int len)
2055 {
2056 const u_char *cp0 = cp;
2057 const u_int len0 = len;
2058
2059 while (len) {
2060 if (len < OF_QUEUE_STATS_LEN)
2061 goto invalid;
2062 /* port_no */
2063 ND_PRINT("\n\t port_no %s",
2064 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
2065 cp += 2;
2066 /* pad */
2067 ND_TCHECK_2(cp);
2068 cp += 2;
2069 /* queue_id */
2070 ND_PRINT(", queue_id %u", GET_BE_U_4(cp));
2071 cp += 4;
2072 /* tx_bytes */
2073 ND_PRINT(", tx_bytes %" PRIu64, GET_BE_U_8(cp));
2074 cp += 8;
2075 /* tx_packets */
2076 ND_PRINT(", tx_packets %" PRIu64, GET_BE_U_8(cp));
2077 cp += 8;
2078 /* tx_errors */
2079 ND_PRINT(", tx_errors %" PRIu64, GET_BE_U_8(cp));
2080 cp += 8;
2081
2082 len -= OF_QUEUE_STATS_LEN;
2083 } /* while */
2084 return cp;
2085
2086 invalid: /* skip the undersized trailing data */
2087 nd_print_invalid(ndo);
2088 ND_TCHECK_LEN(cp0, len0);
2089 return cp0 + len0;
2090 trunc:
2091 nd_print_trunc(ndo);
2092 return ep;
2093 }
2094
2095 /* ibid */
2096 static const u_char *
2097 of10_stats_reply_print(netdissect_options *ndo,
2098 const u_char *cp, const u_char *ep, const u_int len)
2099 {
2100 const u_char *cp0 = cp;
2101 uint16_t type;
2102
2103 /* type */
2104 type = GET_BE_U_2(cp);
2105 ND_PRINT("\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type));
2106 cp += 2;
2107 /* flags */
2108 ND_PRINT(", flags 0x%04x", GET_BE_U_2(cp));
2109 of10_bitmap_print(ndo, ofpsf_reply_bm, GET_BE_U_2(cp),
2110 OFPSF_REPLY_U);
2111 cp += 2;
2112
2113 if (ndo->ndo_vflag > 0) {
2114 const u_char *(*decoder)(netdissect_options *, const u_char *, const u_char *, u_int) =
2115 type == OFPST_DESC ? of10_desc_stats_reply_print :
2116 type == OFPST_FLOW ? of10_flow_stats_reply_print :
2117 type == OFPST_AGGREGATE ? of10_aggregate_stats_reply_print :
2118 type == OFPST_TABLE ? of10_table_stats_reply_print :
2119 type == OFPST_PORT ? of10_port_stats_reply_print :
2120 type == OFPST_QUEUE ? of10_queue_stats_reply_print :
2121 type == OFPST_VENDOR ? of10_vendor_data_print :
2122 NULL;
2123 if (decoder != NULL)
2124 return decoder(ndo, cp, ep, len - OF_STATS_REPLY_LEN);
2125 }
2126 ND_TCHECK_LEN(cp0, len);
2127 return cp0 + len;
2128
2129 trunc:
2130 nd_print_trunc(ndo);
2131 return ep;
2132 }
2133
2134 /* [OF10] Section 5.3.6 */
2135 static const u_char *
2136 of10_packet_out_print(netdissect_options *ndo,
2137 const u_char *cp, const u_char *ep, const u_int len)
2138 {
2139 const u_char *cp0 = cp;
2140 const u_int len0 = len;
2141 uint16_t actions_len;
2142
2143 /* buffer_id */
2144 ND_PRINT("\n\t buffer_id 0x%08x", GET_BE_U_4(cp));
2145 cp += 4;
2146 /* in_port */
2147 ND_PRINT(", in_port %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
2148 cp += 2;
2149 /* actions_len */
2150 actions_len = GET_BE_U_2(cp);
2151 cp += 2;
2152 if (actions_len > len - OF_PACKET_OUT_LEN)
2153 goto invalid;
2154 /* actions */
2155 if (ep == (cp = of10_actions_print(ndo, "\n\t ", cp, ep, actions_len)))
2156 return ep; /* end of snapshot */
2157 /* data */
2158 return of10_packet_data_print(ndo, cp, ep, len - OF_PACKET_OUT_LEN - actions_len);
2159
2160 invalid: /* skip the rest of the message body */
2161 nd_print_invalid(ndo);
2162 ND_TCHECK_LEN(cp0, len0);
2163 return cp0 + len0;
2164 trunc:
2165 nd_print_trunc(ndo);
2166 return ep;
2167 }
2168
2169 /* [OF10] Section 5.4.1 */
2170 static const u_char *
2171 of10_packet_in_print(netdissect_options *ndo,
2172 const u_char *cp, const u_char *ep, const u_int len)
2173 {
2174 /* buffer_id */
2175 ND_PRINT("\n\t buffer_id %s",
2176 tok2str(bufferid_str, "0x%08x", GET_BE_U_4(cp)));
2177 cp += 4;
2178 /* total_len */
2179 ND_PRINT(", total_len %u", GET_BE_U_2(cp));
2180 cp += 2;
2181 /* in_port */
2182 ND_PRINT(", in_port %s", tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
2183 cp += 2;
2184 /* reason */
2185 ND_PRINT(", reason %s",
2186 tok2str(ofpr_str, "invalid (0x%02x)", GET_U_1(cp)));
2187 cp += 1;
2188 /* pad */
2189 ND_TCHECK_1(cp);
2190 cp += 1;
2191 /* data */
2192 /* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
2193 return of10_packet_data_print(ndo, cp, ep, len - (OF_PACKET_IN_LEN - 2));
2194
2195 trunc:
2196 nd_print_trunc(ndo);
2197 return ep;
2198 }
2199
2200 /* [OF10] Section 5.4.2 */
2201 static const u_char *
2202 of10_flow_removed_print(netdissect_options *ndo,
2203 const u_char *cp, const u_char *ep)
2204 {
2205 /* match */
2206 if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
2207 return ep; /* end of snapshot */
2208 /* cookie */
2209 ND_PRINT("\n\t cookie 0x%016" PRIx64, GET_BE_U_8(cp));
2210 cp += 8;
2211 /* priority */
2212 if (GET_BE_U_2(cp))
2213 ND_PRINT(", priority %u", GET_BE_U_2(cp));
2214 cp += 2;
2215 /* reason */
2216 ND_PRINT(", reason %s",
2217 tok2str(ofprr_str, "unknown (0x%02x)", GET_U_1(cp)));
2218 cp += 1;
2219 /* pad */
2220 ND_TCHECK_1(cp);
2221 cp += 1;
2222 /* duration_sec */
2223 ND_PRINT(", duration_sec %u", GET_BE_U_4(cp));
2224 cp += 4;
2225 /* duration_nsec */
2226 ND_PRINT(", duration_nsec %u", GET_BE_U_4(cp));
2227 cp += 4;
2228 /* idle_timeout */
2229 if (GET_BE_U_2(cp))
2230 ND_PRINT(", idle_timeout %u", GET_BE_U_2(cp));
2231 cp += 2;
2232 /* pad2 */
2233 ND_TCHECK_2(cp);
2234 cp += 2;
2235 /* packet_count */
2236 ND_PRINT(", packet_count %" PRIu64, GET_BE_U_8(cp));
2237 cp += 8;
2238 /* byte_count */
2239 ND_PRINT(", byte_count %" PRIu64, GET_BE_U_8(cp));
2240 return cp + 8;
2241
2242 trunc:
2243 nd_print_trunc(ndo);
2244 return ep;
2245 }
2246
2247 /* [OF10] Section 5.4.4 */
2248 static const u_char *
2249 of10_error_print(netdissect_options *ndo,
2250 const u_char *cp, const u_char *ep, const u_int len)
2251 {
2252 uint16_t type;
2253 const struct tok *code_str;
2254
2255 /* type */
2256 type = GET_BE_U_2(cp);
2257 cp += 2;
2258 ND_PRINT("\n\t type %s", tok2str(ofpet_str, "invalid (0x%04x)", type));
2259 /* code */
2260 ND_TCHECK_2(cp);
2261 code_str =
2262 type == OFPET_HELLO_FAILED ? ofphfc_str :
2263 type == OFPET_BAD_REQUEST ? ofpbrc_str :
2264 type == OFPET_BAD_ACTION ? ofpbac_str :
2265 type == OFPET_FLOW_MOD_FAILED ? ofpfmfc_str :
2266 type == OFPET_PORT_MOD_FAILED ? ofppmfc_str :
2267 type == OFPET_QUEUE_OP_FAILED ? ofpqofc_str :
2268 empty_str;
2269 ND_PRINT(", code %s",
2270 tok2str(code_str, "invalid (0x%04x)", GET_BE_U_2(cp)));
2271 cp += 2;
2272 /* data */
2273 return of10_data_print(ndo, cp, ep, len - OF_ERROR_MSG_LEN);
2274
2275 trunc:
2276 nd_print_trunc(ndo);
2277 return ep;
2278 }
2279
2280 const u_char *
2281 of10_header_body_print(netdissect_options *ndo,
2282 const u_char *cp, const u_char *ep, const uint8_t type,
2283 const uint16_t len, const uint32_t xid)
2284 {
2285 const u_char *cp0 = cp;
2286 const u_int len0 = len;
2287 /* Thus far message length is not less than the basic header size, but most
2288 * message types have additional assorted constraints on the length. Wherever
2289 * possible, check that message length meets the constraint, in remaining
2290 * cases check that the length is OK to begin decoding and leave any final
2291 * verification up to a lower-layer function. When the current message is
2292 * invalid, proceed to the next message. */
2293
2294 /* [OF10] Section 5.1 */
2295 ND_PRINT("\n\tversion 1.0, type %s, length %u, xid 0x%08x",
2296 tok2str(ofpt_str, "invalid (0x%02x)", type), len, xid);
2297 switch (type) {
2298 /* OpenFlow header only. */
2299 case OFPT_FEATURES_REQUEST: /* [OF10] Section 5.3.1 */
2300 case OFPT_GET_CONFIG_REQUEST: /* [OF10] Section 5.3.2 */
2301 case OFPT_BARRIER_REQUEST: /* [OF10] Section 5.3.7 */
2302 case OFPT_BARRIER_REPLY: /* ibid */
2303 if (len != OF_HEADER_LEN)
2304 goto invalid;
2305 break;
2306
2307 /* OpenFlow header and fixed-size message body. */
2308 case OFPT_SET_CONFIG: /* [OF10] Section 5.3.2 */
2309 case OFPT_GET_CONFIG_REPLY: /* ibid */
2310 if (len != OF_SWITCH_CONFIG_LEN)
2311 goto invalid;
2312 if (ndo->ndo_vflag < 1)
2313 goto next_message;
2314 /* flags */
2315 ND_PRINT("\n\t flags %s",
2316 tok2str(ofp_config_str, "invalid (0x%04x)", GET_BE_U_2(cp)));
2317 cp += 2;
2318 /* miss_send_len */
2319 ND_PRINT(", miss_send_len %u", GET_BE_U_2(cp));
2320 return cp + 2;
2321 case OFPT_PORT_MOD:
2322 if (len != OF_PORT_MOD_LEN)
2323 goto invalid;
2324 if (ndo->ndo_vflag < 1)
2325 goto next_message;
2326 return of10_port_mod_print(ndo, cp, ep);
2327 case OFPT_QUEUE_GET_CONFIG_REQUEST: /* [OF10] Section 5.3.4 */
2328 if (len != OF_QUEUE_GET_CONFIG_REQUEST_LEN)
2329 goto invalid;
2330 if (ndo->ndo_vflag < 1)
2331 goto next_message;
2332 /* port */
2333 ND_PRINT("\n\t port_no %s",
2334 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
2335 cp += 2;
2336 /* pad */
2337 ND_TCHECK_2(cp);
2338 return cp + 2;
2339 case OFPT_FLOW_REMOVED:
2340 if (len != OF_FLOW_REMOVED_LEN)
2341 goto invalid;
2342 if (ndo->ndo_vflag < 1)
2343 goto next_message;
2344 return of10_flow_removed_print(ndo, cp, ep);
2345 case OFPT_PORT_STATUS: /* [OF10] Section 5.4.3 */
2346 if (len != OF_PORT_STATUS_LEN)
2347 goto invalid;
2348 if (ndo->ndo_vflag < 1)
2349 goto next_message;
2350 /* reason */
2351 ND_PRINT("\n\t reason %s",
2352 tok2str(ofppr_str, "invalid (0x%02x)", GET_U_1(cp)));
2353 cp += 1;
2354 /* pad */
2355 ND_TCHECK_7(cp);
2356 cp += 7;
2357 /* desc */
2358 return of10_phy_ports_print(ndo, cp, ep, OF_PHY_PORT_LEN);
2359
2360 /* OpenFlow header, fixed-size message body and n * fixed-size data units. */
2361 case OFPT_FEATURES_REPLY:
2362 if (len < OF_SWITCH_FEATURES_LEN)
2363 goto invalid;
2364 if (ndo->ndo_vflag < 1)
2365 goto next_message;
2366 return of10_features_reply_print(ndo, cp, ep, len);
2367
2368 /* OpenFlow header and variable-size data. */
2369 case OFPT_HELLO: /* [OF10] Section 5.5.1 */
2370 case OFPT_ECHO_REQUEST: /* [OF10] Section 5.5.2 */
2371 case OFPT_ECHO_REPLY: /* [OF10] Section 5.5.3 */
2372 if (ndo->ndo_vflag < 1)
2373 goto next_message;
2374 return of10_data_print(ndo, cp, ep, len - OF_HEADER_LEN);
2375
2376 /* OpenFlow header, fixed-size message body and variable-size data. */
2377 case OFPT_ERROR:
2378 if (len < OF_ERROR_MSG_LEN)
2379 goto invalid;
2380 if (ndo->ndo_vflag < 1)
2381 goto next_message;
2382 return of10_error_print(ndo, cp, ep, len);
2383 case OFPT_VENDOR:
2384 /* [OF10] Section 5.5.4 */
2385 if (len < OF_VENDOR_HEADER_LEN)
2386 goto invalid;
2387 if (ndo->ndo_vflag < 1)
2388 goto next_message;
2389 return of10_vendor_message_print(ndo, cp, ep, len - OF_HEADER_LEN);
2390 case OFPT_PACKET_IN:
2391 /* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
2392 if (len < OF_PACKET_IN_LEN - 2)
2393 goto invalid;
2394 if (ndo->ndo_vflag < 1)
2395 goto next_message;
2396 return of10_packet_in_print(ndo, cp, ep, len);
2397
2398 /* a. OpenFlow header. */
2399 /* b. OpenFlow header and one of the fixed-size message bodies. */
2400 /* c. OpenFlow header, fixed-size message body and variable-size data. */
2401 case OFPT_STATS_REQUEST:
2402 if (len < OF_STATS_REQUEST_LEN)
2403 goto invalid;
2404 if (ndo->ndo_vflag < 1)
2405 goto next_message;
2406 return of10_stats_request_print(ndo, cp, ep, len);
2407
2408 /* a. OpenFlow header and fixed-size message body. */
2409 /* b. OpenFlow header and n * fixed-size data units. */
2410 /* c. OpenFlow header and n * variable-size data units. */
2411 /* d. OpenFlow header, fixed-size message body and variable-size data. */
2412 case OFPT_STATS_REPLY:
2413 if (len < OF_STATS_REPLY_LEN)
2414 goto invalid;
2415 if (ndo->ndo_vflag < 1)
2416 goto next_message;
2417 return of10_stats_reply_print(ndo, cp, ep, len);
2418
2419 /* OpenFlow header and n * variable-size data units and variable-size data. */
2420 case OFPT_PACKET_OUT:
2421 if (len < OF_PACKET_OUT_LEN)
2422 goto invalid;
2423 if (ndo->ndo_vflag < 1)
2424 goto next_message;
2425 return of10_packet_out_print(ndo, cp, ep, len);
2426
2427 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2428 case OFPT_FLOW_MOD:
2429 if (len < OF_FLOW_MOD_LEN)
2430 goto invalid;
2431 if (ndo->ndo_vflag < 1)
2432 goto next_message;
2433 return of10_flow_mod_print(ndo, cp, ep, len);
2434
2435 /* OpenFlow header, fixed-size message body and n * variable-size data units. */
2436 case OFPT_QUEUE_GET_CONFIG_REPLY: /* [OF10] Section 5.3.4 */
2437 if (len < OF_QUEUE_GET_CONFIG_REPLY_LEN)
2438 goto invalid;
2439 if (ndo->ndo_vflag < 1)
2440 goto next_message;
2441 /* port */
2442 ND_PRINT("\n\t port_no %s",
2443 tok2str(ofpp_str, "%u", GET_BE_U_2(cp)));
2444 cp += 2;
2445 /* pad */
2446 ND_TCHECK_6(cp);
2447 cp += 6;
2448 /* queues */
2449 return of10_queues_print(ndo, cp, ep, len - OF_QUEUE_GET_CONFIG_REPLY_LEN);
2450 } /* switch (type) */
2451 goto next_message;
2452
2453 invalid: /* skip the message body */
2454 nd_print_invalid(ndo);
2455 next_message:
2456 ND_TCHECK_LEN(cp0, len0 - OF_HEADER_LEN);
2457 return cp0 + len0 - OF_HEADER_LEN;
2458 trunc:
2459 nd_print_trunc(ndo);
2460 return ep;
2461 }