Create a separate function from existing code, so the code can be reused in a subsequent patch; no change in functionality.
Acked-by: Bhanuprakash Bodireddy <[email protected]> Signed-off-by: Darrell Ball <[email protected]> --- lib/conntrack.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/conntrack.c b/lib/conntrack.c index 419cb1d..cccba10 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -96,6 +96,11 @@ nat_conn_keys_lookup(struct hmap *nat_conn_keys, const struct conn_key *key, uint32_t basis); +static bool +nat_conn_keys_insert(struct hmap *nat_conn_keys, + const struct conn *nat_conn, + uint32_t hash_basis); + static void nat_conn_keys_remove(struct hmap *nat_conn_keys, const struct conn_key *key, @@ -2065,19 +2070,9 @@ nat_select_range_tuple(struct conntrack *ct, const struct conn *conn, nat_conn->rev_key.src.port = htons(port); } - struct nat_conn_key_node *nat_conn_key_node = - nat_conn_keys_lookup(&ct->nat_conn_keys, &nat_conn->rev_key, - ct->hash_basis); - - if (!nat_conn_key_node) { - struct nat_conn_key_node *nat_conn_key = - xzalloc(sizeof *nat_conn_key); - nat_conn_key->key = nat_conn->rev_key; - nat_conn_key->value = nat_conn->key; - uint32_t nat_conn_key_hash = conn_key_hash(&nat_conn_key->key, - ct->hash_basis); - hmap_insert(&ct->nat_conn_keys, &nat_conn_key->node, - nat_conn_key_hash); + bool new_insert = nat_conn_keys_insert(&ct->nat_conn_keys, nat_conn, + ct->hash_basis); + if (new_insert) { return true; } else if (!all_ports_tried) { if (min_port == max_port) { @@ -2137,6 +2132,26 @@ nat_conn_keys_lookup(struct hmap *nat_conn_keys, return NULL; } +/* This function must be called with the ct->resources lock taken. */ +static bool +nat_conn_keys_insert(struct hmap *nat_conn_keys, const struct conn *nat_conn, + uint32_t basis) +{ + struct nat_conn_key_node *nat_conn_key_node = + nat_conn_keys_lookup(nat_conn_keys, &nat_conn->rev_key, basis); + + if (!nat_conn_key_node) { + struct nat_conn_key_node *nat_conn_key = xzalloc(sizeof *nat_conn_key); + nat_conn_key->key = nat_conn->rev_key; + nat_conn_key->value = nat_conn->key; + uint32_t nat_conn_key_hash = conn_key_hash(&nat_conn_key->key, + basis); + hmap_insert(nat_conn_keys, &nat_conn_key->node, nat_conn_key_hash); + return true; + } + return false; +} + /* This function must be called with the ct->resources write lock taken. */ static void nat_conn_keys_remove(struct hmap *nat_conn_keys, -- 1.9.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
