component/userhosts: use github.com/figiel/hosts for compatibility with recent libc
In ubuntu 21.04 (libc6 2.33-0ubuntu5) or current debian testing (libc6 2.32-5) no longer use open to open /etc/hosts, but what appears as "openat" in strace output - but can not be replaced by defining an openat function. This uses https://github.com/figiel/hosts which uses another approach of replacing getaddrinfo, gethostbyname* and inet_aton. Users have been updated a bit, because there are some small differences: - the /etc/hosts replacement file is defined by HOSTS_FILE environment variable, not HOSTS - the library name is libuserhosts.so, not userhosts.so Other notable differences, for which we did not need code change are: - the new library also try to load a file when HOSTS_FILE is not set - the new library still use original /etc/hosts file - the new library supports aliases to hostnames, not only ip addresses
-
Owner
I just noticed now, but unlike the previous userhost, this does not support the scenario on which caucase test relies on, which causes a test to be skipped (see test result):
testHttpNetlocIPv6 (caucase.test.CaucaseTest) ... skipped "Cannot resolve 'testhost' as AF_INET6"
This caucase test uses a host file like this
127.0.0.1 testhost ::1 testhost
but the approach in https://github.com/figiel/hosts/blob/fdb45fe219593d63453f4be55cfc2a1199c18f59/userhosts.c is to hook system calls like
int getaddrinfo(const char *restrict node, const char *restrict service, const struct addrinfo *restrict hints, struct addrinfo **restrict res);
and, lookup the
node
from the first matching line in the hosts file:127.0.0.1 testhost <-- ::1 testhost
and call the original method with the alias.
With this example file, when called with
getaddrinfo("testhost", service, hints, res)
the "real"
getaddrinfo
will be called with the resolved value:getaddrinfo("127.0.0.1", service, hints, res)
I don't see how this could easily support names with both IPv4 and IPv6 addresses like this with this approach.
In this caucase test, it's used like this https://lab.nexedi.com/nexedi/caucase/blob/0d663926441f7be6413745f89b1d8756824bbb05/caucase/test.py#L3528-3532 so
hints
argument will containAF_INET6
, we could add support for this exact case, but that seems nonsense because we won't be able to fully support a host files like that: withAF_UNSPEC
it should return both127.0.0.1
and::1
, which seems impossible with this approach.For now, we can say that such a hosts file is not supported by https://github.com/figiel/hosts/ and I don't know how we could make this test run again.
This use case does not seem critically important, we use this only in caucase test and in ERP5. In ERP5 we are only using IPv4 so the problem is only in caucase test, maybe there's a way to change the caucase test to use another approach.
-
mentioned in merge request !1074 (merged)
-
Owner
I don't see how this could easily support names with both IPv4 and IPv6 addresses like this with this approach.
+1
This is a bug in
userhosts.c
, and not immediately trivial to fix.This use case does not seem critically important, we use this only in caucase test and in ERP5. In ERP5 we are only using IPv4 so the problem is only in caucase test, maybe there's a way to change the caucase test to use another approach.
The plain caucased software release (which I rely on) makes caucased listen on IPv6, so having this test skipped is not ideal.