39 #define msg_spp_err(s)                          \    41     fprintf(stderr,(i8 *)s);                    \    42     fputs("\n", stderr);                        \    47 #define PM_90_PERCENT_USE 58980    76     for (i = 0; i < pm_len; i++) {
    84                              "private_ip_users_count %d\n",
   107 #ifndef NO_BULK_LOGGING   110             u16 static_port_range)
   112     uword bit_test_result;
   115     if(i_port < static_port_range) 
return 1; 
   117     i_port = (i_port/bulk_size) * bulk_size;
   119     return(bit_test_result);
   124             u16 static_port_range)
   144                  u16                   static_port_range
   145 #ifndef NO_BULK_LOGGING
   152     u32 i, hash_value, my_index, found, max_attempts;
   153     u16 start_bit, new_port;
   156     uword bit_test_result;
   158 #ifndef NO_BULK_LOGGING   175         hash_value = (i_ipv4_address & 0xffff) ^
   176                         ((i_ipv4_address > 16) & 0xffff);
   182             hash_value = (hash_value & 0xff) ^ ((hash_value > 8) & 0xff);
   188         my_index = hash_value % pm_len;
   191             my_pm = pm + my_index;
   200 #ifndef NO_BULK_LOGGING
   218 #ifndef NO_BULK_LOGGING
   228             my_index = (my_index + 1) % pm_len;
   236             u32 min_inuse_any, min_inuse_myport;
   237             u32 min_index_any, min_index_myport;
   240             min_index_any = min_index_myport = ~0;
   241             for (i = 0; i < pm_len; i++) {
   246                             min_inuse_any = my_pm->
inuse;
   247                             min_index_any = my_pm - pm;
   251                                              my_pm->
bm,i_port) == 1) 
   252 #ifndef NO_BULK_LOGGING
   254                                             i_port,bulk_size,static_port_range)
   257                                 min_inuse_myport = my_pm->
inuse;
   258                                 min_index_myport = my_pm - pm;
   266                         min_inuse_any = my_pm->
inuse;
   267                         min_index_any = my_pm - pm;
   271                                          my_pm->
bm, i_port) == 1) 
   272 #ifndef NO_BULK_LOGGING
   274                                                  bulk_size, static_port_range)
   277                             min_inuse_myport = my_pm->
