- tcp_timer_update (tc, TCP_TIMER_WAITCLOSE, TCP_CLEANUP_TIME);
-}
-
-void *
-ip_interface_get_first_ip (u32 sw_if_index, u8 is_ip4)
-{
- ip_lookup_main_t *lm4 = &ip4_main.lookup_main;
- ip_lookup_main_t *lm6 = &ip6_main.lookup_main;
- ip_interface_address_t *ia = 0;
-
- if (is_ip4)
- {
- /* *INDENT-OFF* */
- foreach_ip_interface_address (lm4, ia, sw_if_index, 1 /* unnumbered */ ,
- ({
- return ip_interface_address_get_address (lm4, ia);
- }));
- /* *INDENT-ON* */
- }
- else
- {
- /* *INDENT-OFF* */
- foreach_ip_interface_address (lm6, ia, sw_if_index, 1 /* unnumbered */ ,
- ({
- ip6_address_t *rv;
- rv = ip_interface_address_get_address (lm6, ia);
- /* Trying to use a link-local ip6 src address is a fool's errand */
- if (!ip6_address_is_link_local_unicast (rv))
- return rv;
- }));
- /* *INDENT-ON* */
- }
-
- return 0;
-}
-
-#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;