+ ndo->ndo_protocol = "openflow";
+ ND_PRINT(": OpenFlow");
+ while (len) {
+ /* Print a single OpenFlow message. */
+ uint8_t version, type;
+ uint16_t length;
+ const struct of_msgtypeinfo *mti;
+
+ /* version */
+ version = GET_U_1(cp);
+ OF_FWD(1);
+ ND_PRINT("\n\tversion %s",
+ tok2str(ofver_str, "unknown (0x%02x)", version));
+ /* type */
+ if (len < 1)
+ goto partial_header;
+ type = GET_U_1(cp);
+ OF_FWD(1);
+ mti =
+ version == OF_VER_1_0 ? of10_identify_msgtype(type) :
+ version == OF_VER_1_3 ? of13_identify_msgtype(type) :
+ NULL;
+ if (mti && mti->name)
+ ND_PRINT(", type %s", mti->name);
+ else
+ ND_PRINT(", type unknown (0x%02x)", type);
+ /* length */
+ if (len < 2)
+ goto partial_header;
+ length = GET_BE_U_2(cp);
+ OF_FWD(2);
+ ND_PRINT(", length %u%s", length,
+ length < OF_HEADER_FIXLEN ? " (too short!)" : "");
+ /* xid */
+ if (len < 4)
+ goto partial_header;
+ ND_PRINT(", xid 0x%08x", GET_BE_U_4(cp));
+ OF_FWD(4);
+
+ /*
+ * When a TCP packet can contain several protocol messages,
+ * and at the same time a protocol message can span several
+ * TCP packets, decoding an incomplete message at the end of
+ * a TCP packet requires attention to detail in this loop.
+ *
+ * Message length includes the header length and a message
+ * always includes the basic header. A message length underrun
+ * fails decoding of the rest of the current packet. At the
+ * same time, try decoding as much of the current message as
+ * possible even when it does not end within the current TCP
+ * segment.
+ *
+ * Specifically, to try to process the message body in this
+ * iteration do NOT require the header "length" to be small
+ * enough for the full declared OpenFlow message to fit into
+ * the remainder of the declared TCP segment, same as the full
+ * declared TCP segment is not required to fit into the
+ * captured packet buffer.
+ *
+ * But DO require the same at the end of this iteration to
+ * decrement "len" and to proceed to the next iteration.
+ * (Ideally the declared TCP payload end will be at or after
+ * the captured packet buffer end, but stay safe even when
+ * that's somehow not the case.)
+ */
+ if (length < OF_HEADER_FIXLEN)
+ goto invalid;
+
+ of_message_print(ndo, cp, length - OF_HEADER_FIXLEN, mti);
+ if (length - OF_HEADER_FIXLEN > len)
+ break;
+ OF_FWD(length - OF_HEADER_FIXLEN);
+ } /* while (len) */
+ return;