ipn/ipnlocal: make peerapi work in netstack mode

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2021-03-30 09:54:52 -07:00
parent 4c83bbf850
commit f01091babe
2 changed files with 40 additions and 10 deletions
+19 -1
View File
@@ -24,6 +24,7 @@ import (
"inet.af/netaddr"
"tailscale.com/net/interfaces"
"tailscale.com/tailcfg"
"tailscale.com/wgengine"
)
var initListenConfig func(*net.ListenConfig, netaddr.IP, *interfaces.State, string) error
@@ -51,6 +52,10 @@ func (s *peerAPIServer) listen(ip netaddr.IP, ifState *interfaces.State) (ln net
}
}
if wgengine.IsNetstack(s.b.e) {
ipStr = ""
}
tcp4or6 := "tcp4"
if ip.Is6() {
tcp4or6 = "tcp6"
@@ -81,12 +86,22 @@ func (s *peerAPIServer) listen(ip netaddr.IP, ifState *interfaces.State) (ln net
type peerAPIListener struct {
ps *peerAPIServer
ip netaddr.IP
ln net.Listener
ln net.Listener // or nil for 2nd+ address family in netstack mdoe
lb *LocalBackend
urlStr string
}
func (pln *peerAPIListener) Close() error {
if pln.ln != nil {
return pln.ln.Close()
}
return nil
}
func (pln *peerAPIListener) Port() int {
if pln.ln == nil {
return 0
}
ta, ok := pln.ln.Addr().(*net.TCPAddr)
if !ok {
return 0
@@ -95,6 +110,9 @@ func (pln *peerAPIListener) Port() int {
}
func (pln *peerAPIListener) serve() {
if pln.ln == nil {
return
}
defer pln.ln.Close()
logf := pln.lb.logf
for {