aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2021-03-15 19:52:57 +0100
committerKlement Sekera <ksekera@cisco.com>2021-03-15 22:07:43 +0100
commit3a5bd85476311d4ad2b0cbbca3f98d53f13a3afb (patch)
tree2a17c25f10fe3227b12460f3bf82743856d18d47
parent7db75dd0d32d92674bbb7aa1b23341e8a349e05a (diff)
nat: get rid of worker selection callbacks
Make code easier to read and debug. Type: improvement Signed-off-by: Klement Sekera <ksekera@cisco.com> Change-Id: Ib52a4cdd3bcdcc475053aa32af3964c00859e1cd
-rw-r--r--src/plugins/nat/nat44-ed/nat44_ed.c49
-rw-r--r--src/plugins/nat/nat44-ed/nat44_ed.h17
-rw-r--r--src/plugins/nat/nat44-ed/nat44_ed_api.c5
-rw-r--r--src/plugins/nat/nat44-ed/nat44_ed_handoff.c30
-rw-r--r--src/plugins/nat/nat44-ei/nat44_ei.c10
-rw-r--r--src/plugins/nat/nat44-ei/nat44_ei.h12
-rw-r--r--src/plugins/nat/nat44-ei/nat44_ei_api.c5
-rw-r--r--src/plugins/nat/nat44-ei/nat44_ei_handoff.c30
8 files changed, 77 insertions, 81 deletions
diff --git a/src/plugins/nat/nat44-ed/nat44_ed.c b/src/plugins/nat/nat44-ed/nat44_ed.c
index 007296e065f..c01a2454e0f 100644
--- a/src/plugins/nat/nat44-ed/nat44_ed.c
+++ b/src/plugins/nat/nat44-ed/nat44_ed.c
@@ -176,13 +176,6 @@ static void nat44_ed_db_init (u32 translations, u32 translation_buckets);
static void nat44_ed_db_free ();
-static u32
-nat44_ed_get_worker_out2in_cb (vlib_buffer_t * b, ip4_header_t * ip,
- u32 rx_fib_index, u8 is_output);
-
-static u32 nat44_ed_get_worker_in2out_cb (vlib_buffer_t *b, ip4_header_t *ip,
- u32 rx_fib_index, u8 is_output);
-
u32 nat_calc_bihash_buckets (u32 n_elts);
u8 *
@@ -723,8 +716,8 @@ snat_add_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
ip4_header_t ip = {
.src_address = m->local_addr,
};
- vec_add1 (m->workers,
- sm->worker_in2out_cb (0, &ip, m->fib_index, 0));
+ vec_add1 (m->workers, nat44_ed_get_in2out_worker_index (
+ 0, &ip, m->fib_index, 0));
tsm = vec_elt_at_index (sm->per_thread_data, m->workers[0]);
}
else
@@ -971,7 +964,8 @@ nat44_add_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
.src_address = locals[i].addr,
};
bitmap = clib_bitmap_set (
- bitmap, sm->worker_in2out_cb (0, &ip, m->fib_index, 0), 1);
+ bitmap,
+ nat44_ed_get_in2out_worker_index (0, &ip, m->fib_index, 0), 1);
}
}
@@ -1051,7 +1045,7 @@ nat44_add_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
};
tsm = vec_elt_at_index (
sm->per_thread_data,
- sm->worker_in2out_cb (0, &ip, m->fib_index, 0));
+ nat44_ed_get_in2out_worker_index (0, &ip, m->fib_index, 0));
}
else
tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
@@ -1164,9 +1158,9 @@ nat44_lb_static_mapping_add_del_local (ip4_address_t e_addr, u16 e_port,
ip4_header_t ip = {
.src_address = local->addr,
};
- tsm =
- vec_elt_at_index (sm->per_thread_data,
- sm->worker_in2out_cb (0, &ip, m->fib_index, 0));
+ tsm = vec_elt_at_index (
+ sm->per_thread_data,
+ nat44_ed_get_in2out_worker_index (0, &ip, m->fib_index, 0));
}
else
tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
@@ -1197,7 +1191,8 @@ nat44_lb_static_mapping_add_del_local (ip4_address_t e_addr, u16 e_port,
ip4_header_t ip;
ip.src_address.as_u32 = local->addr.as_u32,
bitmap = clib_bitmap_set (
- bitmap, sm->worker_in2out_cb (0, &ip, local->fib_index, 0), 1);
+ bitmap,
+ nat44_ed_get_in2out_worker_index (0, &ip, local->fib_index, 0), 1);
}
}
@@ -2140,9 +2135,6 @@ nat44_plugin_enable (nat44_config_t c)
sm->outside_fib_index = fib_table_find_or_create_and_lock (
FIB_PROTOCOL_IP4, c.outside_vrf, sm->fib_src_hi);
- sm->worker_in2out_cb = nat44_ed_get_worker_in2out_cb;
- sm->worker_out2in_cb = nat44_ed_get_worker_out2in_cb;
-
nat44_ed_db_init (sm->max_translations_per_thread, sm->translation_buckets);
nat_affinity_enable ();
@@ -2423,8 +2415,8 @@ snat_static_mapping_match (vlib_main_t *vm, snat_main_t *sm,
.src_address = local->addr,
};
- if (sm->worker_in2out_cb (0, &ip, m->fib_index, 0) ==
- thread_index)
+ if (nat44_ed_get_in2out_worker_index (0, &ip, m->fib_index,
+ 0) == thread_index)
{
vec_add1 (tmp, i);
}
@@ -2499,9 +2491,9 @@ end:
return 0;
}
-static u32
-nat44_ed_get_worker_in2out_cb (vlib_buffer_t *b, ip4_header_t *ip,
- u32 rx_fib_index, u8 is_output)
+u32
+nat44_ed_get_in2out_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
+ u32 rx_fib_index, u8 is_output)
{
snat_main_t *sm = &snat_main;
u32 next_worker_index = sm->first_worker_index;
@@ -2602,9 +2594,9 @@ out:
return next_worker_index;
}
-static u32
-nat44_ed_get_worker_out2in_cb (vlib_buffer_t * b, ip4_header_t * ip,
- u32 rx_fib_index, u8 is_output)
+u32
+nat44_ed_get_out2in_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
+ u32 rx_fib_index, u8 is_output)
{
snat_main_t *sm = &snat_main;
clib_bihash_kv_8_8_t kv, value;
@@ -3162,8 +3154,9 @@ nat44_del_ed_session (snat_main_t * sm, ip4_address_t * addr, u16 port,
ip.dst_address.as_u32 = ip.src_address.as_u32 = addr->as_u32;
if (sm->num_workers > 1)
- tsm = vec_elt_at_index (sm->per_thread_data,
- sm->worker_in2out_cb (0, &ip, fib_index, 0));
+ tsm = vec_elt_at_index (
+ sm->per_thread_data,
+ nat44_ed_get_in2out_worker_index (0, &ip, fib_index, 0));
else
tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
diff --git a/src/plugins/nat/nat44-ed/nat44_ed.h b/src/plugins/nat/nat44-ed/nat44_ed.h
index 66276285584..c9ae089210d 100644
--- a/src/plugins/nat/nat44-ed/nat44_ed.h
+++ b/src/plugins/nat/nat44-ed/nat44_ed.h
@@ -489,17 +489,12 @@ typedef struct
struct snat_main_s;
-/* Return worker thread index for given packet */
-typedef u32 (snat_get_worker_in2out_function_t) (vlib_buffer_t *b,
- ip4_header_t *ip,
- u32 rx_fib_index,
- u8 is_output);
-
-typedef u32 (snat_get_worker_out2in_function_t) (vlib_buffer_t * b,
- ip4_header_t * ip,
- u32 rx_fib_index,
- u8 is_output);
+u32 nat44_ed_get_in2out_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
+ u32 rx_fib_index, u8 is_output);
+u32 nat44_ed_get_out2in_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
+ u32 rx_fib_index, u8 is_output);
+/* Return worker thread index for given packet */
/* NAT address and port allocation function */
typedef int (nat_alloc_out_addr_and_port_function_t) (snat_address_t *
addresses,
@@ -517,8 +512,6 @@ typedef struct snat_main_s
u32 num_workers;
u32 first_worker_index;
u32 *workers;
- snat_get_worker_in2out_function_t *worker_in2out_cb;
- snat_get_worker_out2in_function_t *worker_out2in_cb;
u16 port_per_thread;
/* Per thread data */
diff --git a/src/plugins/nat/nat44-ed/nat44_ed_api.c b/src/plugins/nat/nat44-ed/nat44_ed_api.c
index 3089f68950f..22737ad7e56 100644
--- a/src/plugins/nat/nat44-ed/nat44_ed_api.c
+++ b/src/plugins/nat/nat44-ed/nat44_ed_api.c
@@ -1529,8 +1529,9 @@ vl_api_nat44_user_session_dump_t_handler (vl_api_nat44_user_session_dump_t *
ip.src_address.as_u32 = ukey.addr.as_u32;
ukey.fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->vrf_id));
if (sm->num_workers > 1)
- tsm = vec_elt_at_index (sm->per_thread_data,
- sm->worker_in2out_cb (0, &ip, ukey.fib_index, 0));
+ tsm = vec_elt_at_index (
+ sm->per_thread_data,
+ nat44_ed_get_in2out_worker_index (0, &ip, ukey.fib_index, 0));
else
tsm = vec_elt_at_index (sm->per_thread_data, sm->num_workers);
diff --git a/src/plugins/nat/nat44-ed/nat44_ed_handoff.c b/src/plugins/nat/nat44-ed/nat44_ed_handoff.c
index e286df93a6e..597a08c77b4 100644
--- a/src/plugins/nat/nat44-ed/nat44_ed_handoff.c
+++ b/src/plugins/nat/nat44-ed/nat44_ed_handoff.c
@@ -157,17 +157,25 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
if (is_in2out)
{
- ti[0] = sm->worker_in2out_cb (b[0], ip0, rx_fib_index0, is_output);
- ti[1] = sm->worker_in2out_cb (b[1], ip1, rx_fib_index1, is_output);
- ti[2] = sm->worker_in2out_cb (b[2], ip2, rx_fib_index2, is_output);
- ti[3] = sm->worker_in2out_cb (b[3], ip3, rx_fib_index3, is_output);
+ ti[0] = nat44_ed_get_in2out_worker_index (b[0], ip0, rx_fib_index0,
+ is_output);
+ ti[1] = nat44_ed_get_in2out_worker_index (b[1], ip1, rx_fib_index1,
+ is_output);
+ ti[2] = nat44_ed_get_in2out_worker_index (b[2], ip2, rx_fib_index2,
+ is_output);
+ ti[3] = nat44_ed_get_in2out_worker_index (b[3], ip3, rx_fib_index3,
+ is_output);
}
else
{
- ti[0] = sm->worker_out2in_cb (b[0], ip0, rx_fib_index0, is_output);
- ti[1] = sm->worker_out2in_cb (b[1], ip1, rx_fib_index1, is_output);
- ti[2] = sm->worker_out2in_cb (b[2], ip2, rx_fib_index2, is_output);
- ti[3] = sm->worker_out2in_cb (b[3], ip3, rx_fib_index3, is_output);
+ ti[0] = nat44_ed_get_out2in_worker_index (b[0], ip0, rx_fib_index0,
+ is_output);
+ ti[1] = nat44_ed_get_out2in_worker_index (b[1], ip1, rx_fib_index1,
+ is_output);
+ ti[2] = nat44_ed_get_out2in_worker_index (b[2], ip2, rx_fib_index2,
+ is_output);
+ ti[3] = nat44_ed_get_out2in_worker_index (b[3], ip3, rx_fib_index3,
+ is_output);
}
if (ti[0] == thread_index)
@@ -218,11 +226,13 @@ nat44_worker_handoff_fn_inline (vlib_main_t * vm,
if (is_in2out)
{
- ti[0] = sm->worker_in2out_cb (b[0], ip0, rx_fib_index0, is_output);
+ ti[0] = nat44_ed_get_in2out_worker_index (b[0], ip0, rx_fib_index0,
+ is_output);
}
else
{
- ti[0] = sm->worker_out2in_cb (b[0], ip0, rx_fib_index0, is_output);
+ ti[0] = nat44_ed_get_out2in_worker_index (b[0], ip0, rx_fib_index0,
+ is_output);
}
if (ti[0] == thread_index)
diff --git a/src/plugins/nat/nat44-ei/nat44_ei.c b/src/plugins/nat/nat44-ei/nat44_ei.c
index 67757015b1d..d7e74bbc725 100644
--- a/src/plugins/nat/nat44-ei/nat44_ei.c
+++ b/src/plugins/nat/nat44-ei/nat44_ei.c
@@ -322,8 +322,6 @@ nat44_ei_init (vlib_main_t *vm)
nm->fq_out2in_index = ~0;
nm->fq_in2out_index = ~0;
nm->fq_in2out_output_index = ~0;
- nm->worker_in2out_cb = nat44_ei_get_in2out_worker_index;
- nm->worker_out2in_cb = nat44_ei_get_out2in_worker_index;
nm->log_level = NAT_LOG_ERROR;
@@ -1751,8 +1749,9 @@ nat44_ei_del_session (nat44_ei_main_t *nm, ip4_address_t *addr, u16 port,
ip.dst_address.as_u32 = ip.src_address.as_u32 = addr->as_u32;
if (nm->num_workers > 1)
- tnm = vec_elt_at_index (nm->per_thread_data,
- nm->worker_in2out_cb (&ip, fib_index, 0));
+ tnm =
+ vec_elt_at_index (nm->per_thread_data,
+ nat44_ei_get_in2out_worker_index (&ip, fib_index, 0));
else
tnm = vec_elt_at_index (nm->per_thread_data, nm->num_workers);
@@ -2036,7 +2035,8 @@ nat44_ei_add_del_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
ip4_header_t ip = {
.src_address = m->local_addr,
};
- vec_add1 (m->workers, nm->worker_in2out_cb (&ip, m->fib_index, 0));
+ vec_add1 (m->workers,
+ nat44_ei_get_in2out_worker_index (&ip, m->fib_index, 0));
tnm = vec_elt_at_index (nm->per_thread_data, m->workers[0]);
}
else
diff --git a/src/plugins/nat/nat44-ei/nat44_ei.h b/src/plugins/nat/nat44-ei/nat44_ei.h
index 7bc1b304fb3..29c92e96cbd 100644
--- a/src/plugins/nat/nat44-ei/nat44_ei.h
+++ b/src/plugins/nat/nat44-ei/nat44_ei.h
@@ -301,16 +301,6 @@ typedef struct
} nat44_ei_main_per_thread_data_t;
-/* Return worker thread index for given packet */
-typedef u32 (nat44_ei_get_worker_in2out_function_t) (ip4_header_t *ip,
- u32 rx_fib_index,
- u8 is_output);
-
-typedef u32 (nat44_ei_get_worker_out2in_function_t) (vlib_buffer_t *b,
- ip4_header_t *ip,
- u32 rx_fib_index,
- u8 is_output);
-
typedef struct
{
u32 cached_sw_if_index;
@@ -366,8 +356,6 @@ typedef struct nat44_ei_main_s
u32 num_workers;
u32 first_worker_index;
u32 *workers;
- nat44_ei_get_worker_in2out_function_t *worker_in2out_cb;
- nat44_ei_get_worker_out2in_function_t *worker_out2in_cb;
u16 port_per_thread;
/* Main lookup tables */
diff --git a/src/plugins/nat/nat44-ei/nat44_ei_api.c b/src/plugins/nat/nat44-ei/nat44_ei_api.c
index 74e077485cc..5ec07b0511f 100644
--- a/src/plugins/nat/nat44-ei/nat44_ei_api.c
+++ b/src/plugins/nat/nat44-ei/nat44_ei_api.c
@@ -1066,8 +1066,9 @@ vl_api_nat44_ei_user_session_dump_t_handler (
ukey.fib_index = fib_table_find (FIB_PROTOCOL_IP4, ntohl (mp->vrf_id));
key.key = ukey.as_u64;
if (nm->num_workers > 1)
- tnm = vec_elt_at_index (nm->per_thread_data,
- nm->worker_in2out_cb (&ip, ukey.fib_index, 0));
+ tnm = vec_elt_at_index (
+ nm->per_thread_data,
+ nat44_ei_get_in2out_worker_index (&ip, ukey.fib_index, 0));
else
tnm = vec_elt_at_index (nm->per_thread_data, nm->num_workers);
diff --git a/src/plugins/nat/nat44-ei/nat44_ei_handoff.c b/src/plugins/nat/nat44-ei/nat44_ei_handoff.c
index 6b8db37d414..6b172dceeb3 100644
--- a/src/plugins/nat/nat44-ei/nat44_ei_handoff.c
+++ b/src/plugins/nat/nat44-ei/nat44_ei_handoff.c
@@ -153,17 +153,25 @@ nat44_ei_worker_handoff_fn_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
if (is_in2out)
{
- ti[0] = nm->worker_in2out_cb (ip0, rx_fib_index0, is_output);
- ti[1] = nm->worker_in2out_cb (ip1, rx_fib_index1, is_output);
- ti[2] = nm->worker_in2out_cb (ip2, rx_fib_index2, is_output);
- ti[3] = nm->worker_in2out_cb (ip3, rx_fib_index3, is_output);
+ ti[0] =
+ nat44_ei_get_in2out_worker_index (ip0, rx_fib_index0, is_output);
+ ti[1] =
+ nat44_ei_get_in2out_worker_index (ip1, rx_fib_index1, is_output);
+ ti[2] =
+ nat44_ei_get_in2out_worker_index (ip2, rx_fib_index2, is_output);
+ ti[3] =
+ nat44_ei_get_in2out_worker_index (ip3, rx_fib_index3, is_output);
}
else
{
- ti[0] = nm->worker_out2in_cb (b[0], ip0, rx_fib_index0, is_output);
- ti[1] = nm->worker_out2in_cb (b[1], ip1, rx_fib_index1, is_output);
- ti[2] = nm->worker_out2in_cb (b[2], ip2, rx_fib_index2, is_output);
- ti[3] = nm->worker_out2in_cb (b[3], ip3, rx_fib_index3, is_output);
+ ti[0] = nat44_ei_get_out2in_worker_index (b[0], ip0, rx_fib_index0,
+ is_output);
+ ti[1] = nat44_ei_get_out2in_worker_index (b[1], ip1, rx_fib_index1,
+ is_output);
+ ti[2] = nat44_ei_get_out2in_worker_index (b[2], ip2, rx_fib_index2,
+ is_output);
+ ti[3] = nat44_ei_get_out2in_worker_index (b[3], ip3, rx_fib_index3,
+ is_output);
}
if (ti[0] == thread_index)
@@ -213,11 +221,13 @@ nat44_ei_worker_handoff_fn_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
if (is_in2out)
{
- ti[0] = nm->worker_in2out_cb (ip0, rx_fib_index0, is_output);
+ ti[0] =
+ nat44_ei_get_in2out_worker_index (ip0, rx_fib_index0, is_output);
}
else
{
- ti[0] = nm->worker_out2in_cb (b[0], ip0, rx_fib_index0, is_output);
+ ti[0] = nat44_ei_get_out2in_worker_index (b[0], ip0, rx_fib_index0,
+ is_output);
}
if (ti[0] == thread_index)