Bug 2483 - use AI_ADDRCONFIG flag for getaddrinfo() hints on Solaris
Summary: use AI_ADDRCONFIG flag for getaddrinfo() hints on Solaris
Status: CLOSED WONTFIX
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: Miscellaneous (show other bugs)
Version: 7.1p1
Hardware: All Solaris
: P5 enhancement
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-27 08:02 AEDT by Ivo Raisr
Modified: 2021-04-23 15:02 AEST (History)
3 users (show)

See Also:


Attachments
the proposed patch (7.48 KB, patch)
2015-10-27 08:02 AEDT, Ivo Raisr
no flags Details | Diff
the proposed patch #2 (6.44 KB, patch)
2015-10-30 17:52 AEDT, Ivo Raisr
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ivo Raisr 2015-10-27 08:02:50 AEDT
Created attachment 2739 [details]
the proposed patch

getaddrinfo() in several places around OpenSSH results in a name service (DNS) queury. For the detailed list, see below.

On Solaris, when the address family specified in the getaddrinfo() hints is AF_UNSPEC, IPv4 and IPv6 queries are sent over the wire. This is regardless IPv4 or IPv6 interface is actually configured on the host.

Now some sites configure only IPv4 interfaces on the hosts; and name service responds only to IPv4 queries (IPv6 ones are ignored). This has very grave impact on the getaddrinfo() execution time because IPv6 queries basically timeout.

On Solaris, there is AI_ADDRCONFIG flag which can be set for getaddrinfo() hints. It specifies that:
"If the AI_ADDRCONFIG flag is specified, IPv4 addresses are returned
only if an IPv4 address is configured on the local system, and IPv6 addresses are returned only if an IPv6 address is configured on the local system. For this case, the loopback address is not considered to
be as valid as a configured address. For example, when using the DNS, a query for AAAA records should occur only if the node has at least one IPv6 address configured (other than IPv6 loopback) and a query for A records should occur only if the node has at least one IPv4 address configured (other than the IPv4 loopback)."

Therefore setting AI_ADDRCONFIG flag for getaddrinfo() hints when address family is AF_UNSPEC helps a lot in this situation.

See attached patch for the proposed fix.
Regression testing on Solaris went ok. On Linux, OpenSSH builds ok.

Unit testing on Solaris:
------------------------
# Setup. Remove IPv6 address:
ipadm delete-addr net0/v6

# Watch for DNS requests out:
snoop port 53 <local-addr> | grep fake
# AAAA means IPv6 lookups are done.

# Test connectivity (change hostname every time to avoid caching):
ssh fake2

# Cleanup. Eventually enable IPv6 addresses again:
ipadm create-addr -T static -a <original-address> net0/v6
Comment 1 Darren Tucker 2015-10-27 09:23:03 AEDT
Comment on attachment 2739 [details]
the proposed patch

>+        AC_DEFINE([HAVE_AI_ADDRCONFIG])

If you were going to do this in configure you should be using AC_CHECK_DECLS, but AI_ADDRCONFIG is already a preprocessor symbol so it'd be simpler to just use that in the ifdef.

All that said, having this different between portable and openbsd is a maintenance burden.  If we're going to do this perhaps it should be done upstream?
Comment 2 Darren Tucker 2015-10-27 09:27:38 AEDT
(In reply to Ivo Raisr from comment #0)
> Now some sites configure only IPv4 interfaces on the hosts; and name
> service responds only to IPv4 queries (IPv6 ones are ignored). This
> has very grave impact on the getaddrinfo() execution time because
> IPv6 queries basically timeout.

BTW that behaviour is so broken there's even an RFC for it: https://www.ietf.org/rfc/rfc4074.txt.  Maybe they should fix their DNS.
Comment 3 Ivo Raisr 2015-10-30 17:51:59 AEDT
(In reply to Darren Tucker from comment #1)
> Comment on attachment 2739 [details]
> the proposed patch
> 
> >+        AC_DEFINE([HAVE_AI_ADDRCONFIG])
> 
> If you were going to do this in configure you should be using
> AC_CHECK_DECLS, but AI_ADDRCONFIG is already a preprocessor symbol
> so it'd be simpler to just use that in the ifdef.

Patch #2 is reworked according to your comment.


> All that said, having this different between portable and openbsd is
> a maintenance burden.  If we're going to do this perhaps it should
> be done upstream?

I will try. Will go back here if that fails.
Comment 4 Ivo Raisr 2015-10-30 17:52:51 AEDT
Created attachment 2743 [details]
the proposed patch #2
Comment 5 Ivo Raisr 2015-10-30 21:14:56 AEDT
The bug was reported "upstream":

From	Ivo Raisr <ivo.raisr@oracle.com>
Subject a small change to OpenSSH upstream
Date	Fri, 30 Oct 2015 11:04:55 +0100

For details see:
http://lists.openbsd.org/cgi-bin/mj_wwwusr?user=ivo.raisr%40oracle.com&passw=F854-3519-0B6F&list=bugs&brief=on&func=archive-get-part&extra=201510/90
Comment 6 Damien Miller 2020-01-25 22:23:28 AEDT
closing five year old bug with no followup
Comment 7 Damien Miller 2021-04-23 15:02:04 AEST
closing resolved bugs as of 8.6p1 release