29 ProcFS(std::string fn_arg, std::string text_arg)
30 :
fn(std::move(fn_arg)),
31 text(std::move(text_arg))
42 catch (
const std::exception &e)
44 os <<
"ProcFS exception: " << e.what() << std::endl;
60 const unsigned int n_retries = 200;
61 const unsigned int milliseconds_per_retry = 100;
62 volatile bool stop =
false;
68 for (
unsigned int i = 0; i < n_retries && !stop; ++i)
71 if (std::filesystem::exists(
fn, ec))
78 catch (
const std::exception &e)
82#ifdef OPENVPN_PROCFS_DEBUG
84 std::string text_verify;
103 OPENVPN_THROW(procfs_error,
"file " <<
fn <<
" : aborting write attempt due to stop signal");
105 OPENVPN_THROW(procfs_error,
"file " <<
fn <<
" failed to appear within " << (n_retries * milliseconds_per_retry / 1000) <<
" seconds");
119 OPENVPN_LOG(
"IPv4ReversePathFilter " << dev <<
" -> " << value);
122 static void write(
const std::string &dev,
const unsigned int value,
Stop *stop =
nullptr)
128 static std::string
key_fn(
const std::string &dev)
130 return printfmt(
"/proc/sys/net/ipv4/conf/%s/rp_filter", dev);
static std::string key_fn(const std::string &dev)
static void write(const std::string &dev, const unsigned int value, Stop *stop=nullptr)
IPv4ReversePathFilter(const std::string &dev, const unsigned int value)
static void write_sys(const std::string &fn, const std::string &text, Stop *async_stop=nullptr)
OPENVPN_EXCEPTION(procfs_error)
ProcFS(std::string fn_arg, std::string text_arg)
virtual std::string to_string() const override
virtual void execute(std::ostream &os) override
static std::string to_string(const std::string &fn, const std::string &text)
#define OPENVPN_THROW(exc, stuff)
#define OPENVPN_LOG(args)
void trim_crlf(STRING &str)
std::string trim_crlf_copy(std::string str)
int read_binary_unix_fast(const STRING &fn, Buffer &out, std::uint64_t *mtime_ns=nullptr)
std::string to_string(const T &t)
Convert a value to a string.
void write_text_unix(const std::string &fn, const mode_t mode, const std::uint64_t mtime_ns, const std::string &content)
bool sleep_milliseconds(const unsigned int milliseconds)
std::string printfmt(const std::string &fmt, Args... args)
std::string buf_to_string(const Buffer &buf)
std::string strerror_str(const int errnum)