net/tstun: use mono.Time

There's a call to Now once per packet.
Move to mono.Now.

Though the current implementation provides high precision,
we document it to be coarse, to preserve the ability
to switch to a coarse monotonic time later.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
Josh Bleecher Snyder
2021-07-21 10:43:53 -07:00
committed by Josh Bleecher Snyder
parent 142670b8c2
commit c2202cc27c
3 changed files with 12 additions and 10 deletions

View File

@ -10,13 +10,13 @@ import (
"fmt"
"strconv"
"strings"
"sync/atomic"
"testing"
"unsafe"
"golang.zx2c4.com/wireguard/tun/tuntest"
"inet.af/netaddr"
"tailscale.com/net/packet"
"tailscale.com/tstime/mono"
"tailscale.com/types/ipproto"
"tailscale.com/types/logger"
"tailscale.com/wgengine/filter"
@ -335,9 +335,9 @@ func TestFilter(t *testing.T) {
// data was actually filtered.
// If it stays zero, nothing made it through
// to the wrapped TUN.
atomic.StoreInt64(&tun.lastActivityAtomic, 0)
tun.lastActivityAtomic.StoreAtomic(0)
_, err = tun.Write(tt.data, 0)
filtered = atomic.LoadInt64(&tun.lastActivityAtomic) == 0
filtered = tun.lastActivityAtomic.LoadAtomic() == 0
} else {
chtun.Outbound <- tt.data
n, err = tun.Read(buf[:], 0)
@ -416,7 +416,7 @@ func TestAtomic64Alignment(t *testing.T) {
}
c := new(Wrapper)
atomic.StoreInt64(&c.lastActivityAtomic, 123)
c.lastActivityAtomic.StoreAtomic(mono.Now())
}
func TestPeerAPIBypass(t *testing.T) {