mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-30 05:25:35 +00:00
more WIP
Change-Id: I228007b4f361a2b63766689f09b1932f86955d0b Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
602adde5dc
commit
583f1b73c5
@ -11,6 +11,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
@ -23,10 +24,12 @@
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/mitchellh/go-ps"
|
||||||
"tailscale.com/client/tailscale"
|
"tailscale.com/client/tailscale"
|
||||||
"tailscale.com/util/must"
|
"tailscale.com/util/must"
|
||||||
"tailscale.com/util/set"
|
"tailscale.com/util/set"
|
||||||
@ -45,11 +48,15 @@ func absify(cmd string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func serveCmd(w http.ResponseWriter, cmd string, args ...string) {
|
func serveCmd(w http.ResponseWriter, cmd string, args ...string) {
|
||||||
|
log.Printf("Got serveCmd for %q %v", cmd, args)
|
||||||
out, err := exec.Command(absify(cmd), args...).CombinedOutput()
|
out, err := exec.Command(absify(cmd), args...).CombinedOutput()
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Header().Set("Exec-Err", err.Error())
|
w.Header().Set("Exec-Err", err.Error())
|
||||||
w.WriteHeader(500)
|
w.WriteHeader(500)
|
||||||
|
log.Printf("Err on serveCmd for %q %v, %d bytes of output: %v", cmd, args, len(out), err)
|
||||||
|
} else {
|
||||||
|
log.Printf("Did serveCmd for %q %v, %d bytes of output", cmd, args, len(out))
|
||||||
}
|
}
|
||||||
w.Write(out)
|
w.Write(out)
|
||||||
}
|
}
|
||||||
@ -74,6 +81,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if distro.Get() == distro.Gokrazy {
|
||||||
|
nsRx := regexp.MustCompile(`(?m)^nameserver (.*)`)
|
||||||
|
for t := time.Now(); time.Since(t) < 10*time.Second; time.Sleep(10 * time.Millisecond) {
|
||||||
|
all, _ := os.ReadFile("/etc/resolv.conf")
|
||||||
|
if nsRx.Match(all) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logc, err := net.Dial("tcp", "9.9.9.9:124")
|
logc, err := net.Dial("tcp", "9.9.9.9:124")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.SetOutput(logc)
|
log.SetOutput(logc)
|
||||||
@ -81,6 +98,34 @@ func main() {
|
|||||||
|
|
||||||
log.Printf("Tailscale Test Agent running.")
|
log.Printf("Tailscale Test Agent running.")
|
||||||
|
|
||||||
|
if distro.Get() == distro.Gokrazy {
|
||||||
|
procs, err := ps.Processes()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("ps.Processes: %v", err)
|
||||||
|
}
|
||||||
|
killed := false
|
||||||
|
for _, p := range procs {
|
||||||
|
if p.Executable() == "tailscaled" {
|
||||||
|
if op, err := os.FindProcess(p.Pid()); err == nil {
|
||||||
|
op.Signal(os.Interrupt)
|
||||||
|
killed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Printf("killed = %v", killed)
|
||||||
|
if killed {
|
||||||
|
for {
|
||||||
|
_, err := exec.Command(absify("tailscale"), "status", "--json").CombinedOutput()
|
||||||
|
if err == nil {
|
||||||
|
log.Printf("tailscaled back up")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
log.Printf("tailscale status error; sleeping before trying again...")
|
||||||
|
time.Sleep(50 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var mux http.ServeMux
|
var mux http.ServeMux
|
||||||
var hs http.Server
|
var hs http.Server
|
||||||
hs.Handler = &mux
|
hs.Handler = &mux
|
||||||
@ -117,6 +162,22 @@ func main() {
|
|||||||
return
|
return
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/up", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/up", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
cmd := exec.Command(absify("tailscale"), "debug", "daemon-logs")
|
||||||
|
out, err := cmd.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer out.Close()
|
||||||
|
cmd.Start()
|
||||||
|
defer cmd.Process.Kill()
|
||||||
|
go func() {
|
||||||
|
bs := bufio.NewScanner(out)
|
||||||
|
for bs.Scan() {
|
||||||
|
log.Printf("Daemon: %s", bs.Text())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
serveCmd(w, "tailscale", "up", "--login-server=http://control.tailscale")
|
serveCmd(w, "tailscale", "up", "--login-server=http://control.tailscale")
|
||||||
})
|
})
|
||||||
mux.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
"tailscale.com/ipn/ipnstate"
|
"tailscale.com/ipn/ipnstate"
|
||||||
"tailscale.com/tstest/natlab/vnet"
|
"tailscale.com/tstest/natlab/vnet"
|
||||||
)
|
)
|
||||||
@ -141,41 +142,37 @@ func (nt *natTest) runTest(node1, node2 addNodeFunc) {
|
|||||||
c1 := &http.Client{Transport: nt.vnet.NodeAgentRoundTripper(nodes[0])}
|
c1 := &http.Client{Transport: nt.vnet.NodeAgentRoundTripper(nodes[0])}
|
||||||
c2 := &http.Client{Transport: nt.vnet.NodeAgentRoundTripper(nodes[1])}
|
c2 := &http.Client{Transport: nt.vnet.NodeAgentRoundTripper(nodes[1])}
|
||||||
|
|
||||||
// var lc1 tailscale.LocalClient
|
var eg errgroup.Group
|
||||||
// lc1.Dial = nt.vnet.NodeAgentDialer(nodes[0])
|
var sts [2]*ipnstate.Status
|
||||||
//st, err := lc1.Status(ctx)
|
|
||||||
|
|
||||||
for i, c := range []*http.Client{c1, c2} {
|
for i, c := range []*http.Client{c1, c2} {
|
||||||
st, err := status(ctx, c)
|
i, c := i, c
|
||||||
if err != nil {
|
eg.Go(func() error {
|
||||||
t.Fatalf("node%d status: %v", i, err)
|
st, err := status(ctx, c)
|
||||||
}
|
if err != nil {
|
||||||
t.Logf("XXX node%d status: %v", i, st)
|
return fmt.Errorf("node%d status: %w", i, err)
|
||||||
if err := up(ctx, c); err != nil {
|
}
|
||||||
t.Fatalf("node%d up: %v", i, err)
|
t.Logf("node%d status: %v", i, st)
|
||||||
}
|
if err := up(ctx, c); err != nil {
|
||||||
t.Logf("XXX node%d up!", i)
|
return fmt.Errorf("node%d up: %w", i, err)
|
||||||
|
}
|
||||||
|
t.Logf("node%d up!", i)
|
||||||
|
st, err = status(ctx, c)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("node%d status: %w", i, err)
|
||||||
|
}
|
||||||
|
sts[i] = st
|
||||||
|
|
||||||
|
if st.BackendState != "Running" {
|
||||||
|
return fmt.Errorf("node%d state = %q", i, st.BackendState)
|
||||||
|
}
|
||||||
|
t.Logf("node%d up with %v", i, sts[i].Self.TailscaleIPs)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
if err := eg.Wait(); err != nil {
|
||||||
t.Logf("both up1")
|
t.Fatalf("initial setup: %v", err)
|
||||||
|
|
||||||
var sts []*ipnstate.Status
|
|
||||||
for i, c := range []*http.Client{c1, c2} {
|
|
||||||
st, err := status(ctx, c)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("node%d status second time: %v", i, err)
|
|
||||||
}
|
|
||||||
if st.BackendState != "Running" {
|
|
||||||
t.Fatalf("node%d state = %q", i, st.BackendState)
|
|
||||||
}
|
|
||||||
if len(st.Peer) != 1 {
|
|
||||||
t.Fatalf("node%d peer count = %d; want 1", i, len(st.Peer))
|
|
||||||
}
|
|
||||||
sts = append(sts, st)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("both up2")
|
|
||||||
|
|
||||||
route, err := ping(ctx, c1, sts[1].Self.TailscaleIPs[0].String())
|
route, err := ping(ctx, c1, sts[1].Self.TailscaleIPs[0].String())
|
||||||
t.Logf("ping route: %v, %v", route, err)
|
t.Logf("ping route: %v, %v", route, err)
|
||||||
}
|
}
|
||||||
|
@ -1373,8 +1373,7 @@ func (s *Server) NodeAgentDialer(n *Node) DialFunc {
|
|||||||
|
|
||||||
func (s *Server) NodeAgentRoundTripper(n *Node) http.RoundTripper {
|
func (s *Server) NodeAgentRoundTripper(n *Node) http.RoundTripper {
|
||||||
return &http.Transport{
|
return &http.Transport{
|
||||||
DisableKeepAlives: true, // XXX
|
DialContext: s.NodeAgentDialer(n),
|
||||||
DialContext: s.NodeAgentDialer(n),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user