|
|
@ -136,23 +136,23 @@ type Wrapper struct {
|
|
|
|
// filterFlags control the verbosity of logging packet drops/accepts.
|
|
|
|
// filterFlags control the verbosity of logging packet drops/accepts.
|
|
|
|
filterFlags filter.RunFlags
|
|
|
|
filterFlags filter.RunFlags
|
|
|
|
|
|
|
|
|
|
|
|
// PreFilterIn is the inbound filter function that runs before the main filter
|
|
|
|
// PreFilterPacketInboundFromWireGuard is the inbound filter function that runs before the main filter
|
|
|
|
// and therefore sees the packets that may be later dropped by it.
|
|
|
|
// and therefore sees the packets that may be later dropped by it.
|
|
|
|
PreFilterIn FilterFunc
|
|
|
|
PreFilterPacketInboundFromWireGuard FilterFunc
|
|
|
|
// PostFilterIn is the inbound filter function that runs after the main filter.
|
|
|
|
// PostFilterPacketInboundFromWireGaurd is the inbound filter function that runs after the main filter.
|
|
|
|
PostFilterIn FilterFunc
|
|
|
|
PostFilterPacketInboundFromWireGaurd FilterFunc
|
|
|
|
// PreFilterFromTunToNetstack is a filter function that runs before the main filter
|
|
|
|
// PreFilterPacketOutboundToWireGuardNetstackIntercept is a filter function that runs before the main filter
|
|
|
|
// for packets from the local system. This filter is populated by netstack to hook
|
|
|
|
// for packets from the local system. This filter is populated by netstack to hook
|
|
|
|
// packets that should be handled by netstack. If set, this filter runs before
|
|
|
|
// packets that should be handled by netstack. If set, this filter runs before
|
|
|
|
// PreFilterFromTunToEngine.
|
|
|
|
// PreFilterFromTunToEngine.
|
|
|
|
PreFilterFromTunToNetstack FilterFunc
|
|
|
|
PreFilterPacketOutboundToWireGuardNetstackIntercept FilterFunc
|
|
|
|
// PreFilterFromTunToEngine is a filter function that runs before the main filter
|
|
|
|
// PreFilterPacketOutboundToWireGuardEngineIntercept is a filter function that runs before the main filter
|
|
|
|
// for packets from the local system. This filter is populated by wgengine to hook
|
|
|
|
// for packets from the local system. This filter is populated by wgengine to hook
|
|
|
|
// packets which it handles internally. If both this and PreFilterFromTunToNetstack
|
|
|
|
// packets which it handles internally. If both this and PreFilterFromTunToNetstack
|
|
|
|
// filter functions are non-nil, this filter runs second.
|
|
|
|
// filter functions are non-nil, this filter runs second.
|
|
|
|
PreFilterFromTunToEngine FilterFunc
|
|
|
|
PreFilterPacketOutboundToWireGuardEngineIntercept FilterFunc
|
|
|
|
// PostFilterOut is the outbound filter function that runs after the main filter.
|
|
|
|
// PostFilterPacketOutboundToWireGuard is the outbound filter function that runs after the main filter.
|
|
|
|
PostFilterOut FilterFunc
|
|
|
|
PostFilterPacketOutboundToWireGuard FilterFunc
|
|
|
|
|
|
|
|
|
|
|
|
// OnTSMPPongReceived, if non-nil, is called whenever a TSMP pong arrives.
|
|
|
|
// OnTSMPPongReceived, if non-nil, is called whenever a TSMP pong arrives.
|
|
|
|
OnTSMPPongReceived func(packet.TSMPPongReply)
|
|
|
|
OnTSMPPongReceived func(packet.TSMPPongReply)
|
|
|
@ -464,7 +464,7 @@ var (
|
|
|
|
magicDNSIPPortv6 = netip.AddrPortFrom(tsaddr.TailscaleServiceIPv6(), 0)
|
|
|
|
magicDNSIPPortv6 = netip.AddrPortFrom(tsaddr.TailscaleServiceIPv6(), 0)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func (t *Wrapper) filterOut(p *packet.Parsed) filter.Response {
|
|
|
|
func (t *Wrapper) filterPacketOutboundToWireGuard(p *packet.Parsed) filter.Response {
|
|
|
|
// Fake ICMP echo responses to MagicDNS (100.100.100.100).
|
|
|
|
// Fake ICMP echo responses to MagicDNS (100.100.100.100).
|
|
|
|
if p.IsEchoRequest() {
|
|
|
|
if p.IsEchoRequest() {
|
|
|
|
switch p.Dst {
|
|
|
|
switch p.Dst {
|
|
|
@ -494,14 +494,14 @@ func (t *Wrapper) filterOut(p *packet.Parsed) filter.Response {
|
|
|
|
return filter.DropSilently
|
|
|
|
return filter.DropSilently
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if t.PreFilterFromTunToNetstack != nil {
|
|
|
|
if t.PreFilterPacketOutboundToWireGuardNetstackIntercept != nil {
|
|
|
|
if res := t.PreFilterFromTunToNetstack(p, t); res.IsDrop() {
|
|
|
|
if res := t.PreFilterPacketOutboundToWireGuardNetstackIntercept(p, t); res.IsDrop() {
|
|
|
|
// Handled by netstack.Impl.handleLocalPackets (quad-100 DNS primarily)
|
|
|
|
// Handled by netstack.Impl.handleLocalPackets (quad-100 DNS primarily)
|
|
|
|
return res
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if t.PreFilterFromTunToEngine != nil {
|
|
|
|
if t.PreFilterPacketOutboundToWireGuardEngineIntercept != nil {
|
|
|
|
if res := t.PreFilterFromTunToEngine(p, t); res.IsDrop() {
|
|
|
|
if res := t.PreFilterPacketOutboundToWireGuardEngineIntercept(p, t); res.IsDrop() {
|
|
|
|
// Handled by userspaceEngine.handleLocalPackets (primarily handles
|
|
|
|
// Handled by userspaceEngine.handleLocalPackets (primarily handles
|
|
|
|
// quad-100 if netstack is not installed).
|
|
|
|
// quad-100 if netstack is not installed).
|
|
|
|
return res
|
|
|
|
return res
|
|
|
@ -518,8 +518,8 @@ func (t *Wrapper) filterOut(p *packet.Parsed) filter.Response {
|
|
|
|
return filter.Drop
|
|
|
|
return filter.Drop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if t.PostFilterOut != nil {
|
|
|
|
if t.PostFilterPacketOutboundToWireGuard != nil {
|
|
|
|
if res := t.PostFilterOut(p, t); res.IsDrop() {
|
|
|
|
if res := t.PostFilterPacketOutboundToWireGuard(p, t); res.IsDrop() {
|
|
|
|
return res
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -575,7 +575,7 @@ func (t *Wrapper) Read(buffs [][]byte, sizes []int, offset int) (int, error) {
|
|
|
|
capt(capture.FromLocal, time.Now(), data[res.dataOffset:])
|
|
|
|
capt(capture.FromLocal, time.Now(), data[res.dataOffset:])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !t.disableFilter {
|
|
|
|
if !t.disableFilter {
|
|
|
|
response := t.filterOut(p)
|
|
|
|
response := t.filterPacketOutboundToWireGuard(p)
|
|
|
|
if response != filter.Accept {
|
|
|
|
if response != filter.Accept {
|
|
|
|
metricPacketOutDrop.Add(1)
|
|
|
|
metricPacketOutDrop.Add(1)
|
|
|
|
continue
|
|
|
|
continue
|
|
|
@ -636,7 +636,7 @@ func (t *Wrapper) injectedRead(res tunInjectedRead, buf []byte, offset int) (int
|
|
|
|
return n, nil
|
|
|
|
return n, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (t *Wrapper) filterIn(p *packet.Parsed) filter.Response {
|
|
|
|
func (t *Wrapper) filterPacketInboundFromWireGuard(p *packet.Parsed) filter.Response {
|
|
|
|
if capt := t.captureHook.Load(); capt != nil {
|
|
|
|
if capt := t.captureHook.Load(); capt != nil {
|
|
|
|
capt(capture.FromPeer, time.Now(), p.Buffer())
|
|
|
|
capt(capture.FromPeer, time.Now(), p.Buffer())
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -672,8 +672,8 @@ func (t *Wrapper) filterIn(p *packet.Parsed) filter.Response {
|
|
|
|
return filter.DropSilently
|
|
|
|
return filter.DropSilently
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if t.PreFilterIn != nil {
|
|
|
|
if t.PreFilterPacketInboundFromWireGuard != nil {
|
|
|
|
if res := t.PreFilterIn(p, t); res.IsDrop() {
|
|
|
|
if res := t.PreFilterPacketInboundFromWireGuard(p, t); res.IsDrop() {
|
|
|
|
return res
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -724,8 +724,8 @@ func (t *Wrapper) filterIn(p *packet.Parsed) filter.Response {
|
|
|
|
return filter.Drop
|
|
|
|
return filter.Drop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if t.PostFilterIn != nil {
|
|
|
|
if t.PostFilterPacketInboundFromWireGaurd != nil {
|
|
|
|
if res := t.PostFilterIn(p, t); res.IsDrop() {
|
|
|
|
if res := t.PostFilterPacketInboundFromWireGaurd(p, t); res.IsDrop() {
|
|
|
|
return res
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -743,7 +743,7 @@ func (t *Wrapper) Write(buffs [][]byte, offset int) (int, error) {
|
|
|
|
defer parsedPacketPool.Put(p)
|
|
|
|
defer parsedPacketPool.Put(p)
|
|
|
|
for _, buff := range buffs {
|
|
|
|
for _, buff := range buffs {
|
|
|
|
p.Decode(buff[offset:])
|
|
|
|
p.Decode(buff[offset:])
|
|
|
|
if t.filterIn(p) != filter.Accept {
|
|
|
|
if t.filterPacketInboundFromWireGuard(p) != filter.Accept {
|
|
|
|
metricPacketInDrop.Add(1)
|
|
|
|
metricPacketInDrop.Add(1)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
buffs[i] = buff
|
|
|
|
buffs[i] = buff
|
|
|
|