summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat.c
diff options
context:
space:
mode:
authorFilip Varga <fivarga@cisco.com>2020-05-07 14:28:56 +0200
committerOle Trøan <otroan@employees.org>2020-05-07 17:04:00 +0000
commit9bb09afb56b1aa787ca574cc732085272059fd5f (patch)
tree38a3051033c5ed864386969f710a07b89c224728 /src/plugins/nat/nat.c
parent5505ee8904fafc7c1f017f88853f80a616784cf2 (diff)
nat: fix per thread data vlib_main_t usage
Type: fix Change-Id: If6784c9eb278f525e05304d10fd1a00641faaaf0 Signed-off-by: Filip Varga <fivarga@cisco.com>
Diffstat (limited to 'src/plugins/nat/nat.c')
-rwxr-xr-xsrc/plugins/nat/nat.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/plugins/nat/nat.c b/src/plugins/nat/nat.c
index c30324b7d9e..9aa5760d598 100755
--- a/src/plugins/nat/nat.c
+++ b/src/plugins/nat/nat.c
@@ -348,7 +348,6 @@ nat44_set_session_limit (u32 session_limit, u32 vrf_id)
return 0;
}
-
void
nat44_free_session_data (snat_main_t * sm, snat_session_t * s,
u32 thread_index, u8 is_ha)
@@ -2551,9 +2550,20 @@ test_ed_make_split ()
ASSERT (value == value2);
}
+always_inline vlib_main_t *
+nat_get_vlib_main (u32 thread_index)
+{
+ vlib_main_t *vm;
+ vm = vlib_mains[thread_index];
+ ASSERT (vm);
+ return vm;
+}
+
static clib_error_t *
snat_init (vlib_main_t * vm)
{
+ snat_main_per_thread_data_t *tsm;
+
snat_main_t *sm = &snat_main;
clib_error_t *error = 0;
ip4_main_t *im = &ip4_main;
@@ -2566,7 +2576,6 @@ snat_init (vlib_main_t * vm)
ip4_add_del_interface_address_callback_t cb4;
vlib_node_t *node;
- sm->vlib_main = vm;
sm->vnet_main = vnet_get_main ();
sm->ip4_main = im;
sm->ip4_lookup_main = lm;
@@ -2663,6 +2672,7 @@ snat_init (vlib_main_t * vm)
{
for (i = 0; i < sm->num_workers; i++)
bitmap = clib_bitmap_set (bitmap, i, 1);
+ // sets thread indexes for workes
snat_set_workers (bitmap);
clib_bitmap_free (bitmap);
}
@@ -2671,6 +2681,11 @@ snat_init (vlib_main_t * vm)
sm->per_thread_data[0].snat_thread_index = 0;
}
+ vec_foreach (tsm, sm->per_thread_data)
+ {
+ tsm->vlib_main = nat_get_vlib_main (tsm->thread_index);
+ }
+
error = snat_api_init (vm, sm);
if (error)
return error;
@@ -3623,14 +3638,14 @@ nat_ha_sadd_cb (ip4_address_t * in_addr, u16 in_port,
u32 fib_index, u16 flags, u32 thread_index)
{
snat_main_t *sm = &snat_main;
+ snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
snat_session_key_t key;
snat_user_t *u;
snat_session_t *s;
clib_bihash_kv_8_8_t kv;
- f64 now = vlib_time_now (sm->vlib_main);
+ f64 now = vlib_time_now (tsm->vlib_main);
nat_outside_fib_t *outside_fib;
fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
- snat_main_per_thread_data_t *tsm;
fib_prefix_t pfx = {
.fp_proto = FIB_PROTOCOL_IP4,
.fp_len = 32,
@@ -3639,8 +3654,6 @@ nat_ha_sadd_cb (ip4_address_t * in_addr, u16 in_port,
},
};
- tsm = vec_elt_at_index (sm->per_thread_data, thread_index);
-
key.addr.as_u32 = out_addr->as_u32;
key.port = out_port;
key.protocol = proto;
@@ -3773,13 +3786,13 @@ nat_ha_sadd_ed_cb (ip4_address_t * in_addr, u16 in_port,
u32 fib_index, u16 flags, u32 thread_index)
{
snat_main_t *sm = &snat_main;
+ snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
snat_session_key_t key;
snat_session_t *s;
clib_bihash_kv_16_8_t kv;
- f64 now = vlib_time_now (sm->vlib_main);
+ f64 now = vlib_time_now (tsm->vlib_main);
nat_outside_fib_t *outside_fib;
fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
- snat_main_per_thread_data_t *tsm;
fib_prefix_t pfx = {
.fp_proto = FIB_PROTOCOL_IP4,
.fp_len = 32,
@@ -3788,8 +3801,6 @@ nat_ha_sadd_ed_cb (ip4_address_t * in_addr, u16 in_port,
},
};
- tsm = vec_elt_at_index (sm->per_thread_data, thread_index);
-
key.addr.as_u32 = out_addr->as_u32;
key.port = out_port;
key.protocol = proto;