diff --git a/link.go b/link.go index fa9b105..5608813 100644 --- a/link.go +++ b/link.go @@ -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) {