16 #ifndef __CNAT_NODE_H__ 17 #define __CNAT_NODE_H__ 36 return ((0 != a->as_u64[0]) || (0 != a->as_u64[1]));
43 u16 new_port[VLIB_N_DIR])
141 if (ip4->
protocol == IP_PROTOCOL_TCP)
152 else if (ip4->
protocol == IP_PROTOCOL_UDP)
179 u16 new_port[VLIB_N_DIR])
199 if (new_port[VLIB_TX])
214 if (new_port[VLIB_RX])
237 if (ip6->
protocol == IP_PROTOCOL_TCP)
248 else if (ip6->
protocol == IP_PROTOCOL_UDP)
274 session->
key.__cs_pad[0] = 0;
275 session->
key.__cs_pad[1] = 0;
289 session->
key.__cs_pad[0] = 0;
290 session->
key.__cs_pad[1] = 0;
321 rsession->
key.__cs_pad[0] = 0;
322 rsession->
key.__cs_pad[1] = 0;
328 rv = clib_bihash_search_inline_2_40_48 (&
cnat_session_db, &rkey, &rvalue);
338 goto create_rsession;
368 (
u8 *) & l,
sizeof (l));
394 rsession->value.cs_ts_index = session->value.cs_ts_index;
396 rsession->value.flags = rsession_flags;
410 u32 n_left, *from, thread_index;
460 next[3] = cnat_sub (vm, node, b[3], &ctx, rv[3], session[3]);
467 next[2] = cnat_sub (vm, node, b[2], &ctx, rv[2], session[2]);
474 next[1] = cnat_sub (vm, node, b[1], &ctx, rv[1], session[1]);
481 next[0] = cnat_sub (vm, node, b[0], &ctx, rv[0], session[0]);
512 &bkey[0], &bvalue[0]);
515 next[0] = cnat_sub (vm, node, b[0], &ctx, rv[0], session[0]);
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
static void cnat_timestamp_inc_refcnt(u32 index)
ip_address_t ** throttle_pool
static f64 vlib_time_now(vlib_main_t *vm)
uword(* cnat_node_sub_t)(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b, cnat_node_ctx_t *ctx, int rv, cnat_session_t *session)
u16 cs_port[VLIB_N_DIR]
ports in rx/tx
static_always_inline void cnat_ip4_translate_l4(ip4_header_t *ip4, udp_header_t *udp, u16 *checksum, ip4_address_t new_addr[VLIB_N_DIR], u16 new_port[VLIB_N_DIR])
static u64 clib_bihash_hash_40_48(const clib_bihash_kv_40_48_t *v)
static_always_inline void ip46_address_set_ip6(ip46_address_t *dst, const ip6_address_t *src)
static_always_inline void cnat_tcp_update_session_lifetime(tcp_header_t *tcp, u32 index)
static_always_inline void cnat_ip6_translate_l4(ip6_header_t *ip6, udp_header_t *udp, u16 *checksum, ip6_address_t new_addr[VLIB_N_DIR], u16 new_port[VLIB_N_DIR])
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
struct _tcp_header tcp_header_t
clib_bihash_40_48_t cnat_session_db
The DB of sessions.
static u32 cnat_timestamp_new(f64 t)
A session represents the memory of a translation.
u8 cs_af
The address family describing the IP addresses.
#define static_always_inline
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
ip46_address_t cs_ip[VLIB_N_DIR]
IP 4/6 address in the rx/tx direction.
u32 cs_ts_index
Timestamp index this session was last used.
static_always_inline u32 cnat_client_cnt_session(cnat_client_t *cc)
Add a session refcnt to this client.
static_always_inline void ip46_address_copy(ip46_address_t *dst, const ip46_address_t *src)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static u64 throttle_seed(throttle_t *t, u32 thread_index, f64 time_now)
static_always_inline cnat_client_t * cnat_client_ip4_find(const ip4_address_t *ip)
Find a client from an IP4 address.
vl_api_address_union_t src_address
static_always_inline void cnat_translation_ip6(const cnat_session_t *session, ip6_header_t *ip6, udp_header_t *udp)
static_always_inline void cnat_session_make_key(vlib_buffer_t *b, ip_address_family_t af, clib_bihash_kv_40_48_t *bkey)
static_always_inline void cnat_ip6_translate_l3(ip6_header_t *ip6, ip6_address_t new_addr[VLIB_N_DIR])
clib_spinlock_t * throttle_pool_lock
static_always_inline void vlib_buffer_enqueue_to_next(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u16 *nexts, uword count)
static_always_inline void cnat_ip4_translate_l3(ip4_header_t *ip4, ip4_address_t new_addr[VLIB_N_DIR])
vlib_main_t vlib_node_runtime_t * node
struct cnat_session_t_::@637 value
this value sits in the same memory location a 'value' in the bihash kvp
static_always_inline void cnat_translation_ip4(const cnat_session_t *session, ip4_header_t *ip4, udp_header_t *udp)
void cnat_client_learn(const cnat_learn_arg_t *l)
Called in the main thread by RPC from the workers to learn a new client.
#define CNAT_DEFAULT_TCP_RST_TIMEOUT
static ip_csum_t ip_csum_sub_even(ip_csum_t c, ip_csum_t x)
ip_address_family_t version
static_always_inline cnat_client_t * cnat_client_ip6_find(const ip6_address_t *ip)
Find a client from an IP6 address.
enum ip_address_family_t_ ip_address_family_t
ip_protocol_t cs_proto
The IP protocol TCP or UDP only supported.
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
VLIB buffer representation.
struct cnat_session_t_::@636 key
this key sits in the same memory location a 'key' in the bihash kvp
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 void ip6_address_copy(ip6_address_t *dst, const ip6_address_t *src)
cnat_client_db_t cnat_client_db
static_always_inline void cnat_session_create(cnat_session_t *session, cnat_node_ctx_t *ctx, u8 rsession_flags)
Create NAT sessions.
static_always_inline void vlib_get_buffers(vlib_main_t *vm, u32 *bi, vlib_buffer_t **b, int count)
Translate array of buffer indices into buffer pointers.
static void cnat_timestamp_set_lifetime(u32 index, u16 lifetime)
static u16 ip_csum_fold(ip_csum_t c)
static void ip46_address_set_ip4(ip46_address_t *ip46, const ip4_address_t *ip)
static uword cnat_node_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, cnat_node_sub_t cnat_sub, ip_address_family_t af, u8 do_trace)
static ip_csum_t ip_csum_add_even(ip_csum_t c, ip_csum_t x)
A client is a representation of an IP address behind the NAT.
static_always_inline u8 has_ip6_address(ip6_address_t *a)
Inline translation functions.
static int throttle_check(throttle_t *t, u32 thread_index, u64 hash, u64 seed)