]> The Tcpdump Group git mirrors - tcpdump/blob - print-openflow-1.3.c
17e44fecd105cd62b8295c34dffe3da9b365a8c5
[tcpdump] / print-openflow-1.3.c
1 /*
2 * This module implements decoding of OpenFlow protocol version 1.3 (wire
3 * protocol 0x04). It is based on the implementation conventions explained in
4 * print-openflow-1.0.c.
5 *
6 * [OF13] https://www.opennetworking.org/wp-content/uploads/2014/10/openflow-switch-v1.3.4.pdf
7 *
8 * Copyright (c) 2020 The TCPDUMP project
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /* \summary: OpenFlow protocol version 1.3 printer */
35
36 #ifdef HAVE_CONFIG_H
37 #include <config.h>
38 #endif
39
40 #include "netdissect-stdinc.h"
41
42 #define ND_LONGJMP_FROM_TCHECK
43 #include "netdissect.h"
44 #include "extract.h"
45 #include "addrtoname.h"
46 #include "openflow.h"
47
48 #define OFPT_HELLO 0U
49 #define OFPT_ERROR 1U
50 #define OFPT_ECHO_REQUEST 2U
51 #define OFPT_ECHO_REPLY 3U
52 #define OFPT_EXPERIMENTER 4U
53 #define OFPT_FEATURES_REQUEST 5U
54 #define OFPT_FEATURES_REPLY 6U
55 #define OFPT_GET_CONFIG_REQUEST 7U
56 #define OFPT_GET_CONFIG_REPLY 8U
57 #define OFPT_SET_CONFIG 9U
58 #define OFPT_PACKET_IN 10U
59 #define OFPT_FLOW_REMOVED 11U
60 #define OFPT_PORT_STATUS 12U
61 #define OFPT_PACKET_OUT 13U
62 #define OFPT_FLOW_MOD 14U
63 #define OFPT_GROUP_MOD 15U
64 #define OFPT_PORT_MOD 16U
65 #define OFPT_TABLE_MOD 17U
66 #define OFPT_MULTIPART_REQUEST 18U
67 #define OFPT_MULTIPART_REPLY 19U
68 #define OFPT_BARRIER_REQUEST 20U
69 #define OFPT_BARRIER_REPLY 21U
70 #define OFPT_QUEUE_GET_CONFIG_REQUEST 22U
71 #define OFPT_QUEUE_GET_CONFIG_REPLY 23U
72 #define OFPT_ROLE_REQUEST 24U
73 #define OFPT_ROLE_REPLY 25U
74 #define OFPT_GET_ASYNC_REQUEST 26U
75 #define OFPT_GET_ASYNC_REPLY 27U
76 #define OFPT_SET_ASYNC 28U
77 #define OFPT_METER_MOD 29U
78 static const struct tok ofpt_str[] = {
79 { OFPT_HELLO, "HELLO" },
80 { OFPT_ERROR, "ERROR" },
81 { OFPT_ECHO_REQUEST, "ECHO_REQUEST" },
82 { OFPT_ECHO_REPLY, "ECHO_REPLY" },
83 { OFPT_EXPERIMENTER, "EXPERIMENTER" },
84 { OFPT_FEATURES_REQUEST, "FEATURES_REQUEST" },
85 { OFPT_FEATURES_REPLY, "FEATURES_REPLY" },
86 { OFPT_GET_CONFIG_REQUEST, "GET_CONFIG_REQUEST" },
87 { OFPT_GET_CONFIG_REPLY, "GET_CONFIG_REPLY" },
88 { OFPT_SET_CONFIG, "SET_CONFIG" },
89 { OFPT_PACKET_IN, "PACKET_IN" },
90 { OFPT_FLOW_REMOVED, "FLOW_REMOVED" },
91 { OFPT_PORT_STATUS, "PORT_STATUS" },
92 { OFPT_PACKET_OUT, "PACKET_OUT" },
93 { OFPT_FLOW_MOD, "FLOW_MOD" },
94 { OFPT_GROUP_MOD, "GROUP_MOD" },
95 { OFPT_PORT_MOD, "PORT_MOD" },
96 { OFPT_TABLE_MOD, "TABLE_MOD" },
97 { OFPT_MULTIPART_REQUEST, "MULTIPART_REQUEST" },
98 { OFPT_MULTIPART_REPLY, "MULTIPART_REPLY" },
99 { OFPT_BARRIER_REQUEST, "BARRIER_REQUEST" },
100 { OFPT_BARRIER_REPLY, "BARRIER_REPLY" },
101 { OFPT_QUEUE_GET_CONFIG_REQUEST, "QUEUE_GET_CONFIG_REQUEST" },
102 { OFPT_QUEUE_GET_CONFIG_REPLY, "QUEUE_GET_CONFIG_REPLY" },
103 { OFPT_ROLE_REQUEST, "ROLE_REQUEST" },
104 { OFPT_ROLE_REPLY, "ROLE_REPLY" },
105 { OFPT_GET_ASYNC_REQUEST, "GET_ASYNC_REQUEST" },
106 { OFPT_GET_ASYNC_REPLY, "GET_ASYNC_REPLY" },
107 { OFPT_SET_ASYNC, "SET_ASYNC" },
108 { OFPT_METER_MOD, "METER_MOD" },
109 { 0, NULL }
110 };
111
112 #define OFPC_FLOW_STATS (1U <<0)
113 #define OFPC_TABLE_STATS (1U <<1)
114 #define OFPC_PORT_STATS (1U <<2)
115 #define OFPC_GROUP_STATS (1U <<3)
116 #define OFPC_IP_REASM (1U <<5)
117 #define OFPC_QUEUE_STATS (1U <<6)
118 #define OFPC_PORT_BLOCKED (1U <<8)
119 static const struct tok ofp_capabilities_bm[] = {
120 { OFPC_FLOW_STATS, "FLOW_STATS" },
121 { OFPC_TABLE_STATS, "TABLE_STATS" },
122 { OFPC_PORT_STATS, "PORT_STATS" },
123 { OFPC_GROUP_STATS, "GROUP_STATS" },
124 { OFPC_IP_REASM, "IP_REASM" },
125 { OFPC_QUEUE_STATS, "QUEUE_STATS" },
126 { OFPC_PORT_BLOCKED, "PORT_BLOCKED" },
127 { 0, NULL }
128 };
129 #define OFPCAP_U (~(OFPC_FLOW_STATS | OFPC_TABLE_STATS | OFPC_PORT_STATS | \
130 OFPC_GROUP_STATS | OFPC_IP_REASM | OFPC_QUEUE_STATS | \
131 OFPC_PORT_BLOCKED))
132
133 #define OFPC_FRAG_NORMAL 0U
134 #define OFPC_FRAG_DROP 1U
135 #define OFPC_FRAG_REASM 2U
136 static const struct tok ofp_config_str[] = {
137 { OFPC_FRAG_NORMAL, "FRAG_NORMAL" },
138 { OFPC_FRAG_DROP, "FRAG_DROP" },
139 { OFPC_FRAG_REASM, "FRAG_REASM" },
140 { 0, NULL }
141 };
142
143 #define OFPTT_MAX 0xfeU
144 #define OFPTT_ALL 0xffU
145 static const struct tok ofptt_str[] = {
146 { OFPTT_MAX, "MAX" },
147 { OFPTT_ALL, "ALL" },
148 { 0, NULL },
149 };
150
151 #define OFPCML_MAX 0xffe5U
152 #define OFPCML_NO_BUFFER 0xffffU
153 static const struct tok ofpcml_str[] = {
154 { OFPCML_MAX, "MAX" },
155 { OFPCML_NO_BUFFER, "NO_BUFFER" },
156 { 0, NULL }
157 };
158
159 #define OFPPC_PORT_DOWN (1U <<0)
160 #define OFPPC_NO_RECV (1U <<2)
161 #define OFPPC_NO_FWD (1U <<5)
162 #define OFPPC_NO_PACKET_IN (1U <<6)
163 static const struct tok ofppc_bm[] = {
164 { OFPPC_PORT_DOWN, "PORT_DOWN" },
165 { OFPPC_NO_RECV, "NO_RECV" },
166 { OFPPC_NO_FWD, "NO_FWD" },
167 { OFPPC_NO_PACKET_IN, "NO_PACKET_IN" },
168 { 0, NULL }
169 };
170 #define OFPPC_U (~(OFPPC_PORT_DOWN | OFPPC_NO_RECV | OFPPC_NO_FWD | \
171 OFPPC_NO_PACKET_IN))
172
173 #define OFPPS_LINK_DOWN (1U << 0)
174 #define OFPPS_BLOCKED (1U << 1)
175 #define OFPPS_LIVE (1U << 2)
176 static const struct tok ofpps_bm[] = {
177 { OFPPS_LINK_DOWN, "LINK_DOWN" },
178 { OFPPS_BLOCKED, "BLOCKED" },
179 { OFPPS_LIVE, "LIVE" },
180 { 0, NULL }
181 };
182 #define OFPPS_U (~(OFPPS_LINK_DOWN | OFPPS_BLOCKED | OFPPS_LIVE))
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_40GB_FD (1U << 7)
192 #define OFPPF_100GB_FD (1U << 8)
193 #define OFPPF_1TB_FD (1U << 9)
194 #define OFPPF_OTHER (1U << 10)
195 #define OFPPF_COPPER (1U << 11)
196 #define OFPPF_FIBER (1U << 12)
197 #define OFPPF_AUTONEG (1U << 13)
198 #define OFPPF_PAUSE (1U << 14)
199 #define OFPPF_PAUSE_ASYM (1U << 15)
200 static const struct tok ofppf_bm[] = {
201 { OFPPF_10MB_HD, "10MB_HD" },
202 { OFPPF_10MB_FD, "10MB_FD" },
203 { OFPPF_100MB_HD, "100MB_HD" },
204 { OFPPF_100MB_FD, "100MB_FD" },
205 { OFPPF_1GB_HD, "1GB_HD" },
206 { OFPPF_1GB_FD, "1GB_FD" },
207 { OFPPF_10GB_FD, "10GB_FD" },
208 { OFPPF_40GB_FD, "40GB_FD" },
209 { OFPPF_100GB_FD, "100GB_FD" },
210 { OFPPF_1TB_FD, "1TB_FD" },
211 { OFPPF_OTHER, "OTHER" },
212 { OFPPF_COPPER, "COPPER" },
213 { OFPPF_FIBER, "FIBER" },
214 { OFPPF_AUTONEG, "AUTONEG" },
215 { OFPPF_PAUSE, "PAUSE" },
216 { OFPPF_PAUSE_ASYM, "PAUSE_ASYM" },
217 { 0, NULL }
218 };
219 #define OFPPF_U (~(OFPPF_10MB_HD | OFPPF_10MB_FD | OFPPF_100MB_HD | \
220 OFPPF_100MB_FD | OFPPF_1GB_HD | OFPPF_1GB_FD | \
221 OFPPF_10GB_FD | OFPPF_40GB_FD | OFPPF_100GB_FD | \
222 OFPPF_1TB_FD | OFPPF_OTHER | OFPPF_COPPER | OFPPF_FIBER | \
223 OFPPF_AUTONEG | OFPPF_PAUSE | OFPPF_PAUSE_ASYM))
224
225 #define OFPHET_VERSIONBITMAP 1U
226 static const struct tok ofphet_str[] = {
227 { OFPHET_VERSIONBITMAP, "VERSIONBITMAP" },
228 { 0, NULL }
229 };
230
231 #define OFPP_MAX 0xffffff00U
232 #define OFPP_IN_PORT 0xfffffff8U
233 #define OFPP_TABLE 0xfffffff9U
234 #define OFPP_NORMAL 0xfffffffaU
235 #define OFPP_FLOOD 0xfffffffbU
236 #define OFPP_ALL 0xfffffffcU
237 #define OFPP_CONTROLLER 0xfffffffdU
238 #define OFPP_LOCAL 0xfffffffeU
239 #define OFPP_ANY 0xffffffffU
240 static const struct tok ofpp_str[] = {
241 { OFPP_MAX, "MAX" },
242 { OFPP_IN_PORT, "IN_PORT" },
243 { OFPP_TABLE, "TABLE" },
244 { OFPP_NORMAL, "NORMAL" },
245 { OFPP_FLOOD, "FLOOD" },
246 { OFPP_ALL, "ALL" },
247 { OFPP_CONTROLLER, "CONTROLLER" },
248 { OFPP_LOCAL, "LOCAL" },
249 { OFPP_ANY, "ANY" },
250 { 0, NULL }
251 };
252
253 #define OFPCR_ROLE_NOCHANGE 0U
254 #define OFPCR_ROLE_EQUAL 1U
255 #define OFPCR_ROLE_MASTER 2U
256 #define OFPCR_ROLE_SLAVE 3U
257 static const struct tok ofpcr_str[] = {
258 { OFPCR_ROLE_NOCHANGE, "NOCHANGE" },
259 { OFPCR_ROLE_EQUAL, "EQUAL" },
260 { OFPCR_ROLE_MASTER, "MASTER" },
261 { OFPCR_ROLE_SLAVE, "SLAVE" },
262 { 0, NULL }
263 };
264
265 #define OF_BIT_VER_1_0 (1U << (OF_VER_1_0 - 1))
266 #define OF_BIT_VER_1_1 (1U << (OF_VER_1_1 - 1))
267 #define OF_BIT_VER_1_2 (1U << (OF_VER_1_2 - 1))
268 #define OF_BIT_VER_1_3 (1U << (OF_VER_1_3 - 1))
269 #define OF_BIT_VER_1_4 (1U << (OF_VER_1_4 - 1))
270 #define OF_BIT_VER_1_5 (1U << (OF_VER_1_5 - 1))
271 static const struct tok ofverbm_str[] = {
272 { OF_BIT_VER_1_0, "1.0" },
273 { OF_BIT_VER_1_1, "1.1" },
274 { OF_BIT_VER_1_2, "1.2" },
275 { OF_BIT_VER_1_3, "1.3" },
276 { OF_BIT_VER_1_4, "1.4" },
277 { OF_BIT_VER_1_5, "1.5" },
278 { 0, NULL }
279 };
280 #define OF_BIT_VER_U (~(OF_BIT_VER_1_0 | OF_BIT_VER_1_1 | OF_BIT_VER_1_2 | \
281 OF_BIT_VER_1_3 | OF_BIT_VER_1_4 | OF_BIT_VER_1_5))
282
283 #define OFPR_NO_MATCH 0U
284 #define OFPR_ACTION 1U
285 #define OFPR_INVALID_TTL 2U
286 #if 0 /* for OFPT_PACKET_IN */
287 static const struct tok ofpr_str[] = {
288 { OFPR_NO_MATCH, "NO_MATCH" },
289 { OFPR_ACTION, "ACTION" },
290 { OFPR_INVALID_TTL, "OFPR_INVALID_TTL" },
291 { 0, NULL }
292 };
293 #endif
294
295 #define ASYNC_OFPR_NO_MATCH (1U << OFPR_NO_MATCH )
296 #define ASYNC_OFPR_ACTION (1U << OFPR_ACTION )
297 #define ASYNC_OFPR_INVALID_TTL (1U << OFPR_INVALID_TTL)
298 static const struct tok async_ofpr_bm[] = {
299 { ASYNC_OFPR_NO_MATCH, "NO_MATCH" },
300 { ASYNC_OFPR_ACTION, "ACTION" },
301 { ASYNC_OFPR_INVALID_TTL, "INVALID_TTL" },
302 { 0, NULL }
303 };
304 #define ASYNC_OFPR_U (~(ASYNC_OFPR_NO_MATCH | ASYNC_OFPR_ACTION | \
305 ASYNC_OFPR_INVALID_TTL))
306
307 #define OFPPR_ADD 0U
308 #define OFPPR_DELETE 1U
309 #define OFPPR_MODIFY 2U
310 static const struct tok ofppr_str[] = {
311 { OFPPR_ADD, "ADD" },
312 { OFPPR_DELETE, "DELETE" },
313 { OFPPR_MODIFY, "MODIFY" },
314 { 0, NULL }
315 };
316
317 #define ASYNC_OFPPR_ADD (1U << OFPPR_ADD )
318 #define ASYNC_OFPPR_DELETE (1U << OFPPR_DELETE)
319 #define ASYNC_OFPPR_MODIFY (1U << OFPPR_MODIFY)
320 static const struct tok async_ofppr_bm[] = {
321 { ASYNC_OFPPR_ADD, "ADD" },
322 { ASYNC_OFPPR_DELETE, "DELETE" },
323 { ASYNC_OFPPR_MODIFY, "MODIFY" },
324 { 0, NULL }
325 };
326 #define ASYNC_OFPPR_U (~(ASYNC_OFPPR_ADD | ASYNC_OFPPR_DELETE | \
327 ASYNC_OFPPR_MODIFY))
328
329 #define OFPET_HELLO_FAILED 0U
330 #define OFPET_BAD_REQUEST 1U
331 #define OFPET_BAD_ACTION 2U
332 #define OFPET_BAD_INSTRUCTION 3U
333 #define OFPET_BAD_MATCH 4U
334 #define OFPET_FLOW_MOD_FAILED 5U
335 #define OFPET_GROUP_MOD_FAILED 6U
336 #define OFPET_PORT_MOD_FAILED 7U
337 #define OFPET_TABLE_MOD_FAILED 8U
338 #define OFPET_QUEUE_OP_FAILED 9U
339 #define OFPET_SWITCH_CONFIG_FAILED 10U
340 #define OFPET_ROLE_REQUEST_FAILED 11U
341 #define OFPET_METER_MOD_FAILED 12U
342 #define OFPET_TABLE_FEATURES_FAILED 13U
343 #define OFPET_EXPERIMENTER 0xffffU /* a special case */
344 static const struct tok ofpet_str[] = {
345 { OFPET_HELLO_FAILED, "HELLO_FAILED" },
346 { OFPET_BAD_REQUEST, "BAD_REQUEST" },
347 { OFPET_BAD_ACTION, "BAD_ACTION" },
348 { OFPET_BAD_INSTRUCTION, "BAD_INSTRUCTION" },
349 { OFPET_BAD_MATCH, "BAD_MATCH" },
350 { OFPET_FLOW_MOD_FAILED, "FLOW_MOD_FAILED" },
351 { OFPET_GROUP_MOD_FAILED, "GROUP_MOD_FAILED" },
352 { OFPET_PORT_MOD_FAILED, "PORT_MOD_FAILED" },
353 { OFPET_TABLE_MOD_FAILED, "TABLE_MOD_FAILED" },
354 { OFPET_QUEUE_OP_FAILED, "QUEUE_OP_FAILED" },
355 { OFPET_SWITCH_CONFIG_FAILED, "SWITCH_CONFIG_FAILED" },
356 { OFPET_ROLE_REQUEST_FAILED, "ROLE_REQUEST_FAILED" },
357 { OFPET_METER_MOD_FAILED, "METER_MOD_FAILED" },
358 { OFPET_TABLE_FEATURES_FAILED, "TABLE_FEATURES_FAILED" },
359 { OFPET_EXPERIMENTER, "EXPERIMENTER" },
360 { 0, NULL }
361 };
362
363 #define OFPHFC_INCOMPATIBLE 0U
364 #define OFPHFC_EPERM 1U
365 static const struct tok ofphfc_str[] = {
366 { OFPHFC_INCOMPATIBLE, "INCOMPATIBLE" },
367 { OFPHFC_EPERM, "EPERM" },
368 { 0, NULL }
369 };
370
371 #define OFPBRC_BAD_VERSION 0U
372 #define OFPBRC_BAD_TYPE 1U
373 #define OFPBRC_BAD_MULTIPART 2U
374 #define OFPBRC_BAD_EXPERIMENTER 3U
375 #define OFPBRC_BAD_EXP_TYPE 4U
376 #define OFPBRC_EPERM 5U
377 #define OFPBRC_BAD_LEN 6U
378 #define OFPBRC_BUFFER_EMPTY 7U
379 #define OFPBRC_BUFFER_UNKNOWN 8U
380 #define OFPBRC_BAD_TABLE_ID 9U
381 #define OFPBRC_IS_SLAVE 10U
382 #define OFPBRC_BAD_PORT 11U
383 #define OFPBRC_BAD_PACKET 12U
384 #define OFPBRC_MULTIPART_BUFFER_OVERFLOW 13U
385 static const struct tok ofpbrc_str[] = {
386 { OFPBRC_BAD_VERSION, "BAD_VERSION" },
387 { OFPBRC_BAD_TYPE, "BAD_TYPE" },
388 { OFPBRC_BAD_MULTIPART, "BAD_MULTIPART" },
389 { OFPBRC_BAD_EXPERIMENTER, "BAD_EXPERIMENTER" },
390 { OFPBRC_BAD_EXP_TYPE, "BAD_EXP_TYPE" },
391 { OFPBRC_EPERM, "EPERM" },
392 { OFPBRC_BAD_LEN, "BAD_LEN" },
393 { OFPBRC_BUFFER_EMPTY, "BUFFER_EMPTY" },
394 { OFPBRC_BUFFER_UNKNOWN, "BUFFER_UNKNOWN" },
395 { OFPBRC_BAD_TABLE_ID, "BAD_TABLE_ID" },
396 { OFPBRC_IS_SLAVE, "IS_SLAVE" },
397 { OFPBRC_BAD_PORT, "BAD_PORT" },
398 { OFPBRC_BAD_PACKET, "BAD_PACKET" },
399 { OFPBRC_MULTIPART_BUFFER_OVERFLOW, "MULTIPART_BUFFER_OVERFLOW" },
400 { 0, NULL }
401 };
402
403 #define OFPBAC_BAD_TYPE 0U
404 #define OFPBAC_BAD_LEN 1U
405 #define OFPBAC_BAD_EXPERIMENTER 2U
406 #define OFPBAC_BAD_EXP_TYPE 3U
407 #define OFPBAC_BAD_OUT_PORT 4U
408 #define OFPBAC_BAD_ARGUMENT 5U
409 #define OFPBAC_EPERM 6U
410 #define OFPBAC_TOO_MANY 7U
411 #define OFPBAC_BAD_QUEUE 8U
412 #define OFPBAC_BAD_OUT_GROUP 9U
413 #define OFPBAC_MATCH_INCONSISTENT 10U
414 #define OFPBAC_UNSUPPORTED_ORDER 11U
415 #define OFPBAC_BAD_TAG 12U
416 #define OFPBAC_BAD_SET_TYPE 13U
417 #define OFPBAC_BAD_SET_LEN 14U
418 #define OFPBAC_BAD_SET_ARGUMENT 15U
419 static const struct tok ofpbac_str[] = {
420 { OFPBAC_BAD_TYPE, "BAD_TYPE" },
421 { OFPBAC_BAD_LEN, "BAD_LEN" },
422 { OFPBAC_BAD_EXPERIMENTER, "BAD_EXPERIMENTER" },
423 { OFPBAC_BAD_EXP_TYPE, "BAD_EXP_TYPE" },
424 { OFPBAC_BAD_OUT_PORT, "BAD_OUT_PORT" },
425 { OFPBAC_BAD_ARGUMENT, "BAD_ARGUMENT" },
426 { OFPBAC_EPERM, "EPERM" },
427 { OFPBAC_TOO_MANY, "TOO_MANY" },
428 { OFPBAC_BAD_QUEUE, "BAD_QUEUE" },
429 { OFPBAC_BAD_OUT_GROUP, "BAD_OUT_GROUP" },
430 { OFPBAC_MATCH_INCONSISTENT, "MATCH_INCONSISTENT" },
431 { OFPBAC_UNSUPPORTED_ORDER, "UNSUPPORTED_ORDER" },
432 { OFPBAC_BAD_TAG, "BAD_TAG" },
433 { OFPBAC_BAD_SET_TYPE, "BAD_SET_TYPE" },
434 { OFPBAC_BAD_SET_LEN, "BAD_SET_LEN" },
435 { OFPBAC_BAD_SET_ARGUMENT, "BAD_SET_ARGUMENT" },
436 { 0, NULL }
437 };
438
439 #define OFPBIC_UNKNOWN_INST 0U
440 #define OFPBIC_UNSUP_INST 1U
441 #define OFPBIC_BAD_TABLE_ID 2U
442 #define OFPBIC_UNSUP_METADATA 3U
443 #define OFPBIC_UNSUP_METADATA_MASK 4U
444 #define OFPBIC_BAD_EXPERIMENTER 5U
445 #define OFPBIC_BAD_EXP_TYPE 6U
446 #define OFPBIC_BAD_LEN 7U
447 #define OFPBIC_EPERM 8U
448 static const struct tok ofpbic_str[] = {
449 { OFPBIC_UNKNOWN_INST, "UNKNOWN_INST" },
450 { OFPBIC_UNSUP_INST, "UNSUP_INST" },
451 { OFPBIC_BAD_TABLE_ID, "BAD_TABLE_ID" },
452 { OFPBIC_UNSUP_METADATA, "UNSUP_METADATA" },
453 { OFPBIC_UNSUP_METADATA_MASK, "UNSUP_METADATA_MASK" },
454 { OFPBIC_BAD_EXPERIMENTER, "BAD_EXPERIMENTER" },
455 { OFPBIC_BAD_EXP_TYPE, "BAD_EXP_TYPE" },
456 { OFPBIC_BAD_LEN, "BAD_LEN" },
457 { OFPBIC_EPERM, "EPERM" },
458 { 0, NULL }
459 };
460
461 #define OFPBMC_BAD_TYPE 0U
462 #define OFPBMC_BAD_LEN 1U
463 #define OFPBMC_BAD_TAG 2U
464 #define OFPBMC_BAD_DL_ADDR_MASK 3U
465 #define OFPBMC_BAD_NW_ADDR_MASK 4U
466 #define OFPBMC_BAD_WILDCARDS 5U
467 #define OFPBMC_BAD_FIELD 6U
468 #define OFPBMC_BAD_VALUE 7U
469 #define OFPBMC_BAD_MASK 8U
470 #define OFPBMC_BAD_PREREQ 9U
471 #define OFPBMC_DUP_FIELD 10U
472 #define OFPBMC_EPERM 11U
473 static const struct tok ofpbmc_str[] = {
474 { OFPBMC_BAD_TYPE, "BAD_TYPE" },
475 { OFPBMC_BAD_LEN, "BAD_LEN" },
476 { OFPBMC_BAD_TAG, "BAD_TAG" },
477 { OFPBMC_BAD_DL_ADDR_MASK, "BAD_DL_ADDR_MASK" },
478 { OFPBMC_BAD_NW_ADDR_MASK, "BAD_NW_ADDR_MASK" },
479 { OFPBMC_BAD_WILDCARDS, "BAD_WILDCARDS" },
480 { OFPBMC_BAD_FIELD, "BAD_FIELD" },
481 { OFPBMC_BAD_VALUE, "BAD_VALUE" },
482 { OFPBMC_BAD_MASK, "BAD_MASK" },
483 { OFPBMC_BAD_PREREQ, "BAD_PREREQ" },
484 { OFPBMC_DUP_FIELD, "DUP_FIELD" },
485 { OFPBMC_EPERM, "EPERM" },
486 { 0, NULL }
487 };
488
489 #define OFPFMFC_UNKNOWN 0U
490 #define OFPFMFC_TABLE_FULL 1U
491 #define OFPFMFC_BAD_TABLE_ID 2U
492 #define OFPFMFC_OVERLAP 3U
493 #define OFPFMFC_EPERM 4U
494 #define OFPFMFC_BAD_TIMEOUT 5U
495 #define OFPFMFC_BAD_COMMAND 6U
496 #define OFPFMFC_BAD_FLAGS 7U
497 static const struct tok ofpfmfc_str[] = {
498 { OFPFMFC_UNKNOWN, "UNKNOWN" },
499 { OFPFMFC_TABLE_FULL, "TABLE_FULL" },
500 { OFPFMFC_BAD_TABLE_ID, "BAD_TABLE_ID" },
501 { OFPFMFC_OVERLAP, "OVERLAP" },
502 { OFPFMFC_EPERM, "EPERM" },
503 { OFPFMFC_BAD_TIMEOUT, "BAD_TIMEOUT" },
504 { OFPFMFC_BAD_COMMAND, "BAD_COMMAND" },
505 { OFPFMFC_BAD_FLAGS, "BAD_FLAGS" },
506 { 0, NULL }
507 };
508
509 #define OFPGMFC_GROUP_EXISTS 0U
510 #define OFPGMFC_INVALID_GROUP 1U
511 #define OFPGMFC_WEIGHT_UNSUPPORTED 2U
512 #define OFPGMFC_OUT_OF_GROUPS 3U
513 #define OFPGMFC_OUT_OF_BUCKETS 4U
514 #define OFPGMFC_CHAINING_UNSUPPORTED 5U
515 #define OFPGMFC_WATCH_UNSUPPORTED 6U
516 #define OFPGMFC_LOOP 7U
517 #define OFPGMFC_UNKNOWN_GROUP 8U
518 #define OFPGMFC_CHAINED_GROUP 9U
519 #define OFPGMFC_BAD_TYPE 10U
520 #define OFPGMFC_BAD_COMMAND 11U
521 #define OFPGMFC_BAD_BUCKET 12U
522 #define OFPGMFC_BAD_MATCH 13U
523 #define OFPGMFC_EPERM 14U
524 static const struct tok ofpgmfc_str[] = {
525 { OFPGMFC_GROUP_EXISTS, "GROUP_EXISTS" },
526 { OFPGMFC_INVALID_GROUP, "INVALID_GROUP" },
527 { OFPGMFC_WEIGHT_UNSUPPORTED, "WEIGHT_UNSUPPORTED" },
528 { OFPGMFC_OUT_OF_GROUPS, "OUT_OF_GROUPS" },
529 { OFPGMFC_OUT_OF_BUCKETS, "OUT_OF_BUCKETS" },
530 { OFPGMFC_CHAINING_UNSUPPORTED, "CHAINING_UNSUPPORTED" },
531 { OFPGMFC_WATCH_UNSUPPORTED, "WATCH_UNSUPPORTED" },
532 { OFPGMFC_LOOP, "LOOP" },
533 { OFPGMFC_UNKNOWN_GROUP, "UNKNOWN_GROUP" },
534 { OFPGMFC_CHAINED_GROUP, "CHAINED_GROUP" },
535 { OFPGMFC_BAD_TYPE, "BAD_TYPE" },
536 { OFPGMFC_BAD_COMMAND, "BAD_COMMAND" },
537 { OFPGMFC_BAD_BUCKET, "BAD_BUCKET" },
538 { OFPGMFC_BAD_MATCH, "BAD_MATCH" },
539 { OFPGMFC_EPERM, "EPERM" },
540 { 0, NULL }
541 };
542
543 #define OFPPMFC_BAD_PORT 0U
544 #define OFPPMFC_BAD_HW_ADDR 1U
545 #define OFPPMFC_BAD_CONFIG 2U
546 #define OFPPMFC_BAD_ADVERTISE 3U
547 #define OFPPMFC_EPERM 4U
548 static const struct tok ofppmfc_str[] = {
549 { OFPPMFC_BAD_PORT, "BAD_PORT" },
550 { OFPPMFC_BAD_HW_ADDR, "BAD_HW_ADDR" },
551 { OFPPMFC_BAD_CONFIG, "BAD_CONFIG" },
552 { OFPPMFC_BAD_ADVERTISE, "BAD_ADVERTISE" },
553 { OFPPMFC_EPERM, "EPERM" },
554 { 0, NULL }
555 };
556
557 #define OFPTMFC_BAD_TABLE 0U
558 #define OFPTMFC_BAD_CONFIG 1U
559 #define OFPTMFC_EPERM 2U
560 static const struct tok ofptmfc_str[] = {
561 { OFPTMFC_BAD_TABLE, "BAD_TABLE" },
562 { OFPTMFC_BAD_CONFIG, "BAD_CONFIG" },
563 { OFPTMFC_EPERM, "EPERM" },
564 { 0, NULL }
565 };
566
567 #define OFPQOFC_BAD_PORT 0U
568 #define OFPQOFC_BAD_QUEUE 1U
569 #define OFPQOFC_EPERM 2U
570 static const struct tok ofpqofc_str[] = {
571 { OFPQOFC_BAD_PORT, "BAD_PORT" },
572 { OFPQOFC_BAD_QUEUE, "BAD_QUEUE" },
573 { OFPQOFC_EPERM, "EPERM" },
574 { 0, NULL }
575 };
576
577 #define OFPSCFC_BAD_FLAGS 0U
578 #define OFPSCFC_BAD_LEN 1U
579 #define OFPSCFC_EPERM 2U
580 static const struct tok ofpscfc_str[] = {
581 { OFPSCFC_BAD_FLAGS, "BAD_FLAGS" },
582 { OFPSCFC_BAD_LEN, "BAD_LEN" },
583 { OFPSCFC_EPERM, "EPERM" },
584 { 0, NULL }
585 };
586
587 #define OFPRRFC_STALE 0U
588 #define OFPRRFC_UNSUP 1U
589 #define OFPRRFC_BAD_ROLE 2U
590 static const struct tok ofprrfc_str[] = {
591 { OFPRRFC_STALE, "STALE" },
592 { OFPRRFC_UNSUP, "UNSUP" },
593 { OFPRRFC_BAD_ROLE, "BAD_ROLE" },
594 { 0, NULL }
595 };
596
597 #define OFPMMFC_UNKNOWN 0U
598 #define OFPMMFC_METER_EXISTS 1U
599 #define OFPMMFC_INVALID_METER 2U
600 #define OFPMMFC_UNKNOWN_METER 3U
601 #define OFPMMFC_BAD_COMMAND 4U
602 #define OFPMMFC_BAD_FLAGS 5U
603 #define OFPMMFC_BAD_RATE 6U
604 #define OFPMMFC_BAD_BURST 7U
605 #define OFPMMFC_BAD_BAND 8U
606 #define OFPMMFC_BAD_BAND_VALUE 9U
607 #define OFPMMFC_OUT_OF_METERS 10U
608 #define OFPMMFC_OUT_OF_BANDS 11U
609 static const struct tok ofpmmfc_str[] = {
610 { OFPMMFC_UNKNOWN, "UNKNOWN" },
611 { OFPMMFC_METER_EXISTS, "METER_EXISTS" },
612 { OFPMMFC_INVALID_METER, "INVALID_METER" },
613 { OFPMMFC_UNKNOWN_METER, "UNKNOWN_METER" },
614 { OFPMMFC_BAD_COMMAND, "BAD_COMMAND" },
615 { OFPMMFC_BAD_FLAGS, "BAD_FLAGS" },
616 { OFPMMFC_BAD_RATE, "BAD_RATE" },
617 { OFPMMFC_BAD_BURST, "BAD_BURST" },
618 { OFPMMFC_BAD_BAND, "BAD_BAND" },
619 { OFPMMFC_BAD_BAND_VALUE, "BAD_BAND_VALUE" },
620 { OFPMMFC_OUT_OF_METERS, "OUT_OF_METERS" },
621 { OFPMMFC_OUT_OF_BANDS, "OUT_OF_BANDS" },
622 { 0, NULL }
623 };
624
625 #define OFPTFFC_BAD_TABLE 0U
626 #define OFPTFFC_BAD_METADATA 1U
627 #define OFPTFFC_BAD_TYPE 2U
628 #define OFPTFFC_BAD_LEN 3U
629 #define OFPTFFC_BAD_ARGUMENT 4U
630 #define OFPTFFC_EPERM 5U
631 static const struct tok ofptffc_str[] = {
632 { OFPTFFC_BAD_TABLE, "BAD_TABLE" },
633 { OFPTFFC_BAD_METADATA, "BAD_METADATA" },
634 { OFPTFFC_BAD_TYPE, "BAD_TYPE" },
635 { OFPTFFC_BAD_LEN, "BAD_LEN" },
636 { OFPTFFC_BAD_ARGUMENT, "BAD_ARGUMENT" },
637 { OFPTFFC_EPERM, "EPERM" },
638 { 0, NULL }
639 };
640
641 static const struct uint_tokary of13_ofpet2tokary[] = {
642 { OFPET_HELLO_FAILED, ofphfc_str },
643 { OFPET_BAD_REQUEST, ofpbrc_str },
644 { OFPET_BAD_ACTION, ofpbac_str },
645 { OFPET_BAD_INSTRUCTION, ofpbic_str },
646 { OFPET_BAD_MATCH, ofpbmc_str },
647 { OFPET_FLOW_MOD_FAILED, ofpfmfc_str },
648 { OFPET_GROUP_MOD_FAILED, ofpgmfc_str },
649 { OFPET_PORT_MOD_FAILED, ofppmfc_str },
650 { OFPET_TABLE_MOD_FAILED, ofptmfc_str },
651 { OFPET_QUEUE_OP_FAILED, ofpqofc_str },
652 { OFPET_SWITCH_CONFIG_FAILED, ofpscfc_str },
653 { OFPET_ROLE_REQUEST_FAILED, ofprrfc_str },
654 { OFPET_METER_MOD_FAILED, ofpmmfc_str },
655 { OFPET_TABLE_FEATURES_FAILED, ofptffc_str },
656 { OFPET_EXPERIMENTER, NULL }, /* defines no codes */
657 /* uint2tokary() does not use array termination. */
658 };
659
660 /* lengths (fixed or minimal) of particular protocol structures */
661 #define OF_HELLO_ELEM_MINSIZE 4U
662 #define OF_ERROR_MSG_MINLEN 12U
663 #define OF_FEATURES_REPLY_FIXLEN 32U
664 #define OF_PORT_MOD_FIXLEN 40U
665 #define OF_SWITCH_CONFIG_MSG_FIXLEN 12U
666 #define OF_TABLE_MOD_FIXLEN 16U
667 #define OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN 16U
668 #define OF_ROLE_MSG_FIXLEN 24U
669 #define OF_ASYNC_MSG_FIXLEN 32U
670 #define OF_PORT_STATUS_FIXLEN 80U
671 #define OF_EXPERIMENTER_MSG_MINLEN 16U
672
673 /* miscellaneous constants from [OF13] */
674 #define OFP_MAX_PORT_NAME_LEN 16U
675
676 /* [OF13] Section A.1 */
677 const char *
678 of13_msgtype_str(const uint8_t type)
679 {
680 return tok2str(ofpt_str, "invalid (0x%02x)", type);
681 }
682
683 /* [OF13] Section 7.2.1 */
684 static void
685 of13_port_print(netdissect_options *ndo,
686 const u_char *cp)
687 {
688 /* port_no */
689 ND_PRINT("\n\t port_no %s",
690 tok2str(ofpp_str, "%u", GET_BE_U_4(cp)));
691 cp += 4;
692 /* pad */
693 cp += 4;
694 /* hw_addr */
695 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp));
696 cp += MAC_ADDR_LEN;
697 /* pad2 */
698 cp += 2;
699 /* name */
700 ND_PRINT(", name '");
701 (void)nd_print(ndo, cp, cp + OFP_MAX_PORT_NAME_LEN);
702 ND_PRINT("'");
703 cp += OFP_MAX_PORT_NAME_LEN;
704
705 if (ndo->ndo_vflag < 2) {
706 ND_TCHECK_LEN(cp, 32);
707 return;
708 }
709
710 /* config */
711 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp));
712 of_bitmap_print(ndo, ofppc_bm, GET_BE_U_4(cp), OFPPC_U);
713 cp += 4;
714 /* state */
715 ND_PRINT("\n\t state 0x%08x", GET_BE_U_4(cp));
716 of_bitmap_print(ndo, ofpps_bm, GET_BE_U_4(cp), OFPPS_U);;
717 cp += 4;
718 /* curr */
719 ND_PRINT("\n\t curr 0x%08x", GET_BE_U_4(cp));
720 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
721 cp += 4;
722 /* advertised */
723 ND_PRINT("\n\t advertised 0x%08x", GET_BE_U_4(cp));
724 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
725 cp += 4;
726 /* supported */
727 ND_PRINT("\n\t supported 0x%08x", GET_BE_U_4(cp));
728 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
729 cp += 4;
730 /* peer */
731 ND_PRINT("\n\t peer 0x%08x", GET_BE_U_4(cp));
732 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
733 cp += 4;
734 /* curr_speed */
735 ND_PRINT("\n\t curr_speed %ukbps", GET_BE_U_4(cp));
736 cp += 4;
737 /* max_speed */
738 ND_PRINT("\n\t max_speed %ukbps", GET_BE_U_4(cp));
739 }
740
741 /* [OF13] Section 7.3.1 */
742 static void
743 of13_features_reply_print(netdissect_options *ndo,
744 const u_char *cp)
745 {
746 /* datapath_id */
747 ND_PRINT("\n\t dpid 0x%016" PRIx64, GET_BE_U_8(cp));
748 cp += 8;
749 /* n_buffers */
750 ND_PRINT(", n_buffers %u", GET_BE_U_4(cp));
751 cp += 4;
752 /* n_tables */
753 ND_PRINT(", n_tables %u", GET_U_1(cp));
754 cp += 1;
755 /* auxiliary_id */
756 ND_PRINT(", auxiliary_id %u", GET_U_1(cp));
757 cp += 1;
758 /* pad */
759 cp += 2;
760 /* capabilities */
761 ND_PRINT("\n\t capabilities 0x%08x", GET_BE_U_4(cp));
762 of_bitmap_print(ndo, ofp_capabilities_bm, GET_BE_U_4(cp), OFPCAP_U);
763 cp += 4;
764 /* reserved */
765 ND_TCHECK_4(cp);
766 }
767
768 /* [OF13] Section 7.3.2 */
769 static void
770 of13_switch_config_msg_print(netdissect_options *ndo,
771 const u_char *cp)
772 {
773 /* flags */
774 ND_PRINT("\n\t flags %s",
775 tok2str(ofp_config_str, "invalid (0x%04x)", GET_BE_U_2(cp)));
776 cp += 2;
777 /* miss_send_len */
778 ND_PRINT(", miss_send_len %s",
779 tok2str(ofpcml_str, "%u", GET_BE_U_2(cp)));
780 }
781
782 /* [OF13] Section 7.3.3 */
783 static void
784 of13_table_mod_print(netdissect_options *ndo,
785 const u_char *cp)
786 {
787 /* table_id */
788 ND_PRINT("\n\t table_id %s", tok2str(ofptt_str, "%u", GET_U_1(cp)));
789 cp += 1;
790 /* pad */
791 cp += 3;
792 /* config */
793 ND_PRINT(", config 0x%08x", GET_BE_U_4(cp));
794 }
795
796 /* [OF13] Section 7.3.9 */
797 static void
798 of13_role_msg_print(netdissect_options *ndo,
799 const u_char *cp)
800 {
801 /* role */
802 ND_PRINT("\n\t role %s",
803 tok2str(ofpcr_str, "invalid (0x%08x)", GET_BE_U_4(cp)));
804 cp += 4;
805 /* pad */
806 cp += 4;
807 /* generation_id */
808 ND_PRINT(", generation_id 0x%016" PRIx64, GET_BE_U_8(cp));
809 }
810
811 /* [OF13] Section 7.3.10 */
812 static void
813 of13_async_msg_print(netdissect_options *ndo,
814 const u_char *cp)
815 {
816 /* packet_in_mask[0] */
817 ND_PRINT("\n\t packet_in_mask[EM] 0x%08x", GET_BE_U_4(cp));
818 of_bitmap_print(ndo, async_ofpr_bm, GET_BE_U_4(cp), ASYNC_OFPR_U);
819 cp += 4;
820 /* packet_in_mask[1] */
821 ND_PRINT("\n\t packet_in_mask[S] 0x%08x", GET_BE_U_4(cp));
822 of_bitmap_print(ndo, async_ofpr_bm, GET_BE_U_4(cp), ASYNC_OFPR_U);
823 cp += 4;
824 /* port_status_mask[0] */
825 ND_PRINT("\n\t port_status_mask[EM] 0x%08x", GET_BE_U_4(cp));
826 of_bitmap_print(ndo, async_ofppr_bm, GET_BE_U_4(cp), ASYNC_OFPPR_U);
827 cp += 4;
828 /* port_status_mask[1] */
829 ND_PRINT("\n\t port_status_mask[S] 0x%08x", GET_BE_U_4(cp));
830 of_bitmap_print(ndo, async_ofppr_bm, GET_BE_U_4(cp), ASYNC_OFPPR_U);
831 cp += 4;
832 /* flow_removed_mask[0] */
833 ND_PRINT("\n\t flow_removed_mask[EM] 0x%08x", GET_BE_U_4(cp));
834 of_bitmap_print(ndo, async_ofppr_bm, GET_BE_U_4(cp), ASYNC_OFPPR_U);
835 cp += 4;
836 /* flow_removed_mask[1] */
837 ND_PRINT("\n\t flow_removed_mask[S] 0x%08x", GET_BE_U_4(cp));
838 of_bitmap_print(ndo, async_ofppr_bm, GET_BE_U_4(cp), ASYNC_OFPPR_U);
839 }
840
841 /* [OF13] Section 7.3.4.3 */
842 static void
843 of13_port_mod_print(netdissect_options *ndo,
844 const u_char *cp)
845 {
846 /* port_no */
847 ND_PRINT("\n\t port_no %s", tok2str(ofpp_str, "%u", GET_BE_U_4(cp)));
848 cp += 4;
849 /* pad */
850 cp += 4;
851 /* hw_addr */
852 ND_PRINT(", hw_addr %s", GET_ETHERADDR_STRING(cp));
853 cp += MAC_ADDR_LEN;
854 /* pad2 */
855 cp += 2;
856 /* config */
857 ND_PRINT("\n\t config 0x%08x", GET_BE_U_4(cp));
858 of_bitmap_print(ndo, ofppc_bm, GET_BE_U_4(cp), OFPPC_U);
859 cp += 4;
860 /* mask */
861 ND_PRINT("\n\t mask 0x%08x", GET_BE_U_4(cp));
862 of_bitmap_print(ndo, ofppc_bm, GET_BE_U_4(cp), OFPPC_U);
863 cp += 4;
864 /* advertise */
865 ND_PRINT("\n\t advertise 0x%08x", GET_BE_U_4(cp));
866 of_bitmap_print(ndo, ofppf_bm, GET_BE_U_4(cp), OFPPF_U);
867 cp += 4;
868 /* pad3 */
869 /* Always the last field, check bounds. */
870 ND_TCHECK_4(cp);
871 }
872
873 /* [OF13] Section 7.4.3 */
874 static void
875 of13_port_status_print(netdissect_options *ndo,
876 const u_char *cp)
877 {
878 /* reason */
879 ND_PRINT("\n\t reason %s",
880 tok2str(ofppr_str, "invalid (0x02x)", GET_U_1(cp)));
881 cp += 1;
882 /* pad */
883 cp += 7;
884 /* desc */
885 of13_port_print(ndo, cp);
886 }
887
888 /* [OF13] Section 7.5.1 */
889 static void
890 of13_hello_elements_print(netdissect_options *ndo,
891 const u_char *cp, u_int len)
892 {
893 while (len) {
894 uint16_t type, bmlen;
895
896 if (len < OF_HELLO_ELEM_MINSIZE)
897 goto invalid;
898 /* type */
899 type = GET_BE_U_2(cp);
900 OF_FWD(2);
901 ND_PRINT("\n\t type %s",
902 tok2str(ofphet_str, "unknown (0x%04x)", type));
903 /* length */
904 bmlen = GET_BE_U_2(cp);
905 OF_FWD(2);
906 ND_PRINT(", length %u", bmlen);
907 /* cp is OF_HELLO_ELEM_MINSIZE bytes in */
908 if (bmlen < OF_HELLO_ELEM_MINSIZE ||
909 bmlen > OF_HELLO_ELEM_MINSIZE + len)
910 goto invalid;
911 switch (type) {
912 case OFPHET_VERSIONBITMAP:
913 /*
914 * The specification obviously overprovisions the space
915 * for version bitmaps in this element ("ofp versions
916 * 32 to 63 are encoded in the second bitmap and so
917 * on"). Keep this code simple for now and recognize
918 * only a single bitmap with no padding.
919 */
920 if (bmlen == OF_HELLO_ELEM_MINSIZE + 4) {
921 uint32_t bitmap = GET_BE_U_4(cp);
922 ND_PRINT(", bitmap 0x%08x", bitmap);
923 of_bitmap_print(ndo, ofverbm_str, bitmap,
924 OF_BIT_VER_U);
925 } else {
926 ND_PRINT(" (bogus)");
927 ND_TCHECK_LEN(cp, bmlen - OF_HELLO_ELEM_MINSIZE);
928 }
929 break;
930 default:
931 ND_TCHECK_LEN(cp, bmlen - OF_HELLO_ELEM_MINSIZE);
932 }
933 OF_FWD(bmlen - OF_HELLO_ELEM_MINSIZE);
934 }
935 return;
936
937 invalid:
938 nd_print_invalid(ndo);
939 ND_TCHECK_LEN(cp, len);
940 }
941
942 /* [OF13] Section 7.5.4 */
943 static void
944 of13_experimenter_message_print(netdissect_options *ndo,
945 const u_char *cp, u_int len)
946 {
947 uint32_t experimenter;
948
949 /* experimenter */
950 experimenter = GET_BE_U_4(cp);
951 OF_FWD(4);
952 ND_PRINT("\n\t experimenter 0x%08x (%s)", experimenter,
953 of_vendor_name(experimenter));
954 /* exp_type */
955 ND_PRINT(", exp_type 0x%08x", GET_BE_U_4(cp));
956 OF_FWD(4);
957 /* data */
958 of_data_print(ndo, cp, len);
959 }
960
961 /* [OF13] Section A.4.4 */
962 static void
963 of13_error_print(netdissect_options *ndo,
964 const u_char *cp, u_int len)
965 {
966 uint16_t type, code;
967 const struct tok *code_str;
968
969 /* type */
970 type = GET_BE_U_2(cp);
971 OF_FWD(2);
972 ND_PRINT("\n\t type %s", tok2str(ofpet_str, "invalid (0x%04x)", type));
973 /* code */
974 code = GET_BE_U_2(cp);
975 OF_FWD(2);
976 code_str = uint2tokary(of13_ofpet2tokary, type);
977 if (code_str != NULL)
978 ND_PRINT(", code %s",
979 tok2str(code_str, "invalid (0x%04x)", code));
980 else
981 ND_PRINT(", code invalid (0x%04x)", code);
982 /* data */
983 of_data_print(ndo, cp, len);
984 }
985
986 void
987 of13_message_print(netdissect_options *ndo,
988 const u_char *cp, uint16_t len, const uint8_t type)
989 {
990 /* See the comment at the beginning of of10_message_print(). */
991 switch (type) {
992 /* OpenFlow header only. */
993 case OFPT_FEATURES_REQUEST: /* [OF13] Section A.3.1 */
994 case OFPT_GET_CONFIG_REQUEST: /* [OF13] Section A.3.2 */
995 case OFPT_BARRIER_REQUEST: /* [OF13] Section A.3.8 */
996 case OFPT_BARRIER_REPLY: /* ibid */
997 case OFPT_GET_ASYNC_REQUEST: /* [OF13] Section 7.3.10 */
998 if (len)
999 goto invalid;
1000 return;
1001
1002 /* OpenFlow header and fixed-size message body. */
1003 case OFPT_FEATURES_REPLY:
1004 if (len != OF_FEATURES_REPLY_FIXLEN - OF_HEADER_FIXLEN)
1005 goto invalid;
1006 if (ndo->ndo_vflag < 1)
1007 break;
1008 of13_features_reply_print(ndo, cp);
1009 return;
1010 case OFPT_QUEUE_GET_CONFIG_REQUEST: /* [OF13] Section A.3.6 */
1011 if (len != OF_QUEUE_GET_CONFIG_REQUEST_FIXLEN - OF_HEADER_FIXLEN)
1012 goto invalid;
1013 if (ndo->ndo_vflag < 1)
1014 break;
1015 /* port */
1016 ND_PRINT("\n\t port %s",
1017 tok2str(ofpp_str, "%u", GET_BE_U_4(cp)));
1018 OF_FWD(4);
1019 /* pad */
1020 /* Always the last field, check bounds. */
1021 ND_TCHECK_4(cp);
1022 return;
1023 case OFPT_GET_CONFIG_REPLY: /* [OF13] Section 7.3.2 */
1024 case OFPT_SET_CONFIG: /* ibid */
1025 if (len != OF_SWITCH_CONFIG_MSG_FIXLEN - OF_HEADER_FIXLEN)
1026 goto invalid;
1027 if (ndo->ndo_vflag < 1)
1028 break;
1029 of13_switch_config_msg_print(ndo, cp);
1030 return;
1031 case OFPT_PORT_MOD: /* [OF13] Section 7.3.4.3 */
1032 if (len != OF_PORT_MOD_FIXLEN - OF_HEADER_FIXLEN)
1033 goto invalid;
1034 if (ndo->ndo_vflag < 1)
1035 break;
1036 of13_port_mod_print(ndo, cp);
1037 return;
1038 case OFPT_ROLE_REQUEST: /* [OF13] Section 7.3.9 */
1039 case OFPT_ROLE_REPLY: /* ibid */
1040 if (len != OF_ROLE_MSG_FIXLEN - OF_HEADER_FIXLEN)
1041 goto invalid;
1042 if (ndo->ndo_vflag < 1)
1043 break;
1044 of13_role_msg_print(ndo, cp);
1045 return;
1046 case OFPT_PORT_STATUS: /* [OF13] Section 7.4.3 */
1047 if (len != OF_PORT_STATUS_FIXLEN - OF_HEADER_FIXLEN)
1048 goto invalid;
1049 if (ndo->ndo_vflag < 1)
1050 break;
1051 of13_port_status_print(ndo, cp);
1052 return;
1053 case OFPT_TABLE_MOD: /* [OF13] Section 7.3.3 */
1054 if (len != OF_TABLE_MOD_FIXLEN - OF_HEADER_FIXLEN)
1055 goto invalid;
1056 if (ndo->ndo_vflag < 1)
1057 break;
1058 of13_table_mod_print(ndo, cp);
1059 return;
1060 case OFPT_SET_ASYNC: /* [OF13] Section 7.3.10 */
1061 case OFPT_GET_ASYNC_REPLY: /* ibid */
1062 if (len != OF_ASYNC_MSG_FIXLEN - OF_HEADER_FIXLEN)
1063 goto invalid;
1064 if (ndo->ndo_vflag < 1)
1065 break;
1066 of13_async_msg_print(ndo, cp);
1067 return;
1068
1069 /* OpenFlow header and variable-size data. */
1070 case OFPT_ECHO_REQUEST: /* [OF13] Section A.5.2 */
1071 case OFPT_ECHO_REPLY: /* [OF13] Section A.5.3 */
1072 if (ndo->ndo_vflag < 1)
1073 break;
1074 of_data_print(ndo, cp, len);
1075 return;
1076
1077 /* OpenFlow header and n * variable-size data units. */
1078 case OFPT_HELLO: /* [OF13] Section A.5.1 */
1079 if (ndo->ndo_vflag < 1)
1080 break;
1081 of13_hello_elements_print(ndo, cp, len);
1082 return;
1083
1084 /* OpenFlow header, fixed-size message body and variable-size data. */
1085 case OFPT_ERROR:
1086 if (len < OF_ERROR_MSG_MINLEN - OF_HEADER_FIXLEN)
1087 goto invalid;
1088 if (ndo->ndo_vflag < 1)
1089 break;
1090 of13_error_print(ndo, cp, len);
1091 return;
1092 case OFPT_EXPERIMENTER: /* [OF13] Section 7.5.4 */
1093 if (len < OF_EXPERIMENTER_MSG_MINLEN - OF_HEADER_FIXLEN)
1094 goto invalid;
1095 if (ndo->ndo_vflag < 1)
1096 break;
1097 of13_experimenter_message_print(ndo, cp, len);
1098 return;
1099 }
1100 /*
1101 * Not a recognised type or did not print the details, fall back to
1102 * a bounds check.
1103 */
1104 ND_TCHECK_LEN(cp, len);
1105 return;
1106
1107 invalid: /* skip the message body */
1108 nd_print_invalid(ndo);
1109 ND_TCHECK_LEN(cp, len);
1110 }