Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix anonymous sets and XT #9

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use serde::{Deserialize, Serialize};
use std::collections::HashSet;

use crate::stmt::Statement;

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
/// Expressions are the building blocks of (most) statements.
Expand All @@ -26,7 +28,7 @@ pub enum NamedExpression {
Concat(Vec<Expression>),
/// This object constructs an anonymous set.
/// For mappings, an array of arrays with exactly two elements is expected.
Set(Vec<Expression>),
Set(Vec<SetItem>),
Map(Box<Map>),
Prefix(Prefix),

Expand Down Expand Up @@ -59,6 +61,19 @@ pub struct Map {
pub data: Expression,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
/// Item in an anonymous set.
pub enum SetItem{
/// A set item containing a single expression.
Element(Expression),
/// A set item mapping two expressions.
Mapping(Expression, Expression),
/// A set item mapping an expression to a statement.
MappingStatement(Expression, Statement),
}


#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename = "prefix")]
/// Construct an IPv4 or IPv6 prefix consisting of address part in `addr` and prefix length in `len`.
Expand Down
6 changes: 3 additions & 3 deletions src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub enum Statement {

/// This represents an xt statement from xtables compat interface.
/// Sadly, at this point, it is not possible to provide any further information about its content.
XT(Option<bool>),
XT(Option<serde_json::Value>),
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -118,10 +118,10 @@ pub struct Match {
pub struct Counter {
#[serde(skip_serializing_if = "Option::is_none")]
/// Packets counted.
pub packets: Option<u32>,
pub packets: Option<usize>,
#[serde(skip_serializing_if = "Option::is_none")]
/// Bytes counted.
pub bytes: Option<u32>,
pub bytes: Option<usize>,
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
Expand Down