1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-05 07:50:24 +08:00

feat: add MTU random range

This commit is contained in:
源文雨
2023-08-04 09:12:22 +08:00
parent 6f1829fef2
commit 3839182c85
5 changed files with 46 additions and 29 deletions

View File

@@ -107,7 +107,7 @@ func (wg *WG) init(srcport, dstport uint16) {
}
n := copy(peerkey[:], base14.Decode(k))
if n != 32 {
panic("peer public key length < 32")
panic("peer " + peer.IP + ": public key length < 32")
}
var pshk *[32]byte
if peer.PresharedKey != "" {
@@ -118,21 +118,28 @@ func (wg *WG) init(srcport, dstport uint16) {
pshk = &[32]byte{}
n := copy(pshk[:], base14.Decode(k))
if n != 32 {
panic("peer preshared key length < 32")
panic("peer " + peer.IP + ": preshared key length < 32")
}
}
if peer.MTU >= 65535 {
panic("peer " + peer.IP + ": MTU too large")
}
if peer.MTURandomRange >= peer.MTU/2 {
panic("peer " + peer.IP + ": MTURandomRange too large")
}
wg.me.AddPeer(&link.PeerConfig{
PeerIP: peer.IP,
EndPoint: peer.EndPoint,
AllowedIPs: peer.AllowedIPs,
Querys: peer.QueryList,
PubicKey: &peerkey,
PresharedKey: pshk,
KeepAliveDur: peer.KeepAliveSeconds,
QueryTick: peer.QuerySeconds,
MTU: uint16(peer.MTU),
AllowTrans: peer.AllowTrans,
NoPipe: true,
PeerIP: peer.IP,
EndPoint: peer.EndPoint,
AllowedIPs: peer.AllowedIPs,
Querys: peer.QueryList,
PubicKey: &peerkey,
PresharedKey: pshk,
KeepAliveDur: peer.KeepAliveSeconds,
QueryTick: peer.QuerySeconds,
MTU: uint16(peer.MTU),
MTURandomRange: uint16(peer.MTURandomRange),
AllowTrans: peer.AllowTrans,
NoPipe: true,
})
}
}