aboutsummaryrefslogtreecommitdiff
path: root/src/wg2nd.cpp
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2023-11-20 17:45:24 -0600
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2023-11-20 17:46:39 -0600
commit50df8f91a90d8c91676b81cc9668b58914f85b08 (patch)
tree3a201d743adaf1d4212c3c52dcb873bc93001758 /src/wg2nd.cpp
parent24488352a124556001f3a32bf76570754a9d389c (diff)
downloadwg2nd-50df8f91a90d8c91676b81cc9668b58914f85b08.tar.xz
wg2nd-50df8f91a90d8c91676b81cc9668b58914f85b08.zip
Allow configurable activation policy, allow -h before dropping caps
Diffstat (limited to 'src/wg2nd.cpp')
-rw-r--r--src/wg2nd.cpp33
1 files changed, 27 insertions, 6 deletions
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<std::string> const & filename
+ std::optional<std::string> const & filename,
+ ActivationPolicy activation_policy
) {
// If the table is explicitly specified with Table=<number>,
@@ -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<std::string> 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<std::string> const & filename,
+ ActivationPolicy activation_policy) {
+ return gen_systemd_config(
+ parse_config(interface_name, stream),
+ keyfile_or_output_path,
+ filename,
+ activation_policy
+ );
}
}