From 13e1aff8b96166af5283e21a10d2d7cc7896dc6a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 9 May 2014 14:12:06 -0700 Subject: [PATCH] ofp-util: Remove ofputil_get_phy_port_size(). The size is not fixed for OpenFLow 1.4 and later, so it's a little deceptive to return any particular value. This function was only used in one place, so move it inline there. Signed-off-by: Ben Pfaff --- lib/ofp-util.c | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 7a64070de..b039d3132 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -3808,22 +3808,6 @@ ofputil_pull_ofp14_port(struct ofputil_phy_port *pp, struct ofpbuf *msg) return 0; } -static size_t -ofputil_get_phy_port_size(enum ofp_version ofp_version) -{ - switch (ofp_version) { - case OFP10_VERSION: - return sizeof(struct ofp10_phy_port); - case OFP11_VERSION: - case OFP12_VERSION: - case OFP13_VERSION: - case OFP14_VERSION: - return sizeof(struct ofp11_port); - default: - OVS_NOT_REACHED(); - } -} - static void ofputil_encode_ofp10_phy_port(const struct ofputil_phy_port *pp, struct ofp10_phy_port *opp) @@ -4043,14 +4027,6 @@ ofputil_decode_switch_features(const struct ofp_header *oh, return 0; } -/* Returns true if the maximum number of ports are in 'oh'. */ -static bool -max_ports_in_features(const struct ofp_header *oh) -{ - size_t pp_size = ofputil_get_phy_port_size(oh->version); - return ntohs(oh->length) + pp_size > UINT16_MAX; -} - /* In OpenFlow 1.0, 1.1, and 1.2, an OFPT_FEATURES_REPLY message lists all the * switch's ports, unless there are too many to fit. In OpenFlow 1.3 and * later, an OFPT_FEATURES_REPLY does not list ports at all. @@ -4067,16 +4043,28 @@ bool ofputil_switch_features_has_ports(struct ofpbuf *b) { struct ofp_header *oh = ofpbuf_data(b); + size_t phy_port_size; if (oh->version >= OFP13_VERSION) { + /* OpenFlow 1.3+ never has ports in the feature reply. */ return false; - } else if (max_ports_in_features(oh)) { - ofpbuf_set_size(b, sizeof *oh + sizeof(struct ofp_switch_features)); - ofpmsg_update_length(b); - return false; - } else { + } + + phy_port_size = (oh->version == OFP10_VERSION + ? sizeof(struct ofp10_phy_port) + : sizeof(struct ofp11_port)); + if (ntohs(oh->length) + phy_port_size <= UINT16_MAX) { + /* There's room for additional ports in the feature reply. + * Assume that the list is complete. */ return true; } + + /* The feature reply has no room for more ports. Probably the list is + * truncated. Drop the ports and tell the caller to retrieve them with + * OFPST_PORT_DESC. */ + ofpbuf_set_size(b, sizeof *oh + sizeof(struct ofp_switch_features)); + ofpmsg_update_length(b); + return false; } static ovs_be32 -- 2.39.5