Skip to content

Commit

Permalink
Merge branch 'add-daemoncli-support-for-social-media-blocklist-des-354'
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Sep 20, 2023
2 parents d9fb71a + 412b799 commit 070c406
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ data class DefaultDnsOptions(
val blockMalware: Boolean = false,
val blockAdultContent: Boolean = false,
val blockGambling: Boolean = false,
val blockSocialMedia: Boolean = false,
) : Parcelable {
fun isAnyBlockerEnabled(): Boolean {
return blockAds || blockTrackers || blockMalware || blockAdultContent || blockGambling
return blockAds ||
blockTrackers ||
blockMalware ||
blockAdultContent ||
blockGambling ||
blockSocialMedia
}
}
12 changes: 12 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,10 @@ 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 +122,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 +134,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 070c406

Please sign in to comment.