summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/nat.h
diff options
context:
space:
mode:
authorKlement Sekera <ksekera@cisco.com>2020-05-19 17:47:23 +0000
committerOle Trøan <otroan@employees.org>2020-06-08 13:46:35 +0000
commite3621518046ad7f37ccf77c549a93375ab89da19 (patch)
treeaab4446172fe661f3a2eaa58c1fc4cc1d209219b /src/plugins/nat/nat.h
parentc1f0d9c105c25c67d9ef86a53c10d43d40b61fe0 (diff)
nat: more long read after short write optimization
Replace whitespread (mis)use of snat_session_key_t by proper function arguments where applicable and inline functions to calculate hash keys instead of using structs for that. Make all hash tables use same network byte order port so that there is no longer a discrepancy between static mappings using host byte order while in2out/out2in tables using network byte order. Type: improvement Signed-off-by: Klement Sekera <ksekera@cisco.com> Change-Id: I80786d2f947c67824c101a13bb608f1fe1080f34
Diffstat (limited to 'src/plugins/nat/nat.h')
-rw-r--r--src/plugins/nat/nat.h134
1 files changed, 76 insertions, 58 deletions
diff --git a/src/plugins/nat/nat.h b/src/plugins/nat/nat.h
index fbf2105dea3..8b04e18b18b 100644
--- a/src/plugins/nat/nat.h
+++ b/src/plugins/nat/nat.h
@@ -68,21 +68,6 @@ typedef struct
u32 arc_next_index;
} nat_pre_trace_t;
-/* session key (4-tuple) */
-typedef struct
-{
- union
- {
- struct
- {
- ip4_address_t addr;
- u16 port;
- u16 protocol:3, fib_index:13;
- };
- u64 as_u64;
- };
-} snat_session_key_t;
-
/* deterministic session outside key */
typedef struct
{
@@ -251,11 +236,23 @@ typedef enum
/* *INDENT-OFF* */
typedef CLIB_PACKED(struct
{
- /* Outside network key */
- snat_session_key_t out2in;
+ /* Outside network tuple */
+ struct
+ {
+ ip4_address_t addr;
+ u32 fib_index;
+ u16 port;
+ } out2in;
- /* Inside network key */
- snat_session_key_t in2out;
+ /* Inside network tuple */
+ struct
+ {
+ ip4_address_t addr;
+ u32 fib_index;
+ u16 port;
+ } in2out;
+
+ nat_protocol_t nat_proto;
/* Flags */
u32 flags;
@@ -491,10 +488,13 @@ 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, u8 * p_proto,
- snat_session_key_t * p_value,
- u8 * p_dont_translate, void *d,
- void *e);
+ ip4_header_t * ip0,
+ ip4_address_t * addr,
+ u16 * port,
+ u32 * fib_index,
+ nat_protocol_t * proto,
+ void *d, void *e,
+ u8 * dont_translate);
/* Return worker thread index for given packet */
typedef u32 (snat_get_worker_in2out_function_t) (ip4_header_t * ip,
@@ -511,7 +511,9 @@ typedef int (nat_alloc_out_addr_and_port_function_t) (snat_address_t *
addresses,
u32 fib_index,
u32 thread_index,
- snat_session_key_t * k,
+ nat_protocol_t proto,
+ ip4_address_t * addr,
+ u16 * port,
u16 port_per_thread,
u32 snat_thread_index);
@@ -1008,48 +1010,54 @@ do \
/* 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, u8 * p_proto,
- snat_session_key_t * p_value,
- u8 * p_dont_translate, void *d, void *e);
+ 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, u8 * p_proto,
- snat_session_key_t * p_value,
- u8 * p_dont_translate, void *d, void *e);
+ 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, u8 * p_proto,
- snat_session_key_t * p_value,
- u8 * p_dont_translate, void *d, void *e);
+ 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, u8 * p_proto,
- snat_session_key_t * p_value,
- u8 * p_dont_translate, void *d, void *e);
+ 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 deterministic NAT session match functions */
u32 icmp_match_out2in_det (snat_main_t * sm, vlib_node_runtime_t * node,
u32 thread_index, vlib_buffer_t * b0,
- ip4_header_t * ip0, u8 * p_proto,
- snat_session_key_t * p_value,
- u8 * p_dont_translate, void *d, void *e);
+ 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_det (snat_main_t * sm, vlib_node_runtime_t * node,
u32 thread_index, vlib_buffer_t * b0,
- ip4_header_t * ip0, u8 * p_proto,
- snat_session_key_t * p_value,
- u8 * p_dont_translate, void *d, void *e);
+ 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 endpoint-dependent session match functions */
u32 icmp_match_out2in_ed (snat_main_t * sm, vlib_node_runtime_t * node,
u32 thread_index, vlib_buffer_t * b0,
- ip4_header_t * ip0, u8 * p_proto,
- snat_session_key_t * p_value,
- u8 * p_dont_translate, void *d, void *e);
+ 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_ed (snat_main_t * sm, vlib_node_runtime_t * node,
u32 thread_index, vlib_buffer_t * b0,
- ip4_header_t * ip0, u8 * p_proto,
- snat_session_key_t * p_value,
- u8 * p_dont_translate, void *d, void *e);
+ 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,
@@ -1348,11 +1356,13 @@ void nat_set_alloc_addr_and_port_default (void);
*
* @param addresses vector of outside addresses
* @param thread_index thread index
- * @param k address, port and protocol
+ * @param key address, port and protocol
*/
-void snat_free_outside_address_and_port (snat_address_t * addresses,
- u32 thread_index,
- snat_session_key_t * k);
+void
+snat_free_outside_address_and_port (snat_address_t * addresses,
+ u32 thread_index,
+ ip4_address_t * addr,
+ u16 port, nat_protocol_t protocol);
/**
* @brief Alloc outside address and port
@@ -1360,7 +1370,6 @@ void snat_free_outside_address_and_port (snat_address_t * addresses,
* @param addresses vector of outside addresses
* @param fib_index FIB table index
* @param thread_index thread index
- * @param k allocated address and port pair
* @param port_per_thread number of ports per thread
* @param snat_thread_index NAT thread index
*
@@ -1369,15 +1378,19 @@ void snat_free_outside_address_and_port (snat_address_t * addresses,
int snat_alloc_outside_address_and_port (snat_address_t * addresses,
u32 fib_index,
u32 thread_index,
- snat_session_key_t * k,
+ nat_protocol_t proto,
+ ip4_address_t * addr,
+ u16 * port,
u16 port_per_thread,
u32 snat_thread_index);
/**
* @brief Match NAT44 static mapping.
*
- * @param match address and port to match
- * @param mapping external/local address and port of the matched mapping
+ * @param key address and port to match
+ * @param addr external/local address of the matched mapping
+ * @param port port of the matched mapping
+ * @param fib_index fib index of the matched mapping
* @param by_external if 0 match by local address otherwise match by external
* address
* @param is_addr_only 1 if matched mapping is address only
@@ -1388,8 +1401,13 @@ int snat_alloc_outside_address_and_port (snat_address_t * addresses,
* @returns 0 if match found otherwise 1.
*/
int snat_static_mapping_match (snat_main_t * sm,
- snat_session_key_t match,
- snat_session_key_t * mapping,
+ ip4_address_t match_addr,
+ u16 match_port,
+ u32 match_fib_index,
+ nat_protocol_t match_protocol,
+ ip4_address_t * mapping_addr,
+ u16 * mapping_port,
+ u32 * mapping_fib_index,
u8 by_external,
u8 * is_addr_only,
twice_nat_type_t * twice_nat,