Skip to content

Commit

Permalink
Merge pull request #9 from namib-project/anonymous-sets
Browse files Browse the repository at this point in the history
Fix anonymous sets and XT
  • Loading branch information
jwhb authored Sep 20, 2023
2 parents 1bd71ea + c467bd7 commit 1b0c60b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
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

0 comments on commit 1b0c60b

Please sign in to comment.