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))
328 u8 tcp_flags =
vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags;
333 if ((ses->state ==
NAT44_SES_RST) && !(tcp_flags & TCP_FLAG_RST))
342 ses->i2o_fin_seq = clib_net_to_host_u32 (tcp_seq_number);
347 if (clib_net_to_host_u32 (tcp_ack_number) > ses->o2i_fin_seq)
362 u8 tcp_flags,
u32 tcp_ack_number,
363 u32 tcp_seq_number,
u32 thread_index)
367 if ((ses->state ==
NAT44_SES_RST) && !(tcp_flags & TCP_FLAG_RST))
376 ses->o2i_fin_seq = clib_net_to_host_u32 (tcp_seq_number);
381 if (clib_net_to_host_u32 (tcp_ack_number) > ses->i2o_fin_seq)
396 switch (s->in2out.protocol)
398 case SNAT_PROTOCOL_ICMP:
400 case SNAT_PROTOCOL_UDP:
402 case SNAT_PROTOCOL_TCP:
422 s->total_bytes += bytes;
423 nat_ha_sref (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
424 s->ext_host_port, s->out2in.protocol, s->out2in.fib_index,
425 s->total_pkts, s->total_bytes, thread_index,
426 &s->ha_last_refreshed, now);
437 s->per_user_list_head_index, s->per_user_index);
476 icmp46_header_t *icmp0;
481 icmp46_header_t *inner_icmp0;
487 (
vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags))
489 key0.
proto = IP_PROTOCOL_ICMP;
504 case SNAT_PROTOCOL_ICMP:
505 inner_icmp0 = (icmp46_header_t *) l4_header;
510 case SNAT_PROTOCOL_UDP:
511 case SNAT_PROTOCOL_TCP:
516 return NAT_IN2OUT_ED_ERROR_UNSUPPORTED_PROTOCOL;
528 icmp46_header_t *icmp0;
533 icmp46_header_t *inner_icmp0;
539 (
vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags))
541 key0.
proto = IP_PROTOCOL_ICMP;
556 case SNAT_PROTOCOL_ICMP:
557 inner_icmp0 = (icmp46_header_t *) l4_header;
562 case SNAT_PROTOCOL_UDP:
563 case SNAT_PROTOCOL_TCP:
579 u8 opt_len, opts_len, kind;
586 data = (
u8 *) (tcp + 1);
587 for (; opts_len > 0; opts_len -= opt_len, data += opt_len)
604 if (opt_len < 2 || opt_len > opts_len)
610 mss = *(
u16 *) (data + 2);
666 if (sw_if_index == ~0)
674 if (sw_if_index != ~0)
679 if (sw_if_index == ~0)
686 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)
#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
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.
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)
static_always_inline int get_icmp_i2o_ed_key(vlib_buffer_t *b, ip4_header_t *ip0, nat_ed_ses_key_t *p_key0)
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)
static int nat44_set_tcp_session_state_i2o(snat_main_t *sm, snat_session_t *ses, vlib_buffer_t *b, u32 thread_index)
Set TCP session state.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static_always_inline u8 icmp_type_is_error_message(u8 icmp_type)
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 int nat44_set_tcp_session_state_o2i(snat_main_t *sm, snat_session_t *ses, u8 tcp_flags, u32 tcp_ack_number, u32 tcp_seq_number, u32 thread_index)
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)
vlib_main_t vlib_node_runtime_t * node
u32 tcp_transitory_timeout
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_always_inline int get_icmp_o2i_ed_key(vlib_buffer_t *b, ip4_header_t *ip0, nat_ed_ses_key_t *p_key0)
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.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
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
u32 tcp_established_timeout
static uword pool_elts(void *v)
Number of active elements in a pool.