From owner-svn-src-head@FreeBSD.ORG Thu Feb 5 15:04:24 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 49255106564A; Thu, 5 Feb 2009 15:04:24 +0000 (UTC) (envelope-from jamie@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1D6668FC1C; Thu, 5 Feb 2009 15:04:24 +0000 (UTC) (envelope-from jamie@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n15F4ODI030208; Thu, 5 Feb 2009 15:04:24 GMT (envelope-from jamie@svn.freebsd.org) Received: (from jamie@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n15F4O46030207; Thu, 5 Feb 2009 15:04:24 GMT (envelope-from jamie@svn.freebsd.org) Message-Id: <200902051504.n15F4O46030207@svn.freebsd.org> From: Jamie Gritton Date: Thu, 5 Feb 2009 15:04:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r188151 - head/sys/netinet6 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Feb 2009 15:04:24 -0000 Author: jamie Date: Thu Feb 5 15:04:23 2009 New Revision: 188151 URL: http://svn.freebsd.org/changeset/base/188151 Log: Don't bother null-checking the thread pointer before the prison checks in udp6_connect (td is already dereferenced elsewhere without such a check). This makes the conversion from a sockaddr to a sockaddr_in6 always happen, so convert once at the beginning of the function rather than twice in the middle. Approved by: bz (mentor) Modified: head/sys/netinet6/udp6_usrreq.c Modified: head/sys/netinet6/udp6_usrreq.c ============================================================================== --- head/sys/netinet6/udp6_usrreq.c Thu Feb 5 15:03:35 2009 (r188150) +++ head/sys/netinet6/udp6_usrreq.c Thu Feb 5 15:04:23 2009 (r188151) @@ -883,48 +883,43 @@ udp6_connect(struct socket *so, struct s { INIT_VNET_INET(so->so_vnet); struct inpcb *inp; + struct sockaddr_in6 *sin6; int error; inp = sotoinpcb(so); + sin6 = (struct sockaddr_in6 *)nam; KASSERT(inp != NULL, ("udp6_connect: inp == NULL")); INP_INFO_WLOCK(&V_udbinfo); INP_WLOCK(inp); - if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) { - struct sockaddr_in6 *sin6_p; - - sin6_p = (struct sockaddr_in6 *)nam; - if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) { - struct sockaddr_in sin; + if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0 && + IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { + struct sockaddr_in sin; - if (inp->inp_faddr.s_addr != INADDR_ANY) { - error = EISCONN; - goto out; - } - in6_sin6_2_sin(&sin, sin6_p); - if (td && (error = prison_remote_ip4(td->td_ucred, - &sin.sin_addr)) != 0) - goto out; - error = in_pcbconnect(inp, (struct sockaddr *)&sin, - td->td_ucred); - if (error == 0) { - inp->inp_vflag |= INP_IPV4; - inp->inp_vflag &= ~INP_IPV6; - soisconnected(so); - } + if (inp->inp_faddr.s_addr != INADDR_ANY) { + error = EISCONN; goto out; } + in6_sin6_2_sin(&sin, sin6); + error = prison_remote_ip4(td->td_ucred, &sin.sin_addr); + if (error != 0) + goto out; + error = in_pcbconnect(inp, (struct sockaddr *)&sin, + td->td_ucred); + if (error == 0) { + inp->inp_vflag |= INP_IPV4; + inp->inp_vflag &= ~INP_IPV6; + soisconnected(so); + } + goto out; } if (!IN6_IS_ADDR_UNSPECIFIED(&inp->in6p_faddr)) { error = EISCONN; goto out; } - if (td) { - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam; - if ((error = prison_remote_ip6(td->td_ucred, - &sin6->sin6_addr)) != 0) - goto out; - } + error = prison_remote_ip6(td->td_ucred, &sin6->sin6_addr); + if (error != 0) + goto out; error = in6_pcbconnect(inp, nam, td->td_ucred); if (error == 0) { if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0) {