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