mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-21 06:01:42 +00:00
ipn: don't listen on the unspecified address in test
To avoid the Mac firewall dialog of (test) death.
See 4521a59f30
which I added to help debug this.
This commit is contained in:
parent
d2b7cb1e45
commit
e1526b796e
@ -13,6 +13,7 @@ import (
|
|||||||
"net/http/cookiejar"
|
"net/http/cookiejar"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -26,6 +27,13 @@ import (
|
|||||||
"tailscale.io/control" // not yet released
|
"tailscale.io/control" // not yet released
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// Hacky way to signal to magicsock for now not to bind on the
|
||||||
|
// unspecified address. TODO(bradfitz): clean up wgengine's
|
||||||
|
// constructors.
|
||||||
|
os.Setenv("IN_TS_TEST", "1")
|
||||||
|
}
|
||||||
|
|
||||||
func TestIPN(t *testing.T) {
|
func TestIPN(t *testing.T) {
|
||||||
testy.FixLogs(t)
|
testy.FixLogs(t)
|
||||||
defer testy.UnfixLogs(t)
|
defer testy.UnfixLogs(t)
|
||||||
|
@ -1487,16 +1487,20 @@ func (c *Conn) initialBind() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) bind1(ruc **RebindingUDPConn, which string) error {
|
func (c *Conn) bind1(ruc **RebindingUDPConn, which string) error {
|
||||||
|
host := ""
|
||||||
|
if v, _ := strconv.ParseBool(os.Getenv("IN_TS_TEST")); v {
|
||||||
|
host = "127.0.0.1"
|
||||||
|
}
|
||||||
var pc net.PacketConn
|
var pc net.PacketConn
|
||||||
var err error
|
var err error
|
||||||
if c.pconnPort == 0 && DefaultPort != 0 {
|
if c.pconnPort == 0 && DefaultPort != 0 {
|
||||||
pc, err = net.ListenPacket(which, fmt.Sprintf(":%d", DefaultPort))
|
pc, err = net.ListenPacket(which, fmt.Sprintf("%s:%d", host, DefaultPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logf("magicsock: bind: default port %s/%v unavailable; picking random", which, DefaultPort)
|
c.logf("magicsock: bind: default port %s/%v unavailable; picking random", which, DefaultPort)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if pc == nil {
|
if pc == nil {
|
||||||
pc, err = net.ListenPacket(which, fmt.Sprintf(":%d", c.pconnPort))
|
pc, err = net.ListenPacket(which, fmt.Sprintf("%s:%d", host, c.pconnPort))
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logf("magicsock: bind(%s/%v): %v", which, c.pconnPort, err)
|
c.logf("magicsock: bind(%s/%v): %v", which, c.pconnPort, err)
|
||||||
@ -1512,12 +1516,16 @@ func (c *Conn) bind1(ruc **RebindingUDPConn, which string) error {
|
|||||||
// Rebind closes and re-binds the UDP sockets.
|
// Rebind closes and re-binds the UDP sockets.
|
||||||
// It should be followed by a call to ReSTUN.
|
// It should be followed by a call to ReSTUN.
|
||||||
func (c *Conn) Rebind() {
|
func (c *Conn) Rebind() {
|
||||||
|
host := ""
|
||||||
|
if v, _ := strconv.ParseBool(os.Getenv("IN_TS_TEST")); v {
|
||||||
|
host = "127.0.0.1"
|
||||||
|
}
|
||||||
if c.pconnPort != 0 {
|
if c.pconnPort != 0 {
|
||||||
c.pconn4.mu.Lock()
|
c.pconn4.mu.Lock()
|
||||||
if err := c.pconn4.pconn.Close(); err != nil {
|
if err := c.pconn4.pconn.Close(); err != nil {
|
||||||
c.logf("magicsock: link change close failed: %v", err)
|
c.logf("magicsock: link change close failed: %v", err)
|
||||||
}
|
}
|
||||||
packetConn, err := net.ListenPacket("udp4", fmt.Sprintf(":%d", c.pconnPort))
|
packetConn, err := net.ListenPacket("udp4", fmt.Sprintf("%s:%d", host, c.pconnPort))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
c.logf("magicsock: link change rebound port: %d", c.pconnPort)
|
c.logf("magicsock: link change rebound port: %d", c.pconnPort)
|
||||||
c.pconn4.pconn = packetConn.(*net.UDPConn)
|
c.pconn4.pconn = packetConn.(*net.UDPConn)
|
||||||
@ -1528,7 +1536,7 @@ func (c *Conn) Rebind() {
|
|||||||
c.pconn4.mu.Unlock()
|
c.pconn4.mu.Unlock()
|
||||||
}
|
}
|
||||||
c.logf("magicsock: link change, binding new port")
|
c.logf("magicsock: link change, binding new port")
|
||||||
packetConn, err := net.ListenPacket("udp4", ":0")
|
packetConn, err := net.ListenPacket("udp4", host+":0")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logf("magicsock: link change failed to bind new port: %v", err)
|
c.logf("magicsock: link change failed to bind new port: %v", err)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user