27 v = clib_net_to_host_u32 (addr->
as_u32) + 1;
28 addr->
as_u32 = clib_host_to_net_u32 (v);
51 return NAT_ERROR_VALUE_EXIST;
54 #define _(N, i, n, s) \ 55 clib_bitmap_alloc (a->busy_##n##_port_bitmap, 65535); \ 56 a->busy_##n##_ports = 0; \ 57 vec_validate_init_empty (a->busy_##n##_ports_per_thread, tm->n_vlib_mains - 1, 0); 64 return NAT_ERROR_NO_SUCH_ENTRY;
65 #define _(N, id, n, s) \ 66 clib_bitmap_free (a->busy_##n##_port_bitmap); \ 67 vec_free (a->busy_##n##_ports_per_thread); 82 for (i = 0; i <
count; i++)
115 u32 nat_thread_index,
129 #define _(N, j, n, s) \ 130 case NAT_PROTOCOL_##N: \ 131 if (a->busy_##n##_ports_per_thread[thread_index] < port_per_thread) \ 133 if (a->fib_index == fib_index) \ 137 portnum = (port_per_thread * \ 138 nat_thread_index) + \ 139 nat_random_port(&pool->random_seed, 1, port_per_thread) + 1024; \ 140 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, portnum)) \ 142 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, portnum, 1); \ 143 a->busy_##n##_ports_per_thread[thread_index]++; \ 144 a->busy_##n##_ports++; \ 145 out->addr = a->addr; \ 146 out->port = clib_host_to_net_u16(portnum); \ 150 else if (a->fib_index == ~0) \ 159 return NAT_ERROR_UNKNOWN_PROTOCOL;
168 #define _(N, j, n, s) \ 169 case NAT_PROTOCOL_##N: \ 172 portnum = (port_per_thread * \ 173 nat_thread_index) + \ 174 nat_random_port(&pool->random_seed, 1, port_per_thread) + 1024; \ 175 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, portnum)) \ 177 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, portnum, 1); \ 178 a->busy_##n##_ports_per_thread[thread_index]++; \ 179 a->busy_##n##_ports++; \ 180 out->addr = a->addr; \ 181 out->port = clib_host_to_net_u16(portnum); \ 188 return NAT_ERROR_UNKNOWN_PROTOCOL;
191 return NAT_ERROR_OUT_OF_TRANSLATIONS;
198 u32 nat_thread_index,
206 port_per_thread, protocol, out);
230 return NAT_ERROR_NO_SUCH_ENTRY;
235 #define _(N, i, n, s) \ 236 case NAT_PROTOCOL_##N: \ 237 ASSERT (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 239 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, \ 241 a->busy_##n##_ports--; \ 242 a->busy_##n##_ports_per_thread[thread_index]--; \ 247 return NAT_ERROR_UNKNOWN_PROTOCOL;
int nat_alloc_ip4_addr_and_port_cb_default(nat_ip4_pool_t *pool, u32 fib_index, u32 thread_index, u32 nat_thread_index, u16 port_per_thread, u16 protocol, nat_ip4_addr_port_t *out)
vl_api_ip_proto_t protocol
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
NAT port/address allocation lib.
static_always_inline void nat_ip4_addr_increment(ip4_address_t *addr)
#define static_always_inline
nat_alloc_ip4_addr_and_port_cb_t * alloc_addr_and_port_cb
static_always_inline u16 nat_random_port(u32 *random_seed, u16 min, u16 max)
#define vec_del1(v, i)
Delete the element at index I.
int nat_add_del_ip4_pool_addr(nat_ip4_pool_t *pool, ip4_address_t addr, u8 is_add)
nat_add_del_ip4_pool_addr_cb_t * add_del_pool_addr_cb
nat_ip4_pool_addr_t * pool_addr
NAT port/address allocation lib.
static u32 random_u32_max(void)
Maximum value returned by random_u32()
sll srl srl sll sra u16x4 i
int nat_alloc_ip4_addr_and_port(nat_ip4_pool_t *pool, u32 fib_index, u32 thread_index, u32 nat_thread_index, u16 port_per_thread, u16 protocol, nat_ip4_addr_port_t *out)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static u32 random_u32(u32 *seed)
32-bit random number generator
static vlib_thread_main_t * vlib_get_thread_main()
int nat_add_del_ip4_pool_addrs(nat_ip4_pool_t *pool, ip4_address_t addr, u32 count, u8 is_add, void *opaque)
int nat_free_ip4_addr_and_port(nat_ip4_pool_t *pool, u32 thread_index, u16 protocol, nat_ip4_addr_port_t *addr_port)