Skip to content

Commit

Permalink
Merge pull request #11 from RegalisTechnologies/map
Browse files Browse the repository at this point in the history
Implement map support
  • Loading branch information
jwhb authored Jan 19, 2024
2 parents b798d96 + 3c87c23 commit 21b69e7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
use std::collections::HashSet;

use crate::stmt::Statement;
use crate::stmt::JumpTarget;

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
Expand All @@ -18,6 +19,7 @@ pub enum Expression {
Range(Range),

Named(NamedExpression),
Verdict(Verdict),
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -46,7 +48,6 @@ pub enum NamedExpression {
JHash(JHash),
SymHash(SymHash),
Fib(Fib),
Verdict(Verdict),
Elem(Elem),
Socket(Socket),
Osf(Osf),
Expand Down Expand Up @@ -347,8 +348,8 @@ pub enum Verdict {
Drop,
Continue,
Return,
Jump(String),
Goto(String),
Jump(JumpTarget),
Goto(JumpTarget),
}

#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
Expand Down
23 changes: 22 additions & 1 deletion src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,28 @@ pub struct Set {

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct Map {
// TODO
pub family: NfFamily,
pub table: String,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub handle: Option<u32>,
#[serde(rename = "type")]
pub set_type: SetTypeValue,
pub map: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub policy: Option<SetPolicy>,
#[serde(skip_serializing_if = "Option::is_none")]
pub flags: Option<HashSet<SetFlag>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub elem: Option<Vec<Expression>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout: Option<u32>,
#[serde(rename = "gc-interval", skip_serializing_if = "Option::is_none")]
pub gc_interval: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub size: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub comment: Option<String>,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
Expand Down
17 changes: 17 additions & 0 deletions tests/helper_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ fn example_ruleset() -> schema::Nftables {
gc_interval: None,
size: None,
}));
let map_name = "test_map".to_string();
let map_type = "verdict".to_string();
batch.add(schema::NfListObject::Map(schema::Map {
family: types::NfFamily::IP,
table: table_name.clone(),
name: map_name.clone(),
handle: None,
map: map_type.clone(),
set_type: schema::SetTypeValue::Single(schema::SetType::Ipv4Addr),
policy: None,
flags: None,
elem: None,
timeout: None,
gc_interval: None,
size: None,
comment: None,
}));
// add element to set
batch.add(schema::NfListObject::Element(schema::Element {
family: types::NfFamily::IP,
Expand Down

0 comments on commit 21b69e7

Please sign in to comment.