Chinese Services & Domestic Traffic Rules
Relevant source files
The following files were used as context for generating this wiki page: - [Clash/GeneralClashConfig.yml](https://github.com/happy-endless/Self-Rule/blob/HEAD/Clash/GeneralClashConfig.yml) - [Clash/Providers/BanProgramAD.yaml](https://github.com/happy-endless/Self-Rule/blob/HEAD/Clash/Providers/BanProgramAD.yaml) - [Clash/Providers/BanAD.yaml](https://github.com/happy-endless/Self-Rule/blob/HEAD/Clash/Providers/BanAD.yaml) - [update_providers.py](https://github.com/happy-endless/Self-Rule/blob/HEAD/update_providers.py) - [Tool/New.md](https://github.com/happy-endless/Self-Rule/blob/HEAD/Tool/New.md) - [Clash/Providers/UnBan.yaml](https://github.com/happy-endless/Self-Rule/blob/HEAD/Clash/Providers/UnBan.yaml) - [README.md](https://github.com/happy-endless/Self-Rule/blob/HEAD/README.md)The "Self-Rule" project, based on ACL4SSR, implements a sophisticated system for managing network traffic, with a significant focus on differentiating between domestic (Chinese) and international services. The primary goals are to ensure that traffic to Chinese services is routed directly for optimal performance and to block advertisements and trackers associated with these services, thereby enhancing user privacy and experience.
This is achieved through a combination of main configuration files, specialized rule provider files, and maintenance scripts. The core logic resides in the Clash/GeneralClashConfig.yml file, which defines system-wide bypass rules, and is supplemented by provider files like Clash/Providers/BanProgramAD.yaml for blocking ads in specific applications.
System Configuration for Domestic Traffic
The main configuration file, Clash/GeneralClashConfig.yml, is central to routing domestic traffic. It utilizes the cfw-bypass list to specify domains and IP ranges that should not be routed through the proxy, ensuring direct and fast connections to Chinese services.
Sources: Clash/GeneralClashConfig.yml
cfw-bypass Mechanism
The cfw-bypass list contains an extensive collection of domain wildcards for common Chinese services. When the system proxy is enabled, any request matching a pattern in this list will bypass the proxy and connect directly.
This diagram illustrates the bypass logic for a request to a Chinese domain.
Sources: Clash/GeneralClashConfig.yml:230-891
Categorization of Bypassed Services
The cfw-bypass list is meticulously organized by company and service type, covering a vast range of Chinese internet services. This ensures comprehensive coverage for direct connection.
| Company/Category | Example Domains |
|---|---|
| Alibaba Group | *.alibaba.com, *.taobao.com, *.alipay.com, *.youku.com, *.dingtalk.com |
| Baidu | *.baidu.com, *.baidupcs.com, *.bdstatic.com, *.hao123.com |
| Tencent | *.qq.com, *.tencent.com, *.weixin.com, *.myqcloud.com |
| ByteDance | *.douyin.com, *.toutiao.com, *.ixigua.com |
| NetEase | *.163.com, *.126.com, *.youdao.com, *.lofter.com |
| Xiaomi (MI) | *.mi.com, *.xiaomi.com, *.miui.com |
| JD.com | *.jd.com, *.360buy.com, *.jdcloud.com |
| Bilibili | *.bilibili.com, *.b23.tv, *.acgvideo.com |
| Sina | *.sina.com.cn, *.weibo.com, *.weibo.cn |
| Public CDN | *.baomitu.com, *.staticfile.org, *.upaiyun.com |
Sources: Clash/GeneralClashConfig.yml:249-891
Below is a snippet from the configuration file showing how these rules are defined.
# Clash/GeneralClashConfig.yml:315
cfw-bypass:
# ...
# Alibaba
- "*.1688.com"
- "*.aliapp.org"
- "*.alibaba.com"
- "*.alibabacloud.com"
# ...
# Baidu
- "*.baidu.com"
- "*.baidubcr.com"
- "*.baidupcs.com"
# ...
# Tencent
- "*.foxmail.com"
- "*.gtimg.com"
- "*.idqqimg.com"
# ...
Sources: Clash/GeneralClashConfig.yml:315-348, Clash/GeneralClashConfig.yml:349-363, Clash/GeneralClashConfig.yml:517-533
Ad and Tracker Blocking for Chinese Services
A key feature is the aggressive blocking of advertisements and trackers from Chinese applications and websites. This is handled by dedicated rule provider files.
Ad Blocking Rule Providers
The repository contains provider files specifically for blocking ads.
Clash/Providers/BanAD.yaml: Blocks common ad networks and keywords.Clash/Providers/BanProgramAD.yaml: Blocks ads within specific popular Chinese applications.
These files are composed of DOMAIN-SUFFIX and DOMAIN-KEYWORD rules that are used in a Clash configuration to reject matching traffic.
Sources: Clash/Providers/BanAD.yaml, Clash/Providers/BanProgramAD.yaml
Examples of Blocked Ad Domains
The rule lists are extensive and target ad-serving domains from major Chinese tech companies.
| Company | Example Blocked Ad/Tracker Domains | Source File |
|---|---|---|
| NetEase (163) | a.youdao.com, dsp.youdao.com, g.corp.163.com | BanProgramAD.yaml |
| Baidu | ad.duapps.com, adm.baidu.com, cpro.baidu.com, mobads.baidu.com | BanProgramAD.yaml |
| Alibaba | adash-c.m.taobao.com, g.click.taobao.com, userimg.qunar.com | BanProgramAD.yaml |
| Tencent (QQ) | adsmind.gdtimg.com, ad.qun.qq.com, gdt.qq.com, tcss.qq.com | BanProgramAD.yaml |
| Xiaomi (MIUI) | ad.xiaomi.com, adv.sec.miui.com, data.mistat.xiaomi.com | BanProgramAD.yaml |
| Sina | ad.sina.com.cn, sax.sina.com.cn, tui.weibo.com | BanProgramAD.yaml |
| Ad Keywords | admaster, adsage, guanggao, duomeng | BanAD.yaml |
Sources: Clash/Providers/BanProgramAD.yaml:5-40, Clash/Providers/BanProgramAD.yaml:153-248, Clash/Providers/BanProgramADyaml:97-120, Clash/Providers/BanProgramAD.yaml:652-669, Clash/Providers/BanProgramAD.yaml:609-629, Clash/Providers/BanProgramAD.yaml:681-711, Clash/Providers/BanAD.yaml:5-28
Un-banning Necessary Services
To prevent breaking essential functionality, an UnBan.yaml provider exists. It lists domains that might otherwise be blocked by broad ad-blocking rules but are required for applications to work correctly. For example, Umeng's error logging and message services are explicitly allowed.
# Clash/Providers/UnBan.yaml:18
payload:
# ...
# Umeng
- DOMAIN,errlog.umeng.com
- DOMAIN,msg.umeng.com
- DOMAIN,msg.umengcloud.com
# ...
Sources: Clash/Providers/UnBan.yaml:18-24
Rule Generation and Maintenance
The rule files are not manually maintained in their final YAML format. A Python script, update_providers.py, automates the conversion from simpler .list files to the Clash-compatible .yaml provider format.
The update_providers.py Script
This script performs the following actions:
- Walks through the
Clash/directory, ignoring theProvidersandconfigsubdirectories. - Finds all
.listfiles. - For each
.listfile, it reads the contents line by line. - It creates a corresponding
.yamlfile in theClash/Providers/directory. - It formats each line from the
.listfile into thepayload:section of the YAML file. - It handles comments and ignores certain rule types like
USER-AGENTby commenting them out.
This process is visualized in the following flowchart:
Sources: update_providers.py:9-41
Historical Maintenance
The Tool/New.md file serves as a detailed changelog, showing the active maintenance and evolution of these rules. Entries indicate a continuous effort to refine the rules for Chinese services, such as:
- 2017-03-16: Merged China IP segments, improved rules for Baidu and LeTV.
- 2017-03-03: Blocked ads for Xiaomi MIUI and Meizu Flyme ROMs.
- 2017-02-18: Merged mainland IP addresses, reducing rule count by nearly 1700.
- 2017-02-04: Merged ad-blocking rules for Sina, QQ, Baidu, NetEase, and Taobao to improve matching speed.
This history demonstrates a long-standing focus on optimizing performance and privacy for users interacting with the Chinese internet ecosystem.
Sources: Tool/New.md:6-12, Tool/New.md:21-23, Tool/New.md:46-51, Tool/New.md:60-64
Conclusion
The system for handling Chinese services and domestic traffic within the "Self-Rule" project is a two-pronged approach. It uses a comprehensive bypass list (cfw-bypass) to ensure that domestic traffic is routed directly for speed, while simultaneously employing targeted ad-blocking rule sets (BanAD.yaml, BanProgramAD.yaml) to filter out unwanted advertising and tracking content from these same services. This entire structure is efficiently maintained through automation scripts and has been refined over several years, as evidenced by the project's changelogs.