From owner-svn-src-head@FreeBSD.ORG Fri Aug 22 19:08:12 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B557BE3D; Fri, 22 Aug 2014 19:08:12 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A13D83820; Fri, 22 Aug 2014 19:08:12 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7MJ8C4d005548; Fri, 22 Aug 2014 19:08:12 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s7MJ8Csa005547; Fri, 22 Aug 2014 19:08:12 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201408221908.s7MJ8Csa005547@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Fri, 22 Aug 2014 19:08:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r270347 - head/sys/netinet X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 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: Fri, 22 Aug 2014 19:08:12 -0000 Author: delphij Date: Fri Aug 22 19:08:12 2014 New Revision: 270347 URL: http://svnweb.freebsd.org/changeset/base/270347 Log: Restore historical behavior of in_control, which, when no matching address is found, the first usable address is returned for legacy ioctls like SIOCGIFBRDADDR, SIOCGIFDSTADDR, SIOCGIFNETMASK and SIOCGIFADDR. While there also fix a subtle issue that a caller from a jail asking for INADDR_ANY may get the first IP of the host that do not belong to the jail. Submitted by: glebius Differential Revision: https://reviews.freebsd.org/D667 Modified: head/sys/netinet/in.c Modified: head/sys/netinet/in.c ============================================================================== --- head/sys/netinet/in.c Fri Aug 22 18:59:19 2014 (r270346) +++ head/sys/netinet/in.c Fri Aug 22 19:08:12 2014 (r270347) @@ -242,19 +242,26 @@ in_control(struct socket *so, u_long cmd return (EADDRNOTAVAIL); /* - * For SIOCGIFADDR, pick the first address. For the rest of - * ioctls, try to find specified address. + * Find address for this interface, if it exists. If an + * address was specified, find that one instead of the + * first one on the interface, if possible. */ IF_ADDR_RLOCK(ifp); TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { if (ifa->ifa_addr->sa_family != AF_INET) continue; ia = (struct in_ifaddr *)ifa; - if (cmd == SIOCGIFADDR || addr->sin_addr.s_addr == INADDR_ANY) - break; if (ia->ia_addr.sin_addr.s_addr == addr->sin_addr.s_addr) break; } + if (ifa == NULL) + TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) + if (ifa->ifa_addr->sa_family == AF_INET) { + ia = (struct in_ifaddr *)ifa; + if (prison_check_ip4(td->td_ucred, + &ia->ia_addr.sin_addr) == 0) + break; + } if (ifa == NULL) { IF_ADDR_RUNLOCK(ifp);