mirror of
https://github.com/golang/go
synced 2024-11-18 06:44:49 -07:00
next step for 6.out on Borg: fix and test
net code on IPv4-only machines. R=r DELTA=27 (25 added, 0 deleted, 2 changed) OCL=28404 CL=28411
This commit is contained in:
parent
88a1aa8e1a
commit
0d33992866
@ -10,6 +10,7 @@ import (
|
|||||||
"io";
|
"io";
|
||||||
"net";
|
"net";
|
||||||
"os";
|
"os";
|
||||||
|
"syscall";
|
||||||
"testing";
|
"testing";
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -81,7 +82,17 @@ func TestDialGoogle(t *testing.T) {
|
|||||||
doDialTCP(t, "tcp", addr);
|
doDialTCP(t, "tcp", addr);
|
||||||
if addr[0] != '[' {
|
if addr[0] != '[' {
|
||||||
doDial(t, "tcp4", addr);
|
doDial(t, "tcp4", addr);
|
||||||
doDialTCP(t, "tcp4", addr)
|
doDialTCP(t, "tcp4", addr);
|
||||||
|
|
||||||
|
if !preferIPv4 {
|
||||||
|
// make sure preferIPv4 flag works.
|
||||||
|
preferIPv4 = true;
|
||||||
|
syscall.SocketDisableIPv6 = true;
|
||||||
|
doDial(t, "tcp4", addr);
|
||||||
|
doDialTCP(t, "tcp4", addr);
|
||||||
|
syscall.SocketDisableIPv6 = false;
|
||||||
|
preferIPv4 = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
doDial(t, "tcp6", addr);
|
doDial(t, "tcp6", addr);
|
||||||
doDialTCP(t, "tcp6", addr)
|
doDialTCP(t, "tcp6", addr)
|
||||||
|
@ -345,7 +345,7 @@ func internetSocket(net, laddr, raddr string, proto int64, mode string)
|
|||||||
default:
|
default:
|
||||||
// Otherwise, guess.
|
// Otherwise, guess.
|
||||||
// If the addresses are IPv4 and we prefer IPv4, use 4; else 6.
|
// If the addresses are IPv4 and we prefer IPv4, use 4; else 6.
|
||||||
if preferIPv4 && lip.To4() != nil && rip.To4() != nil {
|
if preferIPv4 && (lip == nil || lip.To4() != nil) && (rip == nil || rip.To4() != nil) {
|
||||||
vers = 4
|
vers = 4
|
||||||
} else {
|
} else {
|
||||||
vers = 6
|
vers = 6
|
||||||
|
@ -12,12 +12,19 @@ import (
|
|||||||
"unsafe";
|
"unsafe";
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// For testing: clients can set this flag to force
|
||||||
|
// creation of IPv6 sockets to return EAFNOSUPPORT.
|
||||||
|
var SocketDisableIPv6 bool
|
||||||
|
|
||||||
func SockaddrToSockaddrInet4(s *Sockaddr) *SockaddrInet4;
|
func SockaddrToSockaddrInet4(s *Sockaddr) *SockaddrInet4;
|
||||||
func SockaddrToSockaddrInet6(s *Sockaddr) *SockaddrInet6;
|
func SockaddrToSockaddrInet6(s *Sockaddr) *SockaddrInet6;
|
||||||
func SockaddrInet4ToSockaddr(s *SockaddrInet4) *Sockaddr;
|
func SockaddrInet4ToSockaddr(s *SockaddrInet4) *Sockaddr;
|
||||||
func SockaddrInet6ToSockaddr(s *SockaddrInet6) *Sockaddr;
|
func SockaddrInet6ToSockaddr(s *SockaddrInet6) *Sockaddr;
|
||||||
|
|
||||||
func Socket(domain, proto, typ int64) (ret int64, err int64) {
|
func Socket(domain, proto, typ int64) (ret int64, err int64) {
|
||||||
|
if domain == AF_INET6 && SocketDisableIPv6 {
|
||||||
|
return -1, EAFNOSUPPORT
|
||||||
|
}
|
||||||
r1, r2, e := Syscall(SYS_SOCKET, domain, proto, typ);
|
r1, r2, e := Syscall(SYS_SOCKET, domain, proto, typ);
|
||||||
return r1, e
|
return r1, e
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,10 @@ import (
|
|||||||
"unsafe";
|
"unsafe";
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// For testing: clients can set this flag to force
|
||||||
|
// creation of IPv6 sockets to return EAFNOSUPPORT.
|
||||||
|
var SocketDisableIPv6 bool
|
||||||
|
|
||||||
func SockaddrToSockaddrInet4(s *Sockaddr) *SockaddrInet4;
|
func SockaddrToSockaddrInet4(s *Sockaddr) *SockaddrInet4;
|
||||||
func SockaddrToSockaddrInet6(s *Sockaddr) *SockaddrInet6;
|
func SockaddrToSockaddrInet6(s *Sockaddr) *SockaddrInet6;
|
||||||
func SockaddrInet4ToSockaddr(s *SockaddrInet4) *Sockaddr;
|
func SockaddrInet4ToSockaddr(s *SockaddrInet4) *Sockaddr;
|
||||||
@ -30,6 +34,9 @@ func saLen(s *Sockaddr) int64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Socket(domain, proto, typ int64) (ret int64, err int64) {
|
func Socket(domain, proto, typ int64) (ret int64, err int64) {
|
||||||
|
if domain == AF_INET6 && SocketDisableIPv6 {
|
||||||
|
return -1, EAFNOSUPPORT
|
||||||
|
}
|
||||||
r1, r2, e := Syscall(SYS_SOCKET, domain, proto, typ);
|
r1, r2, e := Syscall(SYS_SOCKET, domain, proto, typ);
|
||||||
return r1, e
|
return r1, e
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user