mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-03 23:22:23 -08:00
net/memnet: accept tcp4 and tcp6 in Listener.Dial
Listener.Dial checked strings.HasSuffix(network, "tcp"), so it rejected "tcp4" and "tcp6", which Network.Dial accepts and passes through. A derphttp region client dials each DERP node with "tcp4" or "tcp6", so it couldn't reach a DERP server on a memnet Network. Accept exactly "tcp", "tcp4" and "tcp6". Updates #22831 Change-Id: I699c40ed9c0b4a41fa3509514bd1f1bf828adb25 Signed-off-by: Brad Fitzpatrick <[email protected]>
This commit is contained in:
1 parent
667f2ffce4
commit
ebb46e100d
2 files changed
+19
-12
No files matched your search
@@ -6,7 +6,6 @@ package memnet
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
@@ -71,7 +70,9 @@ func (ln *Listener) Accept() (net.Conn, error) {
|
||||
// connection is complete, an error is returned. Once successfully connected
|
||||
// any expiration of the context will not affect the connection.
|
||||
func (ln *Listener) Dial(ctx context.Context, network, addr string) (_ net.Conn, err error) {
|
||||
if !strings.HasSuffix(network, "tcp") {
|
||||
switch network {
|
||||
case "tcp", "tcp4", "tcp6":
|
||||
default:
|
||||
return nil, net.UnknownNetworkError(network)
|
||||
}
|
||||
if connAddr(addr) != ln.addr {
|
||||
|
||||
+16
-10
@@ -12,22 +12,28 @@ func TestListener(t *testing.T) {
|
||||
ln := Listen("srv.local")
|
||||
defer ln.Close()
|
||||
go func() {
|
||||
c, err := ln.Accept()
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
for {
|
||||
c, err := ln.Accept()
|
||||
if err != nil {
|
||||
return // closed
|
||||
}
|
||||
c.Close()
|
||||
}
|
||||
defer c.Close()
|
||||
}()
|
||||
|
||||
if c, err := ln.Dial(context.Background(), "tcp", "invalid"); err == nil {
|
||||
c.Close()
|
||||
t.Fatalf("dial to invalid address succeeded")
|
||||
}
|
||||
c, err := ln.Dial(context.Background(), "tcp", "srv.local")
|
||||
if err != nil {
|
||||
t.Fatalf("dial failed: %v", err)
|
||||
return
|
||||
if c, err := ln.Dial(context.Background(), "udp", "srv.local"); err == nil {
|
||||
c.Close()
|
||||
t.Fatalf("dial with network udp succeeded")
|
||||
}
|
||||
for _, network := range []string{"tcp", "tcp4", "tcp6"} {
|
||||
c, err := ln.Dial(context.Background(), network, "srv.local")
|
||||
if err != nil {
|
||||
t.Fatalf("dial with network %s failed: %v", network, err)
|
||||
}
|
||||
c.Close()
|
||||
}
|
||||
c.Close()
|
||||
}
|
||||
Reference in new issue
Block a user