Gentoo Archives: gentoo-portage-dev

From: Mike Gilbert <floppym@g.o>
To: Zac Medico <zmedico@g.o>
Cc: gentoo-portage-dev@l.g.o, Mart Raudsepp <leio@g.o>
Subject: Re: [gentoo-portage-dev] [PATCH] Configure a dummy network interface for network-sandbox
Date: Wed, 31 Jul 2019 18:28:21
Message-Id: CAJ0EP43NXS-WidNd=RER1X+kpvP8tcSJz5wDk-sXx+ECCWYOCA@mail.gmail.com
In Reply to: Re: [gentoo-portage-dev] [PATCH] Configure a dummy network interface for network-sandbox by Zac Medico
1 On Wed, Jul 31, 2019 at 2:00 PM Zac Medico <zmedico@g.o> wrote:
2 >
3 > On 7/31/19 9:06 AM, Mike Gilbert wrote:
4 > > This works around some strange behavior in glibc's getaddrinfo()
5 > > implementation when the AI_ADDRCONFIG flag is set.
6 > >
7 > > For example:
8 > >
9 > > struct addrinfo *res, hints = { .ai_family = AF_INET, .ai_flags = AI_ADDRCONFIG };
10 > > getaddrinfo("localhost", NULL, &hints, &res);
11 > >
12 > > This returns no results if there is no non-loopback interface configured with an
13 > > IPv4 address.
14 > >
15 > > Bug: https://bugs.gentoo.org/690758
16 > > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12377#c13
17 > > Signed-off-by: Mike Gilbert <floppym@g.o>
18 > > ---
19 > > lib/portage/process.py | 24 ++++++++++++++++++++++++
20 > > 1 file changed, 24 insertions(+)
21 > >
22 > > diff --git a/lib/portage/process.py b/lib/portage/process.py
23 > > index dfbda75de..c284c04f3 100644
24 > > --- a/lib/portage/process.py
25 > > +++ b/lib/portage/process.py
26 > > @@ -446,6 +446,29 @@ def spawn(mycommand, env=None, opt_name=None, fd_pipes=None, returnpid=False,
27 > > # Everything succeeded
28 > > return 0
29 > >
30 > > +def _configure_dummy_interface():
31 > > + """
32 > > + Configure a dummy interface to work around odd behavior in glibc's
33 > > + getaddrinfo() implementation when the AI_ADDRCONFIG flag is set.
34 > > +
35 > > + For example:
36 > > +
37 > > + struct addrinfo *res, hints = { .ai_family = AF_INET, .ai_flags = AI_ADDRCONFIG };
38 > > + getaddrinfo("localhost", NULL, &hints, &res);
39 > > +
40 > > + This returns no results if there is no non-loopback interface configured with an
41 > > + IPv4 address.
42 > > +
43 > > + Bug: https://bugs.gentoo.org/690758
44 > > + Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=12377#c13
45 > > + """
46 > > + try:
47 > > + subprocess.check_call(['ip','link','add','dummy','type','dummy'])
48 > > + subprocess.check_call(['ip','link','set','dummy','up'])
49 > > + subprocess.check_call(['ip','address','add','10.0.0.1/8','dev','dummy'])
50 > > + except subprocess.CalledProcessError:
51 > > + writemsg("Unable to configure dummy network interface\n")
52 > > +
53 > > def _exec(binary, mycommand, opt_name, fd_pipes,
54 > > env, gid, groups, uid, umask, cwd,
55 > > pre_exec, close_fds, unshare_net, unshare_ipc, unshare_mount, unshare_pid,
56 > > @@ -637,6 +660,7 @@ def _exec(binary, mycommand, opt_name, fd_pipes,
57 > > errno.errorcode.get(e.errno, '?')),
58 > > noiselevel=-1)
59 > > sock.close()
60 > > + _configure_dummy_interface()
61 > > except AttributeError:
62 > > # unshare() not supported by libc
63 > > pass
64 > >
65 >
66 > Maybe it will suffice to add the address to the loopback interface?
67
68 I wasn't expecting that to work, but it actually does! That makes this
69 a bit simpler indeed. I'll send a new patch in a bit.