From 50df8f91a90d8c91676b81cc9668b58914f85b08 Mon Sep 17 00:00:00 2001 From: flu0r1ne Date: Mon, 20 Nov 2023 17:45:24 -0600 Subject: Allow configurable activation policy, allow -h before dropping caps --- src/wg2nd.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/wg2nd.cpp') diff --git a/src/wg2nd.cpp b/src/wg2nd.cpp index deb3212..afe3132 100644 --- a/src/wg2nd.cpp +++ b/src/wg2nd.cpp @@ -446,7 +446,18 @@ namespace wg2nd { return netdev.str(); } - static std::string _gen_network_cfg(Config const & cfg, uint32_t fwd_table) { + static std::string_view activation_policy_keyword(ActivationPolicy activation_policy) { + switch(activation_policy) { + case ActivationPolicy::MANUAL: + return "manual"; + case ActivationPolicy::UP: + return "up"; + } + + return "none"; + } + + static std::string _gen_network_cfg(Config const & cfg, uint32_t fwd_table, ActivationPolicy activation_policy) { std::stringstream network; network << "# Autogenerated by wg2nd\n"; @@ -455,7 +466,9 @@ namespace wg2nd { network << "\n"; network << "[Link]" << "\n"; - network << "ActivationPolicy = manual\n"; + + network << "ActivationPolicy = " << activation_policy_keyword(activation_policy) << "\n"; + if(!cfg.intf.mtu.empty()) { network << "MTUBytes = " << cfg.intf.mtu << "\n"; } @@ -551,7 +564,8 @@ namespace wg2nd { SystemdConfig gen_systemd_config( Config const & cfg, std::filesystem::path const & keyfile_or_output_path, - std::optional const & filename + std::optional const & filename, + ActivationPolicy activation_policy ) { // If the table is explicitly specified with Table=, @@ -608,7 +622,7 @@ if(!cfg.intf.field_.empty()) { \ }, .network = { .name = basename + ".network", - .contents = _gen_network_cfg(cfg, fwd_table) + .contents = _gen_network_cfg(cfg, fwd_table, activation_policy) }, .private_keyfile = { .name = keyfile_path.filename(), @@ -621,8 +635,15 @@ if(!cfg.intf.field_.empty()) { \ } SystemdConfig wg2nd(std::string const & interface_name, std::istream & stream, - std::filesystem::path const & keyfile_or_output_path, std::optional const & filename) { - return gen_systemd_config(parse_config(interface_name, stream), keyfile_or_output_path, filename); + std::filesystem::path const & keyfile_or_output_path, + std::optional const & filename, + ActivationPolicy activation_policy) { + return gen_systemd_config( + parse_config(interface_name, stream), + keyfile_or_output_path, + filename, + activation_policy + ); } } -- cgit v1.2.3