|
|
@ -19,6 +19,7 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"inet.af/netaddr"
|
|
|
|
"inet.af/netaddr"
|
|
|
|
"tailscale.com/logtail/backoff"
|
|
|
|
"tailscale.com/logtail/backoff"
|
|
|
|
|
|
|
|
"tailscale.com/net/netns"
|
|
|
|
"tailscale.com/types/logger"
|
|
|
|
"tailscale.com/types/logger"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -290,7 +291,7 @@ type fwdConn struct {
|
|
|
|
// closed tracks whether fwdConn has been permanently closed.
|
|
|
|
// closed tracks whether fwdConn has been permanently closed.
|
|
|
|
closed bool
|
|
|
|
closed bool
|
|
|
|
// conn is the current active connection.
|
|
|
|
// conn is the current active connection.
|
|
|
|
conn *net.UDPConn
|
|
|
|
conn net.PacketConn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func newFwdConn(logf logger.Logf, idx int) *fwdConn {
|
|
|
|
func newFwdConn(logf logger.Logf, idx int) *fwdConn {
|
|
|
@ -388,7 +389,7 @@ func (c *fwdConn) send(packet []byte, dst net.Addr) {
|
|
|
|
func (c *fwdConn) read(out []byte) int {
|
|
|
|
func (c *fwdConn) read(out []byte) int {
|
|
|
|
for {
|
|
|
|
for {
|
|
|
|
// Gather the current connection.
|
|
|
|
// Gather the current connection.
|
|
|
|
// We can't hold the lock while we call Read.
|
|
|
|
// We can't hold the lock while we call ReadFrom.
|
|
|
|
c.mu.Lock()
|
|
|
|
c.mu.Lock()
|
|
|
|
conn := c.conn
|
|
|
|
conn := c.conn
|
|
|
|
closed := c.closed
|
|
|
|
closed := c.closed
|
|
|
@ -406,7 +407,7 @@ func (c *fwdConn) read(out []byte) int {
|
|
|
|
c.mu.Unlock()
|
|
|
|
c.mu.Unlock()
|
|
|
|
|
|
|
|
|
|
|
|
c.wg.Add(1)
|
|
|
|
c.wg.Add(1)
|
|
|
|
n, err := conn.Read(out)
|
|
|
|
n, _, err := conn.ReadFrom(out)
|
|
|
|
c.wg.Done()
|
|
|
|
c.wg.Done()
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|
// Success.
|
|
|
|
// Success.
|
|
|
@ -428,9 +429,9 @@ func (c *fwdConn) read(out []byte) int {
|
|
|
|
func (c *fwdConn) reconnectLocked() {
|
|
|
|
func (c *fwdConn) reconnectLocked() {
|
|
|
|
c.closeConnLocked()
|
|
|
|
c.closeConnLocked()
|
|
|
|
// Make a new connection.
|
|
|
|
// Make a new connection.
|
|
|
|
conn, err := net.ListenUDP("udp", nil)
|
|
|
|
conn, err := netns.Listener().ListenPacket(context.Background(), "udp", "")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
c.logf("ListenUDP failed: %v", err)
|
|
|
|
c.logf("ListenPacket failed: %v", err)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
c.conn = conn
|
|
|
|
c.conn = conn
|
|
|
|
}
|
|
|
|
}
|
|
|
|