Skip to main content

dfw/iptables/
types.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//! The types in this module make up the structure of the iptables backend-specific configurations.
11//!
12//! # Example
13//!
14//! ```
15//! # use dfw::iptables::Iptables;
16//! # use dfw::types::*;
17//! # use toml;
18//! # toml::from_str::<DFW<Iptables>>(r#"
19//! [backend_defaults.initialization.v4]
20//! filter = [
21//!     "-P INPUT DROP",
22//!     "-F INPUT",
23//! ]
24//! [backend_defaults.initialization.v6]
25//! nat = [
26//!     "-P PREROUTING DROP",
27//! ]
28//! # "#).unwrap();
29//! ```
30
31use serde::Deserialize;
32use std::collections::HashMap;
33
34/// The defaults/configuration for the iptables backend.
35#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
36#[serde(deny_unknown_fields)]
37pub struct Defaults {
38    /// The optional initialization section.
39    ///
40    /// # Example
41    ///
42    /// ```
43    /// # use dfw::iptables::types::*;
44    /// # use toml;
45    /// # toml::from_str::<Defaults>(r#"
46    /// [initialization.v4]
47    /// filter = [
48    ///     "-P INPUT DROP",
49    ///     "-F INPUT",
50    /// ]
51    /// # "#).unwrap();
52    ///
53    /// # toml::from_str::<Defaults>(r#"
54    /// [initialization.v6]
55    /// nat = [
56    ///     "-P PREROUTING DROP",
57    /// ]
58    /// # "#).unwrap();
59    /// ```
60    pub initialization: Option<Initialization>,
61}
62
63/// The initialization section allows you to add custom rules to any table in both iptables and
64/// ip6tables.
65///
66/// # Example
67///
68/// ```
69/// # use dfw::iptables::types::*;
70/// # use toml;
71/// # toml::from_str::<Defaults>(r#"
72/// [initialization.v4]
73/// filter = [
74///     "-P INPUT DROP",
75///     "-F INPUT",
76/// ]
77///
78/// [initialization.v6]
79/// nat = [
80///     "-P PREROUTING DROP",
81/// ]
82/// # "#).unwrap();
83/// ```
84#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
85#[serde(deny_unknown_fields)]
86pub struct Initialization {
87    /// Initialization rules for iptables (IPv4). Expects a map where the key is a specific table
88    /// and the value is a list of rules.
89    ///
90    /// # Example
91    ///
92    /// ```
93    /// # use dfw::iptables::types::*;
94    /// # use toml;
95    /// # toml::from_str::<Defaults>(r#"
96    /// [initialization.v4]
97    /// filter = [
98    ///     "-P INPUT DROP",
99    ///     "-F INPUT",
100    /// ]
101    /// # "#).unwrap();
102    /// ```
103    pub v4: Option<HashMap<String, Vec<String>>>,
104
105    /// Initialization rules for ip6tables (IPv6). Expects a map where the key is a specific table
106    /// and the value is a list of rules.
107    ///
108    /// # Example
109    ///
110    /// ```
111    /// # use dfw::iptables::types::*;
112    /// # use toml;
113    /// # toml::from_str::<Defaults>(r#"
114    /// [initialization.v6]
115    /// nat = [
116    ///     "-P PREROUTING DROP",
117    /// ]
118    /// # "#).unwrap();
119    /// ```
120    pub v6: Option<HashMap<String, Vec<String>>>,
121}