diff mbox series

[ovs-dev,v2,3/3] conntrack: Add 'conn_lookup()' api.

Message ID 1559067284-48389-3-git-send-email-dlu998@gmail.com
State Accepted
Commit 4048c5088f95f336a7311eb484e80af6764ff71c
Headers show
Series [ovs-dev,v2,1/3] conntrack: Don't re-add cleaned 'conn' to expiry list. | expand

Commit Message

Darrell Ball May 28, 2019, 6:14 p.m. UTC
The new api incorporates the hash calculation which can be a
distraction.

Signed-off-by: Darrell Ball <dlu998@gmail.com>
---

v2: Newly introduced patch.

 lib/conntrack.c | 49 +++++++++++++++++++++++--------------------------
 1 file changed, 23 insertions(+), 26 deletions(-)

Comments

Ben Pfaff June 5, 2019, 10:07 p.m. UTC | #1
On Tue, May 28, 2019 at 11:14:44AM -0700, Darrell Ball wrote:
> The new api incorporates the hash calculation which can be a
> distraction.
> 
> Signed-off-by: Darrell Ball <dlu998@gmail.com>

I applied this series to master.  If any of it needs backporting, please
let me know.
diff mbox series

Patch

diff --git a/lib/conntrack.c b/lib/conntrack.c
index e9d6720..67c3a58 100644
--- a/lib/conntrack.c
+++ b/lib/conntrack.c
@@ -428,6 +428,14 @@  conn_key_lookup(struct conntrack *ct, const struct conn_key *key,
     return found;
 }
 
+static bool
+conn_lookup(struct conntrack *ct, const struct conn_key *key,
+            long long now, struct conn **conn_out, bool *reply)
+{
+    uint32_t hash = conn_key_hash(key, ct->hash_basis);
+    return conn_key_lookup(ct, key, hash, now, conn_out, reply);
+}
+
 static void
 write_ct_md(struct dp_packet *pkt, uint16_t zone, const struct conn *conn,
             const struct conn_key *key, const struct alg_exp_node *alg_exp)
