19 #ifndef __included_nat_inlines_h__ 20 #define __included_nat_inlines_h__ 31 u32 n_left_from, *from, *to_next;
38 while (n_left_from > 0)
44 while (n_left_from >= 4 && n_left_to_next >= 2)
47 u32 arc_next0, arc_next1;
66 to_next[0] = bi0 = from[0];
67 to_next[1] = bi1 = from[1];
87 if (b0->
flags & VLIB_BUFFER_IS_TRACED)
93 if (b1->
flags & VLIB_BUFFER_IS_TRACED)
103 to_next, n_left_to_next,
104 bi0, bi1, next0, next1);
107 while (n_left_from > 0 && n_left_to_next > 0)
128 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
136 to_next, n_left_to_next,
151 snat_proto = (ip_proto == IP_PROTOCOL_UDP) ? SNAT_PROTOCOL_UDP : snat_proto;
152 snat_proto = (ip_proto == IP_PROTOCOL_TCP) ? SNAT_PROTOCOL_TCP : snat_proto;
154 (ip_proto == IP_PROTOCOL_ICMP) ? SNAT_PROTOCOL_ICMP : snat_proto;
156 (ip_proto == IP_PROTOCOL_ICMP6) ? SNAT_PROTOCOL_ICMP : snat_proto;
166 ip_proto = (snat_proto == SNAT_PROTOCOL_UDP) ? IP_PROTOCOL_UDP : ip_proto;
167 ip_proto = (snat_proto == SNAT_PROTOCOL_TCP) ? IP_PROTOCOL_TCP : ip_proto;
168 ip_proto = (snat_proto == SNAT_PROTOCOL_ICMP) ? IP_PROTOCOL_ICMP : ip_proto;
178 case ICMP4_destination_unreachable:
179 case ICMP4_time_exceeded:
180 case ICMP4_parameter_problem:
181 case ICMP4_source_quench:
183 case ICMP4_alternate_host_address:
191 u32 sw_if_index0,
u32 ip4_addr)
229 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
232 n_left_from =
vec_len (bi_vector);
234 while (n_left_from > 0)
237 while (n_left_from > 0 && n_left_to_next > 0)
239 u32 bi0 = to_next[0] = from[0];
248 n_left_to_next, bi0, next);
282 clib_bihash_add_del_8_8 (&tsm->
user_hash, &kv, 0);
297 .
addr = ses->in2out.addr,
298 .fib_index = ses->in2out.fib_index
309 if (!clib_bihash_search_8_8 (&tsm->
user_hash, &kv, &value))
339 ses->i2o_fin_seq = clib_net_to_host_u32 (tcp->seq_number);
344 if (clib_net_to_host_u32 (tcp->ack_number) > ses->o2i_fin_seq)
372 ses->o2i_fin_seq = clib_net_to_host_u32 (tcp->seq_number);
377 if (clib_net_to_host_u32 (tcp->ack_number) > ses->i2o_fin_seq)
392 switch (s->in2out.protocol)
394 case SNAT_PROTOCOL_ICMP:
396 case SNAT_PROTOCOL_UDP:
398 case SNAT_PROTOCOL_TCP:
418 s->total_bytes += bytes;
419 nat_ha_sref (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
420 s->ext_host_port, s->out2in.protocol, s->out2in.fib_index,
421 s->total_pkts, s->total_bytes, thread_index,
422 &s->ha_last_refreshed, now);
433 s->per_user_list_head_index, s->per_user_index);
471 icmp46_header_t *icmp0;
476 icmp46_header_t *inner_icmp0;
483 key0.
proto = IP_PROTOCOL_ICMP;
498 case SNAT_PROTOCOL_ICMP:
499 inner_icmp0 = (icmp46_header_t *) l4_header;
504 case SNAT_PROTOCOL_UDP:
505 case SNAT_PROTOCOL_TCP:
510 return NAT_IN2OUT_ED_ERROR_UNSUPPORTED_PROTOCOL;
521 icmp46_header_t *icmp0;
526 icmp46_header_t *inner_icmp0;
533 key0.
proto = IP_PROTOCOL_ICMP;
548 case SNAT_PROTOCOL_ICMP:
549 inner_icmp0 = (icmp46_header_t *) l4_header;
554 case SNAT_PROTOCOL_UDP:
555 case SNAT_PROTOCOL_TCP:
571 u8 opt_len, opts_len, kind;
578 data = (
u8 *) (tcp + 1);
579 for (; opts_len > 0; opts_len -= opt_len, data += opt_len)
596 if (opt_len < 2 || opt_len > opts_len)
602 mss = *(
u16 *) (data + 2);
658 if (sw_if_index == ~0)
666 if (sw_if_index != ~0)
671 if (sw_if_index == ~0)
678 if ((nat_interface_is_outside (i)) && (sw_if_index == i->sw_if_index))
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
fib_protocol_t fp_proto
protocol type
nat_outside_fib_t * outside_fibs
#define nat_buffer_opaque(b)
#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 int get_icmp_i2o_ed_key(ip4_header_t *ip0, nat_ed_ses_key_t *p_key0)
static_always_inline u8 icmp_is_error_message(icmp46_header_t *icmp)
#define clib_memcpy_fast(a, b, c)
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)
void nat_free_session_data(snat_main_t *sm, snat_session_t *s, u32 thread_index, u8 is_ha)
Free NAT44 session data (lookup keys, external addrres 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
void nat_ha_sref(ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index, u32 total_pkts, u64 total_bytes, u32 thread_index, f64 *last_refreshed, f64 now)
Create session refresh HA event.
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.
static_always_inline int get_icmp_o2i_ed_key(ip4_header_t *ip0, nat_ed_ses_key_t *p_key0)
vl_api_interface_index_t sw_if_index
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
#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.
Aggregate type for a prefix.
static void * ip4_next_header(ip4_header_t *i)
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)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
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.
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
static void vlib_set_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 value)
Set a simple counter.
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
#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).
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)
static u8 snat_proto_to_ip_proto(snat_protocol_t snat_proto)
#define CLIB_PREFETCH(addr, size, type)
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
static void nat44_session_update_counters(snat_session_t *s, f64 now, uword bytes, u32 thread_index)
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 uword nat_pre_node_fn_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, u32 def_next)
The NAT inline functions.
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
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
vlib_simple_counter_main_t total_users
static u32 ip_proto_to_snat_proto(u8 ip_proto)
#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)
VLIB buffer representation.
snat_main_per_thread_data_t * per_thread_data
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector 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.
u16 flags
Copy of main node flags.
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 VLIB_NODE_FLAG_TRACE
#define CLIB_CACHE_LINE_BYTES
#define NAT44_SES_O2I_FIN_ACK
vlib_simple_counter_main_t total_sessions
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
vl_api_fib_path_nh_proto_t proto
u32 tcp_established_timeout
static uword pool_elts(void *v)
Number of active elements in a pool.