- tcp_timer_update (tc, TCP_TIMER_WAITCLOSE, TCP_CLEANUP_TIME);
-}
-
-#define PORT_MASK ((1 << 16)- 1)
-/**
- * Allocate local port and add if successful add entry to local endpoint
- * table to mark the pair as used.
- */
-int
-tcp_allocate_local_port (ip46_address_t * ip)
-{
- tcp_main_t *tm = vnet_get_tcp_main ();
- transport_endpoint_t *tep;
- u32 tei;
- u16 min = 1024, max = 65535; /* XXX configurable ? */
- int tries, limit;
-
- limit = max - min;
-
- /* Only support active opens from thread 0 */
- ASSERT (vlib_get_thread_index () == 0);
-
- /* Search for first free slot */
- for (tries = 0; tries < limit; tries++)
- {
- u16 port = 0;
-
- /* Find a port in the specified range */
- while (1)
- {
- port = random_u32 (&tm->port_allocator_seed) & PORT_MASK;
- if (PREDICT_TRUE (port >= min && port < max))
- break;
- }
-
- /* Look it up */
- tei = transport_endpoint_lookup (&tm->local_endpoints_table, ip, port);
- /* If not found, we're done */
- if (tei == TRANSPORT_ENDPOINT_INVALID_INDEX)
- {
- clib_spinlock_lock_if_init (&tm->local_endpoints_lock);
- tep = transport_endpoint_new ();
- clib_memcpy (&tep->ip, ip, sizeof (*ip));
- tep->port = port;
- transport_endpoint_table_add (&tm->local_endpoints_table, tep,
- tep - tm->local_endpoints);
- clib_spinlock_unlock_if_init (&tm->local_endpoints_lock);
-
- return tep->port;
- }
- }
- return -1;