xref: /freebsd/contrib/tcpdump/print-openflow-1.0.c (revision 545ddfbe7d4fe8adfb862903b24eac1d5896c1ef)
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  * Decoding of Ethernet frames nested in OFPT_PACKET_IN and OFPT_PACKET_OUT
12  * messages is done only when the verbosity level set by command-line argument
13  * is "-vvv" or higher. In that case the verbosity level is temporarily
14  * decremented by 3 during the nested frame decoding. For example, running
15  * tcpdump with "-vvvv" will do full decoding of OpenFlow and "-v" decoding of
16  * the nested frames.
17  *
18  *
19  * Copyright (c) 2013 The TCPDUMP project
20  * All rights reserved.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the above copyright
26  *    notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  *    notice, this list of conditions and the following disclaimer in the
29  *    documentation and/or other materials provided with the distribution.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
34  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
35  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
36  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
37  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
39  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
41  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42  * POSSIBILITY OF SUCH DAMAGE.
43  */
44 
45 #define NETDISSECT_REWORKED
46 #ifdef HAVE_CONFIG_H
47 #include "config.h"
48 #endif
49 
50 #include <tcpdump-stdinc.h>
51 
52 #include "interface.h"
53 #include "extract.h"
54 #include "addrtoname.h"
55 #include "ether.h"
56 #include "ethertype.h"
57 #include "ipproto.h"
58 #include "openflow.h"
59 
60 static const char tstr[] = " [|openflow]";
61 static const char cstr[] = " (corrupt)";
62 
63 #define OFPT_HELLO                    0x00
64 #define OFPT_ERROR                    0x01
65 #define OFPT_ECHO_REQUEST             0x02
66 #define OFPT_ECHO_REPLY               0x03
67 #define OFPT_VENDOR                   0x04
68 #define OFPT_FEATURES_REQUEST         0x05
69 #define OFPT_FEATURES_REPLY           0x06
70 #define OFPT_GET_CONFIG_REQUEST       0x07
71 #define OFPT_GET_CONFIG_REPLY         0x08
72 #define OFPT_SET_CONFIG               0x09
73 #define OFPT_PACKET_IN                0x0a
74 #define OFPT_FLOW_REMOVED             0x0b
75 #define OFPT_PORT_STATUS              0x0c
76 #define OFPT_PACKET_OUT               0x0d
77 #define OFPT_FLOW_MOD                 0x0e
78 #define OFPT_PORT_MOD                 0x0f
79 #define OFPT_STATS_REQUEST            0x10
80 #define OFPT_STATS_REPLY              0x11
81 #define OFPT_BARRIER_REQUEST          0x12
82 #define OFPT_BARRIER_REPLY            0x13
83 #define OFPT_QUEUE_GET_CONFIG_REQUEST 0x14
84 #define OFPT_QUEUE_GET_CONFIG_REPLY   0x15
85 static const struct tok ofpt_str[] = {
86 	{ OFPT_HELLO,                    "HELLO"                    },
87 	{ OFPT_ERROR,                    "ERROR"                    },
88 	{ OFPT_ECHO_REQUEST,             "ECHO_REQUEST"             },
89 	{ OFPT_ECHO_REPLY,               "ECHO_REPLY"               },
90 	{ OFPT_VENDOR,                   "VENDOR"                   },
91 	{ OFPT_FEATURES_REQUEST,         "FEATURES_REQUEST"         },
92 	{ OFPT_FEATURES_REPLY,           "FEATURES_REPLY"           },
93 	{ OFPT_GET_CONFIG_REQUEST,       "GET_CONFIG_REQUEST"       },
94 	{ OFPT_GET_CONFIG_REPLY,         "GET_CONFIG_REPLY"         },
95 	{ OFPT_SET_CONFIG,               "SET_CONFIG"               },
96 	{ OFPT_PACKET_IN,                "PACKET_IN"                },
97 	{ OFPT_FLOW_REMOVED,             "FLOW_REMOVED"             },
98 	{ OFPT_PORT_STATUS,              "PORT_STATUS"              },
99 	{ OFPT_PACKET_OUT,               "PACKET_OUT"               },
100 	{ OFPT_FLOW_MOD,                 "FLOW_MOD"                 },
101 	{ OFPT_PORT_MOD,                 "PORT_MOD"                 },
102 	{ OFPT_STATS_REQUEST,            "STATS_REQUEST"            },
103 	{ OFPT_STATS_REPLY,              "STATS_REPLY"              },
104 	{ OFPT_BARRIER_REQUEST,          "BARRIER_REQUEST"          },
105 	{ OFPT_BARRIER_REPLY,            "BARRIER_REPLY"            },
106 	{ OFPT_QUEUE_GET_CONFIG_REQUEST, "QUEUE_GET_CONFIG_REQUEST" },
107 	{ OFPT_QUEUE_GET_CONFIG_REPLY,   "QUEUE_GET_CONFIG_REPLY"   },
108 	{ 0, NULL }
109 };
110 
111 #define OFPPC_PORT_DOWN    (1 << 0)
112 #define OFPPC_NO_STP       (1 << 1)
113 #define OFPPC_NO_RECV      (1 << 2)
114 #define OFPPC_NO_RECV_STP  (1 << 3)
115 #define OFPPC_NO_FLOOD     (1 << 4)
116 #define OFPPC_NO_FWD       (1 << 5)
117 #define OFPPC_NO_PACKET_IN (1 << 6)
118 static const struct tok ofppc_bm[] = {
119 	{ OFPPC_PORT_DOWN,    "PORT_DOWN"    },
120 	{ OFPPC_NO_STP,       "NO_STP"       },
121 	{ OFPPC_NO_RECV,      "NO_RECV"      },
122 	{ OFPPC_NO_RECV_STP,  "NO_RECV_STP"  },
123 	{ OFPPC_NO_FLOOD,     "NO_FLOOD"     },
124 	{ OFPPC_NO_FWD,       "NO_FWD"       },
125 	{ OFPPC_NO_PACKET_IN, "NO_PACKET_IN" },
126 	{ 0, NULL }
127 };
128 #define OFPPC_U (~(OFPPC_PORT_DOWN | OFPPC_NO_STP | OFPPC_NO_RECV | \
129                    OFPPC_NO_RECV_STP | OFPPC_NO_FLOOD | OFPPC_NO_FWD | \
130                    OFPPC_NO_PACKET_IN))
131 
132 #define OFPPS_LINK_DOWN   (1 << 0)
133 #define OFPPS_STP_LISTEN  (0 << 8)
134 #define OFPPS_STP_LEARN   (1 << 8)
135 #define OFPPS_STP_FORWARD (2 << 8)
136 #define OFPPS_STP_BLOCK   (3 << 8)
137 #define OFPPS_STP_MASK    (3 << 8)
138 static const struct tok ofpps_bm[] = {
139 	{ OFPPS_LINK_DOWN,   "LINK_DOWN"   },
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        0xff00
150 #define OFPP_IN_PORT    0xfff8
151 #define OFPP_TABLE      0xfff9
152 #define OFPP_NORMAL     0xfffa
153 #define OFPP_FLOOD      0xfffb
154 #define OFPP_ALL        0xfffc
155 #define OFPP_CONTROLLER 0xfffd
156 #define OFPP_LOCAL      0xfffe
157 #define OFPP_NONE       0xffff
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    (1 <<  0)
172 #define OFPPF_10MB_FD    (1 <<  1)
173 #define OFPPF_100MB_HD   (1 <<  2)
174 #define OFPPF_100MB_FD   (1 <<  3)
175 #define OFPPF_1GB_HD     (1 <<  4)
176 #define OFPPF_1GB_FD     (1 <<  5)
177 #define OFPPF_10GB_FD    (1 <<  6)
178 #define OFPPF_COPPER     (1 <<  7)
179 #define OFPPF_FIBER      (1 <<  8)
180 #define OFPPF_AUTONEG    (1 <<  9)
181 #define OFPPF_PAUSE      (1 << 10)
182 #define OFPPF_PAUSE_ASYM (1 << 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      (1 << 0)
212 #define OFPFW_DL_VLAN      (1 << 1)
213 #define OFPFW_DL_SRC       (1 << 2)
214 #define OFPFW_DL_DST       (1 << 3)
215 #define OFPFW_DL_TYPE      (1 << 4)
216 #define OFPFW_NW_PROTO     (1 << 5)
217 #define OFPFW_TP_SRC       (1 << 6)
218 #define OFPFW_TP_DST       (1 << 7)
219 #define OFPFW_NW_SRC_SHIFT 8
220 #define OFPFW_NW_SRC_BITS  6
221 #define OFPFW_NW_SRC_MASK  (((1 << 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  (((1 << OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT)
225 #define OFPFW_DL_VLAN_PCP  (1 << 20)
226 #define OFPFW_NW_TOS       (1 << 21)
227 #define OFPFW_ALL          ((1 << 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       0x0000
248 #define OFPAT_SET_VLAN_VID 0x0001
249 #define OFPAT_SET_VLAN_PCP 0x0002
250 #define OFPAT_STRIP_VLAN   0x0003
251 #define OFPAT_SET_DL_SRC   0x0004
252 #define OFPAT_SET_DL_DST   0x0005
253 #define OFPAT_SET_NW_SRC   0x0006
254 #define OFPAT_SET_NW_DST   0x0007
255 #define OFPAT_SET_NW_TOS   0x0008
256 #define OFPAT_SET_TP_SRC   0x0009
257 #define OFPAT_SET_TP_DST   0x000a
258 #define OFPAT_ENQUEUE      0x000b
259 #define OFPAT_VENDOR       0xffff
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 	{ 1 << OFPAT_OUTPUT,       "OUTPUT"       },
280 	{ 1 << OFPAT_SET_VLAN_VID, "SET_VLAN_VID" },
281 	{ 1 << OFPAT_SET_VLAN_PCP, "SET_VLAN_PCP" },
282 	{ 1 << OFPAT_STRIP_VLAN,   "STRIP_VLAN"   },
283 	{ 1 << OFPAT_SET_DL_SRC,   "SET_DL_SRC"   },
284 	{ 1 << OFPAT_SET_DL_DST,   "SET_DL_DST"   },
285 	{ 1 << OFPAT_SET_NW_SRC,   "SET_NW_SRC"   },
286 	{ 1 << OFPAT_SET_NW_DST,   "SET_NW_DST"   },
287 	{ 1 << OFPAT_SET_NW_TOS,   "SET_NW_TOS"   },
288 	{ 1 << OFPAT_SET_TP_SRC,   "SET_TP_SRC"   },
289 	{ 1 << OFPAT_SET_TP_DST,   "SET_TP_DST"   },
290 	{ 1 << OFPAT_ENQUEUE,      "ENQUEUE"      },
291 	{ 0, NULL }
292 };
293 #define OFPAT_U (~(1 << OFPAT_OUTPUT | 1 << OFPAT_SET_VLAN_VID | \
294                    1 << OFPAT_SET_VLAN_PCP | 1 << OFPAT_STRIP_VLAN | \
295                    1 << OFPAT_SET_DL_SRC | 1 << OFPAT_SET_DL_DST | \
296                    1 << OFPAT_SET_NW_SRC | 1 << OFPAT_SET_NW_DST | \
297                    1 << OFPAT_SET_NW_TOS | 1 << OFPAT_SET_TP_SRC | \
298                    1 << OFPAT_SET_TP_DST | 1 << OFPAT_ENQUEUE))
299 
300 #define OFPC_FLOW_STATS   (1 << 0)
301 #define OFPC_TABLE_STATS  (1 << 1)
302 #define OFPC_PORT_STATS   (1 << 2)
303 #define OFPC_STP          (1 << 3)
304 #define OFPC_RESERVED     (1 << 4)
305 #define OFPC_IP_REASM     (1 << 5)
306 #define OFPC_QUEUE_STATS  (1 << 6)
307 #define OFPC_ARP_MATCH_IP (1 << 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 0x0000
324 #define OFPC_FRAG_DROP   0x0001
325 #define OFPC_FRAG_REASM  0x0002
326 #define OFPC_FRAG_MASK   0x0003
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           0x0000
335 #define OFPFC_MODIFY        0x0001
336 #define OFPFC_MODIFY_STRICT 0x0002
337 #define OFPFC_DELETE        0x0003
338 #define OFPFC_DELETE_STRICT 0x0004
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 (1 << 0)
354 #define OFPFF_CHECK_OVERLAP (1 << 1)
355 #define OFPFF_EMERG         (1 << 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      0x0000
365 #define OFPST_FLOW      0x0001
366 #define OFPST_AGGREGATE 0x0002
367 #define OFPST_TABLE     0x0003
368 #define OFPST_PORT      0x0004
369 #define OFPST_QUEUE     0x0005
370 #define OFPST_VENDOR    0xffff
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 	{ 0xfe, "EMERG" },
384 	{ 0xff, "ALL"   },
385 	{ 0, NULL }
386 };
387 
388 #define OFPQ_ALL      0xffffffff
389 static const struct tok ofpq_str[] = {
390 	{ OFPQ_ALL, "ALL" },
391 	{ 0, NULL }
392 };
393 
394 #define OFPSF_REPLY_MORE 0x0001
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 0x00
402 #define OFPR_ACTION   0x01
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 0x00
410 #define OFPRR_HARD_TIMEOUT 0x01
411 #define OFPRR_DELETE       0x02
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    0x00
420 #define OFPPR_DELETE 0x01
421 #define OFPPR_MODIFY 0x02
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    0x0000
430 #define OFPET_BAD_REQUEST     0x0001
431 #define OFPET_BAD_ACTION      0x0002
432 #define OFPET_FLOW_MOD_FAILED 0x0003
433 #define OFPET_PORT_MOD_FAILED 0x0004
434 #define OFPET_QUEUE_OP_FAILED 0x0005
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 0x0000
446 #define OFPHFC_EPERM        0x0001
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    0x0000
454 #define OFPBRC_BAD_TYPE       0x0001
455 #define OFPBRC_BAD_STAT       0x0002
456 #define OFPBRC_BAD_VENDOR     0x0003
457 #define OFPBRC_BAD_SUBTYPE    0x0004
458 #define OFPBRC_EPERM          0x0005
459 #define OFPBRC_BAD_LEN        0x0006
460 #define OFPBRC_BUFFER_EMPTY   0x0007
461 #define OFPBRC_BUFFER_UNKNOWN 0x0008
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        0x0000
476 #define OFPBAC_BAD_LEN         0x0001
477 #define OFPBAC_BAD_VENDOR      0x0002
478 #define OFPBAC_BAD_VENDOR_TYPE 0x0003
479 #define OFPBAC_BAD_OUT_PORT    0x0004
480 #define OFPBAC_BAD_ARGUMENT    0x0005
481 #define OFPBAC_EPERM           0x0006
482 #define OFPBAC_TOO_MANY        0x0007
483 #define OFPBAC_BAD_QUEUE       0x0008
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   0x0000
498 #define OFPFMFC_OVERLAP           0x0001
499 #define OFPFMFC_EPERM             0x0002
500 #define OFPFMFC_BAD_EMERG_TIMEOUT 0x0003
501 #define OFPFMFC_BAD_COMMAND       0x0004
502 #define OFPFMFC_UNSUPPORTED       0x0005
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    0x0000
514 #define OFPPMFC_BAD_HW_ADDR 0x0001
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  0x0000
522 #define OFPQOFC_BAD_QUEUE 0x0001
523 #define OFPQOFC_EPERM     0x0002
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 tok empty_str[] = {
532 	{ 0, NULL }
533 };
534 
535 /* lengths (fixed or minimal) of particular protocol structures */
536 #define OF_SWITCH_CONFIG_LEN              12
537 #define OF_PHY_PORT_LEN                   48
538 #define OF_SWITCH_FEATURES_LEN            32
539 #define OF_PORT_STATUS_LEN                64
540 #define OF_PORT_MOD_LEN                   32
541 #define OF_PACKET_IN_LEN                  20
542 #define OF_ACTION_OUTPUT_LEN               8
543 #define OF_ACTION_VLAN_VID_LEN             8
544 #define OF_ACTION_VLAN_PCP_LEN             8
545 #define OF_ACTION_DL_ADDR_LEN             16
546 #define OF_ACTION_NW_ADDR_LEN              8
547 #define OF_ACTION_TP_PORT_LEN              8
548 #define OF_ACTION_NW_TOS_LEN               8
549 #define OF_ACTION_VENDOR_HEADER_LEN        8
550 #define OF_ACTION_HEADER_LEN               8
551 #define OF_PACKET_OUT_LEN                 16
552 #define OF_MATCH_LEN                      40
553 #define OF_FLOW_MOD_LEN                   72
554 #define OF_FLOW_REMOVED_LEN               88
555 #define OF_ERROR_MSG_LEN                  12
556 #define OF_STATS_REQUEST_LEN              12
557 #define OF_STATS_REPLY_LEN                12
558 #define OF_DESC_STATS_LEN               1056
559 #define OF_FLOW_STATS_REQUEST_LEN         44
560 #define OF_FLOW_STATS_LEN                 88
561 #define OF_AGGREGATE_STATS_REQUEST_LEN    44
562 #define OF_AGGREGATE_STATS_REPLY_LEN      24
563 #define OF_TABLE_STATS_LEN                64
564 #define OF_PORT_STATS_REQUEST_LEN          8
565 #define OF_PORT_STATS_LEN                104
566 #define OF_VENDOR_HEADER_LEN              12
567 #define OF_QUEUE_PROP_HEADER_LEN           8
568 #define OF_QUEUE_PROP_MIN_RATE_LEN        16
569 #define OF_PACKET_QUEUE_LEN                8
570 #define OF_QUEUE_GET_CONFIG_REQUEST_LEN   12
571 #define OF_QUEUE_GET_CONFIG_REPLY_LEN     16
572 #define OF_ACTION_ENQUEUE_LEN             16
573 #define OF_QUEUE_STATS_REQUEST_LEN         8
574 #define OF_QUEUE_STATS_LEN                32
575 
576 /* miscellaneous constants from [OF10] */
577 #define OFP_MAX_TABLE_NAME_LEN     32
578 #define OFP_MAX_PORT_NAME_LEN      16
579 #define DESC_STR_LEN              256
580 #define SERIAL_NUM_LEN             32
581 #define OFP_VLAN_NONE          0xffff
582 
583 static const char *
584 vlan_str(const uint16_t vid) {
585 	static char buf[sizeof("65535 (bogus)")];
586 	const char *fmt;
587 
588 	if (vid == OFP_VLAN_NONE)
589 		return "NONE";
590 	fmt = (vid > 0 && vid < 0x0fff) ? "%u" : "%u (bogus)";
591 	snprintf(buf, sizeof(buf), fmt, vid);
592 	return buf;
593 }
594 
595 static const char *
596 pcp_str(const uint8_t pcp) {
597 	static char buf[sizeof("255 (bogus)")];
598 	snprintf(buf, sizeof(buf), pcp <= 7 ? "%u" : "%u (bogus)", pcp);
599 	return buf;
600 }
601 
602 static void
603 of10_bitmap_print(netdissect_options *ndo,
604                   const struct tok *t, const uint32_t v, const uint32_t u) {
605 	const char *sep = " (";
606 
607 	if (v == 0)
608 		return;
609 	/* assigned bits */
610 	for (; t->s != NULL; t++)
611 		if (v & t->v) {
612 			ND_PRINT((ndo, "%s%s", sep, t->s));
613 			sep = ", ";
614 		}
615 	/* unassigned bits? */
616 	ND_PRINT((ndo, v & u ? ") (bogus)" : ")"));
617 }
618 
619 static const u_char *
620 of10_data_print(netdissect_options *ndo,
621                 const u_char *cp, const u_char *ep, const u_int len) {
622 	if (len == 0)
623 		return cp;
624 	/* data */
625 	ND_PRINT((ndo, "\n\t data (%u octets)", len));
626 	ND_TCHECK2(*cp, len);
627 	if (ndo->ndo_vflag >= 2)
628 		hex_and_ascii_print(ndo, "\n\t  ", cp, len);
629 	return cp + len;
630 
631 trunc:
632 	ND_PRINT((ndo, "%s", tstr));
633 	return ep;
634 }
635 
636 /* Vendor ID is mandatory, data is optional. */
637 static const u_char *
638 of10_vendor_data_print(netdissect_options *ndo,
639                        const u_char *cp, const u_char *ep, const u_int len) {
640 	if (len < 4)
641 		goto corrupt;
642 	/* vendor */
643 	ND_TCHECK2(*cp, 4);
644 	ND_PRINT((ndo, ", vendor 0x%08x", EXTRACT_32BITS(cp)));
645 	cp += 4;
646 	/* data */
647 	return of10_data_print(ndo, cp, ep, len - 4);
648 
649 corrupt: /* skip the undersized data */
650 	ND_PRINT((ndo, "%s", cstr));
651 	ND_TCHECK2(*cp, len);
652 	return cp + len;
653 trunc:
654 	ND_PRINT((ndo, "%s", tstr));
655 	return ep;
656 }
657 
658 static const u_char *
659 of10_packet_data_print(netdissect_options *ndo,
660                        const u_char *cp, const u_char *ep, const u_int len) {
661 	if (len == 0)
662 		return cp;
663 	/* data */
664 	ND_PRINT((ndo, "\n\t data (%u octets)", len));
665 	if (ndo->ndo_vflag < 3)
666 		return cp + len;
667 	ND_TCHECK2(*cp, len);
668 	ndo->ndo_vflag -= 3;
669 	ND_PRINT((ndo, ", frame decoding below\n"));
670 	ether_print(ndo, cp, len, ndo->ndo_snapend - cp, NULL, NULL);
671 	ndo->ndo_vflag += 3;
672 	return cp + len;
673 
674 trunc:
675 	ND_PRINT((ndo, "%s", tstr));
676 	return ep;
677 }
678 
679 /* [OF10] Section 5.2.1 */
680 static const u_char *
681 of10_phy_ports_print(netdissect_options *ndo,
682                      const u_char *cp, const u_char *ep, u_int len) {
683 	const u_char *cp0 = cp;
684 	const u_int len0 = len;
685 
686 	while (len) {
687 		if (len < OF_PHY_PORT_LEN)
688 			goto corrupt;
689 		/* port_no */
690 		ND_TCHECK2(*cp, 2);
691 		ND_PRINT((ndo, "\n\t  port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
692 		cp += 2;
693 		/* hw_addr */
694 		ND_TCHECK2(*cp, ETHER_ADDR_LEN);
695 		ND_PRINT((ndo, ", hw_addr %s", etheraddr_string(ndo, cp)));
696 		cp += ETHER_ADDR_LEN;
697 		/* name */
698 		ND_TCHECK2(*cp, OFP_MAX_PORT_NAME_LEN);
699 		ND_PRINT((ndo, ", name '"));
700 		fn_print(ndo, cp, cp + OFP_MAX_PORT_NAME_LEN);
701 		ND_PRINT((ndo, "'"));
702 		cp += OFP_MAX_PORT_NAME_LEN;
703 
704 		if (ndo->ndo_vflag < 2) {
705 			ND_TCHECK2(*cp, 24);
706 			cp += 24;
707 			goto next_port;
708 		}
709 		/* config */
710 		ND_TCHECK2(*cp, 4);
711 		ND_PRINT((ndo, "\n\t   config 0x%08x", EXTRACT_32BITS(cp)));
712 		of10_bitmap_print(ndo, ofppc_bm, EXTRACT_32BITS(cp), OFPPC_U);
713 		cp += 4;
714 		/* state */
715 		ND_TCHECK2(*cp, 4);
716 		ND_PRINT((ndo, "\n\t   state 0x%08x", EXTRACT_32BITS(cp)));
717 		of10_bitmap_print(ndo, ofpps_bm, EXTRACT_32BITS(cp), OFPPS_U);
718 		cp += 4;
719 		/* curr */
720 		ND_TCHECK2(*cp, 4);
721 		ND_PRINT((ndo, "\n\t   curr 0x%08x", EXTRACT_32BITS(cp)));
722 		of10_bitmap_print(ndo, ofppf_bm, EXTRACT_32BITS(cp), OFPPF_U);
723 		cp += 4;
724 		/* advertised */
725 		ND_TCHECK2(*cp, 4);
726 		ND_PRINT((ndo, "\n\t   advertised 0x%08x", EXTRACT_32BITS(cp)));
727 		of10_bitmap_print(ndo, ofppf_bm, EXTRACT_32BITS(cp), OFPPF_U);
728 		cp += 4;
729 		/* supported */
730 		ND_TCHECK2(*cp, 4);
731 		ND_PRINT((ndo, "\n\t   supported 0x%08x", EXTRACT_32BITS(cp)));
732 		of10_bitmap_print(ndo, ofppf_bm, EXTRACT_32BITS(cp), OFPPF_U);
733 		cp += 4;
734 		/* peer */
735 		ND_TCHECK2(*cp, 4);
736 		ND_PRINT((ndo, "\n\t   peer 0x%08x", EXTRACT_32BITS(cp)));
737 		of10_bitmap_print(ndo, ofppf_bm, EXTRACT_32BITS(cp), OFPPF_U);
738 		cp += 4;
739 next_port:
740 		len -= OF_PHY_PORT_LEN;
741 	} /* while */
742 	return cp;
743 
744 corrupt: /* skip the undersized trailing data */
745 	ND_PRINT((ndo, "%s", cstr));
746 	ND_TCHECK2(*cp0, len0);
747 	return cp0 + len0;
748 trunc:
749 	ND_PRINT((ndo, "%s", tstr));
750 	return ep;
751 }
752 
753 /* [OF10] Section 5.2.2 */
754 static const u_char *
755 of10_queue_props_print(netdissect_options *ndo,
756                        const u_char *cp, const u_char *ep, u_int len) {
757 	const u_char *cp0 = cp;
758 	const u_int len0 = len;
759 	uint16_t property, plen, rate;
760 
761 	while (len) {
762 		u_char plen_bogus = 0, skip = 0;
763 
764 		if (len < OF_QUEUE_PROP_HEADER_LEN)
765 			goto corrupt;
766 		/* property */
767 		ND_TCHECK2(*cp, 2);
768 		property = EXTRACT_16BITS(cp);
769 		cp += 2;
770 		ND_PRINT((ndo, "\n\t   property %s", tok2str(ofpqt_str, "invalid (0x%04x)", property)));
771 		/* len */
772 		ND_TCHECK2(*cp, 2);
773 		plen = EXTRACT_16BITS(cp);
774 		cp += 2;
775 		ND_PRINT((ndo, ", len %u", plen));
776 		if (plen < OF_QUEUE_PROP_HEADER_LEN || plen > len)
777 			goto corrupt;
778 		/* pad */
779 		ND_TCHECK2(*cp, 4);
780 		cp += 4;
781 		/* property-specific constraints and decoding */
782 		switch (property) {
783 		case OFPQT_NONE:
784 			plen_bogus = plen != OF_QUEUE_PROP_HEADER_LEN;
785 			break;
786 		case OFPQT_MIN_RATE:
787 			plen_bogus = plen != OF_QUEUE_PROP_MIN_RATE_LEN;
788 			break;
789 		default:
790 			skip = 1;
791 		}
792 		if (plen_bogus) {
793 			ND_PRINT((ndo, " (bogus)"));
794 			skip = 1;
795 		}
796 		if (skip) {
797 			ND_TCHECK2(*cp, plen - 4);
798 			cp += plen - 4;
799 			goto next_property;
800 		}
801 		if (property == OFPQT_MIN_RATE) { /* the only case of property decoding */
802 			/* rate */
803 			ND_TCHECK2(*cp, 2);
804 			rate = EXTRACT_16BITS(cp);
805 			cp += 2;
806 			if (rate > 1000)
807 				ND_PRINT((ndo, ", rate disabled"));
808 			else
809 				ND_PRINT((ndo, ", rate %u.%u%%", rate / 10, rate % 10));
810 			/* pad */
811 			ND_TCHECK2(*cp, 6);
812 			cp += 6;
813 		}
814 next_property:
815 		len -= plen;
816 	} /* while */
817 	return cp;
818 
819 corrupt: /* skip the rest of queue properties */
820 	ND_PRINT((ndo, "%s", cstr));
821 	ND_TCHECK2(*cp0, len0);
822 	return cp0 + len0;
823 trunc:
824 	ND_PRINT((ndo, "%s", tstr));
825 	return ep;
826 }
827 
828 /* ibid */
829 static const u_char *
830 of10_queues_print(netdissect_options *ndo,
831                   const u_char *cp, const u_char *ep, u_int len) {
832 	const u_char *cp0 = cp;
833 	const u_int len0 = len;
834 	uint16_t desclen;
835 
836 	while (len) {
837 		if (len < OF_PACKET_QUEUE_LEN)
838 			goto corrupt;
839 		/* queue_id */
840 		ND_TCHECK2(*cp, 4);
841 		ND_PRINT((ndo, "\n\t  queue_id %u", EXTRACT_32BITS(cp)));
842 		cp += 4;
843 		/* len */
844 		ND_TCHECK2(*cp, 2);
845 		desclen = EXTRACT_16BITS(cp);
846 		cp += 2;
847 		ND_PRINT((ndo, ", len %u", desclen));
848 		if (desclen < OF_PACKET_QUEUE_LEN || desclen > len)
849 			goto corrupt;
850 		/* pad */
851 		ND_TCHECK2(*cp, 2);
852 		cp += 2;
853 		/* properties */
854 		if (ndo->ndo_vflag < 2) {
855 			ND_TCHECK2(*cp, desclen - OF_PACKET_QUEUE_LEN);
856 			cp += desclen - OF_PACKET_QUEUE_LEN;
857 			goto next_queue;
858 		}
859 		if (ep == (cp = of10_queue_props_print(ndo, cp, ep, desclen - OF_PACKET_QUEUE_LEN)))
860 			return ep; /* end of snapshot */
861 next_queue:
862 		len -= desclen;
863 	} /* while */
864 	return cp;
865 
866 corrupt: /* skip the rest of queues */
867 	ND_PRINT((ndo, "%s", cstr));
868 	ND_TCHECK2(*cp0, len0);
869 	return cp0 + len0;
870 trunc:
871 	ND_PRINT((ndo, "%s", tstr));
872 	return ep;
873 }
874 
875 /* [OF10] Section 5.2.3 */
876 static const u_char *
877 of10_match_print(netdissect_options *ndo,
878                  const char *pfx, const u_char *cp, const u_char *ep) {
879 	uint32_t wildcards;
880 	uint16_t dl_type;
881 	uint8_t nw_proto;
882 	u_char nw_bits;
883 	const char *field_name;
884 
885 	/* wildcards */
886 	ND_TCHECK2(*cp, 4);
887 	wildcards = EXTRACT_32BITS(cp);
888 	if (wildcards & OFPFW_U)
889 		ND_PRINT((ndo, "%swildcards 0x%08x (bogus)", pfx, wildcards));
890 	cp += 4;
891 	/* in_port */
892 	ND_TCHECK2(*cp, 2);
893 	if (! (wildcards & OFPFW_IN_PORT))
894 		ND_PRINT((ndo, "%smatch in_port %s", pfx, tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
895 	cp += 2;
896 	/* dl_src */
897 	ND_TCHECK2(*cp, ETHER_ADDR_LEN);
898 	if (! (wildcards & OFPFW_DL_SRC))
899 		ND_PRINT((ndo, "%smatch dl_src %s", pfx, etheraddr_string(ndo, cp)));
900 	cp += ETHER_ADDR_LEN;
901 	/* dl_dst */
902 	ND_TCHECK2(*cp, ETHER_ADDR_LEN);
903 	if (! (wildcards & OFPFW_DL_DST))
904 		ND_PRINT((ndo, "%smatch dl_dst %s", pfx, etheraddr_string(ndo, cp)));
905 	cp += ETHER_ADDR_LEN;
906 	/* dl_vlan */
907 	ND_TCHECK2(*cp, 2);
908 	if (! (wildcards & OFPFW_DL_VLAN))
909 		ND_PRINT((ndo, "%smatch dl_vlan %s", pfx, vlan_str(EXTRACT_16BITS(cp))));
910 	cp += 2;
911 	/* dl_vlan_pcp */
912 	ND_TCHECK2(*cp, 1);
913 	if (! (wildcards & OFPFW_DL_VLAN_PCP))
914 		ND_PRINT((ndo, "%smatch dl_vlan_pcp %s", pfx, pcp_str(*cp)));
915 	cp += 1;
916 	/* pad1 */
917 	ND_TCHECK2(*cp, 1);
918 	cp += 1;
919 	/* dl_type */
920 	ND_TCHECK2(*cp, 2);
921 	dl_type = EXTRACT_16BITS(cp);
922 	cp += 2;
923 	if (! (wildcards & OFPFW_DL_TYPE))
924 		ND_PRINT((ndo, "%smatch dl_type 0x%04x", pfx, dl_type));
925 	/* nw_tos */
926 	ND_TCHECK2(*cp, 1);
927 	if (! (wildcards & OFPFW_NW_TOS))
928 		ND_PRINT((ndo, "%smatch nw_tos 0x%02x", pfx, *cp));
929 	cp += 1;
930 	/* nw_proto */
931 	ND_TCHECK2(*cp, 1);
932 	nw_proto = *cp;
933 	cp += 1;
934 	if (! (wildcards & OFPFW_NW_PROTO)) {
935 		field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_ARP
936 		  ? "arp_opcode" : "nw_proto";
937 		ND_PRINT((ndo, "%smatch %s %u", pfx, field_name, nw_proto));
938 	}
939 	/* pad2 */
940 	ND_TCHECK2(*cp, 2);
941 	cp += 2;
942 	/* nw_src */
943 	ND_TCHECK2(*cp, 4);
944 	nw_bits = (wildcards & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT;
945 	if (nw_bits < 32)
946 		ND_PRINT((ndo, "%smatch nw_src %s/%u", pfx, ipaddr_string(ndo, cp), 32 - nw_bits));
947 	cp += 4;
948 	/* nw_dst */
949 	ND_TCHECK2(*cp, 4);
950 	nw_bits = (wildcards & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT;
951 	if (nw_bits < 32)
952 		ND_PRINT((ndo, "%smatch nw_dst %s/%u", pfx, ipaddr_string(ndo, cp), 32 - nw_bits));
953 	cp += 4;
954 	/* tp_src */
955 	ND_TCHECK2(*cp, 2);
956 	if (! (wildcards & OFPFW_TP_SRC)) {
957 		field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_IP
958 		  && ! (wildcards & OFPFW_NW_PROTO) && nw_proto == IPPROTO_ICMP
959 		  ? "icmp_type" : "tp_src";
960 		ND_PRINT((ndo, "%smatch %s %u", pfx, field_name, EXTRACT_16BITS(cp)));
961 	}
962 	cp += 2;
963 	/* tp_dst */
964 	ND_TCHECK2(*cp, 2);
965 	if (! (wildcards & OFPFW_TP_DST)) {
966 		field_name = ! (wildcards & OFPFW_DL_TYPE) && dl_type == ETHERTYPE_IP
967 		  && ! (wildcards & OFPFW_NW_PROTO) && nw_proto == IPPROTO_ICMP
968 		  ? "icmp_code" : "tp_dst";
969 		ND_PRINT((ndo, "%smatch %s %u", pfx, field_name, EXTRACT_16BITS(cp)));
970 	}
971 	return cp + 2;
972 
973 trunc:
974 	ND_PRINT((ndo, "%s", tstr));
975 	return ep;
976 }
977 
978 /* [OF10] Section 5.2.4 */
979 static const u_char *
980 of10_actions_print(netdissect_options *ndo,
981                    const char *pfx, const u_char *cp, const u_char *ep,
982                    u_int len) {
983 	const u_char *cp0 = cp;
984 	const u_int len0 = len;
985 	uint16_t type, alen, output_port;
986 
987 	while (len) {
988 		u_char alen_bogus = 0, skip = 0;
989 
990 		if (len < OF_ACTION_HEADER_LEN)
991 			goto corrupt;
992 		/* type */
993 		ND_TCHECK2(*cp, 2);
994 		type = EXTRACT_16BITS(cp);
995 		cp += 2;
996 		ND_PRINT((ndo, "%saction type %s", pfx, tok2str(ofpat_str, "invalid (0x%04x)", type)));
997 		/* length */
998 		ND_TCHECK2(*cp, 2);
999 		alen = EXTRACT_16BITS(cp);
1000 		cp += 2;
1001 		ND_PRINT((ndo, ", len %u", alen));
1002 		/* On action size underrun/overrun skip the rest of the action list. */
1003 		if (alen < OF_ACTION_HEADER_LEN || alen > len)
1004 			goto corrupt;
1005 		/* On action size inappropriate for the given type or invalid type just skip
1006 		 * the current action, as the basic length constraint has been met. */
1007 		switch (type) {
1008 		case OFPAT_OUTPUT:
1009 		case OFPAT_SET_VLAN_VID:
1010 		case OFPAT_SET_VLAN_PCP:
1011 		case OFPAT_STRIP_VLAN:
1012 		case OFPAT_SET_NW_SRC:
1013 		case OFPAT_SET_NW_DST:
1014 		case OFPAT_SET_NW_TOS:
1015 		case OFPAT_SET_TP_SRC:
1016 		case OFPAT_SET_TP_DST:
1017 			alen_bogus = alen != 8;
1018 			break;
1019 		case OFPAT_SET_DL_SRC:
1020 		case OFPAT_SET_DL_DST:
1021 		case OFPAT_ENQUEUE:
1022 			alen_bogus = alen != 16;
1023 			break;
1024 		case OFPAT_VENDOR:
1025 			alen_bogus = alen % 8 != 0; /* already >= 8 so far */
1026 			break;
1027 		default:
1028 			skip = 1;
1029 		}
1030 		if (alen_bogus) {
1031 			ND_PRINT((ndo, " (bogus)"));
1032 			skip = 1;
1033 		}
1034 		if (skip) {
1035 			ND_TCHECK2(*cp, alen - 4);
1036 			cp += alen - 4;
1037 			goto next_action;
1038 		}
1039 		/* OK to decode the rest of the action structure */
1040 		switch (type) {
1041 		case OFPAT_OUTPUT:
1042 			/* port */
1043 			ND_TCHECK2(*cp, 2);
1044 			output_port = EXTRACT_16BITS(cp);
1045 			cp += 2;
1046 			ND_PRINT((ndo, ", port %s", tok2str(ofpp_str, "%u", output_port)));
1047 			/* max_len */
1048 			ND_TCHECK2(*cp, 2);
1049 			if (output_port == OFPP_CONTROLLER)
1050 				ND_PRINT((ndo, ", max_len %u", EXTRACT_16BITS(cp)));
1051 			cp += 2;
1052 			break;
1053 		case OFPAT_SET_VLAN_VID:
1054 			/* vlan_vid */
1055 			ND_TCHECK2(*cp, 2);
1056 			ND_PRINT((ndo, ", vlan_vid %s", vlan_str(EXTRACT_16BITS(cp))));
1057 			cp += 2;
1058 			/* pad */
1059 			ND_TCHECK2(*cp, 2);
1060 			cp += 2;
1061 			break;
1062 		case OFPAT_SET_VLAN_PCP:
1063 			/* vlan_pcp */
1064 			ND_TCHECK2(*cp, 1);
1065 			ND_PRINT((ndo, ", vlan_pcp %s", pcp_str(*cp)));
1066 			cp += 1;
1067 			/* pad */
1068 			ND_TCHECK2(*cp, 3);
1069 			cp += 3;
1070 			break;
1071 		case OFPAT_SET_DL_SRC:
1072 		case OFPAT_SET_DL_DST:
1073 			/* dl_addr */
1074 			ND_TCHECK2(*cp, ETHER_ADDR_LEN);
1075 			ND_PRINT((ndo, ", dl_addr %s", etheraddr_string(ndo, cp)));
1076 			cp += ETHER_ADDR_LEN;
1077 			/* pad */
1078 			ND_TCHECK2(*cp, 6);
1079 			cp += 6;
1080 			break;
1081 		case OFPAT_SET_NW_SRC:
1082 		case OFPAT_SET_NW_DST:
1083 			/* nw_addr */
1084 			ND_TCHECK2(*cp, 4);
1085 			ND_PRINT((ndo, ", nw_addr %s", ipaddr_string(ndo, cp)));
1086 			cp += 4;
1087 			break;
1088 		case OFPAT_SET_NW_TOS:
1089 			/* nw_tos */
1090 			ND_TCHECK2(*cp, 1);
1091 			ND_PRINT((ndo, ", nw_tos 0x%02x", *cp));
1092 			cp += 1;
1093 			/* pad */
1094 			ND_TCHECK2(*cp, 3);
1095 			cp += 3;
1096 			break;
1097 		case OFPAT_SET_TP_SRC:
1098 		case OFPAT_SET_TP_DST:
1099 			/* nw_tos */
1100 			ND_TCHECK2(*cp, 2);
1101 			ND_PRINT((ndo, ", tp_port %u", EXTRACT_16BITS(cp)));
1102 			cp += 2;
1103 			/* pad */
1104 			ND_TCHECK2(*cp, 2);
1105 			cp += 2;
1106 			break;
1107 		case OFPAT_ENQUEUE:
1108 			/* port */
1109 			ND_TCHECK2(*cp, 2);
1110 			ND_PRINT((ndo, ", port %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1111 			cp += 2;
1112 			/* pad */
1113 			ND_TCHECK2(*cp, 6);
1114 			cp += 6;
1115 			/* queue_id */
1116 			ND_TCHECK2(*cp, 4);
1117 			ND_PRINT((ndo, ", queue_id %s", tok2str(ofpq_str, "%u", EXTRACT_32BITS(cp))));
1118 			cp += 4;
1119 			break;
1120 		case OFPAT_VENDOR:
1121 			if (ep == (cp = of10_vendor_data_print(ndo, cp, ep, alen - 4)))
1122 				return ep; /* end of snapshot */
1123 			break;
1124 		case OFPAT_STRIP_VLAN:
1125 			/* pad */
1126 			ND_TCHECK2(*cp, 4);
1127 			cp += 4;
1128 			break;
1129 		} /* switch */
1130 next_action:
1131 		len -= alen;
1132 	} /* while */
1133 	return cp;
1134 
1135 corrupt: /* skip the rest of actions */
1136 	ND_PRINT((ndo, "%s", cstr));
1137 	ND_TCHECK2(*cp0, len0);
1138 	return cp0 + len0;
1139 trunc:
1140 	ND_PRINT((ndo, "%s", tstr));
1141 	return ep;
1142 }
1143 
1144 /* [OF10] Section 5.3.1 */
1145 static const u_char *
1146 of10_features_reply_print(netdissect_options *ndo,
1147                           const u_char *cp, const u_char *ep, const u_int len) {
1148 	/* datapath_id */
1149 	ND_TCHECK2(*cp, 8);
1150 	ND_PRINT((ndo, "\n\t dpid 0x%016" PRIx64, EXTRACT_64BITS(cp)));
1151 	cp += 8;
1152 	/* n_buffers */
1153 	ND_TCHECK2(*cp, 4);
1154 	ND_PRINT((ndo, ", n_buffers %u", EXTRACT_32BITS(cp)));
1155 	cp += 4;
1156 	/* n_tables */
1157 	ND_TCHECK2(*cp, 1);
1158 	ND_PRINT((ndo, ", n_tables %u", *cp));
1159 	cp += 1;
1160 	/* pad */
1161 	ND_TCHECK2(*cp, 3);
1162 	cp += 3;
1163 	/* capabilities */
1164 	ND_TCHECK2(*cp, 4);
1165 	ND_PRINT((ndo, "\n\t capabilities 0x%08x", EXTRACT_32BITS(cp)));
1166 	of10_bitmap_print(ndo, ofp_capabilities_bm, EXTRACT_32BITS(cp), OFPCAP_U);
1167 	cp += 4;
1168 	/* actions */
1169 	ND_TCHECK2(*cp, 4);
1170 	ND_PRINT((ndo, "\n\t actions 0x%08x", EXTRACT_32BITS(cp)));
1171 	of10_bitmap_print(ndo, ofpat_bm, EXTRACT_32BITS(cp), OFPAT_U);
1172 	cp += 4;
1173 	/* ports */
1174 	return of10_phy_ports_print(ndo, cp, ep, len - OF_SWITCH_FEATURES_LEN);
1175 
1176 trunc:
1177 	ND_PRINT((ndo, "%s", tstr));
1178 	return ep;
1179 }
1180 
1181 /* [OF10] Section 5.3.3 */
1182 static const u_char *
1183 of10_flow_mod_print(netdissect_options *ndo,
1184                     const u_char *cp, const u_char *ep, const u_int len) {
1185 	uint16_t command;
1186 
1187 	/* match */
1188 	if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
1189 		return ep; /* end of snapshot */
1190 	/* cookie */
1191 	ND_TCHECK2(*cp, 8);
1192 	ND_PRINT((ndo, "\n\t cookie 0x%016" PRIx64, EXTRACT_64BITS(cp)));
1193 	cp += 8;
1194 	/* command */
1195 	ND_TCHECK2(*cp, 2);
1196 	command = EXTRACT_16BITS(cp);
1197 	ND_PRINT((ndo, ", command %s", tok2str(ofpfc_str, "invalid (0x%04x)", command)));
1198 	cp += 2;
1199 	/* idle_timeout */
1200 	ND_TCHECK2(*cp, 2);
1201 	if (EXTRACT_16BITS(cp))
1202 		ND_PRINT((ndo, ", idle_timeout %u", EXTRACT_16BITS(cp)));
1203 	cp += 2;
1204 	/* hard_timeout */
1205 	ND_TCHECK2(*cp, 2);
1206 	if (EXTRACT_16BITS(cp))
1207 		ND_PRINT((ndo, ", hard_timeout %u", EXTRACT_16BITS(cp)));
1208 	cp += 2;
1209 	/* priority */
1210 	ND_TCHECK2(*cp, 2);
1211 	if (EXTRACT_16BITS(cp))
1212 		ND_PRINT((ndo, ", priority %u", EXTRACT_16BITS(cp)));
1213 	cp += 2;
1214 	/* buffer_id */
1215 	ND_TCHECK2(*cp, 4);
1216 	if (command == OFPFC_ADD || command == OFPFC_MODIFY ||
1217 	    command == OFPFC_MODIFY_STRICT)
1218 		ND_PRINT((ndo, ", buffer_id %s", tok2str(bufferid_str, "0x%08x", EXTRACT_32BITS(cp))));
1219 	cp += 4;
1220 	/* out_port */
1221 	ND_TCHECK2(*cp, 2);
1222 	if (command == OFPFC_DELETE || command == OFPFC_DELETE_STRICT)
1223 		ND_PRINT((ndo, ", out_port %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1224 	cp += 2;
1225 	/* flags */
1226 	ND_TCHECK2(*cp, 2);
1227 	ND_PRINT((ndo, ", flags 0x%04x", EXTRACT_16BITS(cp)));
1228 	of10_bitmap_print(ndo, ofpff_bm, EXTRACT_16BITS(cp), OFPFF_U);
1229 	cp += 2;
1230 	/* actions */
1231 	return of10_actions_print(ndo, "\n\t ", cp, ep, len - OF_FLOW_MOD_LEN);
1232 
1233 trunc:
1234 	ND_PRINT((ndo, "%s", tstr));
1235 	return ep;
1236 }
1237 
1238 /* ibid */
1239 static const u_char *
1240 of10_port_mod_print(netdissect_options *ndo,
1241                     const u_char *cp, const u_char *ep) {
1242 	/* port_no */
1243 	ND_TCHECK2(*cp, 2);
1244 	ND_PRINT((ndo, "\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1245 	cp += 2;
1246 	/* hw_addr */
1247 	ND_TCHECK2(*cp, ETHER_ADDR_LEN);
1248 	ND_PRINT((ndo, ", hw_addr %s", etheraddr_string(ndo, cp)));
1249 	cp += ETHER_ADDR_LEN;
1250 	/* config */
1251 	ND_TCHECK2(*cp, 4);
1252 	ND_PRINT((ndo, "\n\t config 0x%08x", EXTRACT_32BITS(cp)));
1253 	of10_bitmap_print(ndo, ofppc_bm, EXTRACT_32BITS(cp), OFPPC_U);
1254 	cp += 4;
1255 	/* mask */
1256 	ND_TCHECK2(*cp, 4);
1257 	ND_PRINT((ndo, "\n\t mask 0x%08x", EXTRACT_32BITS(cp)));
1258 	of10_bitmap_print(ndo, ofppc_bm, EXTRACT_32BITS(cp), OFPPC_U);
1259 	cp += 4;
1260 	/* advertise */
1261 	ND_TCHECK2(*cp, 4);
1262 	ND_PRINT((ndo, "\n\t advertise 0x%08x", EXTRACT_32BITS(cp)));
1263 	of10_bitmap_print(ndo, ofppf_bm, EXTRACT_32BITS(cp), OFPPF_U);
1264 	cp += 4;
1265 	/* pad */
1266 	ND_TCHECK2(*cp, 4);
1267 	return cp + 4;
1268 
1269 trunc:
1270 	ND_PRINT((ndo, "%s", tstr));
1271 	return ep;
1272 }
1273 
1274 /* [OF10] Section 5.3.5 */
1275 static const u_char *
1276 of10_stats_request_print(netdissect_options *ndo,
1277                          const u_char *cp, const u_char *ep, u_int len) {
1278 	const u_char *cp0 = cp;
1279 	const u_int len0 = len;
1280 	uint16_t type;
1281 
1282 	/* type */
1283 	ND_TCHECK2(*cp, 2);
1284 	type = EXTRACT_16BITS(cp);
1285 	cp += 2;
1286 	ND_PRINT((ndo, "\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type)));
1287 	/* flags */
1288 	ND_TCHECK2(*cp, 2);
1289 	ND_PRINT((ndo, ", flags 0x%04x", EXTRACT_16BITS(cp)));
1290 	if (EXTRACT_16BITS(cp))
1291 		ND_PRINT((ndo, " (bogus)"));
1292 	cp += 2;
1293 	/* type-specific body of one of fixed lengths */
1294 	len -= OF_STATS_REQUEST_LEN;
1295 	switch(type) {
1296 	case OFPST_DESC:
1297 	case OFPST_TABLE:
1298 		if (len)
1299 			goto corrupt;
1300 		return cp;
1301 	case OFPST_FLOW:
1302 	case OFPST_AGGREGATE:
1303 		if (len != OF_FLOW_STATS_REQUEST_LEN)
1304 			goto corrupt;
1305 		/* match */
1306 		if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
1307 			return ep; /* end of snapshot */
1308 		/* table_id */
1309 		ND_TCHECK2(*cp, 1);
1310 		ND_PRINT((ndo, "\n\t table_id %s", tok2str(tableid_str, "%u", *cp)));
1311 		cp += 1;
1312 		/* pad */
1313 		ND_TCHECK2(*cp, 1);
1314 		cp += 1;
1315 		/* out_port */
1316 		ND_TCHECK2(*cp, 2);
1317 		ND_PRINT((ndo, ", out_port %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1318 		return cp + 2;
1319 	case OFPST_PORT:
1320 		if (len != OF_PORT_STATS_REQUEST_LEN)
1321 			goto corrupt;
1322 		/* port_no */
1323 		ND_TCHECK2(*cp, 2);
1324 		ND_PRINT((ndo, "\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1325 		cp += 2;
1326 		/* pad */
1327 		ND_TCHECK2(*cp, 6);
1328 		return cp + 6;
1329 	case OFPST_QUEUE:
1330 		if (len != OF_QUEUE_STATS_REQUEST_LEN)
1331 			goto corrupt;
1332 		/* port_no */
1333 		ND_TCHECK2(*cp, 2);
1334 		ND_PRINT((ndo, "\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1335 		cp += 2;
1336 		/* pad */
1337 		ND_TCHECK2(*cp, 2);
1338 		cp += 2;
1339 		/* queue_id */
1340 		ND_TCHECK2(*cp, 4);
1341 		ND_PRINT((ndo, ", queue_id %s", tok2str(ofpq_str, "%u", EXTRACT_32BITS(cp))));
1342 		return cp + 4;
1343 	case OFPST_VENDOR:
1344 		return of10_vendor_data_print(ndo, cp, ep, len);
1345 	}
1346 	return cp;
1347 
1348 corrupt: /* skip the message body */
1349 	ND_PRINT((ndo, "%s", cstr));
1350 	ND_TCHECK2(*cp0, len0);
1351 	return cp0 + len0;
1352 trunc:
1353 	ND_PRINT((ndo, "%s", tstr));
1354 	return ep;
1355 }
1356 
1357 /* ibid */
1358 static const u_char *
1359 of10_desc_stats_reply_print(netdissect_options *ndo,
1360                             const u_char *cp, const u_char *ep, const u_int len) {
1361 	if (len != OF_DESC_STATS_LEN)
1362 		goto corrupt;
1363 	/* mfr_desc */
1364 	ND_TCHECK2(*cp, DESC_STR_LEN);
1365 	ND_PRINT((ndo, "\n\t  mfr_desc '"));
1366 	fn_print(ndo, cp, cp + DESC_STR_LEN);
1367 	ND_PRINT((ndo, "'"));
1368 	cp += DESC_STR_LEN;
1369 	/* hw_desc */
1370 	ND_TCHECK2(*cp, DESC_STR_LEN);
1371 	ND_PRINT((ndo, "\n\t  hw_desc '"));
1372 	fn_print(ndo, cp, cp + DESC_STR_LEN);
1373 	ND_PRINT((ndo, "'"));
1374 	cp += DESC_STR_LEN;
1375 	/* sw_desc */
1376 	ND_TCHECK2(*cp, DESC_STR_LEN);
1377 	ND_PRINT((ndo, "\n\t  sw_desc '"));
1378 	fn_print(ndo, cp, cp + DESC_STR_LEN);
1379 	ND_PRINT((ndo, "'"));
1380 	cp += DESC_STR_LEN;
1381 	/* serial_num */
1382 	ND_TCHECK2(*cp, SERIAL_NUM_LEN);
1383 	ND_PRINT((ndo, "\n\t  serial_num '"));
1384 	fn_print(ndo, cp, cp + SERIAL_NUM_LEN);
1385 	ND_PRINT((ndo, "'"));
1386 	cp += SERIAL_NUM_LEN;
1387 	/* dp_desc */
1388 	ND_TCHECK2(*cp, DESC_STR_LEN);
1389 	ND_PRINT((ndo, "\n\t  dp_desc '"));
1390 	fn_print(ndo, cp, cp + DESC_STR_LEN);
1391 	ND_PRINT((ndo, "'"));
1392 	return cp + DESC_STR_LEN;
1393 
1394 corrupt: /* skip the message body */
1395 	ND_PRINT((ndo, "%s", cstr));
1396 	ND_TCHECK2(*cp, len);
1397 	return cp + len;
1398 trunc:
1399 	ND_PRINT((ndo, "%s", tstr));
1400 	return ep;
1401 }
1402 
1403 /* ibid */
1404 static const u_char *
1405 of10_flow_stats_reply_print(netdissect_options *ndo,
1406                             const u_char *cp, const u_char *ep, u_int len) {
1407 	const u_char *cp0 = cp;
1408 	const u_int len0 = len;
1409 	uint16_t entry_len;
1410 
1411 	while (len) {
1412 		if (len < OF_FLOW_STATS_LEN)
1413 			goto corrupt;
1414 		/* length */
1415 		ND_TCHECK2(*cp, 2);
1416 		entry_len = EXTRACT_16BITS(cp);
1417 		ND_PRINT((ndo, "\n\t length %u", entry_len));
1418 		if (entry_len < OF_FLOW_STATS_LEN || entry_len > len)
1419 			goto corrupt;
1420 		cp += 2;
1421 		/* table_id */
1422 		ND_TCHECK2(*cp, 1);
1423 		ND_PRINT((ndo, ", table_id %s", tok2str(tableid_str, "%u", *cp)));
1424 		cp += 1;
1425 		/* pad */
1426 		ND_TCHECK2(*cp, 1);
1427 		cp += 1;
1428 		/* match */
1429 		if (ep == (cp = of10_match_print(ndo, "\n\t  ", cp, ep)))
1430 			return ep; /* end of snapshot */
1431 		/* duration_sec */
1432 		ND_TCHECK2(*cp, 4);
1433 		ND_PRINT((ndo, "\n\t  duration_sec %u", EXTRACT_32BITS(cp)));
1434 		cp += 4;
1435 		/* duration_nsec */
1436 		ND_TCHECK2(*cp, 4);
1437 		ND_PRINT((ndo, ", duration_nsec %u", EXTRACT_32BITS(cp)));
1438 		cp += 4;
1439 		/* priority */
1440 		ND_TCHECK2(*cp, 2);
1441 		ND_PRINT((ndo, ", priority %u", EXTRACT_16BITS(cp)));
1442 		cp += 2;
1443 		/* idle_timeout */
1444 		ND_TCHECK2(*cp, 2);
1445 		ND_PRINT((ndo, ", idle_timeout %u", EXTRACT_16BITS(cp)));
1446 		cp += 2;
1447 		/* hard_timeout */
1448 		ND_TCHECK2(*cp, 2);
1449 		ND_PRINT((ndo, ", hard_timeout %u", EXTRACT_16BITS(cp)));
1450 		cp += 2;
1451 		/* pad2 */
1452 		ND_TCHECK2(*cp, 6);
1453 		cp += 6;
1454 		/* cookie */
1455 		ND_TCHECK2(*cp, 8);
1456 		ND_PRINT((ndo, ", cookie 0x%016" PRIx64, EXTRACT_64BITS(cp)));
1457 		cp += 8;
1458 		/* packet_count */
1459 		ND_TCHECK2(*cp, 8);
1460 		ND_PRINT((ndo, ", packet_count %" PRIu64, EXTRACT_64BITS(cp)));
1461 		cp += 8;
1462 		/* byte_count */
1463 		ND_TCHECK2(*cp, 8);
1464 		ND_PRINT((ndo, ", byte_count %" PRIu64, EXTRACT_64BITS(cp)));
1465 		cp += 8;
1466 		/* actions */
1467 		if (ep == (cp = of10_actions_print(ndo, "\n\t  ", cp, ep, entry_len - OF_FLOW_STATS_LEN)))
1468 			return ep; /* end of snapshot */
1469 
1470 		len -= entry_len;
1471 	} /* while */
1472 	return cp;
1473 
1474 corrupt: /* skip the rest of flow statistics entries */
1475 	ND_PRINT((ndo, "%s", cstr));
1476 	ND_TCHECK2(*cp0, len0);
1477 	return cp0 + len0;
1478 trunc:
1479 	ND_PRINT((ndo, "%s", tstr));
1480 	return ep;
1481 }
1482 
1483 /* ibid */
1484 static const u_char *
1485 of10_aggregate_stats_reply_print(netdissect_options *ndo,
1486                                  const u_char *cp, const u_char *ep,
1487                                  const u_int len) {
1488 	if (len != OF_AGGREGATE_STATS_REPLY_LEN)
1489 		goto corrupt;
1490 	/* packet_count */
1491 	ND_TCHECK2(*cp, 8);
1492 	ND_PRINT((ndo, "\n\t packet_count %" PRIu64, EXTRACT_64BITS(cp)));
1493 	cp += 8;
1494 	/* byte_count */
1495 	ND_TCHECK2(*cp, 8);
1496 	ND_PRINT((ndo, ", byte_count %" PRIu64, EXTRACT_64BITS(cp)));
1497 	cp += 8;
1498 	/* flow_count */
1499 	ND_TCHECK2(*cp, 4);
1500 	ND_PRINT((ndo, ", flow_count %u", EXTRACT_32BITS(cp)));
1501 	cp += 4;
1502 	/* pad */
1503 	ND_TCHECK2(*cp, 4);
1504 	return cp + 4;
1505 
1506 corrupt: /* skip the message body */
1507 	ND_PRINT((ndo, "%s", cstr));
1508 	ND_TCHECK2(*cp, len);
1509 	return cp + len;
1510 trunc:
1511 	ND_PRINT((ndo, "%s", tstr));
1512 	return ep;
1513 }
1514 
1515 /* ibid */
1516 static const u_char *
1517 of10_table_stats_reply_print(netdissect_options *ndo,
1518                              const u_char *cp, const u_char *ep, u_int len) {
1519 	const u_char *cp0 = cp;
1520 	const u_int len0 = len;
1521 
1522 	while (len) {
1523 		if (len < OF_TABLE_STATS_LEN)
1524 			goto corrupt;
1525 		/* table_id */
1526 		ND_TCHECK2(*cp, 1);
1527 		ND_PRINT((ndo, "\n\t table_id %s", tok2str(tableid_str, "%u", *cp)));
1528 		cp += 1;
1529 		/* pad */
1530 		ND_TCHECK2(*cp, 3);
1531 		cp += 3;
1532 		/* name */
1533 		ND_TCHECK2(*cp, OFP_MAX_TABLE_NAME_LEN);
1534 		ND_PRINT((ndo, ", name '"));
1535 		fn_print(ndo, cp, cp + OFP_MAX_TABLE_NAME_LEN);
1536 		ND_PRINT((ndo, "'"));
1537 		cp += OFP_MAX_TABLE_NAME_LEN;
1538 		/* wildcards */
1539 		ND_TCHECK2(*cp, 4);
1540 		ND_PRINT((ndo, "\n\t  wildcards 0x%08x", EXTRACT_32BITS(cp)));
1541 		of10_bitmap_print(ndo, ofpfw_bm, EXTRACT_32BITS(cp), OFPFW_U);
1542 		cp += 4;
1543 		/* max_entries */
1544 		ND_TCHECK2(*cp, 4);
1545 		ND_PRINT((ndo, "\n\t  max_entries %u", EXTRACT_32BITS(cp)));
1546 		cp += 4;
1547 		/* active_count */
1548 		ND_TCHECK2(*cp, 4);
1549 		ND_PRINT((ndo, ", active_count %u", EXTRACT_32BITS(cp)));
1550 		cp += 4;
1551 		/* lookup_count */
1552 		ND_TCHECK2(*cp, 8);
1553 		ND_PRINT((ndo, ", lookup_count %" PRIu64, EXTRACT_64BITS(cp)));
1554 		cp += 8;
1555 		/* matched_count */
1556 		ND_TCHECK2(*cp, 8);
1557 		ND_PRINT((ndo, ", matched_count %" PRIu64, EXTRACT_64BITS(cp)));
1558 		cp += 8;
1559 
1560 		len -= OF_TABLE_STATS_LEN;
1561 	} /* while */
1562 	return cp;
1563 
1564 corrupt: /* skip the undersized trailing data */
1565 	ND_PRINT((ndo, "%s", cstr));
1566 	ND_TCHECK2(*cp0, len0);
1567 	return cp0 + len0;
1568 trunc:
1569 	ND_PRINT((ndo, "%s", tstr));
1570 	return ep;
1571 }
1572 
1573 /* ibid */
1574 static const u_char *
1575 of10_port_stats_reply_print(netdissect_options *ndo,
1576                             const u_char *cp, const u_char *ep, u_int len) {
1577 	const u_char *cp0 = cp;
1578 	const u_int len0 = len;
1579 
1580 	while (len) {
1581 		if (len < OF_PORT_STATS_LEN)
1582 			goto corrupt;
1583 		/* port_no */
1584 		ND_TCHECK2(*cp, 2);
1585 		ND_PRINT((ndo, "\n\t  port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1586 		cp += 2;
1587 		if (ndo->ndo_vflag < 2) {
1588 			ND_TCHECK2(*cp, OF_PORT_STATS_LEN - 2);
1589 			cp += OF_PORT_STATS_LEN - 2;
1590 			goto next_port;
1591 		}
1592 		/* pad */
1593 		ND_TCHECK2(*cp, 6);
1594 		cp += 6;
1595 		/* rx_packets */
1596 		ND_TCHECK2(*cp, 8);
1597 		ND_PRINT((ndo, ", rx_packets %" PRIu64, EXTRACT_64BITS(cp)));
1598 		cp += 8;
1599 		/* tx_packets */
1600 		ND_TCHECK2(*cp, 8);
1601 		ND_PRINT((ndo, ", tx_packets %" PRIu64, EXTRACT_64BITS(cp)));
1602 		cp += 8;
1603 		/* rx_bytes */
1604 		ND_TCHECK2(*cp, 8);
1605 		ND_PRINT((ndo, ", rx_bytes %" PRIu64, EXTRACT_64BITS(cp)));
1606 		cp += 8;
1607 		/* tx_bytes */
1608 		ND_TCHECK2(*cp, 8);
1609 		ND_PRINT((ndo, ", tx_bytes %" PRIu64, EXTRACT_64BITS(cp)));
1610 		cp += 8;
1611 		/* rx_dropped */
1612 		ND_TCHECK2(*cp, 8);
1613 		ND_PRINT((ndo, ", rx_dropped %" PRIu64, EXTRACT_64BITS(cp)));
1614 		cp += 8;
1615 		/* tx_dropped */
1616 		ND_TCHECK2(*cp, 8);
1617 		ND_PRINT((ndo, ", tx_dropped %" PRIu64, EXTRACT_64BITS(cp)));
1618 		cp += 8;
1619 		/* rx_errors */
1620 		ND_TCHECK2(*cp, 8);
1621 		ND_PRINT((ndo, ", rx_errors %" PRIu64, EXTRACT_64BITS(cp)));
1622 		cp += 8;
1623 		/* tx_errors */
1624 		ND_TCHECK2(*cp, 8);
1625 		ND_PRINT((ndo, ", tx_errors %" PRIu64, EXTRACT_64BITS(cp)));
1626 		cp += 8;
1627 		/* rx_frame_err */
1628 		ND_TCHECK2(*cp, 8);
1629 		ND_PRINT((ndo, ", rx_frame_err %" PRIu64, EXTRACT_64BITS(cp)));
1630 		cp += 8;
1631 		/* rx_over_err */
1632 		ND_TCHECK2(*cp, 8);
1633 		ND_PRINT((ndo, ", rx_over_err %" PRIu64, EXTRACT_64BITS(cp)));
1634 		cp += 8;
1635 		/* rx_crc_err */
1636 		ND_TCHECK2(*cp, 8);
1637 		ND_PRINT((ndo, ", rx_crc_err %" PRIu64, EXTRACT_64BITS(cp)));
1638 		cp += 8;
1639 		/* collisions */
1640 		ND_TCHECK2(*cp, 8);
1641 		ND_PRINT((ndo, ", collisions %" PRIu64, EXTRACT_64BITS(cp)));
1642 		cp += 8;
1643 next_port:
1644 		len -= OF_PORT_STATS_LEN;
1645 	} /* while */
1646 	return cp;
1647 
1648 corrupt: /* skip the undersized trailing data */
1649 	ND_PRINT((ndo, "%s", cstr));
1650 	ND_TCHECK2(*cp0, len0);
1651 	return cp0 + len0;
1652 trunc:
1653 	ND_PRINT((ndo, "%s", tstr));
1654 	return ep;
1655 }
1656 
1657 /* ibid */
1658 static const u_char *
1659 of10_queue_stats_reply_print(netdissect_options *ndo,
1660                              const u_char *cp, const u_char *ep, u_int len) {
1661 	const u_char *cp0 = cp;
1662 	const u_int len0 = len;
1663 
1664 	while (len) {
1665 		if (len < OF_QUEUE_STATS_LEN)
1666 			goto corrupt;
1667 		/* port_no */
1668 		ND_TCHECK2(*cp, 2);
1669 		ND_PRINT((ndo, "\n\t  port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1670 		cp += 2;
1671 		/* pad */
1672 		ND_TCHECK2(*cp, 2);
1673 		cp += 2;
1674 		/* queue_id */
1675 		ND_TCHECK2(*cp, 4);
1676 		ND_PRINT((ndo, ", queue_id %u", EXTRACT_32BITS(cp)));
1677 		cp += 4;
1678 		/* tx_bytes */
1679 		ND_TCHECK2(*cp, 8);
1680 		ND_PRINT((ndo, ", tx_bytes %" PRIu64, EXTRACT_64BITS(cp)));
1681 		cp += 8;
1682 		/* tx_packets */
1683 		ND_TCHECK2(*cp, 8);
1684 		ND_PRINT((ndo, ", tx_packets %" PRIu64, EXTRACT_64BITS(cp)));
1685 		cp += 8;
1686 		/* tx_errors */
1687 		ND_TCHECK2(*cp, 8);
1688 		ND_PRINT((ndo, ", tx_errors %" PRIu64, EXTRACT_64BITS(cp)));
1689 		cp += 8;
1690 
1691 		len -= OF_QUEUE_STATS_LEN;
1692 	} /* while */
1693 	return cp;
1694 
1695 corrupt: /* skip the undersized trailing data */
1696 	ND_PRINT((ndo, "%s", cstr));
1697 	ND_TCHECK2(*cp0, len0);
1698 	return cp0 + len0;
1699 trunc:
1700 	ND_PRINT((ndo, "%s", tstr));
1701 	return ep;
1702 }
1703 
1704 /* ibid */
1705 static const u_char *
1706 of10_stats_reply_print(netdissect_options *ndo,
1707                        const u_char *cp, const u_char *ep, const u_int len) {
1708 	const u_char *cp0 = cp;
1709 	uint16_t type;
1710 
1711 	/* type */
1712 	ND_TCHECK2(*cp, 2);
1713 	type = EXTRACT_16BITS(cp);
1714 	ND_PRINT((ndo, "\n\t type %s", tok2str(ofpst_str, "invalid (0x%04x)", type)));
1715 	cp += 2;
1716 	/* flags */
1717 	ND_TCHECK2(*cp, 2);
1718 	ND_PRINT((ndo, ", flags 0x%04x", EXTRACT_16BITS(cp)));
1719 	of10_bitmap_print(ndo, ofpsf_reply_bm, EXTRACT_16BITS(cp), OFPSF_REPLY_U);
1720 	cp += 2;
1721 
1722 	if (ndo->ndo_vflag > 0) {
1723 		const u_char *(*decoder)(netdissect_options *, const u_char *, const u_char *, u_int) =
1724 			type == OFPST_DESC      ? of10_desc_stats_reply_print      :
1725 			type == OFPST_FLOW      ? of10_flow_stats_reply_print      :
1726 			type == OFPST_AGGREGATE ? of10_aggregate_stats_reply_print :
1727 			type == OFPST_TABLE     ? of10_table_stats_reply_print     :
1728 			type == OFPST_PORT      ? of10_port_stats_reply_print      :
1729 			type == OFPST_QUEUE     ? of10_queue_stats_reply_print     :
1730 			type == OFPST_VENDOR    ? of10_vendor_data_print           :
1731 			NULL;
1732 		if (decoder != NULL)
1733 			return decoder(ndo, cp, ep, len - OF_STATS_REPLY_LEN);
1734 	}
1735 	ND_TCHECK2(*cp0, len);
1736 	return cp0 + len;
1737 
1738 trunc:
1739 	ND_PRINT((ndo, "%s", tstr));
1740 	return ep;
1741 }
1742 
1743 /* [OF10] Section 5.3.6 */
1744 static const u_char *
1745 of10_packet_out_print(netdissect_options *ndo,
1746                       const u_char *cp, const u_char *ep, const u_int len) {
1747 	const u_char *cp0 = cp;
1748 	const u_int len0 = len;
1749 	uint16_t actions_len;
1750 
1751 	/* buffer_id */
1752 	ND_TCHECK2(*cp, 4);
1753 	ND_PRINT((ndo, "\n\t buffer_id 0x%08x", EXTRACT_32BITS(cp)));
1754 	cp += 4;
1755 	/* in_port */
1756 	ND_TCHECK2(*cp, 2);
1757 	ND_PRINT((ndo, ", in_port %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1758 	cp += 2;
1759 	/* actions_len */
1760 	ND_TCHECK2(*cp, 2);
1761 	actions_len = EXTRACT_16BITS(cp);
1762 	cp += 2;
1763 	if (actions_len > len - OF_PACKET_OUT_LEN)
1764 		goto corrupt;
1765 	/* actions */
1766 	if (ep == (cp = of10_actions_print(ndo, "\n\t ", cp, ep, actions_len)))
1767 		return ep; /* end of snapshot */
1768 	/* data */
1769 	return of10_packet_data_print(ndo, cp, ep, len - OF_PACKET_OUT_LEN - actions_len);
1770 
1771 corrupt: /* skip the rest of the message body */
1772 	ND_PRINT((ndo, "%s", cstr));
1773 	ND_TCHECK2(*cp0, len0);
1774 	return cp0 + len0;
1775 trunc:
1776 	ND_PRINT((ndo, "%s", tstr));
1777 	return ep;
1778 }
1779 
1780 /* [OF10] Section 5.4.1 */
1781 static const u_char *
1782 of10_packet_in_print(netdissect_options *ndo,
1783                      const u_char *cp, const u_char *ep, const u_int len) {
1784 	/* buffer_id */
1785 	ND_TCHECK2(*cp, 4);
1786 	ND_PRINT((ndo, "\n\t buffer_id %s", tok2str(bufferid_str, "0x%08x", EXTRACT_32BITS(cp))));
1787 	cp += 4;
1788 	/* total_len */
1789 	ND_TCHECK2(*cp, 2);
1790 	ND_PRINT((ndo, ", total_len %u", EXTRACT_16BITS(cp)));
1791 	cp += 2;
1792 	/* in_port */
1793 	ND_TCHECK2(*cp, 2);
1794 	ND_PRINT((ndo, ", in_port %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1795 	cp += 2;
1796 	/* reason */
1797 	ND_TCHECK2(*cp, 1);
1798 	ND_PRINT((ndo, ", reason %s", tok2str(ofpr_str, "invalid (0x%02x)", *cp)));
1799 	cp += 1;
1800 	/* pad */
1801 	ND_TCHECK2(*cp, 1);
1802 	cp += 1;
1803 	/* data */
1804 	/* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
1805 	return of10_packet_data_print(ndo, cp, ep, len - (OF_PACKET_IN_LEN - 2));
1806 
1807 trunc:
1808 	ND_PRINT((ndo, "%s", tstr));
1809 	return ep;
1810 }
1811 
1812 /* [OF10] Section 5.4.2 */
1813 static const u_char *
1814 of10_flow_removed_print(netdissect_options *ndo,
1815                         const u_char *cp, const u_char *ep) {
1816 	/* match */
1817 	if (ep == (cp = of10_match_print(ndo, "\n\t ", cp, ep)))
1818 		return ep; /* end of snapshot */
1819 	/* cookie */
1820 	ND_TCHECK2(*cp, 8);
1821 	ND_PRINT((ndo, "\n\t cookie 0x%016" PRIx64, EXTRACT_64BITS(cp)));
1822 	cp += 8;
1823 	/* priority */
1824 	ND_TCHECK2(*cp, 2);
1825 	if (EXTRACT_16BITS(cp))
1826 		ND_PRINT((ndo, ", priority %u", EXTRACT_16BITS(cp)));
1827 	cp += 2;
1828 	/* reason */
1829 	ND_TCHECK2(*cp, 1);
1830 	ND_PRINT((ndo, ", reason %s", tok2str(ofprr_str, "unknown (0x%02x)", *cp)));
1831 	cp += 1;
1832 	/* pad */
1833 	ND_TCHECK2(*cp, 1);
1834 	cp += 1;
1835 	/* duration_sec */
1836 	ND_TCHECK2(*cp, 4);
1837 	ND_PRINT((ndo, ", duration_sec %u", EXTRACT_32BITS(cp)));
1838 	cp += 4;
1839 	/* duration_nsec */
1840 	ND_TCHECK2(*cp, 4);
1841 	ND_PRINT((ndo, ", duration_nsec %u", EXTRACT_32BITS(cp)));
1842 	cp += 4;
1843 	/* idle_timeout */
1844 	ND_TCHECK2(*cp, 2);
1845 	if (EXTRACT_16BITS(cp))
1846 		ND_PRINT((ndo, ", idle_timeout %u", EXTRACT_16BITS(cp)));
1847 	cp += 2;
1848 	/* pad2 */
1849 	ND_TCHECK2(*cp, 2);
1850 	cp += 2;
1851 	/* packet_count */
1852 	ND_TCHECK2(*cp, 8);
1853 	ND_PRINT((ndo, ", packet_count %" PRIu64, EXTRACT_64BITS(cp)));
1854 	cp += 8;
1855 	/* byte_count */
1856 	ND_TCHECK2(*cp, 8);
1857 	ND_PRINT((ndo, ", byte_count %" PRIu64, EXTRACT_64BITS(cp)));
1858 	return cp + 8;
1859 
1860 trunc:
1861 	ND_PRINT((ndo, "%s", tstr));
1862 	return ep;
1863 }
1864 
1865 /* [OF10] Section 5.4.4 */
1866 static const u_char *
1867 of10_error_print(netdissect_options *ndo,
1868                  const u_char *cp, const u_char *ep, const u_int len) {
1869 	uint16_t type;
1870 	const struct tok *code_str;
1871 
1872 	/* type */
1873 	ND_TCHECK2(*cp, 2);
1874 	type = EXTRACT_16BITS(cp);
1875 	cp += 2;
1876 	ND_PRINT((ndo, "\n\t type %s", tok2str(ofpet_str, "invalid (0x%04x)", type)));
1877 	/* code */
1878 	ND_TCHECK2(*cp, 2);
1879 	code_str =
1880 		type == OFPET_HELLO_FAILED    ? ofphfc_str  :
1881 		type == OFPET_BAD_REQUEST     ? ofpbrc_str  :
1882 		type == OFPET_BAD_ACTION      ? ofpbac_str  :
1883 		type == OFPET_FLOW_MOD_FAILED ? ofpfmfc_str :
1884 		type == OFPET_PORT_MOD_FAILED ? ofppmfc_str :
1885 		type == OFPET_QUEUE_OP_FAILED ? ofpqofc_str :
1886 		empty_str;
1887 	ND_PRINT((ndo, ", code %s", tok2str(code_str, "invalid (0x%04x)", EXTRACT_16BITS(cp))));
1888 	cp += 2;
1889 	/* data */
1890 	return of10_data_print(ndo, cp, ep, len - OF_ERROR_MSG_LEN);
1891 
1892 trunc:
1893 	ND_PRINT((ndo, "%s", tstr));
1894 	return ep;
1895 }
1896 
1897 const u_char *
1898 of10_header_body_print(netdissect_options *ndo,
1899                        const u_char *cp, const u_char *ep, const uint8_t type,
1900                        const uint16_t len, const uint32_t xid) {
1901 	const u_char *cp0 = cp;
1902 	const u_int len0 = len;
1903 	/* Thus far message length is not less than the basic header size, but most
1904 	 * message types have additional assorted constraints on the length. Wherever
1905 	 * possible, check that message length meets the constraint, in remaining
1906 	 * cases check that the length is OK to begin decoding and leave any final
1907 	 * verification up to a lower-layer function. When the current message is
1908 	 * corrupt, proceed to the next message. */
1909 
1910 	/* [OF10] Section 5.1 */
1911 	ND_PRINT((ndo, "\n\tversion 1.0, type %s, length %u, xid 0x%08x",
1912 	       tok2str(ofpt_str, "invalid (0x%02x)", type), len, xid));
1913 	switch (type) {
1914 	/* OpenFlow header only. */
1915 	case OFPT_FEATURES_REQUEST: /* [OF10] Section 5.3.1 */
1916 	case OFPT_GET_CONFIG_REQUEST: /* [OF10] Section 5.3.2 */
1917 	case OFPT_BARRIER_REQUEST: /* [OF10] Section 5.3.7 */
1918 	case OFPT_BARRIER_REPLY: /* ibid */
1919 		if (len != OF_HEADER_LEN)
1920 			goto corrupt;
1921 		break;
1922 
1923 	/* OpenFlow header and fixed-size message body. */
1924 	case OFPT_SET_CONFIG: /* [OF10] Section 5.3.2 */
1925 	case OFPT_GET_CONFIG_REPLY: /* ibid */
1926 		if (len != OF_SWITCH_CONFIG_LEN)
1927 			goto corrupt;
1928 		if (ndo->ndo_vflag < 1)
1929 			goto next_message;
1930 		/* flags */
1931 		ND_TCHECK2(*cp, 2);
1932 		ND_PRINT((ndo, "\n\t flags %s", tok2str(ofp_config_str, "invalid (0x%04x)", EXTRACT_16BITS(cp))));
1933 		cp += 2;
1934 		/* miss_send_len */
1935 		ND_TCHECK2(*cp, 2);
1936 		ND_PRINT((ndo, ", miss_send_len %u", EXTRACT_16BITS(cp)));
1937 		return cp + 2;
1938 	case OFPT_PORT_MOD:
1939 		if (len != OF_PORT_MOD_LEN)
1940 			goto corrupt;
1941 		if (ndo->ndo_vflag < 1)
1942 			goto next_message;
1943 		return of10_port_mod_print(ndo, cp, ep);
1944 	case OFPT_QUEUE_GET_CONFIG_REQUEST: /* [OF10] Section 5.3.4 */
1945 		if (len != OF_QUEUE_GET_CONFIG_REQUEST_LEN)
1946 			goto corrupt;
1947 		if (ndo->ndo_vflag < 1)
1948 			goto next_message;
1949 		/* port */
1950 		ND_TCHECK2(*cp, 2);
1951 		ND_PRINT((ndo, "\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
1952 		cp += 2;
1953 		/* pad */
1954 		ND_TCHECK2(*cp, 2);
1955 		return cp + 2;
1956 	case OFPT_FLOW_REMOVED:
1957 		if (len != OF_FLOW_REMOVED_LEN)
1958 			goto corrupt;
1959 		if (ndo->ndo_vflag < 1)
1960 			goto next_message;
1961 		return of10_flow_removed_print(ndo, cp, ep);
1962 	case OFPT_PORT_STATUS: /* [OF10] Section 5.4.3 */
1963 		if (len != OF_PORT_STATUS_LEN)
1964 			goto corrupt;
1965 		if (ndo->ndo_vflag < 1)
1966 			goto next_message;
1967 		/* reason */
1968 		ND_TCHECK2(*cp, 1);
1969 		ND_PRINT((ndo, "\n\t reason %s", tok2str(ofppr_str, "invalid (0x%02x)", *cp)));
1970 		cp += 1;
1971 		/* pad */
1972 		ND_TCHECK2(*cp, 7);
1973 		cp += 7;
1974 		/* desc */
1975 		return of10_phy_ports_print(ndo, cp, ep, OF_PHY_PORT_LEN);
1976 
1977 	/* OpenFlow header, fixed-size message body and n * fixed-size data units. */
1978 	case OFPT_FEATURES_REPLY:
1979 		if (len < OF_SWITCH_FEATURES_LEN)
1980 			goto corrupt;
1981 		if (ndo->ndo_vflag < 1)
1982 			goto next_message;
1983 		return of10_features_reply_print(ndo, cp, ep, len);
1984 
1985 	/* OpenFlow header and variable-size data. */
1986 	case OFPT_HELLO: /* [OF10] Section 5.5.1 */
1987 	case OFPT_ECHO_REQUEST: /* [OF10] Section 5.5.2 */
1988 	case OFPT_ECHO_REPLY: /* [OF10] Section 5.5.3 */
1989 		if (ndo->ndo_vflag < 1)
1990 			goto next_message;
1991 		return of10_data_print(ndo, cp, ep, len - OF_HEADER_LEN);
1992 
1993 	/* OpenFlow header, fixed-size message body and variable-size data. */
1994 	case OFPT_ERROR:
1995 		if (len < OF_ERROR_MSG_LEN)
1996 			goto corrupt;
1997 		if (ndo->ndo_vflag < 1)
1998 			goto next_message;
1999 		return of10_error_print(ndo, cp, ep, len);
2000 	case OFPT_VENDOR:
2001 	  /* [OF10] Section 5.5.4 */
2002 		if (len < OF_VENDOR_HEADER_LEN)
2003 			goto corrupt;
2004 		if (ndo->ndo_vflag < 1)
2005 			goto next_message;
2006 		return of10_vendor_data_print(ndo, cp, ep, len - OF_HEADER_LEN);
2007 	case OFPT_PACKET_IN:
2008 		/* 2 mock octets count in OF_PACKET_IN_LEN but not in len */
2009 		if (len < OF_PACKET_IN_LEN - 2)
2010 			goto corrupt;
2011 		if (ndo->ndo_vflag < 1)
2012 			goto next_message;
2013 		return of10_packet_in_print(ndo, cp, ep, len);
2014 
2015 	/* a. OpenFlow header. */
2016 	/* b. OpenFlow header and one of the fixed-size message bodies. */
2017 	/* c. OpenFlow header, fixed-size message body and variable-size data. */
2018 	case OFPT_STATS_REQUEST:
2019 		if (len < OF_STATS_REQUEST_LEN)
2020 			goto corrupt;
2021 		if (ndo->ndo_vflag < 1)
2022 			goto next_message;
2023 		return of10_stats_request_print(ndo, cp, ep, len);
2024 
2025 	/* a. OpenFlow header and fixed-size message body. */
2026 	/* b. OpenFlow header and n * fixed-size data units. */
2027 	/* c. OpenFlow header and n * variable-size data units. */
2028 	/* d. OpenFlow header, fixed-size message body and variable-size data. */
2029 	case OFPT_STATS_REPLY:
2030 		if (len < OF_STATS_REPLY_LEN)
2031 			goto corrupt;
2032 		if (ndo->ndo_vflag < 1)
2033 			goto next_message;
2034 		return of10_stats_reply_print(ndo, cp, ep, len);
2035 
2036 	/* OpenFlow header and n * variable-size data units and variable-size data. */
2037 	case OFPT_PACKET_OUT:
2038 		if (len < OF_PACKET_OUT_LEN)
2039 			goto corrupt;
2040 		if (ndo->ndo_vflag < 1)
2041 			goto next_message;
2042 		return of10_packet_out_print(ndo, cp, ep, len);
2043 
2044 	/* OpenFlow header, fixed-size message body and n * variable-size data units. */
2045 	case OFPT_FLOW_MOD:
2046 		if (len < OF_FLOW_MOD_LEN)
2047 			goto corrupt;
2048 		if (ndo->ndo_vflag < 1)
2049 			goto next_message;
2050 		return of10_flow_mod_print(ndo, cp, ep, len);
2051 
2052 	/* OpenFlow header, fixed-size message body and n * variable-size data units. */
2053 	case OFPT_QUEUE_GET_CONFIG_REPLY: /* [OF10] Section 5.3.4 */
2054 		if (len < OF_QUEUE_GET_CONFIG_REPLY_LEN)
2055 			goto corrupt;
2056 		if (ndo->ndo_vflag < 1)
2057 			goto next_message;
2058 		/* port */
2059 		ND_TCHECK2(*cp, 2);
2060 		ND_PRINT((ndo, "\n\t port_no %s", tok2str(ofpp_str, "%u", EXTRACT_16BITS(cp))));
2061 		cp += 2;
2062 		/* pad */
2063 		ND_TCHECK2(*cp, 6);
2064 		cp += 6;
2065 		/* queues */
2066 		return of10_queues_print(ndo, cp, ep, len - OF_QUEUE_GET_CONFIG_REPLY_LEN);
2067 	} /* switch (type) */
2068 	goto next_message;
2069 
2070 corrupt: /* skip the message body */
2071 	ND_PRINT((ndo, "%s", cstr));
2072 next_message:
2073 	ND_TCHECK2(*cp0, len0 - OF_HEADER_LEN);
2074 	return cp0 + len0 - OF_HEADER_LEN;
2075 trunc:
2076 	ND_PRINT((ndo, "%s", tstr));
2077 	return ep;
2078 }
2079