From ac3d3b7ab0791d67159d33f5aa3626a11096bd39 Mon Sep 17 00:00:00 2001 From: jwhb Date: Sat, 12 Aug 2023 17:12:37 +0000 Subject: [PATCH 1/3] expr: implement mapping anonymous sets --- src/expr.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/expr.rs b/src/expr.rs index f5811ae..5640e4d 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -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. @@ -26,7 +28,7 @@ pub enum NamedExpression { Concat(Vec), /// This object constructs an anonymous set. /// For mappings, an array of arrays with exactly two elements is expected. - Set(Vec), + Set(Vec), Map(Box), Prefix(Prefix), @@ -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`. From e46af5e1e95889bbf317a2d6a6d35f4bb20d2ca4 Mon Sep 17 00:00:00 2001 From: jwhb Date: Sat, 12 Aug 2023 17:26:55 +0000 Subject: [PATCH 2/3] stmt: counter values as usize --- src/stmt.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stmt.rs b/src/stmt.rs index f16c8fd..df23c19 100644 --- a/src/stmt.rs +++ b/src/stmt.rs @@ -118,10 +118,10 @@ pub struct Match { pub struct Counter { #[serde(skip_serializing_if = "Option::is_none")] /// Packets counted. - pub packets: Option, + pub packets: Option, #[serde(skip_serializing_if = "Option::is_none")] /// Bytes counted. - pub bytes: Option, + pub bytes: Option, } #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] From c467bd7428f63df171fbdba283d80d42f0b1c5ec Mon Sep 17 00:00:00 2001 From: jwhb Date: Sat, 12 Aug 2023 17:30:08 +0000 Subject: [PATCH 3/3] stmt: declare XT as serde value --- src/stmt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stmt.rs b/src/stmt.rs index df23c19..0230c2a 100644 --- a/src/stmt.rs +++ b/src/stmt.rs @@ -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), + XT(Option), } #[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]