diff options
| author | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2023-08-17 17:43:48 -0500 | 
|---|---|---|
| committer | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2023-08-17 17:44:22 -0500 | 
| commit | d6e19ce0a112bd2403ad0cb274808ce3e749b459 (patch) | |
| tree | 9c0a430436ff81e13754ac167f6f90a911982b98 | |
| parent | dd9b0671503c27a6dca04b5d6d95b936cae60549 (diff) | |
| download | wg2nd-d6e19ce0a112bd2403ad0cb274808ce3e749b459.tar.xz wg2nd-d6e19ce0a112bd2403ad0cb274808ce3e749b459.zip | |
Add warnings for PreUp, PostUp, PreDown, PostDown, and SaveConfig configuration, no systemd-networkd eqiv
| -rw-r--r-- | src/main.cpp | 4 | ||||
| -rw-r--r-- | src/wg2sd.cpp | 30 | ||||
| -rw-r--r-- | src/wg2sd.hpp | 6 | 
3 files changed, 39 insertions, 1 deletions
| diff --git a/src/main.cpp b/src/main.cpp index 724b479..b592aa9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -190,6 +190,10 @@ int main(int argc, char ** argv) {  		output_path = std::filesystem::absolute(output_path);  	} +	for(std::string const & warning : cfg.warnings) { +		err("warning: %s", warning.c_str()); +	} +  	write_systemd_file(cfg.netdev, output_path, false);  	write_systemd_file(cfg.network, output_path, false);  	write_systemd_file(cfg.private_keyfile, output_path, true); diff --git a/src/wg2sd.cpp b/src/wg2sd.cpp index 23c6546..2087cf5 100644 --- a/src/wg2sd.cpp +++ b/src/wg2sd.cpp @@ -208,6 +208,16 @@ namespace wg2sd {  					}  					cfg.intf.listen_port = port; +				} else if (key == "PreUp") { +					cfg.intf.preup = value; +				} else if (key == "PostUp") { +					cfg.intf.postup = value; +				} else if (key == "PreDown") { +					cfg.intf.predown = value; +				} else if (key == "PostDown") { +					cfg.intf.postdown = value; +				} else if (key == "SaveConfig") { +					cfg.intf.save_config = value;  				} else {  					throw ParsingException("Invalid key in [Interface] section: " + key, line_no);  				} @@ -485,6 +495,23 @@ namespace wg2sd {  		std::string private_keyfile = hashed_keyfile_name(cfg.intf.private_key); +		std::vector<std::string> warnings; + +#define WarnOnIntfField(field_, field_name) \ +if(!cfg.intf.field_.empty()) { \ +	warnings.push_back("[Interface] section contains a field \"" field_name "\" which does not have a systemd-networkd analog, omitting"); \ +} + +		WarnOnIntfField(preup, "PreUp") +		WarnOnIntfField(postup, "PostUp") +		WarnOnIntfField(predown, "PreDown") +		WarnOnIntfField(postdown, "PostDown") +		WarnOnIntfField(save_config, "SaveConfig") + +		if(!cfg.intf.preup.empty()) { +			warnings.push_back("[Interface] section contains a field \"PreUp\" which does not have a systemd-networkd analog"); +		} +  		return SystemdConfig {  			.netdev = {  				.name = cfg.intf.name + ".netdev", @@ -498,7 +525,8 @@ namespace wg2sd {  				.name = private_keyfile,  				.contents = cfg.intf.private_key + "\n",  			}, -			.symmetric_keyfiles = std::move(symmetric_keyfiles) +			.symmetric_keyfiles = std::move(symmetric_keyfiles), +			.warnings = std::move(warnings)  		};  	} diff --git a/src/wg2sd.hpp b/src/wg2sd.hpp index 00028b4..ea6f7fe 100644 --- a/src/wg2sd.hpp +++ b/src/wg2sd.hpp @@ -33,6 +33,10 @@ namespace wg2sd {  		// ListenPort=...  		// The port number on which the interface will listen  		std::optional<uint16_t> listen_port; +		// PreUp, PostUp, PreDown PostDown +		std::string preup, postup, predown, postdown; +		// SaveConfig +		std::string save_config;  		Interface()  			: should_create_routes { false } @@ -121,6 +125,8 @@ namespace wg2sd {  		SystemdFilespec network;  		SystemdFilespec private_keyfile;  		std::vector<SystemdFilespec> symmetric_keyfiles; + +		std::vector<std::string> warnings;  	};  	std::string interface_name_from_filename(std::filesystem::path config_path); | 
