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