bugfix: Free net.IP from pool on DeletePeer

This commit is contained in:
HeshamTB 2024-03-18 02:06:56 +03:00
parent 11340e4d7a
commit 6c032e1d97

23
link.go
View File

@ -142,7 +142,28 @@ func (wg *WGLink) DeletePeer(publickey string) error {
func (wg *WGLink) deletePeer(publickey wgtypes.Key) error {
rmCfg := createARemovePeerCfg(publickey)
return wg.ApplyConfig(rmCfg)
ip, err := wg.getPeerIP(publickey)
if err != nil {
return err
}
err = wg.ApplyConfig(rmCfg)
if err != nil {
return err
}
err = wg.Free(ip)
if err != nil {
return err
}
return nil
}
func (wg *WGLink) getPeerIP(publickey wgtypes.Key) (net.IP, error) {
peer, err := wg.getPeer(publickey)
if err != nil { return nil, err }
return peer.AllowedIPs[0].IP, nil
}
func (wg *WGLink) Exists(publicKey string) (bool, error) {