wireguard-rs icon indicating copy to clipboard operation
wireguard-rs copied to clipboard

Is there any way to set FwMark?

Open kr105 opened this issue 7 months ago • 0 comments

I did look on the code, but I could not find anything, is there any way to set the FwMark value like in the wg0.conf file?

[Interface]
PrivateKey = xxxxxxxxxxxxxxxxx
Address = 10.10.10.2/24
ListenPort = 51820
FwMark = 0x10

Currently I made this workaround, but I don't like it 😆

fn configure_wg_fwmark(interface_name: &str, fwmark: u32) -> Result<(), Box<dyn std::error::Error>> {
	let output = Command::new("wg")
		.args(["set", interface_name, "fwmark", &fwmark.to_string()])
		.output()?;

	if !output.status.success() {
		let error_msg = String::from_utf8_lossy(&output.stderr);
		return Err(format!("Failed to set fwmark: {error_msg}").into());
	}

	Ok(())
}

kr105 avatar Jul 13 '25 22:07 kr105