dfw/lib.rs
1// Copyright Pit Kleyersburg <pitkley@googlemail.com>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified or distributed
8// except according to those terms.
9
10//! # DFW - Docker Firewall Framework in Rust
11//!
12//! For detailed introductions, see the [README][github-readme].
13//!
14//! [github-readme]: https://github.com/pitkley/dfw#readme
15//!
16//! ## License
17//!
18//! DFW is licensed under either of
19//!
20//! * Apache License, Version 2.0, (<http://www.apache.org/licenses/LICENSE-2.0>)
21//! * MIT license (<https://opensource.org/licenses/MIT>)
22//!
23//! at your option.
24
25// Increase the compiler's recursion limit for the `error_chain` crate.
26#![recursion_limit = "1024"]
27#![deny(missing_docs)]
28// Allow upper-case acronyms in types (like `DFWError`).
29// NOTE: while I personally would have preferred to change the type names, DFW does provide a
30// public API through the `dfw` package on crates.io, for which this change would be breaking.
31// We should revisit this in major-version 2 of DFW.
32#![cfg_attr(crate_major_version = "1", allow(clippy::upper_case_acronyms))]
33
34// declare modules
35mod de;
36pub mod errors;
37pub mod iptables;
38pub mod nftables;
39pub mod process;
40pub mod types;
41pub mod util;
42
43use errors::Result;
44use process::{Process, ProcessContext};
45use serde::de::DeserializeOwned;
46use std::fmt::Debug;
47use types::DFW;
48
49/// This trait is used to distinguish between different firewall backends.
50///
51/// To add a new firewall-backend create an empty struct implementing this trait.
52pub trait FirewallBackend: Sized
53where
54 DFW<Self>: Process<Self>,
55{
56 /// Associated type identifying the rule-type returned.
57 type Rule;
58 /// Associated type representing the firewall backend defaults/configuration.
59 type Defaults: Debug + DeserializeOwned;
60
61 /// Apply the processed rules.
62 fn apply(rules: Vec<Self::Rule>, ctx: &ProcessContext<Self>) -> Result<()>;
63}