aboutsummaryrefslogtreecommitdiff
path: root/src/expr
diff options
context:
space:
mode:
Diffstat (limited to 'src/expr')
-rw-r--r--src/expr/cmp.rs5
-rw-r--r--src/expr/ct.rs4
-rw-r--r--src/expr/log.rs14
-rw-r--r--src/expr/mod.rs30
4 files changed, 13 insertions, 40 deletions
diff --git a/src/expr/cmp.rs b/src/expr/cmp.rs
index 223902f..86d3587 100644
--- a/src/expr/cmp.rs
+++ b/src/expr/cmp.rs
@@ -1,7 +1,6 @@
use rustables_macros::{nfnetlink_enum, nfnetlink_struct};
use crate::{
- data_type::DataType,
parser_impls::NfNetlinkData,
sys::{
NFTA_CMP_DATA, NFTA_CMP_OP, NFTA_CMP_SREG, NFT_CMP_EQ, NFT_CMP_GT, NFT_CMP_GTE, NFT_CMP_LT,
@@ -44,11 +43,11 @@ pub struct Cmp {
impl Cmp {
/// Returns a new comparison expression comparing the value loaded in the register with the
/// data in `data` using the comparison operator `op`.
- pub fn new(op: CmpOp, data: impl DataType) -> Self {
+ pub fn new(op: CmpOp, data: impl Into<Vec<u8>>) -> Self {
Cmp {
sreg: Some(Register::Reg1),
op: Some(op),
- data: Some(NfNetlinkData::default().with_value(data.data())),
+ data: Some(NfNetlinkData::default().with_value(data.into())),
}
}
}
diff --git a/src/expr/ct.rs b/src/expr/ct.rs
index ccf61e1..ad76989 100644
--- a/src/expr/ct.rs
+++ b/src/expr/ct.rs
@@ -43,6 +43,10 @@ impl Expression for Conntrack {
}
impl Conntrack {
+ pub fn new(key: ConntrackKey) -> Self {
+ Self::default().with_dreg(Register::Reg1).with_key(key)
+ }
+
pub fn set_mark_value(&mut self, reg: Register) {
self.set_sreg(reg);
self.set_key(ConntrackKey::Mark);
diff --git a/src/expr/log.rs b/src/expr/log.rs
index 80bb7a9..cc2728e 100644
--- a/src/expr/log.rs
+++ b/src/expr/log.rs
@@ -1,7 +1,10 @@
use rustables_macros::nfnetlink_struct;
-use super::{Expression, ExpressionError};
-use crate::sys::{NFTA_LOG_GROUP, NFTA_LOG_PREFIX};
+use super::Expression;
+use crate::{
+ error::BuilderError,
+ sys::{NFTA_LOG_GROUP, NFTA_LOG_PREFIX},
+};
#[derive(Clone, PartialEq, Eq, Default, Debug)]
#[nfnetlink_struct]
@@ -14,10 +17,7 @@ pub struct Log {
}
impl Log {
- pub fn new(
- group: Option<u16>,
- prefix: Option<impl Into<String>>,
- ) -> Result<Log, ExpressionError> {
+ pub fn new(group: Option<u16>, prefix: Option<impl Into<String>>) -> Result<Log, BuilderError> {
let mut res = Log::default();
if let Some(group) = group {
res.set_group(group);
@@ -26,7 +26,7 @@ impl Log {
let prefix = prefix.into();
if prefix.bytes().count() > 127 {
- return Err(ExpressionError::TooLongLogPrefix);
+ return Err(BuilderError::TooLongLogPrefix);
}
res.set_prefix(prefix);
}
diff --git a/src/expr/mod.rs b/src/expr/mod.rs
index 979ebb2..058b0cb 100644
--- a/src/expr/mod.rs
+++ b/src/expr/mod.rs
@@ -6,7 +6,6 @@
use std::fmt::Debug;
use rustables_macros::nfnetlink_struct;
-use thiserror::Error;
use crate::error::DecodeError;
use crate::nlmsg::{NfNetlinkAttribute, NfNetlinkDeserializable};
@@ -55,35 +54,6 @@ pub use self::register::Register;
mod verdict;
pub use self::verdict::*;
-#[derive(Debug, Error)]
-pub enum ExpressionError {
- #[error("The log prefix string is more than 127 characters long")]
- /// The log prefix string is more than 127 characters long
- TooLongLogPrefix,
-
- #[error("The expected expression type doesn't match the name of the raw expression")]
- /// The expected expression type doesn't match the name of the raw expression.
- InvalidExpressionKind,
-
- #[error("Deserializing the requested type isn't implemented yet")]
- /// Deserializing the requested type isn't implemented yet.
- NotImplemented,
-
- #[error("The expression value cannot be deserialized to the requested type")]
- /// The expression value cannot be deserialized to the requested type.
- InvalidValue,
-
- #[error("A pointer was null while a non-null pointer was expected")]
- /// A pointer was null while a non-null pointer was expected.
- NullPointer,
-
- #[error(
- "The size of a raw value was incoherent with the expected type of the deserialized value"
- )]
- /// The size of a raw value was incoherent with the expected type of the deserialized value/
- InvalidDataSize,
-}
-
pub trait Expression {
fn get_name() -> &'static str;
}