|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
19 #ifndef __included_nat44_ed_inlines_h__
20 #define __included_nat44_ed_inlines_h__
32 ASSERT (fib_index <= (1 << 14) - 1);
34 return (
u64)
addr.as_u32 << 32 | (
u64)
port << 16 | fib_index << 3 |
52 *fib_index =
key >> 3 & ((1 << 13) - 1);
80 return init_nat_k (kv, s->in2out.addr, s->in2out.port, s->in2out.fib_index,
88 init_nat_k (kv, s->in2out.addr, s->in2out.port, s->in2out.fib_index,
96 return init_nat_k (kv, s->out2in.addr, s->out2in.port, s->out2in.fib_index,
104 init_nat_k (kv, s->out2in.addr, s->out2in.port, s->out2in.fib_index,
112 return value->value >> 32;
127 (
u64) r_port << 48 | (
u64) l_port << 32 | fib_index << 8 |
proto;
142 return value->value >> 32;
166 *r_port = kv->
key[1] >> 48;
170 *l_port = (kv->
key[1] >> 32) & (
u16) ~0;
174 *fib_index = (kv->
key[1] >> 8) & ((1 << 24) - 1);
187 u16 *lookup_dport,
u8 *lookup_protocol)
189 icmp46_header_t *icmp0;
193 icmp46_header_t *inner_icmp0;
205 *lookup_protocol = IP_PROTOCOL_ICMP;
215 *lookup_protocol = inner_ip0->
protocol;
220 case NAT_PROTOCOL_ICMP:
221 inner_icmp0 = (icmp46_header_t *) l4_header;
226 case NAT_PROTOCOL_UDP:
227 case NAT_PROTOCOL_TCP:
232 return NAT_IN2OUT_ED_ERROR_UNSUPPORTED_PROTOCOL;
241 switch (s->nat_proto)
243 case NAT_PROTOCOL_ICMP:
245 case NAT_PROTOCOL_UDP:
247 case NAT_PROTOCOL_TCP:
278 s->lru_index = lru_list_elt - tsm->
lru_pool;
281 case IP_PROTOCOL_UDP:
284 case IP_PROTOCOL_TCP:
287 case IP_PROTOCOL_ICMP:
296 s->last_lru_update =
now;
303 init_ed_k (kv,
f->match.saddr,
f->match.sport,
f->match.daddr,
304 f->match.dport,
f->match.fib_index,
f->match.proto);
311 init_ed_kv (kv,
f->match.saddr,
f->match.sport,
f->match.daddr,
312 f->match.dport,
f->match.fib_index,
f->match.proto,
thread_idx,
318 snat_session_t *s,
int is_add)
334 return clib_bihash_add_del_16_8 (&sm->
flow_hash, &kv, is_add);
339 snat_session_t *s,
int is_add)
354 return clib_bihash_add_del_16_8 (&sm->
flow_hash, &kv, is_add);
383 snat_session_t *s = NULL;
385 f64 sess_timeout_time;
389 if (~0 != oldest_index)
396 if (
now >= sess_timeout_time ||
397 (s->tcp_closed_timestamp &&
now >= s->tcp_closed_timestamp))
417 if ((rc = nat_lru_free_one_with_head (sm, thread_index, now, \
418 tsm->p##_lru_head_index))) \
444 s->ha_last_refreshed =
now;
447 #if CLIB_ASSERT_ENABLE
460 per_vrf_sessions_t *per_vrf_sessions;
461 u32 *to_free = 0, *
i;
465 if (per_vrf_sessions->expired)
467 if (per_vrf_sessions->ses_count == 0)
492 per_vrf_sessions_t *per_vrf_sessions;
501 if (per_vrf_sessions->expired)
504 if ((s->in2out.fib_index == per_vrf_sessions->rx_fib_index) &&
505 (s->out2in.fib_index == per_vrf_sessions->tx_fib_index))
509 if ((s->in2out.fib_index == per_vrf_sessions->tx_fib_index) &&
510 (s->out2in.fib_index == per_vrf_sessions->rx_fib_index))
518 clib_memset (per_vrf_sessions, 0,
sizeof (*per_vrf_sessions));
520 per_vrf_sessions->rx_fib_index = s->in2out.fib_index;
521 per_vrf_sessions->tx_fib_index = s->out2in.fib_index;
525 per_vrf_sessions->ses_count++;
534 per_vrf_sessions_t *per_vrf_sessions;
536 ASSERT (s->per_vrf_sessions_index != ~0);
542 ASSERT (per_vrf_sessions->ses_count != 0);
544 per_vrf_sessions->ses_count--;
545 s->per_vrf_sessions_index = ~0;
554 per_vrf_sessions_t *per_vrf_sessions;
556 ASSERT (s->per_vrf_sessions_index != ~0);
561 return per_vrf_sessions->expired;
570 f->match.saddr = saddr;
572 f->match.daddr = daddr;
575 f->match.fib_index = fib_index;
622 u32 arc_next0, arc_next1;
656 if (b0->
flags & VLIB_BUFFER_IS_TRACED)
662 if (b1->
flags & VLIB_BUFFER_IS_TRACED)
690 (b0->
flags & VLIB_BUFFER_IS_TRACED)))
704 return frame->n_vectors;
716 if (
r >= min &&
r <= max)
719 return min + (rwide % (max - min + 1));
724 u32 sw_if_index0,
u32 ip4_addr)
735 rt->cached_sw_if_index = ~0;
739 lm, ia, sw_if_index0, 1 , ({
741 hash_set (
rt->cached_presence_by_ip4_address,
a->as_u32, 1);
742 rt->cached_sw_if_index = sw_if_index0;
745 if (
rt->cached_sw_if_index == ~0)
749 ip4_addr_exists = !!
hash_get (
rt->cached_presence_by_ip4_address, ip4_addr);
775 ses->i2o_fin_seq = clib_net_to_host_u32 (tcp_seq_number);
780 if (clib_net_to_host_u32 (tcp_ack_number) > ses->o2i_fin_seq)
786 ses->last_lru_update =
now;
806 u8 tcp_flags,
u32 tcp_ack_number,
821 ses->o2i_fin_seq = clib_net_to_host_u32 (tcp_seq_number);
826 if (clib_net_to_host_u32 (tcp_ack_number) > ses->i2o_fin_seq)
831 ses->last_lru_update =
now;
853 s->total_bytes += bytes;
861 if (s->last_heard > s->last_lru_update + 1)
866 s->lru_head_index, s->lru_index);
867 s->last_lru_update = s->last_heard;
static void init_nat_kv(clib_bihash_kv_8_8_t *kv, ip4_address_t addr, u16 port, u32 fib_index, nat_protocol_t proto, u32 thread_index, u32 session_index)
static u32 ed_value_get_thread_index(clib_bihash_kv_16_8_t *value)
static u32 clib_dlist_remove_head(dlist_elt_t *pool, u32 head_index)
struct nat_timeouts_t::@742 tcp
u32 unk_proto_lru_head_index
static void * ip_interface_address_get_address(ip_lookup_main_t *lm, ip_interface_address_t *a)
#define hash_set(h, key, value)
static u32 ed_value_get_session_index(clib_bihash_kv_16_8_t *value)
vlib_buffer_t * bufs[VLIB_FRAME_SIZE]
#define foreach_ip_interface_address(lm, a, sw_if_index, loop, body)
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
static_always_inline void nat_6t_flow_to_ed_kv(clib_bihash_kv_16_8_t *kv, nat_6t_flow_t *f, u32 thread_idx, u32 session_idx)
static_always_inline void nat_6t_flow_init(nat_6t_flow_t *f, u32 thread_idx, ip4_address_t saddr, u16 sport, ip4_address_t daddr, u16 dport, u32 fib_index, u8 proto, u32 session_idx)
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)
vlib_simple_counter_main_t total_sessions
ip_lookup_main_t lookup_main
static_always_inline void nat_6t_flow_to_ed_k(clib_bihash_kv_16_8_t *kv, nat_6t_flow_t *f)
#define nat_elog_warn(_pm, nat_elog_str)
static u64 calc_nat_key(ip4_address_t addr, u16 port, u32 fib_index, u8 proto)
The NAT inline functions.
#define NAT44_SES_O2I_SYN
static void init_nat_i2o_kv(clib_bihash_kv_8_8_t *kv, snat_session_t *s, u32 thread_index, u32 session_index)
#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, u8 is_ha)
Free NAT44 session data (lookup keys, external address port)
static_always_inline int nat_get_icmp_session_lookup_values(vlib_buffer_t *b, ip4_header_t *ip0, ip4_address_t *lookup_saddr, u16 *lookup_sport, ip4_address_t *lookup_daddr, u16 *lookup_dport, u8 *lookup_protocol)
static u32 nat44_session_get_timeout(snat_main_t *sm, snat_session_t *s)
static_always_inline void nat_6t_o2i_flow_init(snat_main_t *sm, u32 thread_idx, snat_session_t *s, ip4_address_t saddr, u16 sport, ip4_address_t daddr, u16 dport, u32 fib_index, u8 proto)
vlib_get_buffers(vm, from, b, n_left_from)
static nat_protocol_t ip_proto_to_nat_proto(u8 ip_proto)
Common NAT inline functions.
vlib_main_t vlib_node_runtime_t * node
static_always_inline void per_vrf_sessions_unregister_session(snat_session_t *s, u32 thread_index)
#define pool_put(P, E)
Free an object E in pool P.
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
static_always_inline int nat_ed_lru_insert(snat_main_per_thread_data_t *tsm, snat_session_t *s, f64 now, u8 proto)
static void nat44_set_tcp_session_state_i2o(snat_main_t *sm, f64 now, snat_session_t *ses, vlib_buffer_t *b, u32 thread_index)
static_always_inline u8 nat44_ed_maximum_sessions_exceeded(snat_main_t *sm, u32 fib_index, u32 thread_index)
NAT port/address allocation lib.
vlib_buffer_enqueue_to_next(vm, node, from,(u16 *) nexts, frame->n_vectors)
vnet_hw_if_output_node_runtime_t * r
static_always_inline u8 icmp_type_is_error_message(u8 icmp_type)
#define pool_put_index(p, i)
Free pool element with given index.
static void init_nat_o2i_kv(clib_bihash_kv_8_8_t *kv, snat_session_t *s, u32 thread_index, u32 session_index)
static_always_inline void nat_6t_i2o_flow_init(snat_main_t *sm, u32 thread_idx, snat_session_t *s, ip4_address_t saddr, u16 sport, ip4_address_t daddr, u16 dport, u32 fib_index, u8 proto)
static u32 random_u32(u32 *seed)
32-bit random number generator
static_always_inline void per_vrf_sessions_register_session(snat_session_t *s, u32 thread_index)
static bool nat44_is_ses_closed(snat_session_t *s)
Check if NAT44 endpoint-dependent TCP session is closed.
static_always_inline void per_vrf_sessions_cleanup(u32 thread_index)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void 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)
snat_main_per_thread_data_t * per_thread_data
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define NAT44_SES_I2O_FIN
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
clib_bihash_16_8_t flow_hash
void nat_6t_l3_l4_csum_calc(nat_6t_flow_t *f)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static void split_nat_key(u64 key, ip4_address_t *addr, u16 *port, u32 *fib_index, nat_protocol_t *proto)
#define VLIB_NODE_FLAG_TRACE
per_vrf_sessions_t * per_vrf_sessions_vec
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
static_always_inline u16 snat_random_port(u16 min, u16 max)
static void init_nat_i2o_k(clib_bihash_kv_8_8_t *kv, snat_session_t *s)
#define static_always_inline
if(node->flags &VLIB_NODE_FLAG_TRACE) vnet_interface_output_trace(vm
static void init_ed_k(clib_bihash_kv_16_8_t *kv, ip4_address_t l_addr, u16 l_port, ip4_address_t r_addr, u16 r_port, u32 fib_index, u8 proto)
static void clib_dlist_remove(dlist_elt_t *pool, u32 index)
static uword nat_pre_node_fn_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, u32 def_next)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
#define NAT44_SES_I2O_SYN
static void init_nat_k(clib_bihash_kv_8_8_t *kv, ip4_address_t addr, u16 port, u32 fib_index, nat_protocol_t proto)
#define NAT44_SES_I2O_FIN_ACK
snat_session_t * sessions
static void nat_ed_session_delete(snat_main_t *sm, snat_session_t *ses, u32 thread_index, int lru_delete)
static u8 is_interface_addr(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, u32 ip4_addr)
static u32 nat_value_get_thread_index(clib_bihash_kv_8_8_t *value)
static_always_inline int nat_6t_t_eq(nat_6t_t *t1, nat_6t_t *t2)
u32 tcp_trans_lru_head_index
#define vec_free(V)
Free vector's memory (no header).
u32 * max_translations_per_fib
static_always_inline snat_session_t * nat_ed_session_alloc(snat_main_t *sm, u32 thread_index, f64 now, u8 proto)
static void vlib_set_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 value)
Set a simple counter.
static_always_inline int nat_lru_free_one(snat_main_t *sm, int thread_index, f64 now)
static_always_inline void clib_prefetch_load(void *p)
static void nat44_session_update_counters(snat_session_t *s, f64 now, uword bytes, u32 thread_index)
static void init_ed_kv(clib_bihash_kv_16_8_t *kv, ip4_address_t l_addr, u16 l_port, ip4_address_t r_addr, u16 r_port, u32 fib_index, u8 proto, u32 thread_index, u32 session_index)
#define vec_foreach(var, vec)
Vector iterator.
8 octet key, 8 octet key value pair
static_always_inline int nat_lru_free_one_with_head(snat_main_t *sm, int thread_index, f64 now, u32 head_index)
static uword pool_elts(void *v)
Number of active elements in a pool.
static_always_inline int nat_ed_ses_i2o_flow_hash_add_del(snat_main_t *sm, u32 thread_idx, snat_session_t *s, int is_add)
static_always_inline u8 per_vrf_sessions_is_expired(snat_session_t *s, u32 thread_index)
#define NAT44_SES_O2I_FIN_ACK
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void init_nat_o2i_k(clib_bihash_kv_8_8_t *kv, snat_session_t *s)
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
vnet_interface_output_runtime_t * rt
static void clib_dlist_addtail(dlist_elt_t *pool, u32 head_index, u32 new_index)
static void clib_dlist_addhead(dlist_elt_t *pool, u32 head_index, u32 new_index)
u16 nexts[VLIB_FRAME_SIZE]
#define NAT44_SES_O2I_FIN
u32 tcp_estab_lru_head_index
static void nat44_session_update_lru(snat_main_t *sm, snat_session_t *s, u32 thread_index)
Per-user LRU list maintenance.
#define vec_del1(v, i)
Delete the element at index I.
static_always_inline int nat_ed_ses_o2i_flow_hash_add_del(snat_main_t *sm, u32 thread_idx, snat_session_t *s, int is_add)
static void * ip4_next_header(ip4_header_t *i)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
static u32 nat_value_get_session_index(clib_bihash_kv_8_8_t *value)
VLIB buffer representation.