corrected tun offset and improved mtu
This commit is contained in:
parent
6b6aab0cd9
commit
648aab7817
11
tun/tun.go
11
tun/tun.go
@ -10,7 +10,6 @@ import (
|
||||
|
||||
type SourceSink struct {
|
||||
tun wgtun.Device
|
||||
mtu int
|
||||
}
|
||||
|
||||
func NewTun(name string, mtu int) (t wgtun.Device, err error) {
|
||||
@ -26,7 +25,6 @@ func NewFromFile(fd uintptr, mtu int) (ss *SourceSink, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
ss.mtu = mtu
|
||||
return
|
||||
}
|
||||
|
||||
@ -35,7 +33,12 @@ func (t *SourceSink) Close() error {
|
||||
}
|
||||
|
||||
func (t *SourceSink) Source() (proxy.Packet, error) {
|
||||
buf := make([]byte, t.mtu)
|
||||
mtu, err := t.tun.MTU()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
buf := make([]byte, mtu+4)
|
||||
|
||||
read, err := t.tun.Read(buf, 4)
|
||||
if err != nil {
|
||||
@ -46,7 +49,7 @@ func (t *SourceSink) Source() (proxy.Packet, error) {
|
||||
return nil, io.EOF
|
||||
}
|
||||
|
||||
return proxy.SimplePacket(buf[4:read]), nil
|
||||
return proxy.SimplePacket(buf[4:read+4]), nil
|
||||
}
|
||||
|
||||
var good, bad float64
|
||||
|
Loading…
Reference in New Issue
Block a user