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