The getaddrinfo(3) manual page refer to POSIX.1 and RFC 3493 in the STANDARDS section. Both of these documents say getaddrinfo accepts AI_V4MAPPED flag in the hint. In fact if the AI_V4MAPPED bit is set in the ai_flags member of the hint addrinfo structure, getaddrinfo(3) always fails with error code 3 ("Invalid value for ai_flags"). This can be easily demonstrated with the following sample code: #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <string.h> #include <stdio.h> int main(void) { struct addrinfo *ai; struct addrinfo hint; int errcode; memset(&hint, 0, sizeof(hint)); hint.ai_family = PF_INET6; hint.ai_flags = AI_V4MAPPED; errcode = getaddrinfo("freebsd.org", "80", &hint, &ai); if(errcode) { fprintf(stderr, "Error %d: %s\n", errcode, gai_strerror(errcode)); return 1; } freeaddrinfo(ai); return 0; }
Confirmed this is still an issue, and not specific to 10.x. Assigning to -bugs@ for broader exposure.
AI_V4MAPPED is not supported on FreeBSD. While the manual page mentioned RFC 3493, AI_ALL or AI_V4MAPPED returns EAI_BADFLAGS. This is due to a decision on the API implementation.
I hit this too trying to port Titus to FreeBSD (https://github.com/AGWA/titus) It build successfully, but fails to run with an "Invalid value for ai_flags" error I'll also note that AI_ALL and AI_V4MAPPED are both still mentioned in getipnodebyname(3) I was asked to cc bz@ and ume@ as well. r175955 claims to remove support for AI_ALL and AI_V4MAPPED, but perhaps it was incomplete?
If we don't support it, should we remove the flags from netdb.h so that software fails to compile (instead of generating a runtime error)? RFC 3493 requires these flags (by my reading), so we are non-conforming and should not list it in STANDARDS unless we also include a caveat for the parts we don't implement (and arguably we should fix our implementation to be conforming instead).
(In reply to John Baldwin from comment #4) I believe the decision to be non-conforming was intentional due to security issues that RFC presents. The internet seems torn about whether or not V4 mapped V6 addresses should have ever been created because it allows some nasty backdoors if your firewalls don't cover this scenario.
We should document this then.
(In reply to Mark Felder from comment #3) > I'll also note that AI_ALL and AI_V4MAPPED are both still mentioned in getipnodebyname(3) This issue is only for getaddrinfo(3). getipnodebyname(3) is seeing AI_ALL and AI_V4MAPPED and does proper job.
I implemented an AI_V4MAPPED support for getaddrinfo(3). My proposed patch is: https://people.freebsd.org/~ume/getaddrinfo-v4mapped.diff However, I'm skeptical to commit it. This issue is confirmation to standard v.s. security consideration. If there are some opinions to make conformation to standard give priority, I'll commit it.
(In reply to Hajimu UMEMOTO from comment #8) Oops, the attached patch was not applied cleanly on head. It was against stable/10. So, I made the patch against head, again: https://people.freebsd.org/~ume/getaddrinfo-v4mapped-20151123.diff Further, I made the AI_V4MAPPED support optional. It is off by default, and is enabled by specifying WITH_GETADDRINFO_V4MAPPED=yes.
After some discussion with hrs@, I think supporting the v4mapped address by getaddrinfo(3) itself doesn't related to security. And, the destination address selection didn't work against the v4mapped address. So, I re-made the patch: https://people.freebsd.org/~ume/getaddrinfo-v4mapped-20151213.diff If there is no objection, I'll commit it.
I reworked to address the following comments from hrs@: - We need to obey WITHOUT_INET6. - We should use _map_v4v6_address(). https://people.freebsd.org/~ume/getaddrinfo-v4mapped-20151213-2.diff
A commit references this bug: Author: ume Date: Fri Dec 18 17:53:19 UTC 2015 New revision: 292444 URL: https://svnweb.freebsd.org/changeset/base/292444 Log: Add AI_V4MAPPED and AI_ALL support for getaddrinfo(3). PR: 198092 MFC after: 1 week Changes: head/lib/libc/net/getaddrinfo.3 head/lib/libc/net/getaddrinfo.c
A commit references this bug: Author: ume Date: Fri Dec 18 18:08:53 UTC 2015 New revision: 292446 URL: https://svnweb.freebsd.org/changeset/base/292446 Log: Add AI_V4MAPPED and AI_ALL support for getaddrinfo(3). We need to change netdb.h to make it actually enabled. PR: 198092 MFC after: 1 week Changes: head/include/netdb.h
A commit references this bug: Author: ume Date: Fri Dec 25 11:17:22 UTC 2015 New revision: 292722 URL: https://svnweb.freebsd.org/changeset/base/292722 Log: Add AI_V4MAPPED and AI_ALL support for getaddrinfo(3). PR: 198092 Changes: _U stable/10/ stable/10/include/netdb.h stable/10/lib/libc/net/getaddrinfo.3 stable/10/lib/libc/net/getaddrinfo.c
A commit references this bug: Author: ume Date: Fri Dec 25 11:33:09 UTC 2015 New revision: 292724 URL: https://svnweb.freebsd.org/changeset/base/292724 Log: MFC r292444, r292446: Add AI_V4MAPPED and AI_ALL support for getaddrinfo(3). PR: 198092 Changes: _U stable/9/include/ stable/9/include/netdb.h _U stable/9/lib/libc/ stable/9/lib/libc/net/getaddrinfo.3 stable/9/lib/libc/net/getaddrinfo.c