diff options
| author | Kalle Lindström <karl.lindstrom@mullvad.net> | 2025-05-16 08:50:01 +0200 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-05-16 14:32:41 +0200 |
| commit | 1d2470318048f995f9115f4f01cdd7ae54f866cd (patch) | |
| tree | 9d536eb0bdf2cdeb1737d562225ecd3f5d0ae38e | |
| parent | 9e9fc815e042802eed134c80e47958c250e12791 (diff) | |
| download | mullvadvpn-1d2470318048f995f9115f4f01cdd7ae54f866cd.tar.xz mullvadvpn-1d2470318048f995f9115f4f01cdd7ae54f866cd.zip | |
Remove Option and use #[serde(default)] instead
| -rw-r--r-- | ci/ios/test-router/raas/src/block_list/rule.rs | 2 | ||||
| -rw-r--r-- | ci/ios/test-router/raas/src/web/routes.rs | 20 |
2 files changed, 12 insertions, 10 deletions
diff --git a/ci/ios/test-router/raas/src/block_list/rule.rs b/ci/ios/test-router/raas/src/block_list/rule.rs index cc9b0a0bc5..a95dbd55ac 100644 --- a/ci/ios/test-router/raas/src/block_list/rule.rs +++ b/ci/ios/test-router/raas/src/block_list/rule.rs @@ -24,6 +24,8 @@ pub struct Endpoints { } impl BlockRule { + /// Creates one or more nft rules that correspond to this BlockRule. The returned Vec will always + /// have at least one element. pub fn create_nft_rules<'a>(&'a self, chain: &'a Chain<'a>) -> Vec<Rule<'a>> { match self { BlockRule::Host { protocols, .. } if !protocols.is_empty() => protocols diff --git a/ci/ios/test-router/raas/src/web/routes.rs b/ci/ios/test-router/raas/src/web/routes.rs index d6e8a39838..42c4b9687e 100644 --- a/ci/ios/test-router/raas/src/web/routes.rs +++ b/ci/ios/test-router/raas/src/web/routes.rs @@ -22,7 +22,8 @@ pub struct NewRule { /// A list of protocols that should be blocked, e.g. Tcp or WireGuard. The default behavior /// is to block all traffic regardless of protocol, but if `protocols` is non-empty, only /// traffic that uses that protocol is blocked. - pub protocols: Option<BTreeSet<Protocol>>, + #[serde(default)] + pub protocols: BTreeSet<Protocol>, /// A unique identifier for a group of rules. It is possible to add rules to an existing label /// and to remove all rules for a label. pub label: Uuid, @@ -95,10 +96,17 @@ pub async fn add_rule( dst: json.dst, invert_dst: json.block_all_except_dst, }; + let protocols = json.protocols; let mut block_rules = vec![]; - if let Some(protocols) = json.protocols { + if protocols.is_empty() { + // If no protocols are specified we default to blocking everything for (src, dst). + block_rules.push(BlockRule::Host { + endpoints, + protocols: BTreeSet::new(), + }); + } else { let mut transport = BTreeSet::new(); let mut application = BTreeSet::new(); for protocol in protocols { @@ -118,14 +126,6 @@ pub async fn add_rule( } } - // If no protocols are specified we default to blocking everything for (src, dst). - if block_rules.is_empty() { - block_rules.push(BlockRule::Host { - endpoints, - protocols: BTreeSet::new(), - }); - } - fw.add_rules(&block_rules, label)?; for rule in block_rules { log_rule(&rule, &label); |
