Skip to content

Commit

Permalink
Feature flag nflog, clean up macros, and update CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaublitz committed Apr 26, 2020
1 parent 317ce87 commit b00b0bb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 44 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Changelog

## Unreleased

## 0.5.0-rc1
### Additions
* NFLOG support, in the `netfilter` module.
* Feature flagged NFLOG support, in the `netfilter` module.

### Resolved issues
* Resolved issue relating to allowing documentation annotations in
macros for enum variants representing netlink constants.

## 0.4.3
### Breaking changes
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ features = ["copy"]
default = []
stream = ["tokio", "mio"]
logging = ["log", "simple_logger", "lazy_static"]
netfilter = []
2 changes: 2 additions & 0 deletions examples/nflog.rs → no-compile-examples/nflog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
//! ```
//!
//! Both this example and the above command needs to be run as root.
#![cfg(feature = "netfilter")]

extern crate neli;

use neli::consts::netfilter::{LogCmd, LogCopyMode, NetfilterMsg, NfLogCfg};
Expand Down
67 changes: 26 additions & 41 deletions src/consts/macros.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// This is to facillitate the two different ways to call
// `impl_var`: one with doc comments and one without.
#[macro_export]
#[doc(hidden)]
macro_rules! impl_var_base {
macro_rules! impl_var_impls {
($name:ident, $ty:ty, $( $( #[cfg($meta:meta)] )* $var:ident => $val:expr ),* ) => {
impl From<$ty> for $name {
fn from(v: $ty) -> Self {
Expand Down Expand Up @@ -96,8 +94,13 @@ macro_rules! impl_var_base {
macro_rules! impl_var {
(
$( #[$outer:meta] )*
$name:ident, $ty:ty, $( $( #[cfg($meta:meta)] )* $var:ident => $val:expr ),*
) => ( // with comments
$name:ident,
$ty:ty,
$(
$( #[cfg($meta:meta)] )*
$var:ident => $val:expr
),*
) => (
$(#[$outer])*
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum $name {
Expand All @@ -112,28 +115,14 @@ macro_rules! impl_var {
UnrecognizedVariant($ty),
}

impl_var_base!($name, $ty, $( $( #[cfg($meta)] )* $var => $val),* );
);
(
$name:ident, $ty:ty,
$( $( #[cfg($meta:meta)] )* $var:ident => $val:expr ),*
) => ( // without comments
#[allow(missing_docs)]
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum $name {
#[allow(missing_docs)]
impl_var_impls!(
$name,
$ty,
$(
$(
#[cfg($meta)]
)*
#[allow(missing_docs)]
$var,
)*
/// Variant that signifies an invalid value while deserializing
UnrecognizedVariant($ty),
}

impl_var_base!($name, $ty, $( $( #[cfg($meta:meta)] )* $var => $val),* );
$( #[cfg($meta)] )*
$var => $val
),*
);
);
}

Expand All @@ -146,16 +135,10 @@ macro_rules! impl_var {
/// is the generic type and then use `impl_var_trait` to flag the new enum as usable in
/// this field. See the examples below for more details.
macro_rules! impl_trait {
( $(#[$outer:meta])* $trait_name:ident, $to_from_ty:ty ) => { // with comments
( $(#[$outer:meta])* $trait_name:ident, $to_from_ty:ty ) => {
$(#[$outer])*
pub trait $trait_name: $crate::Nl + PartialEq + Clone + From<$to_from_ty> + Into<$to_from_ty> {}

impl $trait_name for $to_from_ty {}
};
( $trait_name:ident, $to_from_ty:ty ) => { // without comments
#[allow(missing_docs)]
pub trait $trait_name: $crate::Nl + PartialEq + Clone + From<$to_from_ty> + Into<$to_from_ty> {}

impl $trait_name for $to_from_ty {}
};
}
Expand All @@ -166,18 +149,20 @@ macro_rules! impl_trait {
/// deserialization conversions, as well as value conversions
/// for serialization and deserialization.
macro_rules! impl_var_trait {
( $( #[$outer:meta] )* $name:ident, $ty:ty, $impl_name:ident,
$( $( #[cfg($meta:meta)] )* $var:ident => $val:expr ),* ) => ( // with comments
(
$( #[$outer:meta] )*
$name:ident,
$ty:ty,
$impl_name:ident,
$(
$( #[cfg($meta:meta)] )*
$var:ident => $val:expr
),*
) => (
impl_var!( $(#[$outer])*
$name, $ty, $( $( #[cfg($meta)] )* $var => $val ),*
);

impl $impl_name for $name {}
);
( $name:ident, $ty:ty, $impl_name:ident,
$( $( #[cfg($meta:meta)] )* $var:ident => $val:expr ),* ) => ( // without comments
impl_var!($name, $ty, $( $( #[cfg($meta)] )* $var => $val ),* );

impl $impl_name for $name {}
);
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub mod consts;
pub mod err;
/// Genetlink (generic netlink) header and attribute helpers
pub mod genl;
#[cfg(feature = "netfilter")]
pub mod netfilter;
/// Top-level netlink header
pub mod nl;
Expand Down

0 comments on commit b00b0bb

Please sign in to comment.