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