summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2021-02-02 20:15:59 +0100
committerOle Tr�an <otroan@employees.org>2021-02-09 09:55:09 +0000
commit070387d3f4b0b5a5742b95fca19404cb50fa9927 (patch)
tree89832d74c698377a33319dbb2985d9cb81dc8e85 /src/plugins/nat
parent751bb131ef504b64fe82f393df21dba95ca92e97 (diff)
nat: improve type safety and remove unused param
Type: improvement Change-Id: I456f9b14e6a4eb46c9c49f6e09acccae530e4ebc Signed-off-by: Klement Sekera <ksekera@cisco.com>
Diffstat (limited to 'src/plugins/nat')
-rw-r--r--src/plugins/nat/nat.h70
-rw-r--r--src/plugins/nat/nat44-ei/nat44_ei_in2out.c47
-rw-r--r--src/plugins/nat/nat44-ei/nat44_ei_out2in.c55
3 files changed, 76 insertions, 96 deletions
diff --git a/src/plugins/nat/nat.h b/src/plugins/nat/nat.h
index d7f60dd2145..e913484887a 100644
--- a/src/plugins/nat/nat.h
+++ b/src/plugins/nat/nat.h
@@ -525,17 +525,11 @@ typedef struct
struct snat_main_s;
/* ICMP session match function */
-typedef u32 (snat_icmp_match_function_t) (struct snat_main_s * sm,
- vlib_node_runtime_t * node,
- u32 thread_index,
- vlib_buffer_t * b0,
- ip4_header_t * ip0,
- ip4_address_t * addr,
- u16 * port,
- u32 * fib_index,
- nat_protocol_t * proto,
- void *d, void *e,
- u8 * dont_translate);
+typedef u32 (snat_icmp_match_function_t) (
+ struct snat_main_s *sm, vlib_node_runtime_t *node, u32 thread_index,
+ vlib_buffer_t *b0, ip4_header_t *ip0, ip4_address_t *addr, u16 *port,
+ u32 *fib_index, nat_protocol_t *proto, snat_session_t **s_out,
+ u8 *dont_translate);
/* Return worker thread index for given packet */
typedef u32 (snat_get_worker_in2out_function_t) (ip4_header_t * ip,
@@ -1132,40 +1126,26 @@ do \
nat_elog_X1(SNAT_LOG_INFO, "[info] " nat_elog_fmt_str, nat_elog_fmt_arg, nat_elog_val1)
/* ICMP session match functions */
-u32 icmp_match_in2out_fast (snat_main_t * sm, vlib_node_runtime_t * node,
- u32 thread_index, vlib_buffer_t * b0,
- ip4_header_t * ip0, ip4_address_t * addr,
- u16 * port, u32 * fib_index,
- nat_protocol_t * proto, void *d, void *e,
- u8 * dont_translate);
-u32 icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
- u32 thread_index, vlib_buffer_t * b0,
- ip4_header_t * ip0, ip4_address_t * addr,
- u16 * port, u32 * fib_index,
- nat_protocol_t * proto, void *d, void *e,
- u8 * dont_translate);
-u32 icmp_match_out2in_fast (snat_main_t * sm, vlib_node_runtime_t * node,
- u32 thread_index, vlib_buffer_t * b0,
- ip4_header_t * ip0, ip4_address_t * addr,
- u16 * port, u32 * fib_index,
- nat_protocol_t * proto, void *d, void *e,
- u8 * dont_translate);
-u32 icmp_match_out2in_slow (snat_main_t * sm, vlib_node_runtime_t * node,
- u32 thread_index, vlib_buffer_t * b0,
- ip4_header_t * ip0, ip4_address_t * addr,
- u16 * port, u32 * fib_index,
- nat_protocol_t * proto, void *d, void *e,
- u8 * dont_translate);
-
-u32 icmp_in2out (snat_main_t * sm, vlib_buffer_t * b0, ip4_header_t * ip0,
- icmp46_header_t * icmp0, u32 sw_if_index0, u32 rx_fib_index0,
- vlib_node_runtime_t * node, u32 next0, u32 thread_index,
- void *d, void *e);
-
-u32 icmp_out2in (snat_main_t * sm, vlib_buffer_t * b0, ip4_header_t * ip0,
- icmp46_header_t * icmp0, u32 sw_if_index0, u32 rx_fib_index0,
- vlib_node_runtime_t * node, u32 next0, u32 thread_index,
- void *d, void *e);
+u32 icmp_match_in2out_fast (snat_main_t *sm, vlib_node_runtime_t *node,
+ u32 thread_index, vlib_buffer_t *b0,
+ ip4_header_t *ip0, ip4_address_t *addr, u16 *port,
+ u32 *fib_index, nat_protocol_t *proto,
+ snat_session_t **s0, u8 *dont_translate);
+u32 icmp_match_in2out_slow (snat_main_t *sm, vlib_node_runtime_t *node,
+ u32 thread_index, vlib_buffer_t *b0,
+ ip4_header_t *ip0, ip4_address_t *addr, u16 *port,
+ u32 *fib_index, nat_protocol_t *proto,
+ snat_session_t **s0, u8 *dont_translate);
+u32 icmp_match_out2in_fast (snat_main_t *sm, vlib_node_runtime_t *node,
+ u32 thread_index, vlib_buffer_t *b0,
+ ip4_header_t *ip0, ip4_address_t *addr, u16 *port,
+ u32 *fib_index, nat_protocol_t *proto,
+ snat_session_t **s0, u8 *dont_translate);
+u32 icmp_match_out2in_slow (snat_main_t *sm, vlib_node_runtime_t *node,
+ u32 thread_index, vlib_buffer_t *b0,
+ ip4_header_t *ip0, ip4_address_t *addr, u16 *port,
+ u32 *fib_index, nat_protocol_t *proto,
+ snat_session_t **s0, u8 *dont_translate);
/* hairpinning functions */
u32 snat_icmp_hairpinning (snat_main_t *sm, vlib_buffer_t *b0,
diff --git a/src/plugins/nat/nat44-ei/nat44_ei_in2out.c b/src/plugins/nat/nat44-ei/nat44_ei_in2out.c
index 6a4658513d7..ad0007bb8df 100644
--- a/src/plugins/nat/nat44-ei/nat44_ei_in2out.c
+++ b/src/plugins/nat/nat44-ei/nat44_ei_in2out.c
@@ -444,11 +444,11 @@ icmp_get_key (vlib_buffer_t * b, ip4_header_t * ip0,
* @param e optional parameter
*/
u32
-icmp_match_in2out_slow (snat_main_t * sm, vlib_node_runtime_t * node,
- u32 thread_index, vlib_buffer_t * b0,
- ip4_header_t * ip0, ip4_address_t * addr, u16 * port,
- u32 * fib_index, nat_protocol_t * proto, void *d,
- void *e, u8 * dont_translate)
+icmp_match_in2out_slow (snat_main_t *sm, vlib_node_runtime_t *node,
+ u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0,
+ ip4_address_t *addr, u16 *port, u32 *fib_index,
+ nat_protocol_t *proto, snat_session_t **p_s0,
+ u8 *dont_translate)
{
snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
u32 sw_if_index0;
@@ -542,8 +542,8 @@ out:
*port = s0->out2in.port;
*fib_index = s0->out2in.fib_index;
}
- if (d)
- *(snat_session_t **) (d) = s0;
+ if (p_s0)
+ *p_s0 = s0;
return next0;
}
#endif
@@ -564,11 +564,11 @@ out:
* @param e optional parameter
*/
u32
-icmp_match_in2out_fast (snat_main_t * sm, vlib_node_runtime_t * node,
- u32 thread_index, vlib_buffer_t * b0,
- ip4_header_t * ip0, ip4_address_t * addr, u16 * port,
- u32 * fib_index, nat_protocol_t * proto, void *d,
- void *e, u8 * dont_translate)
+icmp_match_in2out_fast (snat_main_t *sm, vlib_node_runtime_t *node,
+ u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0,
+ ip4_address_t *addr, u16 *port, u32 *fib_index,
+ nat_protocol_t *proto, snat_session_t **s0,
+ u8 *dont_translate)
{
u32 sw_if_index0;
u8 is_addr_only;
@@ -632,16 +632,17 @@ out:
}
#endif
+u32 icmp_in2out (snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0,
+ icmp46_header_t *icmp0, u32 sw_if_index0, u32 rx_fib_index0,
+ vlib_node_runtime_t *node, u32 next0, u32 thread_index,
+ snat_session_t **p_s0);
+
#ifndef CLIB_MARCH_VARIANT
u32
-icmp_in2out (snat_main_t * sm,
- vlib_buffer_t * b0,
- ip4_header_t * ip0,
- icmp46_header_t * icmp0,
- u32 sw_if_index0,
- u32 rx_fib_index0,
- vlib_node_runtime_t * node,
- u32 next0, u32 thread_index, void *d, void *e)
+icmp_in2out (snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0,
+ icmp46_header_t *icmp0, u32 sw_if_index0, u32 rx_fib_index0,
+ vlib_node_runtime_t *node, u32 next0, u32 thread_index,
+ snat_session_t **p_s0)
{
vlib_main_t *vm = vlib_get_main ();
ip4_address_t addr;
@@ -664,7 +665,7 @@ icmp_in2out (snat_main_t * sm,
next0_tmp =
sm->icmp_match_in2out_cb (sm, node, thread_index, b0, ip0, &addr, &port,
- &fib_index, &protocol, d, e, &dont_translate);
+ &fib_index, &protocol, p_s0, &dont_translate);
if (next0_tmp != ~0)
next0 = next0_tmp;
if (next0 == SNAT_IN2OUT_NEXT_DROP || dont_translate)
@@ -806,7 +807,7 @@ icmp_in2out_slow_path (snat_main_t * sm,
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);
+ next0, thread_index, p_s0);
snat_session_t *s0 = *p_s0;
if (PREDICT_TRUE (next0 != SNAT_IN2OUT_NEXT_DROP && s0))
{
@@ -1819,7 +1820,7 @@ VLIB_NODE_FN (snat_in2out_fast_node) (vlib_main_t * vm,
if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
{
next0 = icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0,
- rx_fib_index0, node, next0, ~0, 0, 0);
+ rx_fib_index0, node, next0, ~0, 0);
goto trace0;
}
diff --git a/src/plugins/nat/nat44-ei/nat44_ei_out2in.c b/src/plugins/nat/nat44-ei/nat44_ei_out2in.c
index f0b6427613a..ca3c272a26c 100644
--- a/src/plugins/nat/nat44-ei/nat44_ei_out2in.c
+++ b/src/plugins/nat/nat44-ei/nat44_ei_out2in.c
@@ -315,12 +315,11 @@ icmp_get_key (vlib_buffer_t * b, ip4_header_t * ip0,
* @param e optional parameter
*/
u32
-icmp_match_out2in_slow (snat_main_t * sm, vlib_node_runtime_t * node,
- u32 thread_index, vlib_buffer_t * b0,
- ip4_header_t * ip0, ip4_address_t * addr,
- u16 * port, u32 * fib_index,
- nat_protocol_t * proto, void *d, void *e,
- u8 * dont_translate)
+icmp_match_out2in_slow (snat_main_t *sm, vlib_node_runtime_t *node,
+ u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0,
+ ip4_address_t *addr, u16 *port, u32 *fib_index,
+ nat_protocol_t *proto, snat_session_t **p_s0,
+ u8 *dont_translate)
{
snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
u32 sw_if_index0;
@@ -434,8 +433,8 @@ out:
*port = s0->in2out.port;
*fib_index = s0->in2out.fib_index;
}
- if (d)
- *(snat_session_t **) d = s0;
+ if (p_s0)
+ *p_s0 = s0;
return next0;
}
#endif
@@ -456,12 +455,11 @@ out:
* @param e optional parameter
*/
u32
-icmp_match_out2in_fast (snat_main_t * sm, vlib_node_runtime_t * node,
- u32 thread_index, vlib_buffer_t * b0,
- ip4_header_t * ip0, ip4_address_t * mapping_addr,
- u16 * mapping_port, u32 * mapping_fib_index,
- nat_protocol_t * proto, void *d, void *e,
- u8 * dont_translate)
+icmp_match_out2in_fast (snat_main_t *sm, vlib_node_runtime_t *node,
+ u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0,
+ ip4_address_t *mapping_addr, u16 *mapping_port,
+ u32 *mapping_fib_index, nat_protocol_t *proto,
+ snat_session_t **p_s0, u8 *dont_translate)
{
u32 sw_if_index0;
u32 rx_fib_index0;
@@ -514,16 +512,17 @@ out:
}
#endif
+u32 icmp_out2in (snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0,
+ icmp46_header_t *icmp0, u32 sw_if_index0, u32 rx_fib_index0,
+ vlib_node_runtime_t *node, u32 next0, u32 thread_index,
+ snat_session_t **p_s0);
+
#ifndef CLIB_MARCH_VARIANT
u32
-icmp_out2in (snat_main_t * sm,
- vlib_buffer_t * b0,
- ip4_header_t * ip0,
- icmp46_header_t * icmp0,
- u32 sw_if_index0,
- u32 rx_fib_index0,
- vlib_node_runtime_t * node,
- u32 next0, u32 thread_index, void *d, void *e)
+icmp_out2in (snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0,
+ icmp46_header_t *icmp0, u32 sw_if_index0, u32 rx_fib_index0,
+ vlib_node_runtime_t *node, u32 next0, u32 thread_index,
+ snat_session_t **p_s0)
{
icmp_echo_header_t *echo0, *inner_echo0 = 0;
ip4_header_t *inner_ip0 = 0;
@@ -543,9 +542,9 @@ icmp_out2in (snat_main_t * sm,
echo0 = (icmp_echo_header_t *) (icmp0 + 1);
- next0_tmp = sm->icmp_match_out2in_cb (sm, node, thread_index, b0, ip0,
- &addr, &port, &fib_index, &proto,
- d, e, &dont_translate);
+ next0_tmp =
+ sm->icmp_match_out2in_cb (sm, node, thread_index, b0, ip0, &addr, &port,
+ &fib_index, &proto, p_s0, &dont_translate);
if (next0_tmp != ~0)
next0 = next0_tmp;
if (next0 == SNAT_OUT2IN_NEXT_DROP || dont_translate)
@@ -670,7 +669,7 @@ icmp_out2in_slow_path (snat_main_t * sm,
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);
+ next0, thread_index, p_s0);
snat_session_t *s0 = *p_s0;
if (PREDICT_TRUE (next0 != SNAT_OUT2IN_NEXT_DROP && s0))
{
@@ -1442,8 +1441,8 @@ VLIB_NODE_FN (snat_out2in_fast_node) (vlib_main_t * vm,
if (PREDICT_FALSE (proto0 == NAT_PROTOCOL_ICMP))
{
- next0 = icmp_out2in (sm, b0, ip0, icmp0, sw_if_index0,
- rx_fib_index0, node, next0, ~0, 0, 0);
+ next0 = icmp_out2in (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
+ node, next0, ~0, 0);
goto trace00;
}