summaryrefslogtreecommitdiff
path: root/print-openflow-1.0.c
diff options
context:
space:
mode:
authorDenis Ovsienko <denis@ovsienko.info>2020-10-01 16:36:45 +0100
committerDenis Ovsienko <denis@ovsienko.info>2020-10-01 17:08:45 +0100
commit3b46f347ca330d3a063aeede8e96e00265dfaab6 (patch)
treea282203e391e58acfa5acc80b78ea248c7b25ed6 /print-openflow-1.0.c
parent63610e417b2d1bd99cb41e0bb5e129015b0aeb4e (diff)
downloadtcpdump-3b46f347ca330d3a063aeede8e96e00265dfaab6.tar.gz
OpenFlow: Use bittok2str(), fix OF1.0 port status.
of_bitmap_print() used to have its own bitmap printing code, which would yield a single closing parenthesis when none of the assigned tokens matched (that was a bug, althought not triggered by any of the existing tests). Simplify the function to use bittok2str() instead, then observe some changes in OpenFlow 1.0 tests output. Apparently, the old code implemented "match any" for multiple-bit tokens, and bittok2str() now implements "match all". However, in that protocol encoding bitmap tokens are always single-bit, so examine the OFPPS_ props closer and realize that the "state" field of the physical port structure includes both a tiny bitmap and a tiny code point. Leave comments to clarify that, update the props and the printing code. Update output for four tests.
Diffstat (limited to 'print-openflow-1.0.c')
-rw-r--r--print-openflow-1.0.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/print-openflow-1.0.c b/print-openflow-1.0.c
index 92b20eb3..dd42866a 100644
--- a/print-openflow-1.0.c
+++ b/print-openflow-1.0.c
@@ -144,14 +144,18 @@ static const struct tok ofppc_bm[] = {
OFPPC_NO_RECV_STP | OFPPC_NO_FLOOD | OFPPC_NO_FWD | \
OFPPC_NO_PACKET_IN))
-#define OFPPS_LINK_DOWN (1U << 0)
-#define OFPPS_STP_LISTEN (0U << 8)
-#define OFPPS_STP_LEARN (1U << 8)
-#define OFPPS_STP_FORWARD (2U << 8)
-#define OFPPS_STP_BLOCK (3U << 8)
-#define OFPPS_STP_MASK (3U << 8)
-static const struct tok ofpps_bm[] = {
- { OFPPS_LINK_DOWN, "LINK_DOWN" },
+/*
+ * [OF10] lists all FPPS_ constants in one enum, but they mean a 1-bit bitmap
+ * in the least significant octet and a 2-bit code point in the next octet.
+ * Remember to mix or to separate these two parts as the context requires.
+ */
+#define OFPPS_LINK_DOWN (1U << 0) /* bitmap */
+#define OFPPS_STP_LISTEN (0U << 8) /* code point */
+#define OFPPS_STP_LEARN (1U << 8) /* code point */
+#define OFPPS_STP_FORWARD (2U << 8) /* code point */
+#define OFPPS_STP_BLOCK (3U << 8) /* code point */
+#define OFPPS_STP_MASK (3U << 8) /* code point bitmask */
+static const struct tok ofpps_stp_str[] = {
{ OFPPS_STP_LISTEN, "STP_LISTEN" },
{ OFPPS_STP_LEARN, "STP_LEARN" },
{ OFPPS_STP_FORWARD, "STP_FORWARD" },
@@ -1058,6 +1062,8 @@ of10_phy_ports_print(netdissect_options *ndo,
const u_char *cp, u_int len)
{
while (len) {
+ uint32_t state;
+
if (len < OF_PHY_PORT_FIXLEN)
goto invalid;
/* port_no */
@@ -1082,8 +1088,16 @@ of10_phy_ports_print(netdissect_options *ndo,
of_bitmap_print(ndo, ofppc_bm, GET_BE_U_4(cp), OFPPC_U);
OF_FWD(4);
/* state */
- ND_PRINT("\n\t state 0x%08x", GET_BE_U_4(cp));
- of_bitmap_print(ndo, ofpps_bm, GET_BE_U_4(cp), OFPPS_U);
+ state = GET_BE_U_4(cp);
+ /*
+ * Decode the code point and the single bit separately, but
+ * format the result as a single sequence of comma-separated
+ * strings (see the comments at the OFPPS_ props).
+ */
+ ND_PRINT("\n\t state 0x%08x (%s%s)%s", state,
+ tok2str(ofpps_stp_str, "", state & OFPPS_STP_MASK),
+ state & OFPPS_LINK_DOWN ? ", LINK_DOWN" : "",
+ state & OFPPS_U ? " (bogus)" : "");
OF_FWD(4);
/* curr */
ND_PRINT("\n\t curr 0x%08x", GET_BE_U_4(cp));