Add assert
This commit is contained in:
parent
b0e750b873
commit
7ed99ce3f7
@ -20,6 +20,8 @@ pub enum BlockRule {
|
|||||||
pub struct Endpoints {
|
pub struct Endpoints {
|
||||||
pub src: IpNetwork,
|
pub src: IpNetwork,
|
||||||
pub dst: IpNetwork,
|
pub dst: IpNetwork,
|
||||||
|
/// Normally a packet sent to `dst` would match the block rule, but this option inverts that
|
||||||
|
/// so that any packet *not* sent to `dst` will match the block rule.
|
||||||
pub invert_dst: bool,
|
pub invert_dst: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,13 +29,15 @@ impl BlockRule {
|
|||||||
/// Creates one or more nft rules that correspond to this BlockRule. The returned Vec will always
|
/// Creates one or more nft rules that correspond to this BlockRule. The returned Vec will always
|
||||||
/// have at least one element.
|
/// have at least one element.
|
||||||
pub fn create_nft_rules<'a>(&'a self, chain: &'a Chain<'a>) -> Vec<Rule<'a>> {
|
pub fn create_nft_rules<'a>(&'a self, chain: &'a Chain<'a>) -> Vec<Rule<'a>> {
|
||||||
match self {
|
let rules = match self {
|
||||||
BlockRule::Host { protocols, .. } if !protocols.is_empty() => protocols
|
BlockRule::Host { protocols, .. } if !protocols.is_empty() => protocols
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|protocol| self.create_nft_rules_inner(chain, Some(*protocol)))
|
.flat_map(|protocol| self.create_nft_rules_inner(chain, Some(*protocol)))
|
||||||
.collect(),
|
.collect(),
|
||||||
_ => self.create_nft_rules_inner(chain, None),
|
_ => self.create_nft_rules_inner(chain, None),
|
||||||
}
|
};
|
||||||
|
assert!(!rules.is_empty());
|
||||||
|
rules
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_nft_rules_inner<'a>(
|
fn create_nft_rules_inner<'a>(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user