diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-11-19 15:39:57 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-11-24 12:29:47 +0100 |
| commit | b3bf892256b2334aac70b3714e9fb0aa6dac51cb (patch) | |
| tree | 25af1c19f4e8db09f812391d054c41dd507055aa | |
| parent | a6ad39b7432e561fce4beb0adcd1cd84450b03de (diff) | |
| download | mullvadvpn-b3bf892256b2334aac70b3714e9fb0aa6dac51cb.tar.xz mullvadvpn-b3bf892256b2334aac70b3714e9fb0aa6dac51cb.zip | |
Define ALL_RULES in one place
| -rw-r--r-- | talpid-core/src/routing/linux.rs | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/talpid-core/src/routing/linux.rs b/talpid-core/src/routing/linux.rs index 2f90bab2fc..de5313f20e 100644 --- a/talpid-core/src/routing/linux.rs +++ b/talpid-core/src/routing/linux.rs @@ -85,6 +85,15 @@ lazy_static! { v6_rule.header.family = AF_INET6 as u8; v6_rule }; + + static ref ALL_RULES: [&'static RuleMessage; 6] = [ + &*NO_FWMARK_RULE_V4, + &*NO_FWMARK_RULE_V6, + &*SUPPRESS_RULE_V4, + &*SUPPRESS_RULE_V6, + &*EXCLUSIONS_RULE_V4, + &*EXCLUSIONS_RULE_V6, + ]; } @@ -192,14 +201,7 @@ impl RouteManagerImpl { self.clear_routing_rules().await?; - for rule in &[ - &*NO_FWMARK_RULE_V4, - &*NO_FWMARK_RULE_V6, - &*SUPPRESS_RULE_V4, - &*SUPPRESS_RULE_V6, - &*EXCLUSIONS_RULE_V4, - &*EXCLUSIONS_RULE_V6, - ] { + for rule in &*ALL_RULES { let mut req = NetlinkMessage::from(RtnlMessage::NewRule((*rule).clone())); req.header.flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE | NLM_F_REPLACE; @@ -216,14 +218,7 @@ impl RouteManagerImpl { async fn clear_routing_rules(&mut self) -> Result<()> { let rules = self.get_rules().await?; - for rule in &[ - &*EXCLUSIONS_RULE_V4, - &*EXCLUSIONS_RULE_V6, - &*SUPPRESS_RULE_V4, - &*SUPPRESS_RULE_V6, - &*NO_FWMARK_RULE_V4, - &*NO_FWMARK_RULE_V6, - ] { + for rule in &*ALL_RULES { let mut matching_rule = None; // `RTM_DELRULE` is way too picky about which rules are considered the same. |
