From 409793741d993123ccd321344a2fbf41693ff0e0 Mon Sep 17 00:00:00 2001
From: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
Date: Fri, 3 May 2019 08:33:37 +0100
Subject: [PATCH 1/2] eliminate variable in conntrack lookup

Eliminate boolean as existing null/none null pointer can be used for
equivalent functionality.

Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
---
 sch_cake.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/sch_cake.c b/sch_cake.c
index 253cb63..f0d651e 100644
--- a/sch_cake.c
+++ b/sch_cake.c
@@ -624,10 +624,10 @@ static bool cobalt_should_drop(struct cobalt_vars *vars,
 static void cake_update_flowkeys(struct flow_keys *keys,
 				 const struct sk_buff *skb)
 {
+	const struct nf_conntrack_tuple_hash *hash = NULL;
 	const struct nf_conntrack_tuple *tuple;
 	enum ip_conntrack_info ctinfo;
 	struct nf_conn *ct;
-	bool rev = false;
 
 	if (tc_skb_protocol(skb) != htons(ETH_P_IP))
 		return;
@@ -636,7 +636,6 @@ static void cake_update_flowkeys(struct flow_keys *keys,
 	if (ct) {
 		tuple = nf_ct_tuple(ct, CTINFO2DIR(ctinfo));
 	} else {
-		const struct nf_conntrack_tuple_hash *hash;
 		struct nf_conntrack_tuple srctuple;
 
 #if KERNEL_VERSION(4, 4, 0) > LINUX_VERSION_CODE
@@ -661,31 +660,30 @@ static void cake_update_flowkeys(struct flow_keys *keys,
 		if (!hash)
 			return;
 
-		rev = true;
 		ct = nf_ct_tuplehash_to_ctrack(hash);
 		tuple = nf_ct_tuple(ct, !hash->tuple.dst.dir);
 	}
 
 #if KERNEL_VERSION(4, 2, 0) > LINUX_VERSION_CODE
-	keys->src = rev ? tuple->dst.u3.ip : tuple->src.u3.ip;
-	keys->dst = rev ? tuple->src.u3.ip : tuple->dst.u3.ip;
+	keys->src = hash ? tuple->dst.u3.ip : tuple->src.u3.ip;
+	keys->dst = hash ? tuple->src.u3.ip : tuple->dst.u3.ip;
 #else
-	keys->addrs.v4addrs.src = rev ? tuple->dst.u3.ip : tuple->src.u3.ip;
-	keys->addrs.v4addrs.dst = rev ? tuple->src.u3.ip : tuple->dst.u3.ip;
+	keys->addrs.v4addrs.src = hash ? tuple->dst.u3.ip : tuple->src.u3.ip;
+	keys->addrs.v4addrs.dst = hash ? tuple->src.u3.ip : tuple->dst.u3.ip;
 #endif
 
 #if KERNEL_VERSION(4, 2, 0) > LINUX_VERSION_CODE
 	if (keys->ports) {
-		keys->port16[0] = rev ? tuple->dst.u.all : tuple->src.u.all;
-		keys->port16[1] = rev ? tuple->src.u.all : tuple->dst.u.all;
+		keys->port16[0] = hash ? tuple->dst.u.all : tuple->src.u.all;
+		keys->port16[1] = hash ? tuple->src.u.all : tuple->dst.u.all;
 	}
 #else
 	if (keys->ports.ports) {
-		keys->ports.src = rev ? tuple->dst.u.all : tuple->src.u.all;
-		keys->ports.dst = rev ? tuple->src.u.all : tuple->dst.u.all;
+		keys->ports.src = hash ? tuple->dst.u.all : tuple->src.u.all;
+		keys->ports.dst = hash ? tuple->src.u.all : tuple->dst.u.all;
 	}
 #endif
-	if (rev)
+	if (hash)
 		nf_ct_put(ct);
 }
 #else
-- 
2.20.1 (Apple Git-117)

