net: delay IP protocol stack-snooping system calls

This change delays IP protocol stack-snooping system calls until the
start of connection setup for the better experience with some system
call auditing, such as seccomp on Linux. See #16789 for examples.

Also updates the documentation on favoriteAddrFamily, which is the
owner of stack-snooping system calls.

Fixes #16789.

Change-Id: I4af27bc1ed06ffb1f657b6f6381c328c1f41c66c
Reviewed-on: https://go-review.googlesource.com/40750
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Mikio Hara 2017-04-14 17:43:42 +09:00
parent bc29313722
commit 6694a6888b
20 changed files with 157 additions and 181 deletions

View file

@ -31,20 +31,20 @@ func testUnixAddr() string {
func newLocalListener(network string) (Listener, error) {
switch network {
case "tcp":
if supportsIPv4 {
if supportsIPv4() {
if ln, err := Listen("tcp4", "127.0.0.1:0"); err == nil {
return ln, nil
}
}
if supportsIPv6 {
if supportsIPv6() {
return Listen("tcp6", "[::1]:0")
}
case "tcp4":
if supportsIPv4 {
if supportsIPv4() {
return Listen("tcp4", "127.0.0.1:0")
}
case "tcp6":
if supportsIPv6 {
if supportsIPv6() {
return Listen("tcp6", "[::1]:0")
}
case "unix", "unixpacket":
@ -333,18 +333,18 @@ func timeoutTransmitter(c Conn, d, min, max time.Duration, ch chan<- error) {
func newLocalPacketListener(network string) (PacketConn, error) {
switch network {
case "udp":
if supportsIPv4 {
if supportsIPv4() {
return ListenPacket("udp4", "127.0.0.1:0")
}
if supportsIPv6 {
if supportsIPv6() {
return ListenPacket("udp6", "[::1]:0")
}
case "udp4":
if supportsIPv4 {
if supportsIPv4() {
return ListenPacket("udp4", "127.0.0.1:0")
}
case "udp6":
if supportsIPv6 {
if supportsIPv6() {
return ListenPacket("udp6", "[::1]:0")
}
case "unixgram":