diff options
Diffstat (limited to 'sys/netinet/in_pcb.c')
-rw-r--r-- | sys/netinet/in_pcb.c | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 9a49353f1538..3774f73a7a8f 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1127,29 +1127,6 @@ in_pcbconnect(struct inpcb *inp, struct sockaddr_in *sin, struct ucred *cred) if (in_nullhost(inp->inp_laddr)) { error = in_pcbladdr(inp, &faddr, &laddr, cred); - /* - * If the destination address is multicast and an outgoing - * interface has been set as a multicast option, prefer the - * address of that interface as our source address. - */ - if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr)) && - inp->inp_moptions != NULL && - inp->inp_moptions->imo_multicast_ifp != NULL) { - struct ifnet *ifp = - inp->inp_moptions->imo_multicast_ifp; - struct in_ifaddr *ia; - - CK_STAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { - if (ia->ia_ifp == ifp && - prison_check_ip4(cred, - &ia->ia_addr.sin_addr) == 0) - break; - } - if (ia == NULL) - return (EADDRNOTAVAIL); - laddr = ia->ia_addr.sin_addr; - error = 0; - } if (error) return (error); } else @@ -1231,6 +1208,27 @@ in_pcbladdr(const struct inpcb *inp, struct in_addr *faddr, if (!prison_saddrsel_ip4(cred, laddr)) return (0); + /* + * If the destination address is multicast and an outgoing + * 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)) && inp->inp_moptions != NULL && + inp->inp_moptions->imo_multicast_ifp != NULL) { + struct ifnet *ifp = inp->inp_moptions->imo_multicast_ifp; + struct in_ifaddr *ia; + + CK_STAILQ_FOREACH(ia, &V_in_ifaddrhead, ia_link) { + if (ia->ia_ifp == ifp && + prison_check_ip4(cred, &ia->ia_addr.sin_addr) == 0) + break; + } + if (ia == NULL) + return (EADDRNOTAVAIL); + *laddr = ia->ia_addr.sin_addr; + return (0); + } + error = 0; nh = NULL; |