[ovs-dev,RFC,v2,2/6] Conntrack: Support "out-of-band" expectations.

Message ID 20180212230829.31624-3-tiagolam@gmail.com
State RFC
Headers show
Series
  • Initial support for new SIP Alg.
Related show

Commit Message

Tiago Lam Feb. 12, 2018, 11:08 p.m.
A new function, expectation_create_outband, is introduced to allow more
flexibility when creating the expectations (e.g. specify the network
protocol for the expectation, or a different destination address from
where the initial request came from).

Signed-off-by: Tiago Lam <tiagolam@gmail.com>
---
 lib/conntrack.c | 49 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 32 insertions(+), 17 deletions(-)

Patch

diff --git a/lib/conntrack.c b/lib/conntrack.c
index fe5fd0fe8..a3cff1575 100644
--- a/lib/conntrack.c
+++ b/lib/conntrack.c
@@ -2631,41 +2631,33 @@  expectation_clean(struct conntrack *ct, const struct conn_key *master_key,
     ct_rwlock_unlock(&ct->resources_lock);
 }
 
-static void
-expectation_create(struct conntrack *ct, ovs_be16 dst_port,
-                   const struct conn *master_conn, bool reply, bool src_ip_wc,
-                   bool skip_nat)
+void
+expectation_create_outband(struct conntrack *ct, struct ct_addr src_addr,
+                           struct ct_addr dst_addr, ovs_be16 dst_port,
+                           const struct conn *master_conn, bool reply,
+                           bool src_ip_wc, bool skip_nat, uint8_t nw_proto)
 {
-    struct ct_addr src_addr;
-    struct ct_addr dst_addr;
-    struct ct_addr alg_nat_repl_addr;
     struct alg_exp_node *alg_exp_node = xzalloc(sizeof *alg_exp_node);
+    struct ct_addr alg_nat_repl_addr;
 
     if (reply) {
-        src_addr = master_conn->key.src.addr;
-        dst_addr = master_conn->key.dst.addr;
+        alg_exp_node->nat_rpl_dst = true;
         if (skip_nat) {
             alg_nat_repl_addr = dst_addr;
         } else {
             alg_nat_repl_addr = master_conn->rev_key.dst.addr;
         }
-        alg_exp_node->nat_rpl_dst = true;
     } else {
-        src_addr = master_conn->rev_key.src.addr;
-        dst_addr = master_conn->rev_key.dst.addr;
+        alg_exp_node->nat_rpl_dst = false;
         if (skip_nat) {
             alg_nat_repl_addr = src_addr;
         } else {
             alg_nat_repl_addr = master_conn->key.src.addr;
         }
-        alg_exp_node->nat_rpl_dst = false;
-    }
-    if (src_ip_wc) {
-        memset(&src_addr, 0, sizeof src_addr);
     }
 
     alg_exp_node->key.dl_type = master_conn->key.dl_type;
-    alg_exp_node->key.nw_proto = master_conn->key.nw_proto;
+    alg_exp_node->key.nw_proto = nw_proto;
     alg_exp_node->key.zone = master_conn->key.zone;
     alg_exp_node->key.src.addr = src_addr;
     alg_exp_node->key.dst.addr = dst_addr;
@@ -2694,6 +2686,29 @@  expectation_create(struct conntrack *ct, ovs_be16 dst_port,
     ct_rwlock_unlock(&ct->resources_lock);
 }
 
+static void
+expectation_create(struct conntrack *ct, ovs_be16 dst_port,
+                   const struct conn *master_conn, bool reply,
+                   bool src_ip_wc, bool skip_nat) {
+    struct ct_addr src_addr;
+    struct ct_addr dst_addr;
+
+    if (reply) {
+        src_addr = master_conn->key.src.addr;
+        dst_addr = master_conn->key.dst.addr;
+    } else {
+        src_addr = master_conn->rev_key.src.addr;
+        dst_addr = master_conn->rev_key.dst.addr;
+    }
+    if (src_ip_wc) {
+        memset(&src_addr, 0, sizeof src_addr);
+    }
+
+    expectation_create_outband(ct, src_addr, dst_addr, dst_port, master_conn,
+                               reply, src_ip_wc, skip_nat,
+                               master_conn->key.nw_proto);
+}
+
 static uint8_t
 get_v4_byte_be(ovs_be32 v4_addr, uint8_t index)
 {