19 #ifndef __included_nat_inlines_h__ 20 #define __included_nat_inlines_h__ 30 snat_proto = (ip_proto == IP_PROTOCOL_UDP) ? SNAT_PROTOCOL_UDP : snat_proto;
31 snat_proto = (ip_proto == IP_PROTOCOL_TCP) ? SNAT_PROTOCOL_TCP : snat_proto;
33 (ip_proto == IP_PROTOCOL_ICMP) ? SNAT_PROTOCOL_ICMP : snat_proto;
35 (ip_proto == IP_PROTOCOL_ICMP6) ? SNAT_PROTOCOL_ICMP : snat_proto;
45 ip_proto = (snat_proto == SNAT_PROTOCOL_UDP) ? IP_PROTOCOL_UDP : ip_proto;
46 ip_proto = (snat_proto == SNAT_PROTOCOL_TCP) ? IP_PROTOCOL_TCP : ip_proto;
47 ip_proto = (snat_proto == SNAT_PROTOCOL_ICMP) ? IP_PROTOCOL_ICMP : ip_proto;
57 case ICMP4_destination_unreachable:
58 case ICMP4_time_exceeded:
59 case ICMP4_parameter_problem:
60 case ICMP4_source_quench:
62 case ICMP4_alternate_host_address:
70 u32 sw_if_index0,
u32 ip4_addr)
108 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
111 n_left_from =
vec_len (bi_vector);
113 while (n_left_from > 0)
116 while (n_left_from > 0 && n_left_to_next > 0)
118 u32 bi0 = to_next[0] = from[0];
127 n_left_to_next, bi0, next);
161 clib_bihash_add_del_8_8 (&tsm->
user_hash, &kv, 0);
181 u_key.
addr = ses->in2out.addr;
184 if (!clib_bihash_search_8_8 (&tsm->
user_hash, &kv, &value))
214 ses->i2o_fin_seq = clib_net_to_host_u32 (tcp->seq_number);
219 if (clib_net_to_host_u32 (tcp->ack_number) > ses->o2i_fin_seq)
249 ses->o2i_fin_seq = clib_net_to_host_u32 (tcp->seq_number);
254 if (clib_net_to_host_u32 (tcp->ack_number) > ses->i2o_fin_seq)
271 switch (s->in2out.protocol)
273 case SNAT_PROTOCOL_ICMP:
275 case SNAT_PROTOCOL_UDP:
277 case SNAT_PROTOCOL_TCP:
296 s->total_bytes += bytes;
307 s->per_user_list_head_index, s->per_user_index);
346 u8 opt_len, opts_len, kind;
353 data = (
u8 *) (tcp + 1);
354 for (; opts_len > 0; opts_len -= opt_len, data += opt_len)
371 if (opt_len < 2 || opt_len > opts_len)
377 mss = *(
u16 *) (data + 2);
433 if (sw_if_index == ~0)
441 if (sw_if_index != ~0)
446 if (sw_if_index == ~0)
453 if ((nat_interface_is_outside (i))
455 i->sw_if_index)) return 0;}
fib_protocol_t fp_proto
protocol type
nat_outside_fib_t * outside_fibs
#define snat_is_session_static(s)
Check if SNAT session is created from static mapping.
u32 sessions_per_user_list_head_index
#define NAT44_SES_I2O_FIN
u8 runtime_data[0]
Function dependent node-runtime data.
static u32 nat44_session_get_timeout(snat_main_t *sm, snat_session_t *s)
static_always_inline u8 icmp_is_error_message(icmp46_header_t *icmp)
ip4_address_t * ip4_interface_first_address(ip4_main_t *im, u32 sw_if_index, ip_interface_address_t **result_ia)
static void make_sm_kv(clib_bihash_kv_8_8_t *kv, ip4_address_t *addr, u8 proto, u32 fib_index, u16 port)
#define nat44_is_ses_closed(s)
Check if NAT44 endpoint-dependent TCP session is closed.
#define NAT44_SES_O2I_FIN
struct _tcp_header tcp_header_t
static int nat44_set_tcp_session_state_o2i(snat_main_t *sm, snat_session_t *ses, tcp_header_t *tcp, u32 thread_index)
clib_bihash_8_8_t user_hash
static int snat_not_translate_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, ip4_header_t *ip0, u32 proto0, u32 rx_fib_index0)
Check if packet should be translated.
u32 max_translations_per_user
#define static_always_inline
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#define SNAT_SESSION_FLAG_OUTPUT_FEATURE
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Aggregrate type for a prefix.
fib_node_index_t fib_table_lookup(u32 fib_index, const fib_prefix_t *prefix)
Perfom a longest prefix match in the non-forwarding table.
static u8 maximum_sessions_exceeded(snat_main_t *sm, u32 thread_index)
static void nat44_delete_session(snat_main_t *sm, snat_session_t *ses, u32 thread_index)
static void mss_clamping(snat_main_t *sm, tcp_header_t *tcp, ip_csum_t *sum)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
void nat_free_session_data(snat_main_t *sm, snat_session_t *s, u32 thread_index)
Free NAT44 session data (lookup keys, external addrres port)
static void clib_dlist_addtail(dlist_elt_t *pool, u32 head_index, u32 new_index)
#define pool_put(P, E)
Free an object E in pool P.
#define NAT44_SES_O2I_SYN
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
vlib_error_t error
Error code for buffers to be enqueued to error handler.
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
static void nat44_delete_user_with_no_session(snat_main_t *sm, snat_user_t *u, u32 thread_index)
#define nat_log_debug(...)
static u8 snat_proto_to_ip_proto(snat_protocol_t snat_proto)
#define clib_memcpy(a, b, c)
static void nat44_session_update_counters(snat_session_t *s, f64 now, uword bytes)
u32 fib_node_index_t
A typedef of a node index.
8 octet key, 8 octet key value pair
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
static void make_ed_kv(clib_bihash_kv_16_8_t *kv, ip4_address_t *l_addr, ip4_address_t *r_addr, u8 proto, u32 fib_index, u16 l_port, u16 r_port)
u32 tcp_transitory_timeout
static int nat44_set_tcp_session_state_i2o(snat_main_t *sm, snat_session_t *ses, tcp_header_t *tcp, u32 thread_index)
Set TCP session state.
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
#define pool_put_index(p, i)
Free pool element with given index.
static void nat44_session_update_lru(snat_main_t *sm, snat_session_t *s, u32 thread_index)
Per-user LRU list maintenance.
static void clib_dlist_remove(dlist_elt_t *pool, u32 index)
#define NAT44_SES_I2O_SYN
format_function_t format_snat_session
static u32 ip_proto_to_snat_proto(u8 ip_proto)
The NAT inline functions.
#define FIB_NODE_INDEX_INVALID
static void user_session_increment(snat_main_t *sm, snat_user_t *u, u8 is_static)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
snat_main_per_thread_data_t * per_thread_data
#define ip_csum_update(sum, old, new, type, field)
static u8 is_interface_addr(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, u32 ip4_addr)
#define NAT44_SES_I2O_FIN_ACK
#define vec_foreach(var, vec)
Vector iterator.
static void nat_send_all_to_node(vlib_main_t *vm, u32 *bi_vector, vlib_node_runtime_t *node, vlib_error_t *error, u32 next)
#define NAT44_SES_O2I_FIN_ACK
snat_session_t * sessions
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
snat_interface_t * interfaces
u32 tcp_established_timeout
static uword pool_elts(void *v)
Number of active elements in a pool.