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)
94 if (b1->
flags & VLIB_BUFFER_IS_TRACED)
105 to_next, n_left_to_next,
106 bi0, bi1, next0, next1);
109 while (n_left_from > 0 && n_left_to_next > 0)
130 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
139 to_next, n_left_to_next,
151 u32 sw_if_index0,
u32 ip4_addr)
189 u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
192 n_left_from =
vec_len (bi_vector);
194 while (n_left_from > 0)
197 while (n_left_from > 0 && n_left_to_next > 0)
199 u32 bi0 = to_next[0] = from[0];
208 n_left_to_next, bi0, next);
242 clib_bihash_add_del_8_8 (&tsm->
user_hash, &kv, 0);
257 .
addr = ses->in2out.addr,
258 .fib_index = ses->in2out.fib_index
274 if (!clib_bihash_search_8_8 (&tsm->
user_hash, &kv, &value))
295 u8 tcp_flags =
vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags;
300 if ((ses->state ==
NAT44_SES_RST) && !(tcp_flags & TCP_FLAG_RST))
309 ses->i2o_fin_seq = clib_net_to_host_u32 (tcp_seq_number);
314 if (clib_net_to_host_u32 (tcp_ack_number) > ses->o2i_fin_seq)
320 ses->last_lru_update = now;
341 snat_session_t * ses,
u8 tcp_flags,
342 u32 tcp_ack_number,
u32 tcp_seq_number,
348 if ((ses->state ==
NAT44_SES_RST) && !(tcp_flags & TCP_FLAG_RST))
357 ses->o2i_fin_seq = clib_net_to_host_u32 (tcp_seq_number);
362 if (clib_net_to_host_u32 (tcp_ack_number) > ses->i2o_fin_seq)
367 ses->last_lru_update = now;
387 switch (s->in2out.protocol)
389 case NAT_PROTOCOL_ICMP:
391 case NAT_PROTOCOL_UDP:
393 case NAT_PROTOCOL_TCP:
413 s->total_bytes += bytes;
414 nat_ha_sref (&s->out2in.addr, s->out2in.port, &s->ext_host_addr,
415 s->ext_host_port, s->out2in.protocol, s->out2in.fib_index,
416 s->total_pkts, s->total_bytes, thread_index,
417 &s->ha_last_refreshed, now);
426 if (s->last_heard > s->last_lru_update + 1)
433 s->per_user_list_head_index, s->per_user_index);
440 s->lru_head_index, s->lru_index);
442 s->last_lru_update = s->last_heard;
453 (
u64) r_port << 48 | (
u64) l_port << 32 | fib_index << 8 | proto;
460 u32 * fib_index,
u16 * l_port,
u16 * r_port)
472 *r_port = kv->
key[1] >> 48;
476 *l_port = (kv->
key[1] >> 32) & (
u16) ~ 0;
480 *fib_index = (kv->
key[1] >> 8) & ((1 << 24) - 1);
484 *proto = kv->
key[1] & (
u8) ~ 0;
492 kv->
key = (
u64) fib_index << 51 | (
u64) proto << 48 | (
u64) port << 32 |
504 u16 _l_port, _r_port;
507 icmp46_header_t *icmp0;
511 icmp46_header_t *inner_icmp0;
517 (
vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags))
519 proto = IP_PROTOCOL_ICMP;
534 case NAT_PROTOCOL_ICMP:
535 inner_icmp0 = (icmp46_header_t *) l4_header;
540 case NAT_PROTOCOL_UDP:
541 case NAT_PROTOCOL_TCP:
546 return NAT_IN2OUT_ED_ERROR_UNSUPPORTED_PROTOCOL;
549 make_ed_kv (l_addr, r_addr, proto, rx_fib_index, _l_port, _r_port, value,
572 icmp46_header_t *icmp0;
575 u16 _l_port, _r_port;
579 icmp46_header_t *inner_icmp0;
585 (
vnet_buffer (b)->ip.reass.icmp_type_or_tcp_flags))
587 proto = IP_PROTOCOL_ICMP;
602 case NAT_PROTOCOL_ICMP:
603 inner_icmp0 = (icmp46_header_t *) l4_header;
608 case NAT_PROTOCOL_UDP:
609 case NAT_PROTOCOL_TCP:
617 make_ed_kv (l_addr, r_addr, proto, rx_fib_index, _l_port, _r_port, value,
638 u8 opt_len, opts_len, kind;
645 data = (
u8 *) (tcp + 1);
646 for (; opts_len > 0; opts_len -= opt_len, data += opt_len)
663 if (opt_len < 2 || opt_len > opts_len)
669 mss = *(
u16 *) (data + 2);
725 if (sw_if_index == ~0)
733 if (sw_if_index != ~0)
738 if (sw_if_index == ~0)
745 if ((nat_interface_is_outside (i)) && (sw_if_index == i->sw_if_index))
759 v = clib_net_to_host_u32 (a->
as_u32) + 1;
760 a->
as_u32 = clib_host_to_net_u32 (v);
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 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)
#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_always_inline int get_icmp_i2o_ed_key(vlib_buffer_t *b, ip4_header_t *ip0, u32 rx_fib_index, u64 value, u8 *nat_proto, u16 *l_port, u16 *r_port, clib_bihash_kv_16_8_t *kv)
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 nat_protocol_t ip_proto_to_nat_proto(u8 ip_proto)
Common NAT inline functions.
vl_api_interface_index_t sw_if_index
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
#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_always_inline u8 icmp_type_is_error_message(u8 icmp_type)
static void split_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)
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 int nat44_set_tcp_session_state_o2i(snat_main_t *sm, f64 now, snat_session_t *ses, u8 tcp_flags, u32 tcp_ack_number, u32 tcp_seq_number, u32 thread_index)
static void nat44_delete_user_with_no_session(snat_main_t *sm, snat_user_t *u, u32 thread_index)
#define CLIB_PREFETCH(addr, size, type)
sll srl srl sll sra u16x4 i
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.
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 int nat44_set_tcp_session_state_i2o(snat_main_t *sm, f64 now, snat_session_t *ses, vlib_buffer_t *b, u32 thread_index)
Set TCP session state.
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
#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)
u32 tcp_trans_lru_head_index
VLIB buffer representation.
u32 tcp_estab_lru_head_index
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)
static_always_inline int get_icmp_o2i_ed_key(vlib_buffer_t *b, ip4_header_t *ip0, u32 rx_fib_index, u64 value, u8 *nat_proto, u16 *l_port, u16 *r_port, clib_bihash_kv_16_8_t *kv)
static void increment_v4_address(ip4_address_t *a)
#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.
static void make_ed_kv(ip4_address_t *l_addr, ip4_address_t *r_addr, u8 proto, u32 fib_index, u16 l_port, u16 r_port, u64 value, clib_bihash_kv_16_8_t *kv)
snat_interface_t * interfaces
u32 tcp_established_timeout
static uword pool_elts(void *v)
Number of active elements in a pool.