mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
netstack: fallback to IPv4 when checking hostinet interface features
This enables hostinet to start on both IPv4-only and IPv6-only hosts. Note that hostinet doesn't have a way to prevent applications inside gVisor from trying to send, for example, IPv6 packets on an IPv4-only host. The result of trying to do so is environment-dependent, but will likely fail during calls to connect(), send(), and the like. Fixes #8253. PiperOrigin-RevId: 492579750
This commit is contained in:
committed by
gVisor bot
parent
85d931396e
commit
9c5cd1cfca
@@ -25,11 +25,12 @@ import (
|
||||
)
|
||||
|
||||
func queryInterfaceFeatures(interfaces map[int32]*inet.Interface) error {
|
||||
fd, err := unix.Socket(unix.AF_INET6, unix.SOCK_STREAM, 0)
|
||||
fd, err := queryFD()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer unix.Close(fd)
|
||||
|
||||
for idx, nic := range interfaces {
|
||||
var ifr linux.IFReq
|
||||
copy(ifr.IFName[:], nic.Name)
|
||||
@@ -85,3 +86,16 @@ func queryInterfaceFeatures(interfaces map[int32]*inet.Interface) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func queryFD() (int, error) {
|
||||
// Try both AF_INET and AF_INET6 in case only one is supported.
|
||||
var fd int
|
||||
var err error
|
||||
for _, family := range []int{unix.AF_INET6, unix.AF_INET} {
|
||||
fd, err = unix.Socket(family, unix.SOCK_STREAM, 0)
|
||||
if err == nil {
|
||||
return fd, err
|
||||
}
|
||||
}
|
||||
return fd, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user