summaryrefslogtreecommitdiffstats
path: root/src/plugins/cnat/cnat_translation.c
diff options
context:
space:
mode:
authorNathan Skrzypczak <nathan.skrzypczak@gmail.com>2021-02-25 17:39:03 +0100
committerDave Barach <openvpp@barachs.net>2021-03-04 12:35:15 +0000
commit3fd77f7dea1ac91c5b4c9ede69b992a4e2243153 (patch)
tree21550f5d6e28f55f4e64ee1ddb7697c9e261dd85 /src/plugins/cnat/cnat_translation.c
parent8786a4cd4a62f2817da7060afd8523857f504912 (diff)
cnat: Prepare extended snat policies
Type: refactor Change-Id: I9ca3333274d6f32b6aff57f0fb3d2049c066337a Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
Diffstat (limited to 'src/plugins/cnat/cnat_translation.c')
-rw-r--r--src/plugins/cnat/cnat_translation.c48
1 files changed, 13 insertions, 35 deletions
diff --git a/src/plugins/cnat/cnat_translation.c b/src/plugins/cnat/cnat_translation.c
index bd456c82fef..049809a8684 100644
--- a/src/plugins/cnat/cnat_translation.c
+++ b/src/plugins/cnat/cnat_translation.c
@@ -26,9 +26,6 @@
cnat_translation_t *cnat_translation_pool;
clib_bihash_8_8_t cnat_translation_db;
addr_resolution_t *tr_resolutions;
-
-typedef void (*cnat_if_addr_add_cb_t) (addr_resolution_t * ar,
- ip_address_t * address, u8 is_del);
cnat_if_addr_add_cb_t *cnat_if_addr_add_cbs;
static fib_node_type_t cnat_translation_fib_node_type;
@@ -775,32 +772,6 @@ cnat_if_addr_add_del_backend_cb (addr_resolution_t * ar,
}
static void
-cnat_if_addr_add_del_snat_cb (addr_resolution_t * ar, ip_address_t * address,
- u8 is_del)
-{
- cnat_endpoint_t *ep;
- ep = AF_IP4 == ar->af ? &cnat_main.snat_ip4 : &cnat_main.snat_ip6;
-
- if (!is_del && ep->ce_flags & CNAT_EP_FLAG_RESOLVED)
- return;
-
- if (is_del)
- {
- ep->ce_flags &= ~CNAT_EP_FLAG_RESOLVED;
- /* Are there remaining addresses ? */
- if (0 == cnat_resolve_addr (ar->sw_if_index, ar->af, address))
- is_del = 0;
- }
-
- if (!is_del)
- {
- ip_address_copy (&ep->ce_ip, address);
- ep->ce_flags |= CNAT_EP_FLAG_RESOLVED;
- }
-
-}
-
-static void
cnat_if_addr_add_del_callback (u32 sw_if_index, ip_address_t * address,
u8 is_del)
{
@@ -839,6 +810,14 @@ cnat_ip4_if_addr_add_del_callback (struct ip4_main_t *im,
cnat_if_addr_add_del_callback (sw_if_index, &addr, is_del);
}
+void
+cnat_translation_register_addr_add_cb (cnat_addr_resol_type_t typ,
+ cnat_if_addr_add_cb_t fn)
+{
+ vec_validate (cnat_if_addr_add_cbs, CNAT_ADDR_N_RESOLUTIONS);
+ cnat_if_addr_add_cbs[typ] = fn;
+}
+
static clib_error_t *
cnat_translation_init (vlib_main_t * vm)
{
@@ -860,12 +839,11 @@ cnat_translation_init (vlib_main_t * vm)
cb6.function = cnat_ip6_if_addr_add_del_callback;
vec_add1 (i6m->add_del_interface_address_callbacks, cb6);
- vec_validate (cnat_if_addr_add_cbs, CNAT_ADDR_N_RESOLUTIONS);
- cnat_if_addr_add_cbs[CNAT_RESOLV_ADDR_BACKEND] =
- cnat_if_addr_add_del_backend_cb;
- cnat_if_addr_add_cbs[CNAT_RESOLV_ADDR_SNAT] = cnat_if_addr_add_del_snat_cb;
- cnat_if_addr_add_cbs[CNAT_RESOLV_ADDR_TRANSLATION] =
- cnat_if_addr_add_del_translation_cb;
+ cnat_translation_register_addr_add_cb (CNAT_RESOLV_ADDR_BACKEND,
+ cnat_if_addr_add_del_backend_cb);
+ cnat_translation_register_addr_add_cb (CNAT_RESOLV_ADDR_TRANSLATION,
+ cnat_if_addr_add_del_translation_cb);
+
return (NULL);
}