From 34522c36672b10ce2a6c17095ffc77499db61de0 Mon Sep 17 00:00:00 2001 From: lafleur Date: Tue, 28 Sep 2021 22:10:51 +0200 Subject: [PATCH] fixes #45 - turn Log in a struct to group future arguments --- nftnl/src/expr/log.rs | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 nftnl/src/expr/log.rs diff --git a/nftnl/src/expr/log.rs b/nftnl/src/expr/log.rs new file mode 100644 index 0000000..9f2f052 --- /dev/null +++ b/nftnl/src/expr/log.rs @@ -0,0 +1,57 @@ +use super::{Expression, Rule}; +use nftnl_sys::{ + self as sys, + libc::c_char, +}; + +/// A log expression. +pub struct Log { + group: Option, +} + +#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] +pub enum LogGroup { + LogGroupZero, + LogGroupOne, + LogGroupTwo, + LogGroupThree, + LogGroupFour, + LogGroupFive, + LogGroupSix, + LogGroupSeven, +} + + +impl Log { + pub fn new(group: Option) -> Self { + Log { group } + } +} + +impl Expression for Log { + fn to_expr(&self, _rule: &Rule) -> *mut sys::nftnl_expr { + unsafe { + let expr = try_alloc!(sys::nftnl_expr_alloc( + b"log\0" as *const _ as *const c_char + )); + if let Some(group) = self.group { + sys::nftnl_expr_set_u32( + expr, + sys::NFTNL_EXPR_LOG_GROUP as u16, + group as u32, + ); + }; + expr + } + } +} + +#[macro_export] +macro_rules! nft_expr_log { + (group $group:ident) => { + $crate::expr::Log::new($group) + }; + () => { + $crate::expr::Log::new(None) + }; +}