|
|
@ -56,6 +56,8 @@ type Logger struct {
|
|
|
|
|
|
|
|
|
|
|
|
addrs map[netip.Addr]bool
|
|
|
|
addrs map[netip.Addr]bool
|
|
|
|
prefixes map[netip.Prefix]bool
|
|
|
|
prefixes map[netip.Prefix]bool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enableLogDst bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Running reports whether the logger is running.
|
|
|
|
// Running reports whether the logger is running.
|
|
|
@ -92,7 +94,8 @@ var testClient *http.Client
|
|
|
|
// The IP protocol and source port are always zero.
|
|
|
|
// The IP protocol and source port are always zero.
|
|
|
|
// The sock is used to populated the PhysicalTraffic field in Message.
|
|
|
|
// The sock is used to populated the PhysicalTraffic field in Message.
|
|
|
|
// The netMon parameter is optional; if non-nil it's used to do faster interface lookups.
|
|
|
|
// The netMon parameter is optional; if non-nil it's used to do faster interface lookups.
|
|
|
|
func (nl *Logger) Startup(nodeID tailcfg.StableNodeID, nodeLogID, domainLogID logid.PrivateID, tun, sock Device, netMon *netmon.Monitor) error {
|
|
|
|
// enableLogDst is a control knob boolean.
|
|
|
|
|
|
|
|
func (nl *Logger) Startup(nodeID tailcfg.StableNodeID, nodeLogID, domainLogID logid.PrivateID, tun, sock Device, netMon *netmon.Monitor, enableLogDst bool) error {
|
|
|
|
nl.mu.Lock()
|
|
|
|
nl.mu.Lock()
|
|
|
|
defer nl.mu.Unlock()
|
|
|
|
defer nl.mu.Unlock()
|
|
|
|
if nl.logger != nil {
|
|
|
|
if nl.logger != nil {
|
|
|
@ -130,7 +133,7 @@ func (nl *Logger) Startup(nodeID tailcfg.StableNodeID, nodeLogID, domainLogID lo
|
|
|
|
addrs := nl.addrs
|
|
|
|
addrs := nl.addrs
|
|
|
|
prefixes := nl.prefixes
|
|
|
|
prefixes := nl.prefixes
|
|
|
|
nl.mu.Unlock()
|
|
|
|
nl.mu.Unlock()
|
|
|
|
recordStatistics(nl.logger, nodeID, start, end, virtual, physical, addrs, prefixes)
|
|
|
|
recordStatistics(nl.logger, nodeID, start, end, virtual, physical, addrs, prefixes, nl.enableLogDst)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// Register the connection tracker into the TUN device.
|
|
|
|
// Register the connection tracker into the TUN device.
|
|
|
@ -147,10 +150,12 @@ func (nl *Logger) Startup(nodeID tailcfg.StableNodeID, nodeLogID, domainLogID lo
|
|
|
|
nl.sock = sock
|
|
|
|
nl.sock = sock
|
|
|
|
nl.sock.SetStatistics(nl.stats)
|
|
|
|
nl.sock.SetStatistics(nl.stats)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nl.enableLogDst = enableLogDst
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func recordStatistics(logger *logtail.Logger, nodeID tailcfg.StableNodeID, start, end time.Time, connstats, sockStats map[netlogtype.Connection]netlogtype.Counts, addrs map[netip.Addr]bool, prefixes map[netip.Prefix]bool) {
|
|
|
|
func recordStatistics(logger *logtail.Logger, nodeID tailcfg.StableNodeID, start, end time.Time, connstats, sockStats map[netlogtype.Connection]netlogtype.Counts, addrs map[netip.Addr]bool, prefixes map[netip.Prefix]bool, enableLogDst bool) {
|
|
|
|
m := netlogtype.Message{NodeID: nodeID, Start: start.UTC(), End: end.UTC()}
|
|
|
|
m := netlogtype.Message{NodeID: nodeID, Start: start.UTC(), End: end.UTC()}
|
|
|
|
|
|
|
|
|
|
|
|
classifyAddr := func(a netip.Addr) (isTailscale, withinRoute bool) {
|
|
|
|
classifyAddr := func(a netip.Addr) (isTailscale, withinRoute bool) {
|
|
|
@ -179,7 +184,7 @@ func recordStatistics(logger *logtail.Logger, nodeID tailcfg.StableNodeID, start
|
|
|
|
m.SubnetTraffic = append(m.SubnetTraffic, netlogtype.ConnectionCounts{Connection: conn, Counts: cnts})
|
|
|
|
m.SubnetTraffic = append(m.SubnetTraffic, netlogtype.ConnectionCounts{Connection: conn, Counts: cnts})
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
const anonymize = true
|
|
|
|
const anonymize = true
|
|
|
|
if anonymize {
|
|
|
|
if anonymize && !enableLogDst {
|
|
|
|
// Only preserve the address if it is a Tailscale IP address.
|
|
|
|
// Only preserve the address if it is a Tailscale IP address.
|
|
|
|
srcOrig, dstOrig := conn.Src, conn.Dst
|
|
|
|
srcOrig, dstOrig := conn.Src, conn.Dst
|
|
|
|
conn = netlogtype.Connection{} // scrub everything by default
|
|
|
|
conn = netlogtype.Connection{} // scrub everything by default
|
|
|
|