Skip to content

Commit

Permalink
[CENNSO-1884] fix: use index instead pointer for nat binding (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
mogaika authored Mar 25, 2024
1 parent b3e978e commit 396916e
Showing 1 changed file with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
From 79649a3bd12ad07b365bb4c1f3b073bcf2339919 Mon Sep 17 00:00:00 2001
From: Vladimir Zhigulin <[email protected]>
Date: Mon, 25 Mar 2024 12:43:17 +0100
Subject: [PATCH] [CENNSO-1884] fix: use index instead pointer for nat binding

---
src/plugins/nat/nat44-ed/nat44_ed.c | 9 ++++++++-
src/plugins/nat/nat44-ed/nat44_ed.h | 2 +-
src/plugins/nat/nat44-ed/nat44_ed_in2out.c | 2 +-
src/plugins/nat/nat44-ed/nat44_ed_inlines.h | 2 ++
4 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/plugins/nat/nat44-ed/nat44_ed.c b/src/plugins/nat/nat44-ed/nat44_ed.c
index 30ee1159d..7e8d5f6dc 100644
--- a/src/plugins/nat/nat44-ed/nat44_ed.c
+++ b/src/plugins/nat/nat44-ed/nat44_ed.c
@@ -2529,6 +2529,7 @@ nat_ed_del_sessions_per_binding (snat_main_per_thread_data_t * tsm,
snat_main_t *sm = &snat_main;
snat_session_t *ses;
u32 *ses_idx = 0;
+ u32 this_bn_idx;
snat_binding_t *this_bn;

vec_foreach (ses_idx, bn->bound_sessions)
@@ -2536,9 +2537,15 @@ nat_ed_del_sessions_per_binding (snat_main_per_thread_data_t * tsm,
if (pool_is_free_index (tsm->sessions, ses_idx[0]))
continue;
ses = pool_elt_at_index (tsm->sessions, ses_idx[0]);
- this_bn = ses->binding;
+ this_bn_idx = ses->snat_binding_idx;
+
+ if (this_bn_idx == ~0)
+ return;
+
+ this_bn = pool_elt_at_index(tsm->bindings, this_bn_idx);
if (!this_bn)
return;
+
if ((this_bn->external_addr.as_u32 == bn->external_addr.as_u32)
&& (this_bn->framed_addr.as_u32 == bn->framed_addr.as_u32)
&& (this_bn->start_port == bn->start_port)
diff --git a/src/plugins/nat/nat44-ed/nat44_ed.h b/src/plugins/nat/nat44-ed/nat44_ed.h
index 13aa34230..014e67927 100644
--- a/src/plugins/nat/nat44-ed/nat44_ed.h
+++ b/src/plugins/nat/nat44-ed/nat44_ed.h
@@ -349,7 +349,7 @@ typedef CLIB_PACKED(struct
u32 per_vrf_sessions_index;

u32 thread_index;
- snat_binding_t *binding;
+ u32 snat_binding_idx;

}) snat_session_t;

diff --git a/src/plugins/nat/nat44-ed/nat44_ed_in2out.c b/src/plugins/nat/nat44-ed/nat44_ed_in2out.c
index 29268ea16..70eaf1bda 100644
--- a/src/plugins/nat/nat44-ed/nat44_ed_in2out.c
+++ b/src/plugins/nat/nat44-ed/nat44_ed_in2out.c
@@ -140,7 +140,7 @@ nat_controlled_alloc_addr_and_port (snat_main_t * sm,
{
*outside_port = clib_host_to_net_u16 (port);
vec_add1 (bn->bound_sessions, s - tsm->sessions);
- s->binding = bn;
+ s->snat_binding_idx = bn - tsm->bindings;
return 0;
}
++port;
diff --git a/src/plugins/nat/nat44-ed/nat44_ed_inlines.h b/src/plugins/nat/nat44-ed/nat44_ed_inlines.h
index 7c7dce02f..cb853a454 100644
--- a/src/plugins/nat/nat44-ed/nat44_ed_inlines.h
+++ b/src/plugins/nat/nat44-ed/nat44_ed_inlines.h
@@ -440,6 +440,8 @@ nat_ed_session_alloc (snat_main_t *sm, u32 thread_index, f64 now, u8 proto)
#if CLIB_ASSERT_ENABLE
s->thread_index = thread_index;
#endif
+ s->snat_binding_idx = ~0;
+
return s;
}

--
2.44.0

0 comments on commit 396916e

Please sign in to comment.