summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2020-05-08 10:02:18 +0200
committerDave Barach <openvpp@barachs.net>2020-05-08 11:23:18 +0000
commit71f62a52a2abaeb8b4fc8c70fde501fa7400417c (patch)
treea7029fc7fe7659d3b5a6d990bb1b83b997b47002 /src/plugins/nat
parent88d6ce2bee53b7c9f876aa78c5db8ab1ea75c08a (diff)
nat: fix per thread data vlib_main_t usage take 2
The original fix access vlib_main before these was initialized. Removed cached vlib_mains structure. Type: fix Fixes: 9bb09afb56b1aa787ca574cc732085272059fd5f Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I686bab9220e27891f66bf60489c1602855786aa8 Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/plugins/nat')
-rwxr-xr-xsrc/plugins/nat/in2out.c12
-rw-r--r--src/plugins/nat/in2out_ed.c8
-rwxr-xr-xsrc/plugins/nat/nat.c22
-rw-r--r--src/plugins/nat/nat.h3
-rw-r--r--src/plugins/nat/nat_det_in2out.c4
-rwxr-xr-xsrc/plugins/nat/out2in.c12
-rw-r--r--src/plugins/nat/out2in_ed.c13
7 files changed, 32 insertions, 42 deletions
diff --git a/src/plugins/nat/in2out.c b/src/plugins/nat/in2out.c
index d5bd9f5c851..936cd59e1d1 100755
--- a/src/plugins/nat/in2out.c
+++ b/src/plugins/nat/in2out.c
@@ -469,6 +469,7 @@ icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
clib_bihash_kv_8_8_t kv0, value0;
u32 next0 = ~0;
int err;
+ vlib_main_t *vm = vlib_get_main ();
sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
rx_fib_index0 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
@@ -521,7 +522,7 @@ icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
}
next0 = slow_path (sm, b0, ip0, rx_fib_index0, &key0, &s0, node, next0,
- thread_index, vlib_time_now (tsm->vlib_main));
+ thread_index, vlib_time_now (vm));
if (PREDICT_FALSE (next0 == SNAT_IN2OUT_NEXT_DROP))
goto out;
@@ -659,7 +660,7 @@ icmp_in2out (snat_main_t * sm,
vlib_node_runtime_t * node,
u32 next0, u32 thread_index, void *d, void *e)
{
- snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
+ vlib_main_t *vm = vlib_get_main ();
snat_session_key_t sm0;
u8 protocol;
icmp_echo_header_t *echo0, *inner_echo0 = 0;
@@ -687,7 +688,7 @@ icmp_in2out (snat_main_t * sm,
if (PREDICT_TRUE (!ip4_is_fragment (ip0)))
{
sum0 =
- ip_incremental_checksum_buffer (tsm->vlib_main, b0,
+ ip_incremental_checksum_buffer (vm, b0,
(u8 *) icmp0 -
(u8 *) vlib_buffer_get_current (b0),
ntohs (ip0->length) -
@@ -819,7 +820,8 @@ icmp_in2out_slow_path (snat_main_t * sm,
u32 next0,
f64 now, u32 thread_index, snat_session_t ** p_s0)
{
- snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
+ vlib_main_t *vm = vlib_get_main ();
+
next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
next0, thread_index, p_s0, 0);
snat_session_t *s0 = *p_s0;
@@ -828,7 +830,7 @@ icmp_in2out_slow_path (snat_main_t * sm,
/* Accounting */
nat44_session_update_counters (s0, now,
vlib_buffer_length_in_chain
- (tsm->vlib_main, b0), thread_index);
+ (vm, b0), thread_index);
/* Per-user LRU list maintenance */
nat44_session_update_lru (sm, s0, thread_index);
}
diff --git a/src/plugins/nat/in2out_ed.c b/src/plugins/nat/in2out_ed.c
index 6e44ddb6f76..f96f6367781 100644
--- a/src/plugins/nat/in2out_ed.c
+++ b/src/plugins/nat/in2out_ed.c
@@ -170,7 +170,8 @@ icmp_in2out_ed_slow_path (snat_main_t * sm, vlib_buffer_t * b0,
vlib_node_runtime_t * node, u32 next0, f64 now,
u32 thread_index, snat_session_t ** p_s0)
{
- snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
+ vlib_main_t *vm = vlib_get_main ();
+
next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
next0, thread_index, p_s0, 0);
snat_session_t *s0 = *p_s0;
@@ -179,7 +180,7 @@ icmp_in2out_ed_slow_path (snat_main_t * sm, vlib_buffer_t * b0,
/* Accounting */
nat44_session_update_counters (s0, now,
vlib_buffer_length_in_chain
- (tsm->vlib_main, b0), thread_index);
+ (vm, b0), thread_index);
/* Per-user LRU list maintenance */
nat44_session_update_lru (sm, s0, thread_index);
}
@@ -645,6 +646,7 @@ icmp_match_in2out_ed (snat_main_t * sm, vlib_node_runtime_t * node,
u32 next = ~0;
int err;
u16 l_port = 0, r_port = 0; // initialize to workaround gcc warning
+ vlib_main_t *vm = vlib_get_main ();
snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
@@ -697,7 +699,7 @@ icmp_match_in2out_ed (snat_main_t * sm, vlib_node_runtime_t * node,
next =
slow_path_ed (sm, b, ip->src_address, ip->dst_address, l_port, r_port,
ip->protocol, rx_fib_index, &s, node, next,
- thread_index, vlib_time_now (tsm->vlib_main));
+ thread_index, vlib_time_now (vm));
if (PREDICT_FALSE (next == NAT_NEXT_DROP))
goto out;
diff --git a/src/plugins/nat/nat.c b/src/plugins/nat/nat.c
index a1d1f853651..cc0789d1194 100755
--- a/src/plugins/nat/nat.c
+++ b/src/plugins/nat/nat.c
@@ -2549,20 +2549,9 @@ 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;
@@ -2680,11 +2669,6 @@ 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;
@@ -3642,7 +3626,8 @@ nat_ha_sadd_cb (ip4_address_t * in_addr, u16 in_port,
snat_user_t *u;
snat_session_t *s;
clib_bihash_kv_8_8_t kv;
- f64 now = vlib_time_now (tsm->vlib_main);
+ vlib_main_t *vm = vlib_get_main ();
+ f64 now = vlib_time_now (vm);
nat_outside_fib_t *outside_fib;
fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
fib_prefix_t pfx = {
@@ -3789,7 +3774,8 @@ nat_ha_sadd_ed_cb (ip4_address_t * in_addr, u16 in_port,
snat_session_key_t key;
snat_session_t *s;
clib_bihash_kv_16_8_t kv;
- f64 now = vlib_time_now (tsm->vlib_main);
+ vlib_main_t *vm = vlib_get_main ();
+ f64 now = vlib_time_now (vm);
nat_outside_fib_t *outside_fib;
fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
fib_prefix_t pfx = {
diff --git a/src/plugins/nat/nat.h b/src/plugins/nat/nat.h
index 1245b850ed0..7b57166a7e1 100644
--- a/src/plugins/nat/nat.h
+++ b/src/plugins/nat/nat.h
@@ -489,9 +489,6 @@ typedef struct
/* real thread index */
u32 thread_index;
- // per thread data structures
- vlib_main_t *vlib_main;
-
} snat_main_per_thread_data_t;
struct snat_main_s;
diff --git a/src/plugins/nat/nat_det_in2out.c b/src/plugins/nat/nat_det_in2out.c
index 762b7b068e6..dc2873ee110 100644
--- a/src/plugins/nat/nat_det_in2out.c
+++ b/src/plugins/nat/nat_det_in2out.c
@@ -99,7 +99,7 @@ icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node,
snat_session_key_t * p_value, u8 * p_dont_translate,
void *d, void *e)
{
- snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
+ vlib_main_t *vm = vlib_get_main ();
icmp46_header_t *icmp0;
u32 sw_if_index0;
u32 rx_fib_index0;
@@ -227,7 +227,7 @@ icmp_match_in2out_det (snat_main_t * sm, vlib_node_runtime_t * node,
goto out;
}
- u32 now = (u32) vlib_time_now (tsm->vlib_main);
+ u32 now = (u32) vlib_time_now (vm);
ses0->state = SNAT_SESSION_ICMP_ACTIVE;
ses0->expire = now + sm->icmp_timeout;
diff --git a/src/plugins/nat/out2in.c b/src/plugins/nat/out2in.c
index 411f193ab23..61719c73081 100755
--- a/src/plugins/nat/out2in.c
+++ b/src/plugins/nat/out2in.c
@@ -341,6 +341,7 @@ icmp_match_out2in_slow (snat_main_t * sm, vlib_node_runtime_t * node,
u32 next0 = ~0;
int err;
u8 identity_nat;
+ vlib_main_t *vm = vlib_get_main ();
sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
rx_fib_index0 = ip4_fib_table_get_index_for_sw_if_index (sw_if_index0);
@@ -404,7 +405,7 @@ icmp_match_out2in_slow (snat_main_t * sm, vlib_node_runtime_t * node,
/* Create session initiated by host from external network */
s0 = create_session_for_static_mapping (sm, b0, sm0, key0,
node, thread_index,
- vlib_time_now (tsm->vlib_main));
+ vlib_time_now (vm));
if (!s0)
{
@@ -530,7 +531,6 @@ icmp_out2in (snat_main_t * sm,
vlib_node_runtime_t * node,
u32 next0, u32 thread_index, void *d, void *e)
{
- snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
snat_session_key_t sm0;
u8 protocol;
icmp_echo_header_t *echo0, *inner_echo0 = 0;
@@ -543,6 +543,7 @@ icmp_out2in (snat_main_t * sm,
ip_csum_t sum0;
u16 checksum0;
u32 next0_tmp;
+ vlib_main_t *vm = vlib_get_main ();
echo0 = (icmp_echo_header_t *) (icmp0 + 1);
@@ -557,7 +558,7 @@ icmp_out2in (snat_main_t * sm,
if (PREDICT_TRUE (!ip4_is_fragment (ip0)))
{
sum0 =
- ip_incremental_checksum_buffer (tsm->vlib_main, b0,
+ ip_incremental_checksum_buffer (vm, b0,
(u8 *) icmp0 -
(u8 *) vlib_buffer_get_current (b0),
ntohs (ip0->length) -
@@ -670,7 +671,8 @@ icmp_out2in_slow_path (snat_main_t * sm,
u32 next0, f64 now,
u32 thread_index, snat_session_t ** p_s0)
{
- snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
+ vlib_main_t *vm = vlib_get_main ();
+
next0 = icmp_out2in (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
next0, thread_index, p_s0, 0);
snat_session_t *s0 = *p_s0;
@@ -679,7 +681,7 @@ icmp_out2in_slow_path (snat_main_t * sm,
/* Accounting */
nat44_session_update_counters (s0, now,
vlib_buffer_length_in_chain
- (tsm->vlib_main, b0), thread_index);
+ (vm, b0), thread_index);
/* Per-user LRU list maintenance */
nat44_session_update_lru (sm, s0, thread_index);
}
diff --git a/src/plugins/nat/out2in_ed.c b/src/plugins/nat/out2in_ed.c
index 798df12b851..667d33e6266 100644
--- a/src/plugins/nat/out2in_ed.c
+++ b/src/plugins/nat/out2in_ed.c
@@ -71,7 +71,8 @@ icmp_out2in_ed_slow_path (snat_main_t * sm, vlib_buffer_t * b0,
vlib_node_runtime_t * node, u32 next0, f64 now,
u32 thread_index, snat_session_t ** p_s0)
{
- snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
+ vlib_main_t *vm = vlib_get_main ();
+
next0 = icmp_out2in (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
next0, thread_index, p_s0, 0);
snat_session_t *s0 = *p_s0;
@@ -80,7 +81,7 @@ icmp_out2in_ed_slow_path (snat_main_t * sm, vlib_buffer_t * b0,
/* Accounting */
nat44_session_update_counters (s0, now,
vlib_buffer_length_in_chain
- (tsm->vlib_main, b0), thread_index);
+ (vm, b0), thread_index);
/* Per-user LRU list maintenance */
nat44_session_update_lru (sm, s0, thread_index);
}
@@ -328,7 +329,8 @@ create_bypass_for_fwd (snat_main_t * sm, vlib_buffer_t * b, ip4_header_t * ip,
udp_header_t *udp;
snat_session_t *s = 0;
snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
- f64 now = vlib_time_now (vlib_mains[thread_index]);
+ vlib_main_t *vm = vlib_get_main ();
+ f64 now = vlib_time_now (vm);
u16 l_port, r_port;
if (ip->protocol == IP_PROTOCOL_ICMP)
@@ -436,6 +438,7 @@ icmp_match_out2in_ed (snat_main_t * sm, vlib_node_runtime_t * node,
u8 dont_translate = 0, is_addr_only, identity_nat;
snat_session_key_t e_key, l_key;
u16 l_port, r_port;
+ vlib_main_t *vm = vlib_get_main ();
sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
rx_fib_index = ip4_fib_table_get_index_for_sw_if_index (sw_if_index);
@@ -508,9 +511,7 @@ icmp_match_out2in_ed (snat_main_t * sm, vlib_node_runtime_t * node,
/* Create session initiated by host from external network */
s = create_session_for_static_mapping_ed (sm, b, l_key, e_key, node,
rx_fib_index, thread_index, 0,
- 0,
- vlib_time_now
- (tsm->vlib_main));
+ 0, vlib_time_now (vm));
if (!s)
{