@@ -784,10 +792,8 @@  conn_seq_skew_set(struct conntrack *ct, const struct conn *conn_in,
     OVS_NO_THREAD_SAFETY_ANALYSIS
 {
     struct conn *conn;
-    bool reply;
-    uint32_t hash = conn_key_hash(&conn_in->key, ct->hash_basis);
     ovs_mutex_unlock(&conn_in->lock);
-    conn_key_lookup(ct, &conn_in->key, hash, now, &conn, &reply);
+    conn_lookup(ct, &conn_in->key, now, &conn, NULL);
     ovs_mutex_lock(&conn_in->lock);
 
     if (conn && seq_skew) {
@@ -956,8 +962,7 @@  conn_update_state(struct conntrack *ct, struct dp_packet *pkt,
             break;
         case CT_UPDATE_NEW:
             ovs_mutex_lock(&ct->ct_lock);
-            uint32_t hash = conn_key_hash(&conn->key, ct->hash_basis);
-            if (conn_key_lookup(ct, &conn->key, hash, now, NULL, NULL)) {
+            if (conn_lookup(ct, &conn->key, now, NULL, NULL)) {
                 conn_clean(ct, conn);
             }
             ovs_mutex_unlock(&ct->ct_lock);
@@ -1042,9 +1047,7 @@  check_orig_tuple(struct conntrack *ct, struct dp_packet *pkt,
 
     key.dl_type = ctx_in->key.dl_type;
     key.zone = pkt->md.ct_zone;
-    uint32_t hash = conn_key_hash(&key, ct->hash_basis);
-    bool reply;
-    conn_key_lookup(ct, &key, hash, now, conn, &reply);
+    conn_lookup(ct, &key, now, conn, NULL);
     return *conn ? true : false;
 }
 
@@ -1092,13 +1095,11 @@  process_one(struct conntrack *ct, struct dp_packet *pkt,
     bool create_new_conn = false;
     conn_key_lookup(ct, &ctx->key, ctx->hash, now, &ctx->conn, &ctx->reply);
     struct conn *conn = ctx->conn;
-    uint32_t hash;
 
     /* Delete found entry if in wrong direction. 'force' implies commit. */
     if (OVS_UNLIKELY(force && ctx->reply && conn)) {
         ovs_mutex_lock(&ct->ct_lock);
-        hash = conn_key_hash(&conn->key, ct->hash_basis);
-        if (conn_key_lookup(ct, &conn->key, hash, now, NULL, NULL)) {
+        if (conn_lookup(ct, &conn->key, now, NULL, NULL)) {
             conn_clean(ct, conn);
         }
         ovs_mutex_unlock(&ct->ct_lock);
@@ -1110,7 +1111,7 @@  process_one(struct conntrack *ct, struct dp_packet *pkt,
 
             ctx->reply = true;
             struct conn *rev_conn = conn;  /* Save for debugging. */
-            hash = conn_key_hash(&conn->rev_key, ct->hash_basis);
+            uint32_t hash = conn_key_hash(&conn->rev_key, ct->hash_basis);
             conn_key_lookup(ct, &ctx->key, hash, now, &conn, &ctx->reply);
 
             if (!conn) {
@@ -1165,8 +1166,7 @@  process_one(struct conntrack *ct, struct dp_packet *pkt,
         ovs_rwlock_unlock(&ct->resources_lock);
 
         ovs_mutex_lock(&ct->ct_lock);
-        hash = conn_key_hash(&ctx->key, ct->hash_basis);
-        if (!conn_key_lookup(ct, &ctx->key, hash, now, NULL, NULL)) {
+        if (!conn_lookup(ct, &ctx->key, now, NULL, NULL)) {
             conn = conn_not_found(ct, pkt, ctx, commit, now, nat_action_info,
                                   helper, alg_exp, ct_alg_ctl);
         }
@@ -2057,10 +2057,8 @@  nat_select_range_tuple(struct conntrack *ct, const struct conn *conn,
             nat_conn->rev_key.src.port = htons(port);
         }
 
-        uint32_t conn_hash = conn_key_hash(&nat_conn->rev_key,
-                                           ct->hash_basis);
-        bool found = conn_key_lookup(ct, &nat_conn->rev_key, conn_hash,
-                                     time_msec(), NULL, NULL);
+        bool found = conn_lookup(ct, &nat_conn->rev_key, time_msec(),
+                                     NULL, NULL);
         if (!found) {
             return true;
         } else if (pat_enabled && !all_ports_tried) {
@@ -2353,18 +2351,17 @@  int
 conntrack_flush_tuple(struct conntrack *ct, const struct ct_dpif_tuple *tuple,
                       uint16_t zone)
 {
-    struct conn_lookup_ctx ctx;
     int error = 0;
+    struct conn_key key;
+    struct conn *conn;
 
-    memset(&ctx, 0, sizeof(ctx));
-    tuple_to_conn_key(tuple, zone, &ctx.key);
-    ctx.hash = conn_key_hash(&ctx.key, ct->hash_basis);
+    memset(&key, 0, sizeof(key));
+    tuple_to_conn_key(tuple, zone, &key);
     ovs_mutex_lock(&ct->ct_lock);
-    conn_key_lookup(ct, &ctx.key, ctx.hash, time_msec(), &ctx.conn,
-                    &ctx.reply);
+    conn_lookup(ct, &key, time_msec(), &conn, NULL);
 
-    if (ctx.conn && ctx.conn->conn_type == CT_CONN_TYPE_DEFAULT) {
-        conn_clean(ct, ctx.conn);
+    if (conn && conn->conn_type == CT_CONN_TYPE_DEFAULT) {
+        conn_clean(ct, conn);
     } else {
         VLOG_WARN("Must flush tuple using the original pre-NATed tuple");
         error = ENOENT;