diff --git a/docs/options.md b/docs/options.md index 6e82e5d..93d1a08 100644 --- a/docs/options.md +++ b/docs/options.md @@ -5069,10 +5069,11 @@ Each entry generates hostlists/list-\\.txt and can clone a built-in zapret family from the active config, clone it from another configName, add custom NFQWS rule fragments, or combine these pieces\. -defaultDomains provides built-in zapret-discord-youtube domain groups -such as “youtube” and “discord”; defaultIps provides upstream IP/CIDR -groups such as “all”\. configName is a higher-level -alternative to nfqwsArgs and cannot be used together with nfqwsArgs\. +defaultDomains selects same-named upstream zapret-discord-youtube +hostlists such as “general” and “google”, with the aliases “discord” +and “youtube” for readability\. defaultIps provides upstream IP/CIDR +groups such as “all”\. configName is a higher-level alternative to +nfqwsArgs and cannot be used together with nfqwsArgs\. @@ -5198,9 +5199,16 @@ null Built-in domain groups copied from zapret-discord-youtube hostlists\. These are expanded and combined with domains\. -“youtube” uses the upstream Google/YouTube list\. “discord” uses -Discord-related domains from the upstream general list\. “other” uses -the non-Discord domains from the upstream general list\. +Each value maps directly to the same-named upstream file: +“general” uses list-general\.txt, “google” uses list-google\.txt, +and the remaining values use their corresponding list-\\.txt\. + +“discord” is an alias for “general”; “youtube” is an alias for +“google”\. + +When “general” or “discord” is used together with configName, the +module also clones the selected config’s Discord UDP voice rule +(–filter-l7=discord,stun)\. When preset is unset, use one defaultDomains entry per rule so the module can infer a single rule family\. Split groups into separate @@ -5209,7 +5217,7 @@ rules when they need different strategies\. *Type:* -list of (one of “youtube”, “discord”, “other”, “instagram”, “soundcloud”, “twitter”) +list of (one of “general”, “google”, “discord”, “youtube”, “instagram”, “soundcloud”, “twitter”) @@ -5225,7 +5233,7 @@ list of (one of “youtube”, “discord”, “other”, “instagram”, “s ```nix [ - "youtube" + "google" ] ``` diff --git a/modules/proxy-suite/options/types.nix b/modules/proxy-suite/options/types.nix index 9bcc737..b65c70a 100644 --- a/modules/proxy-suite/options/types.nix +++ b/modules/proxy-suite/options/types.nix @@ -278,9 +278,10 @@ let ]; zapretDefaultDomainType = types.enum [ - "youtube" + "general" + "google" "discord" - "other" + "youtube" "instagram" "soundcloud" "twitter" @@ -321,15 +322,22 @@ let Built-in domain groups copied from zapret-discord-youtube hostlists. These are expanded and combined with domains. - "youtube" uses the upstream Google/YouTube list. "discord" uses - Discord-related domains from the upstream general list. "other" uses - the non-Discord domains from the upstream general list. + Each value maps directly to the same-named upstream file: + "general" uses list-general.txt, "google" uses list-google.txt, + and the remaining values use their corresponding list-.txt. + + "discord" is an alias for "general"; "youtube" is an alias for + "google". + + When "general" or "discord" is used together with configName, the + module also clones the selected config's Discord UDP voice rule + (--filter-l7=discord,stun). When preset is unset, use one defaultDomains entry per rule so the module can infer a single rule family. Split groups into separate rules when they need different strategies. ''; - example = [ "youtube" ]; + example = [ "google" ]; }; ips = mkOption { diff --git a/modules/proxy-suite/options/zapret.nix b/modules/proxy-suite/options/zapret.nix index 7db818f..0b0329c 100644 --- a/modules/proxy-suite/options/zapret.nix +++ b/modules/proxy-suite/options/zapret.nix @@ -152,10 +152,11 @@ in zapret family from the active config, clone it from another configName, add custom NFQWS rule fragments, or combine these pieces. - defaultDomains provides built-in zapret-discord-youtube domain groups - such as "youtube" and "discord"; defaultIps provides upstream IP/CIDR - groups such as "all". configName is a higher-level - alternative to nfqwsArgs and cannot be used together with nfqwsArgs. + defaultDomains selects same-named upstream zapret-discord-youtube + hostlists such as "general" and "google", with the aliases "discord" + and "youtube" for readability. defaultIps provides upstream IP/CIDR + groups such as "all". configName is a higher-level alternative to + nfqwsArgs and cannot be used together with nfqwsArgs. ''; example = [ { diff --git a/modules/proxy-suite/zapret-domain-groups.nix b/modules/proxy-suite/zapret-domain-groups.nix index b27b68c..838e4a3 100644 --- a/modules/proxy-suite/zapret-domain-groups.nix +++ b/modules/proxy-suite/zapret-domain-groups.nix @@ -6,7 +6,6 @@ let trim = lib.strings.trim; hasPrefix = lib.strings.hasPrefix; - hasInfix = lib.strings.hasInfix; splitString = lib.strings.splitString; zapretSrc = if builtins.isAttrs zapret && zapret ? outPath then zapret.outPath else zapret; @@ -21,21 +20,22 @@ let upstreamHostlist = file: parseListFile "${zapretSrc}/hostlists/${file}"; generalDomains = upstreamHostlist "list-general.txt"; - isDiscordDomain = domain: domain == "dis.gd" || hasInfix "discord" domain; domainGroups = { + general = generalDomains; + google = upstreamHostlist "list-google.txt"; + discord = generalDomains; youtube = upstreamHostlist "list-google.txt"; - discord = builtins.filter isDiscordDomain generalDomains; - other = builtins.filter (domain: !(isDiscordDomain domain)) generalDomains; instagram = upstreamHostlist "list-instagram.txt"; soundcloud = upstreamHostlist "list-soundcloud.txt"; twitter = upstreamHostlist "list-twitter.txt"; }; groupPresets = { - youtube = "google"; + general = "general"; + google = "google"; discord = "general"; - other = "general"; + youtube = "google"; instagram = "instagram"; soundcloud = "soundcloud"; twitter = "twitter"; @@ -45,6 +45,11 @@ let all = upstreamHostlist "ipset-all.txt"; }; + protocolGroups = { + general = [ "discord-voice" ]; + discord = [ "discord-voice" ]; + }; + expandDefaultDomains = groups: lib.unique ( @@ -76,12 +81,24 @@ let effectiveRuleIpsetFamilies = rule: lib.optional (effectiveRuleIps rule != [ ]) "all"; + + effectiveRuleProtocolFamilies = + rule: + lib.optionals (rule.configName != null) ( + lib.unique ( + lib.concatMap ( + group: + if builtins.hasAttr group protocolGroups then protocolGroups.${group} else [ ] + ) rule.defaultDomains + ) + ); in { inherit domainGroups groupPresets ipGroups + protocolGroups expandDefaultDomains expandDefaultIps inferPresets @@ -89,5 +106,6 @@ in effectiveRuleIps effectiveRulePresets effectiveRuleIpsetFamilies + effectiveRuleProtocolFamilies ; } diff --git a/modules/proxy-suite/zapret.nix b/modules/proxy-suite/zapret.nix index 3b8f550..2485b25 100644 --- a/modules/proxy-suite/zapret.nix +++ b/modules/proxy-suite/zapret.nix @@ -46,6 +46,7 @@ let ips = zapretDomainGroups.effectiveRuleIps rule; presets = zapretDomainGroups.effectiveRulePresets rule; ipsets = zapretDomainGroups.effectiveRuleIpsetFamilies rule; + protocols = zapretDomainGroups.effectiveRuleProtocolFamilies rule; } ) zapretCfg.hostlistRules; @@ -73,6 +74,7 @@ let nfqwsArgs ipsets presets + protocols ; hasDomains = rule.domains != [ ]; hasIps = rule.ips != [ ]; diff --git a/nix/checks.nix b/nix/checks.nix index a488b3f..9e1fa4c 100644 --- a/nix/checks.nix +++ b/nix/checks.nix @@ -1185,19 +1185,26 @@ let enableDirectSync = false; } { - name = "youtube-general"; - defaultDomains = [ "youtube" ]; + name = "google-general"; + defaultDomains = [ "google" ]; configName = "general"; } { - name = "discord-alt12"; - defaultDomains = [ "discord" ]; + name = "general-alt12"; + defaultDomains = [ "general" ]; configName = "general (ALT12)"; } { - name = "other"; - defaultDomains = [ "other" ]; - preset = "general"; + name = "youtube-alias"; + defaultDomains = [ "youtube" ]; + configName = "general"; + enableDirectSync = false; + } + { + name = "discord-alias"; + defaultDomains = [ "discord" ]; + configName = "general (ALT12)"; + enableDirectSync = false; } { name = "upstream-ips"; @@ -1273,7 +1280,7 @@ let hostlistRules = [ { name = "conflict"; - defaultDomains = [ "youtube" ]; + defaultDomains = [ "google" ]; configName = "general"; nfqwsArgs = [ "--filter-tcp=443 --dpi-desync=fake" ]; } @@ -3640,19 +3647,30 @@ in grep -F -- '--hostlist="${zapretHostlistBase}/hostlists/list-googlevideo.txt"' "${zapretHostlistBase}/config" grep -F -- '--hostlist="${zapretHostlistBase}/hostlists/list-example.txt"' "${zapretHostlistBase}/config" grep -F -- '--filter-tcp=443 --dpi-desync=fake,multisplit --hostlist="${zapretHostlistBase}/hostlists/list-example.txt" --hostlist-exclude="${zapretHostlistBase}/hostlists/list-exclude.txt" --hostlist-exclude="${zapretHostlistBase}/hostlists/list-exclude-user.txt" --ipset-exclude="${zapretHostlistBase}/hostlists/ipset-exclude.txt" --ipset-exclude="${zapretHostlistBase}/hostlists/ipset-exclude-user.txt" --new' "${zapretHostlistBase}/config" - grep -F 'youtube.com' "${zapretHostlistBase}/hostlists/list-youtube-general.txt" - grep -F 'googlevideo.com' "${zapretHostlistBase}/hostlists/list-youtube-general.txt" - grep -F 'discord.com' "${zapretHostlistBase}/hostlists/list-discord-alt12.txt" - grep -F 'discord.gg' "${zapretHostlistBase}/hostlists/list-discord-alt12.txt" - ! grep -F 'cloudflare-ech.com' "${zapretHostlistBase}/hostlists/list-discord-alt12.txt" - grep -F 'cloudflare-ech.com' "${zapretHostlistBase}/hostlists/list-other.txt" - ! grep -F 'discord.com' "${zapretHostlistBase}/hostlists/list-other.txt" + grep -F 'youtube.com' "${zapretHostlistBase}/hostlists/list-google-general.txt" + grep -F 'googlevideo.com' "${zapretHostlistBase}/hostlists/list-google-general.txt" + grep -F 'discord.com' "${zapretHostlistBase}/hostlists/list-general-alt12.txt" + grep -F 'discord.gg' "${zapretHostlistBase}/hostlists/list-general-alt12.txt" + grep -F 'cloudflare-ech.com' "${zapretHostlistBase}/hostlists/list-general-alt12.txt" + grep -F 'cloudfront.net' "${zapretHostlistBase}/hostlists/list-general-alt12.txt" + grep -F '7tv.app' "${zapretHostlistBase}/hostlists/list-general-alt12.txt" + cmp "${zapretHostlistBase}/hostlists/list-google-general.txt" "${zapretHostlistBase}/hostlists/list-youtube-alias.txt" + cmp "${zapretHostlistBase}/hostlists/list-general-alt12.txt" "${zapretHostlistBase}/hostlists/list-discord-alias.txt" grep -F '1.1.1.0/24' "${zapretHostlistBase}/hostlists/ipset-upstream-ips.txt" grep -F '203.0.113.0/24' "${zapretHostlistBase}/hostlists/ipset-explicit-ips.txt" - grep -F -- '--hostlist="${zapretHostlistBase}/hostlists/list-youtube-general.txt"' "${zapretHostlistBase}/config" + grep -F -- '--hostlist="${zapretHostlistBase}/hostlists/list-google-general.txt"' "${zapretHostlistBase}/config" grep -F -- '--dpi-desync=multisplit --dpi-desync-split-seqovl=681' "${zapretHostlistBase}/config" grep -F -- '--ipset="${zapretHostlistBase}/hostlists/ipset-upstream-ips.txt"' "${zapretHostlistBase}/config" grep -F -- '--ipset="${zapretHostlistBase}/hostlists/ipset-explicit-ips.txt"' "${zapretHostlistBase}/config" + google_rule_line=$(grep -nF -- '--hostlist="${zapretHostlistBase}/hostlists/list-google-general.txt"' "${zapretHostlistBase}/config" | head -n1 | cut -d: -f1) + default_google_rule_line=$(grep -nF -- '--hostlist="${zapretHostlistBase}/hostlists/list-google.txt"' "${zapretHostlistBase}/config" | head -n1 | cut -d: -f1) + general_rule_line=$(grep -nF -- '--hostlist="${zapretHostlistBase}/hostlists/list-general-alt12.txt"' "${zapretHostlistBase}/config" | head -n1 | cut -d: -f1) + default_general_rule_line=$(grep -nF -- '--hostlist="${zapretHostlistBase}/hostlists/list-general.txt"' "${zapretHostlistBase}/config" | head -n1 | cut -d: -f1) + discord_voice_rule_line=$(grep -nF -- '--filter-l7=discord,stun' "${zapretHostlistBase}/config" | grep -F -- '--dpi-desync-repeats=3' | head -n1 | cut -d: -f1) + default_voice_rule_line=$(grep -nF -- '--filter-l7=discord,stun' "${zapretHostlistBase}/config" | grep -F -- '--dpi-desync-repeats=6' | head -n1 | cut -d: -f1) + test "$google_rule_line" -lt "$default_google_rule_line" + test "$general_rule_line" -lt "$default_general_rule_line" + test "$discord_voice_rule_line" -lt "$default_voice_rule_line" touch "$out" ''; } diff --git a/scripts/patch-zapret-config.py b/scripts/patch-zapret-config.py index 3628d39..5188996 100644 --- a/scripts/patch-zapret-config.py +++ b/scripts/patch-zapret-config.py @@ -45,6 +45,12 @@ IPSET_PATTERNS = { }, } +PROTOCOL_PATTERNS = { + "discord-voice": { + "match": ["--filter-l7=discord,stun"], + }, +} + def locate_nfqws_block(lines: list[str]) -> tuple[int, int]: start = None @@ -149,6 +155,10 @@ def _render_ipset_args( return f"{normalize_spaces(rendered)} --new" +def render_protocol_clone(line: str) -> str: + return f"{normalize_spaces(strip_trailing_new(line))} --new" + + def render_preset_clone( line: str, family: str, @@ -225,6 +235,19 @@ def clone_ipset_lines( ] +def clone_protocol_lines(existing_lines: list[str], family: str) -> list[str]: + matches = [ + line + for line in existing_lines + if any(marker in line for marker in PROTOCOL_PATTERNS[family]["match"]) + ] + if not matches: + raise ValueError( + f"Protocol family '{family}' is not present in the selected zapret config" + ) + return [render_protocol_clone(line) for line in matches] + + def activate_builtin_hostlists( existing_lines: list[str], hostlists_dir: Path, @@ -301,6 +324,7 @@ def main() -> int: preset = entry.get("preset") presets = [preset] if preset else [] ipsets = entry.get("ipsets", []) + protocols = entry.get("protocols", []) has_domains = entry.get("hasDomains", bool(presets)) has_ips = entry.get("hasIps", bool(ipsets)) @@ -316,6 +340,8 @@ def main() -> int: entry_nfqws_lines, ipset, ipset_path, standard_excludes ) ) + for protocol in protocols: + generated_lines.extend(clone_protocol_lines(entry_nfqws_lines, protocol)) for fragment in entry.get("nfqwsArgs", []): if has_domains: generated_lines.append( @@ -326,7 +352,7 @@ def main() -> int: render_custom_ipset_args(fragment, ipset_path, standard_excludes) ) - updated_lines = lines[:end] + generated_lines + lines[end:] + updated_lines = lines[: start + 1] + generated_lines + lines[start + 1 :] config_path.write_text("\n".join(updated_lines) + "\n", encoding="utf-8") return 0