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