summaryrefslogtreecommitdiff
path: root/lib/conntrack.c
diff options
context:
space:
mode:
authorDarrell Ball <dlu998@gmail.com>2019-05-28 11:14:44 -0700
committerBen Pfaff <blp@ovn.org>2019-06-05 14:58:46 -0700
commit4048c5088f95f336a7311eb484e80af6764ff71c (patch)
tree4f20cc97fb34a966c9befeacbd2c7bf155c1b57b /lib/conntrack.c
parent28274f774adb3f85a7b351ba24ab0ba7817c9794 (diff)
downloadopenvswitch-4048c5088f95f336a7311eb484e80af6764ff71c.tar.gz
conntrack: Add 'conn_lookup()' api.
The new api incorporates the hash calculation which can be a distraction. Signed-off-by: Darrell Ball <dlu998@gmail.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'lib/conntrack.c')
-rw-r--r--lib/conntrack.c49
1 files changed, 23 insertions, 26 deletions
diff --git a/lib/conntrack.c b/lib/conntrack.c
index e9d672007..67c3a5833 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;