send: account for zero mtu
Don't divide by zero.
This commit is contained in:
parent
6ed56ff2df
commit
9cbcff10dd
|
@ -515,10 +515,18 @@ func (device *Device) RoutineEncryption() {
|
||||||
// pad content to multiple of 16
|
// pad content to multiple of 16
|
||||||
|
|
||||||
mtu := int(atomic.LoadInt32(&device.tun.mtu))
|
mtu := int(atomic.LoadInt32(&device.tun.mtu))
|
||||||
lastUnit := len(elem.packet) % mtu
|
var paddedSize int
|
||||||
paddedSize := (lastUnit + PaddingMultiple - 1) & ^(PaddingMultiple - 1)
|
if mtu == 0 {
|
||||||
if paddedSize > mtu {
|
paddedSize = (len(elem.packet) + PaddingMultiple - 1) & ^(PaddingMultiple - 1)
|
||||||
paddedSize = mtu
|
} else {
|
||||||
|
lastUnit := len(elem.packet)
|
||||||
|
if lastUnit > mtu {
|
||||||
|
lastUnit %= mtu
|
||||||
|
}
|
||||||
|
paddedSize := (lastUnit + PaddingMultiple - 1) & ^(PaddingMultiple - 1)
|
||||||
|
if paddedSize > mtu {
|
||||||
|
paddedSize = mtu
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for i := len(elem.packet); i < paddedSize; i++ {
|
for i := len(elem.packet); i < paddedSize; i++ {
|
||||||
elem.packet = append(elem.packet, 0)
|
elem.packet = append(elem.packet, 0)
|
||||||
|
|
Loading…
Reference in a new issue