- memset (&lcl_addr, 0, sizeof (lcl_addr));
-
- /* Find a FIB path to the destination */
- clib_memcpy (&prefix.fp_addr, &rmt->ip, sizeof (rmt->ip));
- prefix.fp_proto = rmt->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
- prefix.fp_len = rmt->is_ip4 ? 32 : 128;
-
- ASSERT (rmt->fib_index != ENDPOINT_INVALID_INDEX);
- fei = fib_table_lookup (rmt->fib_index, &prefix);
-
- /* Couldn't find route to destination. Bail out. */
- if (fei == FIB_NODE_INDEX_INVALID)
- {
- clib_warning ("no route to destination");
- return -1;
- }
-
- sw_if_index = rmt->sw_if_index;
- if (sw_if_index == ENDPOINT_INVALID_INDEX)
- sw_if_index = fib_entry_get_resolving_interface (fei);
-
- if (sw_if_index == ENDPOINT_INVALID_INDEX)
- {
- clib_warning ("no resolving interface for %U", format_ip46_address,
- &rmt->ip, (rmt->is_ip4 == 0) + 1);
- return -1;
- }
-
- if (rmt->is_ip4)
- {
- ip4_address_t *ip4;
- int index;
- if (vec_len (tm->ip4_src_addresses))
- {
- index = tm->last_v4_address_rotor++;
- if (tm->last_v4_address_rotor >= vec_len (tm->ip4_src_addresses))
- tm->last_v4_address_rotor = 0;
- lcl_addr.ip4.as_u32 = tm->ip4_src_addresses[index].as_u32;
- }
- else
- {
- ip4 = ip_interface_get_first_ip (sw_if_index, 1);
- lcl_addr.ip4.as_u32 = ip4->as_u32;
- }
- }
+ if ((rmt->is_ip4 && vec_len (tm->ip4_src_addresses))
+ || (!rmt->is_ip4 && vec_len (tm->ip6_src_addresses)))
+ rv = tcp_alloc_custom_local_endpoint (tm, &lcl_addr, &lcl_port,
+ rmt->is_ip4);