Skip to content

Commit

Permalink
Merge pull request #3 from rusty-bolt/bolt/cta-mark
Browse files Browse the repository at this point in the history
Fix Mark and SecMark Attribute Parsing
  • Loading branch information
mbolt35 committed Nov 16, 2023
2 parents cfdb208 + 71293ac commit 5acb73c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "conntrack"
version = "0.1.0"
authors = [ "Matt Bolt <mbolt35@gmail.com" ]
version = "0.1.1"
authors = ["Matt Bolt <mbolt35@gmail.com>"]
repository = "https://github.com/rusty-bolt/conntrack-rs"
description = "Netfilter Conntrack"
categories = ["network-programming"]
Expand All @@ -24,4 +24,4 @@ env_logger = "0.10.0"

[[example]]
name = "conntrack-dump"
path = "examples/conntrack_dump.rs"
path = "examples/conntrack_dump.rs"
4 changes: 4 additions & 0 deletions src/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! # Attributes
//! This module contains neli compatible attributes used to read and decode
//! conntrack subsystem responses.

use neli::{
attr::AttrHandle,
consts::genl::NlAttrType,
Expand Down
3 changes: 3 additions & 0 deletions src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! # Connection
//! This module contains the general API for the conntrack library.

use neli::{
consts::{nl::*, socket::*},
genl::Genlmsghdr,
Expand Down
9 changes: 8 additions & 1 deletion src/decoders.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! # Decoders
//! This module contains decoder traits and implementations capable of extracting
//! conntrack table data from neli attributes.

use std::net::IpAddr;
use std::net::Ipv4Addr;
use std::net::Ipv6Addr;
Expand Down Expand Up @@ -143,6 +147,9 @@ impl<'a> AttrDecoder<'a, ConntrackAttr, Flow> for Flow {
ConntrackAttr::CtaTimeout => {
flow.timeout = Some(Duration::from_secs((u32::decode(attr)?) as u64));
}
ConntrackAttr::CtaMark => {
flow.mark = Some(u32::decode(attr)?);
}
ConntrackAttr::CtaSeqAdjOrig => {
let seq_adj_orig_attr = attr.get_attr_handle::<SeqAdjAttr>()?;

Expand All @@ -162,7 +169,7 @@ impl<'a> AttrDecoder<'a, ConntrackAttr, Flow> for Flow {
flow.sec_ctx = Some(SecCtx::decode(sec_ctx_attr)?);
}
ConntrackAttr::CtaSecMark => {
flow.mark = Some(u32::decode(attr)?);
flow.sec_mark = Some(u32::decode(attr)?);
}
ConntrackAttr::CtaMarkMask => {
flow.mark_mask = Some(u32::decode(attr)?);
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! # Error
//! This module contains all the potential error types that can come from
//! the `conntrack` library.

use std::fmt::Debug;

/// Error consolidates and propagates all underlying error types.
Expand Down
3 changes: 3 additions & 0 deletions src/message.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! # Message
//! This module contains neli compatible subsystem messages.

use neli::neli_enum;

#[inline]
Expand Down
4 changes: 4 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! # Model
//! This module contains rust model structs for the decoded conntrack data.

use bitflags::bitflags;
use chrono::prelude::*;
use neli::neli_enum;
Expand Down Expand Up @@ -43,6 +46,7 @@ pub struct Flow {
pub seq_adj_orig: Option<SeqAdj>,
pub seq_adj_repl: Option<SeqAdj>,
pub sec_ctx: Option<SecCtx>,
pub sec_mark: Option<u32>,
pub exp: Option<Exp>,
}
#[neli_enum(serialized_type = "u8")]
Expand Down
3 changes: 3 additions & 0 deletions src/result.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! # Result
//! This module contains the result alias and a module reimport for the error types.

pub use crate::error::Error;

/// Result is an alias for `core::result::Result<T, conntrack::error::Error>`
Expand Down

0 comments on commit 5acb73c

Please sign in to comment.