Skip to content

Commit

Permalink
Add social media blocklists to daemon+CLI
Browse files Browse the repository at this point in the history
When infra has deployed these block lists to the relays,
this setting will allow blocking social media domains
directly with the app
  • Loading branch information
faern committed Sep 19, 2023
1 parent 34874c9 commit d92b40a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mullvad-cli/src/cmds/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub enum DnsSet {
/// Block domains known to be used for gambling
#[arg(long)]
block_gambling: bool,

/// Block domains related to social media
#[arg(long)]
block_social_media: bool,
},

/// Set a list of custom DNS servers
Expand All @@ -62,6 +66,7 @@ impl Dns {
block_malware,
block_adult_content,
block_gambling,
block_social_media,
},
} => {
Self::set_default(
Expand All @@ -70,6 +75,7 @@ impl Dns {
block_malware,
block_adult_content,
block_gambling,
block_social_media,
)
.await
}
Expand All @@ -94,6 +100,7 @@ impl Dns {
options.default_options.block_adult_content
);
println!("Block gambling: {}", options.default_options.block_gambling);
println!("Block social media: {}", options.default_options.block_social_media);
}
DnsState::Custom => {
println!("Custom DNS: yes\nServers:");
Expand All @@ -112,6 +119,7 @@ impl Dns {
block_malware: bool,
block_adult_content: bool,
block_gambling: bool,
block_social_media: bool,
) -> Result<()> {
let mut rpc = MullvadProxyClient::new().await?;
let settings = rpc.get_settings().await?;
Expand All @@ -123,6 +131,7 @@ impl Dns {
block_malware,
block_adult_content,
block_gambling,
block_social_media,
},
..settings.tunnel_options.dns_options
})
Expand Down
4 changes: 4 additions & 0 deletions mullvad-daemon/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const DNS_TRACKER_BLOCKING_IP_BIT: u8 = 1 << 1; // 0b00000010
const DNS_MALWARE_BLOCKING_IP_BIT: u8 = 1 << 2; // 0b00000100
const DNS_ADULT_BLOCKING_IP_BIT: u8 = 1 << 3; // 0b00001000
const DNS_GAMBLING_BLOCKING_IP_BIT: u8 = 1 << 4; // 0b00010000
const DNS_SOCIAL_MEDIA_BLOCKING_IP_BIT: u8 = 1 << 5; // 0b00100000

/// Return the resolvers as a vector of `IpAddr`s. Returns `None` when no special resolvers
/// are requested and the tunnel default gateway should be used.
Expand All @@ -35,6 +36,9 @@ pub fn addresses_from_options(options: &DnsOptions) -> Option<Vec<IpAddr>> {
if options.default_options.block_gambling {
last_byte |= DNS_GAMBLING_BLOCKING_IP_BIT;
}
if options.default_options.block_social_media {
last_byte |= DNS_SOCIAL_MEDIA_BLOCKING_IP_BIT;
}

if last_byte != 0 {
let mut dns_ip = DNS_BLOCKING_IP_BASE.octets();
Expand Down
3 changes: 3 additions & 0 deletions mullvad-daemon/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ impl<'a> Display for SettingsSummary<'a> {
if default_options.block_gambling {
content.push("gambling");
}
if default_options.block_social_media {
content.push("social media");
}
if content.is_empty() {
content.push("default");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ message DefaultDnsOptions {
bool block_malware = 3;
bool block_adult_content = 4;
bool block_gambling = 5;
bool block_social_media = 6;
}

message CustomDnsOptions { repeated string addresses = 1; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl From<&mullvad_types::settings::DnsOptions> for proto::DnsOptions {
block_malware: options.default_options.block_malware,
block_adult_content: options.default_options.block_adult_content,
block_gambling: options.default_options.block_gambling,
block_social_media: options.default_options.block_social_media,
}),
custom_options: Some(proto::CustomDnsOptions {
addresses: options
Expand Down Expand Up @@ -315,6 +316,7 @@ impl TryFrom<proto::DnsOptions> for mullvad_types::settings::DnsOptions {
block_malware: default_options.block_malware,
block_adult_content: default_options.block_adult_content,
block_gambling: default_options.block_gambling,
block_social_media: default_options.block_social_media,
},
custom_options: MullvadCustomDnsOptions {
addresses: custom_options
Expand Down
1 change: 1 addition & 0 deletions mullvad-types/src/settings/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct DefaultDnsOptions {
pub block_malware: bool,
pub block_adult_content: bool,
pub block_gambling: bool,
pub block_social_media: bool,
}

/// Custom DNS config
Expand Down

0 comments on commit d92b40a

Please sign in to comment.