Bug 221385

Summary: v6 mapped v4 addresses not working in 11.1
Product: Base System Reporter: Sebastian Schulze Struchtrup <seb>
Component: kernAssignee: Michael Tuexen <tuexen>
Status: Closed FIXED    
Severity: Affects Only Me CC: tuexen, vsasjason
Priority: --- Keywords: regression
Version: 11.1-RELEASEFlags: tuexen: mfc-stable11+
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Test case to reproduce the problem none

Description Sebastian Schulze Struchtrup 2017-08-10 08:30:58 UTC
Created attachment 185224 [details]
Test case to reproduce the problem

Having set sysctl net.inet6.ip6.v6only=0, v6-mapped v4 addresses used to work on 11.0 and on previous versions.

On 11.1-RELEASE, I am now getting EAFNOSUPPORT on connect() when using a v6-mapped address on a PF_INET6 socket.

Adding an extra setsockopt to clear IPV6_V6ONLY will work around this.


# sysctl net.inet6.ip6.v6only
net.inet6.ip6.v6only: 0

# uname -a
FreeBSD s5.struchtrup.com 11.1-RELEASE FreeBSD 11.1-RELEASE #0 r321309: Fri Jul 21 02:08:28 UTC 2017     root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64

truss output (stripped) - failing case w/o setsockopt:

socket(PF_INET6,SOCK_STREAM,0)                   = 3 (0x3)
connect(3,{ AF_INET6 [::ffff:127.0.0.1]:1234 },28) ERR#47 'Address family not supported by protocol family'


truss output with setsockopt:

socket(PF_INET6,SOCK_STREAM,0)                   = 3 (0x3)
setsockopt(3,IPPROTO_IPV6,IPV6_V6ONLY,0x7fffffffea94,4) = 0 (0x0)
connect(3,{ AF_INET6 [::ffff:127.0.0.1]:1234 },28) = 0 (0x0)
Comment 1 Michael Tuexen freebsd_committer freebsd_triage 2017-08-16 12:30:55 UTC
I can confirm the problem on head (and therefore an 11.1).

This is most likely related to https://svnweb.freebsd.org/changeset/base/318649
which was MFCed in https://svnweb.freebsd.org/changeset/base/319411.

Let me look into it...
Comment 2 commit-hook freebsd_committer freebsd_triage 2017-08-18 07:27:42 UTC
A commit references this bug:

Author: tuexen
Date: Fri Aug 18 07:27:16 UTC 2017
New revision: 322648
URL: https://svnweb.freebsd.org/changeset/base/322648

Log:
  Ensure inp_vflag is consistently set for TCP endpoints.

  Make sure that the flags INP_IPV4 and INP_IPV6 are consistently set
  for inpcbs used for TCP sockets, no matter if the setting is derived
  from the net.inet6.ip6.v6only sysctl or the IPV6_V6ONLY socket option.
  For UDP this was already done right.

  PR:		221385
  MFC after:	1 week

Changes:
  head/sys/netinet/tcp_usrreq.c
Comment 3 Michael Tuexen freebsd_committer freebsd_triage 2017-08-18 07:36:04 UTC
Hi Sebastian,

I fixed the bug in head, it doesn't matter anymore whether the setting comes for the sysctl variable or the socket option. Thanks for reporting the bug.

From a programming perspective, I would prefer using a socket option in a program to ensure the setting which is wanted compared to relying on a host wide sysctl setting. This sysctl setting can be different between different Operating systems and change between versions of a single operating system.

Best regards
Michael
Comment 4 commit-hook freebsd_committer freebsd_triage 2017-10-17 12:42:32 UTC
A commit references this bug:

Author: tuexen
Date: Tue Oct 17 12:42:17 UTC 2017
New revision: 324686
URL: https://svnweb.freebsd.org/changeset/base/324686

Log:
  MFC r322648:

  Ensure inp_vflag is consistently set for TCP endpoints.

  Make sure that the flags INP_IPV4 and INP_IPV6 are consistently set
  for inpcbs used for TCP sockets, no matter if the setting is derived
  from the net.inet6.ip6.v6only sysctl or the IPV6_V6ONLY socket option.
  For UDP this was already done right.

  PR:		221385

Changes:
_U  stable/11/
  stable/11/sys/netinet/tcp_usrreq.c