inuse;
   278                             min_index_myport = my_pm - pm;
   290                 my_pm = pm + min_index_myport;
   291                 my_index = min_index_myport;
   294                 my_pm = pm + min_index_any;
   295                 my_index = min_index_any;
   310         my_pm = pm + my_index;
   321 #ifndef NO_BULK_LOGGING   323         (i_port >= static_port_range)) {
   324         start_bit =  (start_bit/bulk_size) * bulk_size;
   329     for (i = 0; i < max_attempts; i++) {
   330 #ifndef NO_BULK_LOGGING   332             (i_port >= static_port_range)) {
   334                         start_bit, bulk_size);
   341 #ifndef NO_BULK_LOGGING   343             (i_port >= static_port_range)) {
   344             *nfv9_log_req = start_bit;
   345             if(i==0) new_port = i_port; 
   348                 if (pair_type == 
PORT_S_ODD &&  (new_port & 0x1) == 0)
   358                 if ((new_port & 0x1) == 1) {
   363                 if ((new_port & 0x1) == 0) {
   371 #ifndef NO_BULK_LOGGING   375 #ifndef NO_BULK_LOGGING   377                 (i_port >= static_port_range))
   385 #ifndef NO_BULK_LOGGING   425     int min_inuse, min_index;
   442             *rseed_ip = 
randq1(*rseed_ip);
   443             my_index = (*rseed_ip) % pm_len;
   444             my_pm = pm + my_index;
   467         for (i = 0; i < pm_len; i++) {
   472                        min_inuse = my_pm->
inuse;
   473                        min_index = my_pm - pm;
   478                            min_inuse = my_pm->
inuse;
   479                            min_index = my_pm - pm;
   487                     min_inuse = my_pm->
inuse;
   488                     min_index = my_pm - pm;
   494             my_pm = pm + min_index;
   495             my_index = min_index;
   500 #ifdef DEBUG_PRINTF_ENABLED   521         msg_spp_err(
"bad allocation type in cnat_port_alloc");
   561                  u16                  static_port_range
   562 #ifndef NO_BULK_LOGGING
   575     uword bit_test_result;
   576     uword max_trys_to_find_port;
   607     start_bit = start_bit + static_port_range;
   609 #ifndef NO_BULK_LOGGING   616         start_bit= ((start_bit + bulk_size -1)/bulk_size) * bulk_size;
   623     for (i = 0; i < max_trys_to_find_port;  i++) {
   627                     (start_bit < static_port_range))) {
   628                     start_bit = static_port_range;
   629 #ifndef NO_BULK_LOGGING   631             start_bit= ((start_bit + bulk_size -1)/bulk_size) * bulk_size;
   636 #ifndef NO_BULK_LOGGING   639             start_bit, bulk_size);
   647 #ifndef NO_BULK_LOGGING   649                 *nfv9_log_req = new_port;
   652                        (!(new_port & 0x1))) {
   653 #ifndef NO_BULK_LOGGING   671 #ifndef NO_BULK_LOGGING   673         start_bit += bulk_size;
   720 cnat_alloc_port_from_pm (
   725 #ifndef NO_BULK_LOGGING
   733     u32 total_ports = end_port - start_port + 1;
   734     uword bit_test_result;
   735     uword max_trys_to_find_port;
   740     start_bit = start_bit + start_port;
   741 #ifndef NO_BULK_LOGGING   747         max_trys_to_find_port = total_ports/bulk_size;
   748         start_bit= ((start_bit + bulk_size -1)/bulk_size) * bulk_size;
   752     max_trys_to_find_port = total_ports;
   755     for (i = 0; i < max_trys_to_find_port; i++) {
   758                     (start_bit < start_port))) {
   759                     start_bit = start_port;
   760 #ifndef NO_BULK_LOGGING   762                 start_bit= ((start_bit + bulk_size -1)/bulk_size) * bulk_size;
   768 #ifndef NO_BULK_LOGGING   771             start_bit, bulk_size);
   778 #ifndef NO_BULK_LOGGING   781                     *nfv9_log_req = 
bit2port(start_bit);
   790                 if ((start_bit & 0x1) ||
   791                     ((start_bit + 1) > end_port) ||
   793                                     (start_bit + 1)) == 0)) {
   797 #ifndef NO_BULK_LOGGING   803 #ifndef NO_BULK_LOGGING   805             start_bit += bulk_size;
   833 #ifndef NO_BULK_LOGGING
   841     u32 current_timestamp;
   862         cnat_alloc_port_from_pm(start_range, end_range, my_pm, pair_type
   863 #ifndef NO_BULK_LOGGING
   864          , bulk_size, nfv9_log_req
   915 #ifndef NO_BULK_LOGGING
   938 #ifndef NO_BULK_LOGGING
   973         for (i = 0; i < pm_len; i++) {
   994         my_pm = pm + my_index;
  1005         msg_spp_err(
"bad allocation type in cnat_port_alloc");
  1042          u16                static_port_range)
  1064     if(base_port >= static_port_range) {
  1087                 inuse, print_limit);
  1105     if (spp_get_int_prop(
"no_crypto_random_ports") == 0)
  1106         crypto_random32(&seed);
 
static int check_if_stat_alloc_ok_for_bulk(cnat_portmap_v2_t *pm, u16 i_port, bulk_alloc_size_t bulk_size, u16 static_port_range)
sll srl srl sll sra u16x4 i
static u16 bit2port(u32 bit)
u32 private_ip_users_count
static u32 randq1(u32 prev)
Fixed length block allocator. 
clib_error_t * cnat_ports_init(vlib_main_t *vm)
static uword clib_bitmap_get_no_check(uword *ai, uword i)
Gets the ith bit value from a bitmap Does not sanity-check the bit position. 
cnat_portmap_v2_t * portmap_list
vnet_main_t * vnet_get_main(void)
void cnat_portmap_dump_v2(cnat_portmap_v2_t *pm, u16 print_limit)
cnat_errno_t cnat_static_port_alloc_v2(cnat_portmap_v2_t *pm, port_alloc_t atype, port_pair_t pair_type, u32 i_ipv4_address, u16 i_port, u32 *index, u32 *o_ipv4_address, u16 *o_port, u16 static_port_range, bulk_alloc_size_t bulk_size, int *nfv9_log_req, u16 ip_n_to_1)
void cnat_port_free_v2(cnat_portmap_v2_t *pm, int index, port_pair_t pair_type, u16 base_port, u16 static_port_range)
#define VLIB_INIT_FUNCTION(x)
#define CNAT_MAX_VRFMAP_ENTRIES
void cnat_db_dump_portmaps()
u16 vrf_map_array[CNAT_MAX_VRFMAP_ENTRIES]
cnat_errno_t cnat_dynamic_port_alloc_v2(cnat_portmap_v2_t *pm, port_alloc_t atype, port_pair_t pair_type, u32 *index, u32 *o_ipv4_address, u16 *o_port, u16 static_port_range, bulk_alloc_size_t bulk_size, int *nfv9_log_req, u16 ip_n_to_1, u32 *rseed_ip)
static uword cgn_clib_bitmap_clear_no_check(uword *a, uword i)
static uword port2bit(u16 port)
void cnat_db_dump_portmap_for_vrf(u32 vrfmap_index)
#define BULK_ALLOC_NOT_ATTEMPTED
#define CNAT_DEBUG_GLOBAL_ALL
cnat_ports_main_t cnat_ports_main
Bitmaps built as vectors of machine words. 
#define VRF_MAP_ENTRY_EMPTY
cnat_vrfmap_t * cnat_map_by_vrf
uword bm[(BITS_PER_INST+BITS(uword)-1)/BITS(uword)]
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant) 
cnat_errno_t cnat_mapped_static_port_alloc_v2(cnat_portmap_v2_t *pm, port_alloc_t atype, u32 *index, u32 ipv4_address, u16 port, int *nfv9_log_req, bulk_alloc_size_t bulk_size, u16 ip_n_to_1)
cnat_portmap_v2_t * cnat_dynamic_addr_alloc_from_pm(cnat_portmap_v2_t *pm, port_alloc_t atype, u32 *index, cnat_errno_t *err, u16 ip_n_to_1, u32 *rseed_ip)
static uword cgn_clib_bitmap_check_if_all(uword *ai, u16 start, i16 num_bits)
static uword cgn_clib_bitmap_set_no_check(uword *a, uword i)
cnat_errno_t cnat_dynamic_port_alloc_rtsp(cnat_portmap_v2_t *pm, port_alloc_t atype, port_pair_t pair_type, u16 start_range, u16 end_range, u32 *index, u32 *o_ipv4_address, u16 *o_port, bulk_alloc_size_t bulk_size, int *nfv9_log_req, u32 *rseed_ip)
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".