namib-project / nftables-rs

Safe abstraction for nftables JSON API (libnftables-json).
https://crates.io/crates/nftables
Apache License 2.0
32 stars 15 forks source link

Fix TCP option key name #10

Closed Disasm closed 10 months ago

Disasm commented 10 months ago

According to https://manpages.debian.org/testing/libnftables1/libnftables-json.5.en.html the key should be tcp option, not tcpoption. Tested with the following rule: nft 'add rule ip mangle FORWARD tcp flags syn / syn,rst counter tcp option maxseg size set rt mtu' and the following example code:

use nftables::helper::get_current_ruleset;

fn main() {
    let _set = get_current_ruleset(None, None).unwrap();
    println!("Rules were parsed successfully");
}

Before the fix:

thread 'main' panicked at examples/pr.rs:4:48:
called `Result::unwrap()` on an `Err` value: NftInvalidJson(Error("data did not match any variant of untagged enum NfObject", line: 1, column: 1296))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

After the fix:

Rules were parsed successfully
jwhb commented 10 months ago

@Disasm thank you for your contribution!

This brought a repeating issue with key names to my attention. I created #13 as a follow-up issue to fix other related key name issues and create test cases.