1
0
mirror of https://github.com/golang/go synced 2024-11-21 23:34:42 -07:00

net: detect EAI_ADDRFAMILY for cgo host lookup on FreeBSD

For #61095.

Change-Id: Iff9f19f6f2eada739967774b50d949f9c5893ee0
Cq-Include-Trybots: luci.golang.try:gotip-darwin-amd64_14,gotip-freebsd-amd64
Reviewed-on: https://go-review.googlesource.com/c/go/+/618015
TryBot-Bypass: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Michael Anthony Knyszek 2024-10-04 15:46:07 +00:00 committed by Michael Knyszek
parent df97215a34
commit 356ba0f065
4 changed files with 51 additions and 32 deletions

View File

@ -16,12 +16,13 @@ const (
AI_V4MAPPED = 0x800
AI_MASK = 0x1407
EAI_AGAIN = 2
EAI_NODATA = 7
EAI_NONAME = 8
EAI_SERVICE = 9
EAI_SYSTEM = 11
EAI_OVERFLOW = 14
EAI_ADDRFAMILY = 1
EAI_AGAIN = 2
EAI_NODATA = 7
EAI_NONAME = 8
EAI_SERVICE = 9
EAI_SYSTEM = 11
EAI_OVERFLOW = 14
NI_NAMEREQD = 4
)

View File

@ -16,6 +16,7 @@ import (
"errors"
"internal/bytealg"
"net/netip"
"runtime"
"syscall"
"unsafe"
@ -195,6 +196,16 @@ func cgoLookupHostIP(network, name string) (addrs []IPAddr, err error) {
return nil, newDNSError(err, name, "")
case _C_EAI_NONAME, _C_EAI_NODATA:
return nil, newDNSError(errNoSuchHost, name, "")
case _C_EAI_ADDRFAMILY:
if runtime.GOOS == "freebsd" {
// FreeBSD began returning EAI_ADDRFAMILY for valid hosts without
// an A record in 13.2. We previously returned "no such host" for
// this case.
//
// https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=273912
return nil, newDNSError(errNoSuchHost, name, "")
}
fallthrough
default:
return nil, newDNSError(addrinfoErrno(gerrno), name, "")
}

View File

@ -22,6 +22,11 @@ package net
#define EAI_NODATA -5
#endif
// If nothing else defined EAI_ADDRFAMILY, make sure it has a value.
#ifndef EAI_ADDRFAMILY
#define EAI_ADDRFAMILY -9
#endif
// If nothing else defined EAI_OVERFLOW, make sure it has a value.
#ifndef EAI_OVERFLOW
#define EAI_OVERFLOW -12
@ -31,19 +36,20 @@ import "C"
import "unsafe"
const (
_C_AF_INET = C.AF_INET
_C_AF_INET6 = C.AF_INET6
_C_AF_UNSPEC = C.AF_UNSPEC
_C_EAI_AGAIN = C.EAI_AGAIN
_C_EAI_NODATA = C.EAI_NODATA
_C_EAI_NONAME = C.EAI_NONAME
_C_EAI_SERVICE = C.EAI_SERVICE
_C_EAI_OVERFLOW = C.EAI_OVERFLOW
_C_EAI_SYSTEM = C.EAI_SYSTEM
_C_IPPROTO_TCP = C.IPPROTO_TCP
_C_IPPROTO_UDP = C.IPPROTO_UDP
_C_SOCK_DGRAM = C.SOCK_DGRAM
_C_SOCK_STREAM = C.SOCK_STREAM
_C_AF_INET = C.AF_INET
_C_AF_INET6 = C.AF_INET6
_C_AF_UNSPEC = C.AF_UNSPEC
_C_EAI_ADDRFAMILY = C.EAI_ADDRFAMILY
_C_EAI_AGAIN = C.EAI_AGAIN
_C_EAI_NODATA = C.EAI_NODATA
_C_EAI_NONAME = C.EAI_NONAME
_C_EAI_SERVICE = C.EAI_SERVICE
_C_EAI_OVERFLOW = C.EAI_OVERFLOW
_C_EAI_SYSTEM = C.EAI_SYSTEM
_C_IPPROTO_TCP = C.IPPROTO_TCP
_C_IPPROTO_UDP = C.IPPROTO_UDP
_C_SOCK_DGRAM = C.SOCK_DGRAM
_C_SOCK_STREAM = C.SOCK_STREAM
)
type (

View File

@ -14,19 +14,20 @@ import (
)
const (
_C_AF_INET = syscall.AF_INET
_C_AF_INET6 = syscall.AF_INET6
_C_AF_UNSPEC = syscall.AF_UNSPEC
_C_EAI_AGAIN = unix.EAI_AGAIN
_C_EAI_NONAME = unix.EAI_NONAME
_C_EAI_SERVICE = unix.EAI_SERVICE
_C_EAI_NODATA = unix.EAI_NODATA
_C_EAI_OVERFLOW = unix.EAI_OVERFLOW
_C_EAI_SYSTEM = unix.EAI_SYSTEM
_C_IPPROTO_TCP = syscall.IPPROTO_TCP
_C_IPPROTO_UDP = syscall.IPPROTO_UDP
_C_SOCK_DGRAM = syscall.SOCK_DGRAM
_C_SOCK_STREAM = syscall.SOCK_STREAM
_C_AF_INET = syscall.AF_INET
_C_AF_INET6 = syscall.AF_INET6
_C_AF_UNSPEC = syscall.AF_UNSPEC
_C_EAI_ADDRFAMILY = unix.EAI_ADDRFAMILY
_C_EAI_AGAIN = unix.EAI_AGAIN
_C_EAI_NONAME = unix.EAI_NONAME
_C_EAI_SERVICE = unix.EAI_SERVICE
_C_EAI_NODATA = unix.EAI_NODATA
_C_EAI_OVERFLOW = unix.EAI_OVERFLOW
_C_EAI_SYSTEM = unix.EAI_SYSTEM
_C_IPPROTO_TCP = syscall.IPPROTO_TCP
_C_IPPROTO_UDP = syscall.IPPROTO_UDP
_C_SOCK_DGRAM = syscall.SOCK_DGRAM
_C_SOCK_STREAM = syscall.SOCK_STREAM
)
type (