Date: Thu, 17 Mar 2016 11:10:44 +0000 (UTC) From: "Andrey V. Elsukov" <ae@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r296986 - head/sys/netinet6 Message-ID: <201603171110.u2HBAiFR075164@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ae Date: Thu Mar 17 11:10:44 2016 New Revision: 296986 URL: https://svnweb.freebsd.org/changeset/base/296986 Log: Reduce the number of local variables. Remove redundant check that inp pointer isn't NULL, it is safe, because we are handling IPV6_PKTINFO socket option in this block of code. Also, use in6ifa_withaddr() instead of ifa_withaddr(). Modified: head/sys/netinet6/in6_src.c Modified: head/sys/netinet6/in6_src.c ============================================================================== --- head/sys/netinet6/in6_src.c Thu Mar 17 11:06:43 2016 (r296985) +++ head/sys/netinet6/in6_src.c Thu Mar 17 11:10:44 2016 (r296986) @@ -226,9 +226,6 @@ in6_selectsrc(uint32_t fibnum, struct so */ if (opts && (pi = opts->ip6po_pktinfo) && !IN6_IS_ADDR_UNSPECIFIED(&pi->ipi6_addr)) { - struct sockaddr_in6 srcsock; - struct in6_ifaddr *ia6; - /* get the outgoing interface */ if ((error = in6_selectif(dstsock, opts, mopts, &ifp, oifp, fibnum)) @@ -242,18 +239,14 @@ in6_selectsrc(uint32_t fibnum, struct so * the interface must be specified; otherwise, ifa_ifwithaddr() * will fail matching the address. */ - bzero(&srcsock, sizeof(srcsock)); - srcsock.sin6_family = AF_INET6; - srcsock.sin6_len = sizeof(srcsock); - srcsock.sin6_addr = pi->ipi6_addr; + tmp = pi->ipi6_addr; if (ifp) { - error = in6_setscope(&srcsock.sin6_addr, ifp, NULL); + error = in6_setscope(&tmp, ifp, &odstzone); if (error) return (error); } if (cred != NULL && (error = prison_local_ip6(cred, - &srcsock.sin6_addr, (inp != NULL && - (inp->inp_flags & IN6P_IPV6_V6ONLY) != 0))) != 0) + &tmp, (inp->inp_flags & IN6P_IPV6_V6ONLY) != 0)) != 0) return (error); /* @@ -262,19 +255,18 @@ in6_selectsrc(uint32_t fibnum, struct so * ancillary data. */ if ((inp->inp_flags & INP_BINDANY) == 0) { - ia6 = (struct in6_ifaddr *)ifa_ifwithaddr( - (struct sockaddr *)&srcsock); - if (ia6 == NULL || (ia6->ia6_flags & (IN6_IFF_ANYCAST | + ia = in6ifa_ifwithaddr(&tmp, odstzone); + if (ia == NULL || (ia->ia6_flags & (IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) { - if (ia6 != NULL) - ifa_free(&ia6->ia_ifa); + if (ia != NULL) + ifa_free(&ia->ia_ifa); return (EADDRNOTAVAIL); } - bcopy(&ia6->ia_addr.sin6_addr, srcp, sizeof(*srcp)); - ifa_free(&ia6->ia_ifa); + bcopy(&ia->ia_addr.sin6_addr, srcp, sizeof(*srcp)); + ifa_free(&ia->ia_ifa); } else - bcopy(&srcsock.sin6_addr, srcp, sizeof(*srcp)); - pi->ipi6_addr = srcsock.sin6_addr; /* XXX: this overrides pi */ + bcopy(&tmp, srcp, sizeof(*srcp)); + pi->ipi6_addr = tmp; /* XXX: this overrides pi */ if (ifpp) *ifpp = ifp; return (0);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201603171110.u2HBAiFR075164>