Make code easier to read and debug.
Type: improvement
Signed-off-by: Klement Sekera <ksekera@cisco.com>
Change-Id: Ib52a4cdd3bcdcc475053aa32af3964c00859e1cd
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 *
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
.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);
}
}
};
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);
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);
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);
}
}
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 ();
.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);
}
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;
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;
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);
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,
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 */
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);
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)
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)
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;
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);
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
} 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;
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 */
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);
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)
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)