wgengine/tstun: inform userspaceEngine about injected outbound packets in tundev

Signed-off-by: Naman Sood <mail@nsood.in>
naman/netstack-outgoing-udp-test
Naman Sood 3 years ago committed by Brad Fitzpatrick
parent e7caad61fb
commit 07c3df13c6

@ -259,6 +259,8 @@ func (t *TUN) IdleDuration() time.Duration {
func (t *TUN) Read(buf []byte, offset int) (int, error) {
var n int
wasInjectedPacket := false
select {
case <-t.closed:
return 0, io.EOF
@ -273,9 +275,7 @@ func (t *TUN) Read(buf []byte, offset int) (int, error) {
t.bufferConsumed <- struct{}{}
} else {
// If the packet is not from t.buffer, then it is an injected packet.
// In this case, we return early to bypass filtering
t.noteActivity()
return n, nil
wasInjectedPacket = true
}
}
@ -289,6 +289,12 @@ func (t *TUN) Read(buf []byte, offset int) (int, error) {
}
}
// For injected packets, we return early to bypass filtering.
if wasInjectedPacket {
t.noteActivity()
return n, nil
}
if !t.disableFilter {
response := t.filterOut(p)
if response != filter.Accept {

Loading…
Cancel
Save