From owner-freebsd-bugs@FreeBSD.ORG Thu Jul 5 08:20:04 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 4283D16A421 for ; Thu, 5 Jul 2007 08:20:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 1B2B513C45A for ; Thu, 5 Jul 2007 08:20:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l658K3ju052547 for ; Thu, 5 Jul 2007 08:20:03 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l658K34j052546; Thu, 5 Jul 2007 08:20:03 GMT (envelope-from gnats) Resent-Date: Thu, 5 Jul 2007 08:20:03 GMT Resent-Message-Id: <200707050820.l658K34j052546@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Floris Bos Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 77DC716A468 for ; Thu, 5 Jul 2007 08:13:09 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [69.147.83.33]) by mx1.freebsd.org (Postfix) with ESMTP id 50B9213C4CA for ; Thu, 5 Jul 2007 08:13:09 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l658D9M8038943 for ; Thu, 5 Jul 2007 08:13:09 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id l658D9c2038942; Thu, 5 Jul 2007 08:13:09 GMT (envelope-from nobody) Message-Id: <200707050813.l658D9c2038942@www.freebsd.org> Date: Thu, 5 Jul 2007 08:13:09 GMT From: Floris Bos To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.0 Cc: Subject: kern/114325: SIOCGIFADDR ioctl behaves incorrectly inside jail X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Jul 2007 08:20:04 -0000 >Number: 114325 >Category: kern >Synopsis: SIOCGIFADDR ioctl behaves incorrectly inside jail >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Jul 05 08:20:03 GMT 2007 >Closed-Date: >Last-Modified: >Originator: Floris Bos >Release: FreeBSD 6.2-STABLE-200702 >Organization: >Environment: FreeBSD cheetah.to-the-max.net 6.2-STABLE-200702 FreeBSD 6.2-STABLE-200702 #0: Sat Mar 10 01:09:58 CET 2007 max@cheetah.to-the-max.net:/usr/obj/usr/src/sys/MAX amd64 >Description: Inside a jail: When using the SIOCGIFADDR ioctl to retrieve the IP-address of a network device it returns the main IP-address of the parent host instead of the jail's IP-address. Inside a jail with IP-address 83.149.75.179: # ifconfig nve0: flags=8843 mtu 1500 inet 83.149.75.179 netmask 0xffffffff broadcast 83.149.75.179 ether 00:e0:81:5f:b5:ad media: Ethernet autoselect (100baseTX ) status: active bge0: flags=8802 mtu 1500 options=1b ether 00:e0:81:5f:b5:ac media: Ethernet autoselect (none) status: no carrier plip0: flags=108810 mtu 1500 lo0: flags=8049 mtu 16384 # ./ipaddr According to SIOCGIFADDR Device nve0 has IP-address: 83.149.75.182 >How-To-Repeat: - Use a server with multiple IP-addresses. - Create a jail using one of the IP-addresses other than the main address. - Compile and execute the following program inside the jail (change the ETHERNET_DEVICE to the name of the network device): ipaddr.c: == #include #include #include #include #include #include #include #include // The ethernet device to retrieve the IP of #define ETHERNET_DEVICE "nve0" int main(int argc, char **argv) { int sock; struct ifreq ifr; struct sockaddr_in *ifaddr; sock = socket(AF_INET, SOCK_DGRAM, 0); memset(&ifr, 0, sizeof(struct ifreq)); strncpy(ifr.ifr_name, ETHERNET_DEVICE, IF_NAMESIZE); if (ioctl(sock, SIOCGIFADDR, &ifr) == -1) { perror("Error retrieving IP address"); } else { ifaddr = (struct sockaddr_in *)&ifr.ifr_addr; printf("According to SIOCGIFADDR Device %s has IP-address: %s\n", ETHERNET_DEVICE, inet_ntoa(ifaddr->sin_addr)); } return 0; } == Expected behavior: it should return the IP-address of the jail. Actual behavior: it returns the main IP-address of the parent environment. >Fix: >Release-Note: >Audit-Trail: >Unformatted: