aboutsummaryrefslogtreecommitdiff
path: root/src/expr
diff options
context:
space:
mode:
authorlafleur <lafleur@boum.org>2021-11-28 16:42:27 +0100
committerlafleur <lafleur@boum.org>2021-11-28 16:42:27 +0100
commit100e365bc653089d54319355a8dea99b28a77a15 (patch)
tree552b5c9dfc79e1030be31fff514f67211839c31c /src/expr
parent8a41f1de700b573afb5051abaac22f1094ae21ad (diff)
docstrings update + typography
Diffstat (limited to 'src/expr')
-rw-r--r--src/expr/bitwise.rs4
-rw-r--r--src/expr/cmp.rs13
-rw-r--r--src/expr/counter.rs2
-rw-r--r--src/expr/immediate.rs24
-rw-r--r--src/expr/log.rs4
-rw-r--r--src/expr/lookup.rs3
-rw-r--r--src/expr/meta.rs4
-rw-r--r--src/expr/mod.rs20
-rw-r--r--src/expr/nat.rs8
-rw-r--r--src/expr/payload.rs2
-rw-r--r--src/expr/register.rs4
-rw-r--r--src/expr/reject.rs7
-rw-r--r--src/expr/wrapper.rs2
13 files changed, 46 insertions, 51 deletions
diff --git a/src/expr/bitwise.rs b/src/expr/bitwise.rs
index 59ef41b..d34d22c 100644
--- a/src/expr/bitwise.rs
+++ b/src/expr/bitwise.rs
@@ -10,8 +10,8 @@ pub struct Bitwise<M: ToSlice, X: ToSlice> {
}
impl<M: ToSlice, X: ToSlice> Bitwise<M, X> {
- /// Returns a new `Bitwise` instance that first masks the value it's applied to with `mask`
- /// and then performs xor with the value in `xor`.
+ /// Returns a new `Bitwise` instance that first masks the value it's applied to with `mask` and
+ /// then performs xor with the value in `xor`.
pub fn new(mask: M, xor: X) -> Self {
Self { mask, xor }
}
diff --git a/src/expr/cmp.rs b/src/expr/cmp.rs
index 384f0b4..f6ea900 100644
--- a/src/expr/cmp.rs
+++ b/src/expr/cmp.rs
@@ -101,11 +101,10 @@ impl<const N: usize> Expression for Cmp<[u8; N]> {
Cmp::<u8>::get_raw_name()
}
- /// The raw data contained inside `Cmp` expressions can only be deserialized to
- /// arrays of bytes, to ensure that the memory layout of retrieved data cannot be
- /// violated. It is your responsibility to provide the correct length of the byte
- /// data. If the data size is invalid, you will get the error
- /// `DeserializationError::InvalidDataSize`.
+ /// The raw data contained inside `Cmp` expressions can only be deserialized to arrays of
+ /// bytes, to ensure that the memory layout of retrieved data cannot be violated. It is your
+ /// responsibility to provide the correct length of the byte data. If the data size is invalid,
+ /// you will get the error `DeserializationError::InvalidDataSize`.
///
/// Example (warning, no error checking!):
/// ```rust
@@ -183,8 +182,8 @@ macro_rules! nft_expr_cmp {
};
}
-/// Can be used to compare the value loaded by [`Meta::IifName`] and [`Meta::OifName`]. Please
-/// note that it is faster to check interface index than name.
+/// Can be used to compare the value loaded by [`Meta::IifName`] and [`Meta::OifName`]. Please note
+/// that it is faster to check interface index than name.
///
/// [`Meta::IifName`]: enum.Meta.html#variant.IifName
/// [`Meta::OifName`]: enum.Meta.html#variant.OifName
diff --git a/src/expr/counter.rs b/src/expr/counter.rs
index 71064df..4732e85 100644
--- a/src/expr/counter.rs
+++ b/src/expr/counter.rs
@@ -3,7 +3,7 @@ use crate::sys;
use std::os::raw::c_char;
/// A counter expression adds a counter to the rule that is incremented to count number of packets
-/// and number of bytes for all packets that has matched the rule.
+/// and number of bytes for all packets that have matched the rule.
#[derive(Debug, PartialEq)]
pub struct Counter {
pub nb_bytes: u64,
diff --git a/src/expr/immediate.rs b/src/expr/immediate.rs
index 0787e06..71453b3 100644
--- a/src/expr/immediate.rs
+++ b/src/expr/immediate.rs
@@ -3,8 +3,8 @@ use crate::sys;
use std::ffi::c_void;
use std::os::raw::c_char;
-/// An immediate expression. Used to set immediate data.
-/// Verdicts are handled separately by [crate::expr::Verdict].
+/// An immediate expression. Used to set immediate data. Verdicts are handled separately by
+/// [crate::expr::Verdict].
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct Immediate<T> {
pub data: T,
@@ -50,11 +50,10 @@ impl<const N: usize> Expression for Immediate<[u8; N]> {
Immediate::<u8>::get_raw_name()
}
- /// The raw data contained inside `Immediate` expressions can only be deserialized to
- /// arrays of bytes, to ensure that the memory layout of retrieved data cannot be
- /// violated. It is your responsibility to provide the correct length of the byte
- /// data. If the data size is invalid, you will get the error
- /// `DeserializationError::InvalidDataSize`.
+ /// The raw data contained inside `Immediate` expressions can only be deserialized to arrays of
+ /// bytes, to ensure that the memory layout of retrieved data cannot be violated. It is your
+ /// responsibility to provide the correct length of the byte data. If the data size is invalid,
+ /// you will get the error `DeserializationError::InvalidDataSize`.
///
/// Example (warning, no error checking!):
/// ```rust
@@ -72,12 +71,11 @@ impl<const N: usize> Expression for Immediate<[u8; N]> {
/// println!("{:?}", expr.decode_expr::<Immediate<[u8; 1]>>().unwrap());
/// }
/// ```
- /// These limitations occur because casting bytes to any type of the same size
- /// as the raw input would be *extremely* dangerous in terms of memory safety.
- // As casting bytes to any type of the same size as the input would
- // be *extremely* dangerous in terms of memory safety,
- // rustables only accept to deserialize expressions with variable-size data
- // to arrays of bytes, so that the memory layout cannot be invalid.
+ /// These limitations occur because casting bytes to any type of the same size as the raw input
+ /// would be *extremely* dangerous in terms of memory safety.
+ // As casting bytes to any type of the same size as the input would be *extremely* dangerous in
+ // terms of memory safety, rustables only accept to deserialize expressions with variable-size
+ // data to arrays of bytes, so that the memory layout cannot be invalid.
fn from_expr(expr: *const sys::nftnl_expr) -> Result<Self, DeserializationError> {
unsafe {
let ref_len = std::mem::size_of::<[u8; N]>() as u32;
diff --git a/src/expr/log.rs b/src/expr/log.rs
index 5c06897..8d20b48 100644
--- a/src/expr/log.rs
+++ b/src/expr/log.rs
@@ -73,8 +73,8 @@ pub struct LogGroup(pub u16);
pub struct LogPrefix(CString);
impl LogPrefix {
- /// Create a new LogPrefix from a String. Converts it to CString as needed by nftnl. Note
- /// that LogPrefix should not be more than 127 characters long.
+ /// Creates a new LogPrefix from a String. Converts it to CString as needed by nftnl. Note that
+ /// LogPrefix should not be more than 127 characters long.
pub fn new(prefix: &str) -> Result<Self, LogPrefixError> {
if prefix.chars().count() > 127 {
return Err(LogPrefixError::TooLongPrefix);
diff --git a/src/expr/lookup.rs b/src/expr/lookup.rs
index fa12197..a0cc021 100644
--- a/src/expr/lookup.rs
+++ b/src/expr/lookup.rs
@@ -11,8 +11,7 @@ pub struct Lookup {
}
impl Lookup {
- /// Creates a new lookup entry.
- /// May return None if the set have no name.
+ /// Creates a new lookup entry. May return None if the set has no name.
pub fn new<K>(set: &Set<K>) -> Option<Self> {
set.get_name().map(|set_name| Lookup {
set_name: set_name.to_owned(),
diff --git a/src/expr/meta.rs b/src/expr/meta.rs
index bf77774..a015f65 100644
--- a/src/expr/meta.rs
+++ b/src/expr/meta.rs
@@ -14,7 +14,7 @@ pub enum Meta {
Iif,
/// Packet output interface index (dev->ifindex).
Oif,
- /// Packet input interface name (dev->name)
+ /// Packet input interface name (dev->name).
IifName,
/// Packet output interface name (dev->name).
OifName,
@@ -32,7 +32,7 @@ pub enum Meta {
L4Proto,
/// Socket control group (skb->sk->sk_classid).
Cgroup,
- /// A 32bit pseudo-random number
+ /// A 32bit pseudo-random number.
PRandom,
}
diff --git a/src/expr/mod.rs b/src/expr/mod.rs
index fbf49d6..dc59507 100644
--- a/src/expr/mod.rs
+++ b/src/expr/mod.rs
@@ -60,29 +60,29 @@ pub use self::wrapper::ExpressionWrapper;
#[derive(Debug, Error)]
pub enum DeserializationError {
#[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
+ /// 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
+ /// 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
+ /// 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
+ /// 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
+ /// The size of a raw value was incoherent with the expected type of the deserialized value/
InvalidDataSize,
#[error(transparent)]
- /// Couldn't find a matching protocol
+ /// Couldn't find a matching protocol.
InvalidProtolFamily(#[from] super::InvalidProtocolFamily),
}
@@ -91,8 +91,8 @@ pub trait Expression {
/// Returns the raw name used by nftables to identify the rule.
fn get_raw_name() -> *const libc::c_char;
- /// Try to parse the expression from a raw nftables expression,
- /// returning a [DeserializationError] if the attempted parsing failed.
+ /// Try to parse the expression from a raw nftables expression, returning a
+ /// [DeserializationError] if the attempted parsing failed.
fn from_expr(_expr: *const sys::nftnl_expr) -> Result<Self, DeserializationError>
where
Self: Sized,
@@ -100,8 +100,8 @@ pub trait Expression {
Err(DeserializationError::NotImplemented)
}
- /// Allocates and returns the low level `nftnl_expr` representation of this expression.
- /// The caller to this method is responsible for freeing the expression.
+ /// Allocates and returns the low level `nftnl_expr` representation of this expression. The
+ /// caller to this method is responsible for freeing the expression.
fn to_expr(&self, rule: &Rule) -> *mut sys::nftnl_expr;
}
diff --git a/src/expr/nat.rs b/src/expr/nat.rs
index 8beaa30..ce6b881 100644
--- a/src/expr/nat.rs
+++ b/src/expr/nat.rs
@@ -6,9 +6,9 @@ use std::{convert::TryFrom, os::raw::c_char};
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[repr(i32)]
pub enum NatType {
- /// Source NAT. Changes the source address of a packet
+ /// Source NAT. Changes the source address of a packet.
SNat = libc::NFT_NAT_SNAT,
- /// Destination NAT. Changeth the destination address of a packet
+ /// Destination NAT. Changes the destination address of a packet.
DNat = libc::NFT_NAT_DNAT,
}
@@ -22,8 +22,8 @@ impl NatType {
}
}
-/// A source or destination NAT statement. Modifies the source or destination address
-/// (and possibly port) of packets.
+/// A source or destination NAT statement. Modifies the source or destination address (and possibly
+/// port) of packets.
#[derive(Debug, PartialEq)]
pub struct Nat {
pub nat_type: NatType,
diff --git a/src/expr/payload.rs b/src/expr/payload.rs
index 4ba47df..a108fe8 100644
--- a/src/expr/payload.rs
+++ b/src/expr/payload.rs
@@ -51,7 +51,7 @@ pub struct RawPayloadData {
}
/// Because deserializing a `Payload` expression is not possible (there is not enough information
-/// in the expression itself, this enum should be used to deserialize payloads.
+/// in the expression itself), this enum should be used to deserialize payloads.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum RawPayload {
LinkLayer(RawPayloadData),
diff --git a/src/expr/register.rs b/src/expr/register.rs
index f0aed94..a05af7e 100644
--- a/src/expr/register.rs
+++ b/src/expr/register.rs
@@ -4,8 +4,8 @@ use crate::sys::libc;
use super::DeserializationError;
-/// A netfilter data register. The expressions store and read data to and from these
-/// when evaluating rule statements.
+/// A netfilter data register. The expressions store and read data to and from these when
+/// evaluating rule statements.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[repr(i32)]
pub enum Register {
diff --git a/src/expr/reject.rs b/src/expr/reject.rs
index 2ea0cbf..19752ce 100644
--- a/src/expr/reject.rs
+++ b/src/expr/reject.rs
@@ -2,13 +2,12 @@ use super::{DeserializationError, Expression, Rule};
use crate::ProtoFamily;
use crate::sys::{self, libc::{self, c_char}};
-/// A reject expression that defines the type of rejection message sent
-/// when discarding a packet.
+/// A reject expression that defines the type of rejection message sent when discarding a packet.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub enum Reject {
- /// Return an ICMP unreachable packet
+ /// Returns an ICMP unreachable packet.
Icmp(IcmpCode),
- /// Reject by sending a TCP RST packet
+ /// Rejects by sending a TCP RST packet.
TcpRst,
}
diff --git a/src/expr/wrapper.rs b/src/expr/wrapper.rs
index 1bcc520..00c555c 100644
--- a/src/expr/wrapper.rs
+++ b/src/expr/wrapper.rs
@@ -47,7 +47,7 @@ impl ExpressionWrapper {
}
}
- /// Attempt to decode the expression as the type T.
+ /// Attempts to decode the expression as the type T.
pub fn decode_expr<T: Expression>(&self) -> Result<T, DeserializationError> {
if let Some(kind) = self.get_kind() {
let raw_name = unsafe { CStr::from_ptr(T::get_raw_name()) };