From b66753a4f2196c512bff97333fdb4d3a55f1bbae Mon Sep 17 00:00:00 2001 From: deischen Date: Tue, 11 Jan 2011 19:43:35 +0000 Subject: [PATCH] MFC: 217169 Make sure to always do source address selection on an unbound socket, regardless of any multicast options. If an address is specified via a multicast option, then let it override normal the source address selection. This fixes a bug where source address selection was not being performed when multicast options were present but without an interface being specified. Approved by: re git-svn-id: svn://svn.freebsd.org/base/releng/8.2@217280 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/netinet/in_pcb.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 5d1b9af9..02af7419 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -833,9 +833,10 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam, } } if (laddr.s_addr == INADDR_ANY) { + error = in_pcbladdr(inp, &faddr, &laddr, cred); /* * If the destination address is multicast and an outgoing - * interface has been set as a multicast option, use the + * interface has been set as a multicast option, prefer the * address of that interface as our source address. */ if (IN_MULTICAST(ntohl(faddr.s_addr)) && @@ -852,16 +853,16 @@ in_pcbconnect_setup(struct inpcb *inp, struct sockaddr *nam, break; if (ia == NULL) { IN_IFADDR_RUNLOCK(); - return (EADDRNOTAVAIL); + error = EADDRNOTAVAIL; + } else { + laddr = ia->ia_addr.sin_addr; + IN_IFADDR_RUNLOCK(); + error = 0; } - laddr = ia->ia_addr.sin_addr; - IN_IFADDR_RUNLOCK(); } - } else { - error = in_pcbladdr(inp, &faddr, &laddr, cred); - if (error) - return (error); } + if (error) + return (error); } oinp = in_pcblookup_hash(inp->inp_pcbinfo, faddr, fport, laddr, lport, 0, NULL); -- 2.42.0