corrected tun offset and improved mtu
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

This commit is contained in:
Jake Hillion 2021-05-11 22:37:39 +01:00
parent 6b6aab0cd9
commit 648aab7817

View File

@ -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