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