Like for fib and synproxy flags with nft 1.1.4 a single flag value is
printed as string not array so the parser need to account for that.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Like for fib flags with nft 1.1.4 a single flag value is printed as
string not array so the parser need to account for that.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Fixes#165
- changed BinaryOperation::OR to accept Vec<Expression> instead of exactly two.
- added regression test (tests/test_bit_flags)
- note: The fix was tested with deserialization only. I did not test adding an nftables
rule with bit flags
Signed-off-by: stevelr <stevelr.git@pm.me>
This improves the versatility of the API.
With the new API there are more ideomatic options for the user like
&Path, PathBuf and also still &str and more.
This is an API incompatible change.
I think it's not really possible to make this API compatible,
because the None-values need explicit type annotations due to the trait based API.
The default None-based API has been replaced by functions without arguments
to make the common case easier to use.
The user code changes are probably minimal in most cases, because None arguments
can just be removed and string arguments keep working as-is due to the std
implementations of AsRef.
Convenience constants are provided to make use of the None-arguments
to the _with_args() functions more readable and easier to use.
As a side effect this change also removes an unnecessary allocation of the program
name string in case of a successful execution.
This adds a bunch of lifetimes, but it works with `.into()` when a borrowed value's array container is stored in another place, without the need of `Cow::Borrowed`:
```
let objects = [
NfObject::ListObject(NfListObject::Table(Table {
family: NfFamily::INet,
name: "some_inet_table".into(), // here
handle: None,
})),
// ...
];
let expected = Nftables {
objects: objects.into(); // and here
};
```
However, `Cow::{Borrowed, Owned}` still needs to be used when you want to write the above in one statement.
This fails to build on 1.65:
```
error[E0277]: the trait bound `[SetItem]: ToOwned` is not satisfied in `Expression`
--> src/stmt.rs:245:14
|
245 | pub dev: Option<Expression>,
| ^^^^^^^^^^^^^^^^^^ within `Expression`, the trait `ToOwned` is not implemented for `[SetItem]`, which is required by `Expression: Sized`
|
= help: the trait `ToOwned` is implemented for `[T]`
note: required because it appears within the type `Expression`
--> src/expr.rs:10:10
|
10 | pub enum Expression {
| ^^^^^^^^^^
note: required by an implicit `Sized` bound in `std::option::Option`
--> /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/option.rs:572:1
...and many, many similar errors
```
It compiles successfully on Rust >=1.79, so this commit can be reverted once our MSRV reaches it.
A lot of strings and arrays used in nftables structures are static, but
currently we need to do allocations everywhere using owned String and Vec.
Replace them with Cow so we can pass &'static str or &'static [_] whenever
possible, while returning owned value when deserializing.
adds a flush command to the top of the example ruleset so that nftables rules are applied on a clean state.
adds tests that check args passing to nft with get_current_ruleset and specifying invalid nft binary.
The current code cannot handle the ParloadRaw type, serde is unable to
deserialize the json with a raw payload fields.
This is because serde cannot handle two fields with the same name and I
haven't found a way to make this work like that. Instead we have to use
a untagged enum that share both possible payload values.
Therefore this is an API break: NamedExpression now only contains one
Payload field which contains the Payload enum, the old Payload type is
renamed to PayloadField.
Lastly, export the PayloadRaw fields so they can be used externally.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
A Verdict enum was moved from a NamedExpression to an Expression,
placing it in a NamedExpression was a bug. Accroding to
libnftables-json(5) (section VERDICT) a Verdict does not have a
"verdict" key, it is "anonymous". e.g.: { "jump": { "target":
"my_target"}, and not: { "verdict": { "jump": { "target": "my_target"} }
}
Additionally a `Verdict::Jump` and a `Verdict::Goto` data was changed to
a `stmt::JumpTarget` struct from a `String`.
A `Map` and a `Set` use almost the same fields, a map additinally uses a
map field of type `String`.