[ovs-dev,branch-2.7,19/25] datapath: Simplify labels length logic.

Submitted by Jarno Rajahalme on March 15, 2017, 11:31 p.m.

Details

Message ID 1489620689-122370-20-git-send-email-jarno@ovn.org
State New
Headers show

Commit Message

Jarno Rajahalme March 15, 2017, 11:31 p.m.
Upstream commit:

    commit b87cec3814ccc7f6afb0a1378ee7e5110d07cdd3
    Author: Jarno Rajahalme <jarno@ovn.org>
    Date:   Thu Feb 9 11:21:56 2017 -0800

    openvswitch: Simplify labels length logic.

    Since 23014011ba42 ("netfilter: conntrack: support a fixed size of 128
    distinct labels"), the size of conntrack labels extension has fixed to
    128 bits, so we do not need to check for labels sizes shorter than 128
    at run-time.  This patch simplifies labels length logic accordingly,
    but allows the conntrack labels size to be increased in the future
    without breaking the build.  In the event of conntrack labels
    increasing in size OVS would still be able to deal with the 128 first
    label bits.

    Suggested-by: Joe Stringer <joe@ovn.org>
    Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
    Acked-by: Pravin B Shelar <pshelar@ovn.org>
    Acked-by: Joe Stringer <joe@ovn.org>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Signed-off-by: Jarno Rajahalme <jarno@ovn.org>
Acked-by: Joe Stringer <joe@ovn.org>
---
 datapath/conntrack.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

Patch hide | download patch | download mbox

diff --git a/datapath/conntrack.c b/datapath/conntrack.c
index b5c80be..2d095b8 100644
--- a/datapath/conntrack.c
+++ b/datapath/conntrack.c
@@ -145,22 +145,20 @@  static size_t ovs_ct_get_labels_len(struct nf_conn_labels *cl)
 #endif
 }
 
+/* Guard against conntrack labels max size shrinking below 128 bits. */
+#if NF_CT_LABELS_MAX_SIZE < 16
+#error NF_CT_LABELS_MAX_SIZE must be at least 16 bytes
+#endif
+
 static void ovs_ct_get_labels(const struct nf_conn *ct,
 			      struct ovs_key_ct_labels *labels)
 {
 	struct nf_conn_labels *cl = ct ? nf_ct_labels_find(ct) : NULL;
 
-	if (cl) {
-		size_t len = ovs_ct_get_labels_len(cl);
-
-		if (len > OVS_CT_LABELS_LEN)
-			len = OVS_CT_LABELS_LEN;
-		else if (len < OVS_CT_LABELS_LEN)
-			memset(labels, 0, OVS_CT_LABELS_LEN);
-		memcpy(labels, cl->bits, len);
-	} else {
+	if (cl)
+		memcpy(labels, cl->bits, OVS_CT_LABELS_LEN);
+	else
 		memset(labels, 0, OVS_CT_LABELS_LEN);
-	}
 }
 
 static void __ovs_ct_update_key(struct sw_flow_key *key, u8 state,