From cf744713e87e77504a25a4ece5ad95b87f6b5753 Mon Sep 17 00:00:00 2001 From: Andre Oppermann Date: Thu, 16 Feb 2006 15:45:28 +0000 Subject: [PATCH] In in_pcbconnect_setup() reduce code duplication and use ip_rtaddr() to find the outgoing interface for this connection. Sponsored by: TCP/IP Optimization Fundraise 2005 MFC after: 2 weeks --- sys/netinet/in_pcb.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index f96c660916b3..d96a838a65ac 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -591,29 +591,23 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam, &in_ifaddrhead)->ia_broadaddr)->sin_addr; } if (laddr.s_addr == INADDR_ANY) { - struct route sro; - - bzero(&sro, sizeof(sro)); ia = (struct in_ifaddr *)0; /* * If route is known our src addr is taken from the i/f, * else punt. + * + * Find out route to destination */ - if ((inp->inp_socket->so_options & SO_DONTROUTE) == 0) { - /* Find out route to destination */ - sro.ro_dst.sa_family = AF_INET; - sro.ro_dst.sa_len = sizeof(struct sockaddr_in); - ((struct sockaddr_in *)&sro.ro_dst)->sin_addr = faddr; - rtalloc_ign(&sro, RTF_CLONING); - } + if ((inp->inp_socket->so_options & SO_DONTROUTE) == 0) + ia = ip_rtaddr(faddr); /* - * If we found a route, use the address - * corresponding to the outgoing interface. + * If we found a route, use the address corresponding to + * the outgoing interface. + * + * Otherwise assume faddr is reachable on a directly connected + * network and try to find a corresponding interface to take + * the source address from. */ - if (sro.ro_rt) { - ia = ifatoia(sro.ro_rt->rt_ifa); - RTFREE(sro.ro_rt); - } if (ia == 0) { bzero(&sa, sizeof(sa)); sa.sin_addr = faddr;