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>
The inffered type by Deserialize is Option<T> which is wrong and thus
the deserialize call fails as it is called on the wrong type. If we have
an array we need to directly use the HashSet type.
Switch one of the log statements in the tests to use two flags to cover
this path.
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>
These correspond to the behaviour of `nft --echo`, which prints back applied rulesets along with more information like handles. They are especially useful when one needs a rule's handle for later positional insertion or removal.
Basically integrates functions from the nftables_async crate here, with both
tokio and async-process support behind feature gates.
Also corrected some of the behaviour differences in nftables_async, e.g.
get_current_ruleset_raw passes additional arguments (keeping "-j list ruleset"
intact) in nftables_async, but replaces the default arguments (except -j) here.
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.
This evens out some of the large enums' sizes (e.g. Expression and Statement's)
from over 200 bytes to <=144. Further reduction could be done, as this commit
only changes the obvious ones for now.
Also moves BinaryOperation's Box up one level so it only uses one Box.
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.
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>