public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Mike Gilbert <floppym@gentoo.org>
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	[thread overview]
Message-ID: <20190731160647.23986-1-floppym@gentoo.org> (raw)

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 <floppym@gentoo.org>
---
 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



             reply	other threads:[~2019-07-31 16:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-31 16:06 Mike Gilbert [this message]
2019-07-31 18:00 ` [gentoo-portage-dev] [PATCH] Configure a dummy network interface for network-sandbox Zac Medico
2019-07-31 18:28   ` Mike Gilbert
2019-08-01 13:22 ` [gentoo-portage-dev] [PATCH v2] Configure additional addresses on the lo " Mike Gilbert
2019-08-01 18:06   ` Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190731160647.23986-1-floppym@gentoo.org \
    --to=floppym@gentoo.org \
    --cc=gentoo-portage-dev@lists.gentoo.org \
    --cc=leio@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox