Merge branch 'master' of github.com:tailscale/tailscale into HEAD

reviewable/pr187/r1
David Anderson 2020-03-16 18:37:38 -07:00
commit 5758d8d48f
9 changed files with 61 additions and 16 deletions

View File

@ -18,7 +18,6 @@ import (
"syscall" "syscall"
"github.com/apenwarr/fixconsole" "github.com/apenwarr/fixconsole"
"github.com/pborman/getopt/v2"
"github.com/peterbourgon/ff/v2/ffcli" "github.com/peterbourgon/ff/v2/ffcli"
"github.com/tailscale/wireguard-go/wgcfg" "github.com/tailscale/wireguard-go/wgcfg"
"tailscale.com/ipn" "tailscale.com/ipn"
@ -120,7 +119,7 @@ var upArgs = struct {
func runUp(ctx context.Context, args []string) error { func runUp(ctx context.Context, args []string) error {
pol := logpolicy.New("tailnode.log.tailscale.io") pol := logpolicy.New("tailnode.log.tailscale.io")
if len(args) > 0 { if len(args) > 0 {
log.Fatalf("too many non-flag arguments: %#v", getopt.Args()[0]) log.Fatalf("too many non-flag arguments: %q", args)
} }
defer pol.Close() defer pol.Close()
@ -149,7 +148,7 @@ func runUp(ctx context.Context, args []string) error {
c, err := safesocket.Connect(upArgs.socket, 41112) c, err := safesocket.Connect(upArgs.socket, 41112)
if err != nil { if err != nil {
log.Fatalf("safesocket.Connect: %v\n", err) log.Fatalf("Failed to connect to connect to tailscaled. (safesocket.Connect: %v)\n", err)
} }
clientToServer := func(b []byte) { clientToServer := func(b []byte) {
ipn.WriteMsg(c, b) ipn.WriteMsg(c, b)

View File

@ -348,6 +348,53 @@ func TestControl(t *testing.T) {
c3.checkNoStatus(t) c3.checkNoStatus(t)
c4.checkNoStatus(t) c4.checkNoStatus(t)
}) })
t.Run("set hostinfo", func(t *testing.T) {
c1.SetHostinfo(&tailcfg.Hostinfo{
BackendLogID: "set-hostinfo-test",
OS: "linux",
})
c1.waitStatus(t, stateSynchronized)
c2NetMap := c2.status(t).New.NetMap
if len(c2NetMap.Peers) != 1 {
t.Fatalf("wrong number of peers: %v", c2NetMap.Peers)
}
peer := c2NetMap.Peers[0]
if !peer.KeepAlive {
t.Errorf("peer KeepAlive=false, want true")
}
if peer.Hostinfo.OS != "linux" {
t.Errorf("peer hostinfo does not have OS: %v", peer.Hostinfo)
}
c2.SetHostinfo(&tailcfg.Hostinfo{
BackendLogID: "set-hostinfo-test",
OS: "iOS",
})
c1NetMap = c1.status(t).New.NetMap
c2NetMap = c2.status(t).New.NetMap
if len(c1NetMap.Peers) != 1 {
t.Fatalf("wrong number of peers: %v", c1NetMap.Peers)
}
if len(c2NetMap.Peers) != 1 {
t.Fatalf("wrong number of peers: %v", c2NetMap.Peers)
}
peer = c1NetMap.Peers[0]
if peer.KeepAlive {
t.Errorf("peer KeepAlive=true, want false")
}
if peer.Hostinfo.OS != "iOS" {
t.Errorf("peer hostinfo does not have OS: %v", peer.Hostinfo)
}
peer = c2NetMap.Peers[0]
if peer.KeepAlive {
t.Errorf("peer KeepAlive=true, want false")
}
if peer.Hostinfo.OS != "linux" {
t.Errorf("peer hostinfo does not have OS: %v", peer.Hostinfo)
}
})
} }
func hasStringsSuffix(list, suffix []string) bool { func hasStringsSuffix(list, suffix []string) bool {

View File

@ -16,7 +16,6 @@ import (
"github.com/tailscale/wireguard-go/wgcfg" "github.com/tailscale/wireguard-go/wgcfg"
"tailscale.com/tailcfg" "tailscale.com/tailcfg"
"tailscale.com/version"
"tailscale.com/wgengine/filter" "tailscale.com/wgengine/filter"
) )
@ -328,8 +327,7 @@ func (nm *NetworkMap) _WireGuardConfig(uflags int, dnsOverride []wgcfg.IP, allEn
aips = append(aips, aip) aips = append(aips, aip)
} }
fmt.Fprintf(buf, "AllowedIPs = %s\n", strings.Join(aips, ", ")) fmt.Fprintf(buf, "AllowedIPs = %s\n", strings.Join(aips, ", "))
doKeepAlives := !version.IsMobile() if peer.KeepAlive {
if doKeepAlives {
fmt.Fprintf(buf, "PersistentKeepalive = 25\n") fmt.Fprintf(buf, "PersistentKeepalive = 25\n")
} }
} }

View File

@ -169,7 +169,8 @@ func (l *logger) drainPending() (res []byte) {
entries := 0 entries := 0
var batchDone bool var batchDone bool
for buf.Len() < 1<<18 && !batchDone { const maxLen = 256 << 10
for buf.Len() < maxLen && !batchDone {
b, err := l.buffer.TryReadLine() b, err := l.buffer.TryReadLine()
if err == io.EOF { if err == io.EOF {
break break
@ -292,7 +293,7 @@ func (l *logger) upload(ctx context.Context, body []byte) (uploaded bool, err er
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
uploaded = resp.StatusCode == 400 // the server saved the logs anyway uploaded = resp.StatusCode == 400 // the server saved the logs anyway
b, _ := ioutil.ReadAll(resp.Body) b, _ := ioutil.ReadAll(resp.Body)
return uploaded, fmt.Errorf("log upload of %d bytes %s failed %d: %q", len(body), compressedNote, resp.StatusCode, string(b)) return uploaded, fmt.Errorf("log upload of %d bytes %s failed %d: %q", len(body), compressedNote, resp.StatusCode, b)
} }
return true, nil return true, nil
} }
@ -402,10 +403,8 @@ func (l *logger) Write(buf []byte) (int, error) {
} else { } else {
// The log package always line-terminates logs, // The log package always line-terminates logs,
// so this is an uncommon path. // so this is an uncommon path.
bufnl := make([]byte, len(buf)+1) withNL := append(buf[:len(buf):len(buf)], '\n')
copy(bufnl, buf) l.stderr.Write(withNL)
bufnl[len(bufnl)-1] = '\n'
l.stderr.Write(bufnl)
} }
} }
b := l.encode(buf) b := l.encode(buf)

View File

@ -124,7 +124,7 @@ func ParseBindingRequest(b []byte) (TxID, error) {
var ( var (
ErrNotSTUN = errors.New("response is not a STUN packet") ErrNotSTUN = errors.New("response is not a STUN packet")
ErrNotSuccessResponse = errors.New("STUN response error") ErrNotSuccessResponse = errors.New("STUN packet is not a response")
ErrMalformedAttrs = errors.New("STUN response has malformed attributes") ErrMalformedAttrs = errors.New("STUN response has malformed attributes")
ErrNotBindingRequest = errors.New("STUN request not a binding request") ErrNotBindingRequest = errors.New("STUN request not a binding request")
ErrWrongSoftware = errors.New("STUN request came from non-Tailscale software") ErrWrongSoftware = errors.New("STUN request came from non-Tailscale software")

View File

@ -110,7 +110,7 @@ func (s *Stunner) Receive(p []byte, fromAddr *net.UDPAddr) {
// check probe coming in late. Ignore. // check probe coming in late. Ignore.
return return
} }
s.logf("stunner: received bad STUN response: %v", err) s.logf("stunner: received unexpected STUN message response from %v: %v", fromAddr, err)
return return
} }
r, ok := s.removeTX(tx) r, ok := s.removeTX(tx)

View File

@ -134,6 +134,8 @@ type Node struct {
Created time.Time Created time.Time
LastSeen *time.Time `json:",omitempty"` LastSeen *time.Time `json:",omitempty"`
KeepAlive bool // open and keep open a connection to this peer
MachineAuthorized bool // TODO(crawshaw): replace with MachineStatus MachineAuthorized bool // TODO(crawshaw): replace with MachineStatus
// NOTE: any new fields containing pointers in this type // NOTE: any new fields containing pointers in this type

View File

@ -160,7 +160,7 @@ func TestHostinfoEqual(t *testing.T) {
} }
func TestNodeEqual(t *testing.T) { func TestNodeEqual(t *testing.T) {
nodeHandles := []string{"ID", "Name", "User", "Key", "KeyExpiry", "Machine", "Addresses", "AllowedIPs", "Endpoints", "DERP", "Hostinfo", "Created", "LastSeen", "MachineAuthorized"} nodeHandles := []string{"ID", "Name", "User", "Key", "KeyExpiry", "Machine", "Addresses", "AllowedIPs", "Endpoints", "DERP", "Hostinfo", "Created", "LastSeen", "KeepAlive", "MachineAuthorized"}
if have := fieldsOf(reflect.TypeOf(Node{})); !reflect.DeepEqual(have, nodeHandles) { if have := fieldsOf(reflect.TypeOf(Node{})); !reflect.DeepEqual(have, nodeHandles) {
t.Errorf("Node.Equal check might be out of sync\nfields: %q\nhandled: %q\n", t.Errorf("Node.Equal check might be out of sync\nfields: %q\nhandled: %q\n",
have, nodeHandles) have, nodeHandles)

View File

@ -7,5 +7,5 @@
// Package version provides the version that the binary was built at. // Package version provides the version that the binary was built at.
package version package version
const LONG = "date.20200311" const LONG = "date.20200315"
const SHORT = LONG // TODO: unused; remove SHORT? Make it a func? const SHORT = LONG // TODO: unused; remove SHORT? Make it a func?