From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 46ACE138334 for ; Wed, 31 Jul 2019 16:06:52 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4664AE0809; Wed, 31 Jul 2019 16:06:51 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 24095E0809 for ; Wed, 31 Jul 2019 16:06:51 +0000 (UTC) Received: from naomi.gilbertsystems.net (d192-24-229-26.try.wideopenwest.com [24.192.26.229]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: floppym) by smtp.gentoo.org (Postfix) with ESMTPSA id B5C9834905E; Wed, 31 Jul 2019 16:06:49 +0000 (UTC) From: Mike Gilbert To: gentoo-portage-dev@lists.gentoo.org Cc: leio@gentoo.org Subject: [gentoo-portage-dev] [PATCH] Configure a dummy network interface for network-sandbox Date: Wed, 31 Jul 2019 12:06:47 -0400 Message-Id: <20190731160647.23986-1-floppym@gentoo.org> X-Mailer: git-send-email 2.22.0 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-portage-dev@lists.gentoo.org Reply-to: gentoo-portage-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archives-Salt: ab12a2c3-98f9-4b5d-a4f5-fb2e86d3c6e2 X-Archives-Hash: eb7f4f3c8bdc554d69b8d161688a6d51 This works around some strange behavior in glibc's getaddrinfo() implementation when the AI_ADDRCONFIG flag is set. For example: struct addrinfo *res, hints = { .ai_family = AF_INET, .ai_flags = AI_ADDRCONFIG }; getaddrinfo("localhost", NULL, &hints, &res); This returns no results if there is no non-loopback interface configured with an IPv4 address. Bug: https://bugs.gentoo.org/690758 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12377#c13 Signed-off-by: Mike Gilbert --- lib/portage/process.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/portage/process.py b/lib/portage/process.py index dfbda75de..c284c04f3 100644 --- a/lib/portage/process.py +++ b/lib/portage/process.py @@ -446,6 +446,29 @@ def spawn(mycommand, env=None, opt_name=None, fd_pipes=None, returnpid=False, # Everything succeeded return 0 +def _configure_dummy_interface(): + """ + Configure a dummy interface to work around odd behavior in glibc's + getaddrinfo() implementation when the AI_ADDRCONFIG flag is set. + + For example: + + struct addrinfo *res, hints = { .ai_family = AF_INET, .ai_flags = AI_ADDRCONFIG }; + getaddrinfo("localhost", NULL, &hints, &res); + + This returns no results if there is no non-loopback interface configured with an + IPv4 address. + + Bug: https://bugs.gentoo.org/690758 + Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12377#c13 + """ + try: + subprocess.check_call(['ip','link','add','dummy','type','dummy']) + subprocess.check_call(['ip','link','set','dummy','up']) + subprocess.check_call(['ip','address','add','10.0.0.1/8','dev','dummy']) + except subprocess.CalledProcessError: + writemsg("Unable to configure dummy network interface\n") + def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask, cwd, pre_exec, close_fds, unshare_net, unshare_ipc, unshare_mount, unshare_pid, @@ -637,6 +660,7 @@ def _exec(binary, mycommand, opt_name, fd_pipes, errno.errorcode.get(e.errno, '?')), noiselevel=-1) sock.close() + _configure_dummy_interface() except AttributeError: # unshare() not supported by libc pass -- 2.22.0