├── .clang-format ├── .clang-tidy ├── .github ├── ISSUE_TEMPLATE │ ├── feature.md │ └── issue.md └── workflows │ ├── c-cpp.yml │ ├── clean-cache.yml │ ├── deploy-docker-ui.yml │ ├── docker.yml │ ├── fetch upstream.yml │ ├── test-new.yml │ ├── test-openwrt-22.03.yml │ ├── test-openwrt.yml │ └── webui.yml ├── .gitignore ├── Dockerfile ├── Dockerfile.alpine ├── LICENSE ├── Makefile ├── ReadMe.md ├── ReadMe_en.md ├── doc ├── alipay_donate.jpg ├── architecture.png ├── architecture.vsdx ├── smartdns-banner.png ├── smartdns-banner.svg ├── smartdns-webui.png ├── smartdns.png ├── smartdns.svg └── wechat_donate.jpg ├── etc ├── default │ └── smartdns ├── init.d │ └── smartdns └── smartdns │ └── smartdns.conf ├── package ├── build-pkg.sh ├── debian │ ├── DEBIAN │ │ ├── changelog │ │ ├── compat │ │ ├── conffiles │ │ ├── control │ │ ├── copyright │ │ ├── prerm │ │ └── rules │ └── make.sh ├── linux │ ├── install │ └── make.sh ├── luci-compat │ ├── control │ │ ├── control │ │ ├── postinst │ │ └── prerm │ ├── debian-binary │ ├── files │ │ ├── etc │ │ │ └── uci-defaults │ │ │ │ └── 50_luci-smartdns │ │ ├── luci │ │ │ ├── controller │ │ │ │ └── smartdns.lua │ │ │ ├── i18n │ │ │ │ └── smartdns.zh-cn.po │ │ │ ├── model │ │ │ │ ├── cbi │ │ │ │ │ └── smartdns │ │ │ │ │ │ ├── smartdns.lua │ │ │ │ │ │ └── upstream.lua │ │ │ │ └── smartdns.lua │ │ │ └── view │ │ │ │ └── smartdns │ │ │ │ └── smartdns_status.htm │ │ └── usr │ │ │ └── share │ │ │ └── rpcd │ │ │ └── acl.d │ │ │ └── luci-app-smartdns.json │ └── make.sh ├── luci-lite │ ├── control │ │ ├── conffiles │ │ ├── control │ │ ├── postinst │ │ └── prerm │ ├── debian-binary │ ├── files │ │ ├── luci │ │ │ └── i18n │ │ │ │ └── smartdns-lite.zh-cn.po │ │ └── root │ │ │ ├── etc │ │ │ ├── config │ │ │ │ └── smartdns-lite │ │ │ └── init.d │ │ │ │ └── smartdns-lite │ │ │ ├── usr │ │ │ └── share │ │ │ │ ├── luci │ │ │ │ └── menu.d │ │ │ │ │ └── luci-app-smartdns-lite.json │ │ │ │ └── rpcd │ │ │ │ └── acl.d │ │ │ │ └── luci-app-smartdns-lite.json │ │ │ └── www │ │ │ └── luci-static │ │ │ └── resources │ │ │ └── view │ │ │ └── smartdns-lite │ │ │ └── smartdns-lite.js │ └── make.sh ├── luci │ ├── control │ │ ├── control │ │ ├── postinst │ │ └── prerm │ ├── debian-binary │ ├── files │ │ ├── luci │ │ │ └── i18n │ │ │ │ └── smartdns.zh-cn.po │ │ └── root │ │ │ ├── usr │ │ │ └── share │ │ │ │ ├── luci │ │ │ │ └── menu.d │ │ │ │ │ └── luci-app-smartdns.json │ │ │ │ └── rpcd │ │ │ │ └── acl.d │ │ │ │ └── luci-app-smartdns.json │ │ │ └── www │ │ │ └── luci-static │ │ │ └── resources │ │ │ └── view │ │ │ └── smartdns │ │ │ └── smartdns.js │ └── make.sh ├── openwrt │ ├── Makefile │ ├── address.conf │ ├── blacklist-ip.conf │ ├── control │ │ ├── conffiles │ │ ├── control │ │ ├── postinst │ │ └── prerm │ ├── custom.conf │ ├── debian-binary │ ├── domain-block.list │ ├── domain-forwarding.list │ ├── files │ │ └── etc │ │ │ ├── config │ │ │ └── smartdns │ │ │ └── init.d │ │ │ └── smartdns │ ├── make.sh │ ├── make_openwrt.sh │ └── make_openwrt_withui.sh ├── optware │ ├── S50smartdns │ ├── control │ │ ├── conffiles │ │ ├── control │ │ ├── postinst │ │ └── prerm │ ├── debian-binary │ ├── make.sh │ └── smartdns-opt.conf ├── redhat │ └── smartdns.spec ├── tool │ └── po2lmo │ │ ├── Makefile │ │ └── src │ │ ├── po2lmo.c │ │ ├── template_lmo.c │ │ └── template_lmo.h └── windows │ ├── install.bat │ ├── reload.bat │ ├── uninstall.bat │ └── wsl-run.vbs ├── plugin ├── demo │ ├── .gitignore │ ├── Makefile │ ├── demo.c │ └── demo.h └── smartdns-ui │ ├── .gitignore │ ├── Cargo.toml │ ├── Makefile │ ├── build.rs │ ├── src │ ├── data_server.rs │ ├── data_stats.rs │ ├── data_upstream_server.rs │ ├── db.rs │ ├── http_api_msg.rs │ ├── http_error.rs │ ├── http_jwt.rs │ ├── http_server.rs │ ├── http_server_api.rs │ ├── http_server_stream.rs │ ├── lib.rs │ ├── plugin.rs │ ├── server_log.rs │ ├── smartdns.rs │ ├── utils.rs │ └── whois.rs │ └── tests │ ├── common │ ├── client.rs │ ├── mod.rs │ └── server.rs │ ├── httpserver_test.rs │ └── restapi_test.rs ├── src ├── .gitignore ├── Makefile ├── dns.c ├── dns_cache.c ├── dns_client │ ├── client_http3.c │ ├── client_http3.h │ ├── client_https.c │ ├── client_https.h │ ├── client_mdns.c │ ├── client_mdns.h │ ├── client_quic.c │ ├── client_quic.h │ ├── client_socket.c │ ├── client_socket.h │ ├── client_tcp.c │ ├── client_tcp.h │ ├── client_tls.c │ ├── client_tls.h │ ├── client_udp.c │ ├── client_udp.h │ ├── conn_stream.c │ ├── conn_stream.h │ ├── dns_client.c │ ├── dns_client.h │ ├── ecs.c │ ├── ecs.h │ ├── group.c │ ├── group.h │ ├── packet.c │ ├── packet.h │ ├── pending_server.c │ ├── pending_server.h │ ├── proxy.c │ ├── proxy.h │ ├── query.c │ ├── query.h │ ├── server_info.c │ ├── server_info.h │ ├── wake_event.c │ └── wake_event.h ├── dns_conf │ ├── address.c │ ├── address.h │ ├── bind.c │ ├── bind.h │ ├── bootstrap_dns.c │ ├── bootstrap_dns.h │ ├── client_rule.c │ ├── client_rule.h │ ├── client_subnet.c │ ├── client_subnet.h │ ├── cname.c │ ├── cname.h │ ├── conf_file.c │ ├── conf_file.h │ ├── ddns_domain.c │ ├── ddns_domain.h │ ├── dhcp_lease_dnsmasq.c │ ├── dhcp_lease_dnsmasq.h │ ├── dns64.c │ ├── dns64.h │ ├── dns_conf.c │ ├── dns_conf.h │ ├── dns_conf_group.c │ ├── dns_conf_group.h │ ├── domain_rule.c │ ├── domain_rule.h │ ├── domain_set.c │ ├── domain_set.h │ ├── get_domain.c │ ├── get_domain.h │ ├── group.c │ ├── group.h │ ├── host_file.c │ ├── host_file.h │ ├── https_record.c │ ├── https_record.h │ ├── ip_alias.c │ ├── ip_alias.h │ ├── ip_rule.c │ ├── ip_rule.h │ ├── ip_set.c │ ├── ip_set.h │ ├── ipset.c │ ├── ipset.h │ ├── nameserver.c │ ├── nameserver.h │ ├── nftset.c │ ├── nftset.h │ ├── plugin.c │ ├── plugin.h │ ├── proxy_names.c │ ├── proxy_names.h │ ├── proxy_server.c │ ├── proxy_server.h │ ├── ptr.c │ ├── ptr.h │ ├── qtype_soa.c │ ├── qtype_soa.h │ ├── server.c │ ├── server.h │ ├── server_group.c │ ├── server_group.h │ ├── set_file.c │ ├── set_file.h │ ├── smartdns_domain.c │ ├── smartdns_domain.h │ ├── speed_check_mode.c │ ├── speed_check_mode.h │ ├── srv_record.c │ └── srv_record.h ├── dns_plugin.c ├── dns_server │ ├── address.c │ ├── address.h │ ├── answer.c │ ├── answer.h │ ├── audit.c │ ├── audit.h │ ├── cache.c │ ├── cache.h │ ├── client_rule.c │ ├── client_rule.h │ ├── cname.c │ ├── cname.h │ ├── connection.c │ ├── connection.h │ ├── context.c │ ├── context.h │ ├── dns_server.c │ ├── dns_server.h │ ├── dualstack.c │ ├── dualstack.h │ ├── ip_rule.c │ ├── ip_rule.h │ ├── ipset_nftset.c │ ├── ipset_nftset.h │ ├── local_addr.c │ ├── local_addr.h │ ├── mdns.c │ ├── mdns.h │ ├── neighbor.c │ ├── neighbor.h │ ├── prefetch.c │ ├── prefetch.h │ ├── ptr.c │ ├── ptr.h │ ├── request.c │ ├── request.h │ ├── request_pending.c │ ├── request_pending.h │ ├── rules.c │ ├── rules.h │ ├── server_https.c │ ├── server_https.h │ ├── server_socket.c │ ├── server_socket.h │ ├── server_tcp.c │ ├── server_tcp.h │ ├── server_tls.c │ ├── server_tls.h │ ├── server_udp.c │ ├── server_udp.h │ ├── soa.c │ ├── soa.h │ ├── speed_check.c │ └── speed_check.h ├── dns_stats.c ├── fast_ping │ ├── fast_ping.c │ ├── fast_ping.h │ ├── notify_event.c │ ├── notify_event.h │ ├── ping_fake.c │ ├── ping_fake.h │ ├── ping_host.c │ ├── ping_host.h │ ├── ping_icmp.c │ ├── ping_icmp.h │ ├── ping_icmp6.c │ ├── ping_icmp6.h │ ├── ping_tcp.c │ ├── ping_tcp.h │ ├── ping_udp.c │ ├── ping_udp.h │ ├── wakeup_event.c │ └── wakeup_event.h ├── http_parse │ ├── http1_parse.c │ ├── http1_parse.h │ ├── http2_parse.c │ ├── http2_parse.h │ ├── http3_parse.c │ ├── http3_parse.h │ ├── http_parse.c │ ├── http_parse.h │ ├── qpack.c │ └── qpack.h ├── include │ └── smartdns │ │ ├── dns.h │ │ ├── dns_cache.h │ │ ├── dns_client.h │ │ ├── dns_conf.h │ │ ├── dns_plugin.h │ │ ├── dns_server.h │ │ ├── dns_stats.h │ │ ├── fast_ping.h │ │ ├── http_parse.h │ │ ├── lib │ │ ├── art.h │ │ ├── atomic.h │ │ ├── bitmap.h │ │ ├── bitops.h │ │ ├── conf.h │ │ ├── findbit.h │ │ ├── gcc_builtin.h │ │ ├── hash.h │ │ ├── hashtable.h │ │ ├── idna.h │ │ ├── jhash.h │ │ ├── list.h │ │ ├── nftset.h │ │ ├── radix.h │ │ ├── rbtree.h │ │ ├── stringutil.h │ │ └── timer_wheel.h │ │ ├── proxy.h │ │ ├── smartdns.h │ │ ├── timer.h │ │ ├── tlog.h │ │ └── util.h ├── lib │ ├── art.c │ ├── bitops.c │ ├── conf.c │ ├── idna.c │ ├── nftset.c │ ├── radix.c │ ├── rbtree.c │ ├── stringutil.c │ └── timer_wheel.c ├── main.c ├── proxy.c ├── smartdns.c ├── timer.c ├── tlog.c └── utils │ ├── capbility.c │ ├── daemon.c │ ├── dns_debug.c │ ├── ipset.c │ ├── misc.c │ ├── neighbors.c │ ├── net.c │ ├── nftset.c │ ├── ssl.c │ ├── stack.c │ ├── tls_header_parse.c │ └── url.c ├── systemd └── smartdns.service.in └── test ├── Makefile ├── cases ├── test-address.cc ├── test-audit.cc ├── test-bind.cc ├── test-bootstrap.cc ├── test-cache.cc ├── test-client-rule.cc ├── test-cname.cc ├── test-ddns.cc ├── test-discard-block-ip.cc ├── test-dns64.cc ├── test-domain-rule.cc ├── test-domain-set.cc ├── test-dualstack.cc ├── test-edns.cc ├── test-group.cc ├── test-hosts.cc ├── test-http.cc ├── test-https.cc ├── test-idna.cc ├── test-ip-alias.cc ├── test-ip-rule.cc ├── test-mdns.cc ├── test-mock-server.cc ├── test-nameserver.cc ├── test-perf.cc ├── test-ping.cc ├── test-ptr.cc ├── test-qtype-soa.cc ├── test-rule.cc ├── test-same-pending-query.cc ├── test-server.cc ├── test-speed-check.cc ├── test-srv.cc └── test-subnet.cc ├── client.cc ├── client.h ├── include └── utils.h ├── server.cc ├── server.h ├── test.cc └── utils.cc /.clang-format: -------------------------------------------------------------------------------- 1 | #http://clang.llvm.org/docs/ClangFormatStyleOptions.html 2 | 3 | BasedOnStyle: LLVM 4 | IndentWidth: 4 5 | TabWidth: 4 6 | UseTab: ForContinuationAndIndentation 7 | MaxEmptyLinesToKeep: 1 8 | AllowShortFunctionsOnASingleLine: Empty 9 | BreakBeforeBraces: Linux 10 | ColumnLimit: 120 11 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | Checks: > 2 | -*, 3 | modernize-*, 4 | bugprone-*, 5 | concurrency-*, 6 | misc-*, 7 | readability-*, 8 | performance-*, 9 | portability-*, 10 | google-*, 11 | linuxkernel-*, 12 | -bugprone-narrowing-conversions, 13 | -bugprone-branch-clone, 14 | -bugprone-reserved-identifier, 15 | -bugprone-easily-swappable-parameters, 16 | -bugprone-sizeof-expression, 17 | -bugprone-implicit-widening-of-multiplication-result, 18 | -bugprone-suspicious-memory-comparison, 19 | -bugprone-not-null-terminated-result, 20 | -bugprone-signal-handler, 21 | -bugprone-assignment-in-if-condition, 22 | -concurrency-mt-unsafe, 23 | -modernize-macro-to-enum, 24 | -misc-unused-parameters, 25 | -misc-misplaced-widening-cast, 26 | -misc-no-recursion, 27 | -readability-magic-numbers, 28 | -readability-use-anyofallof, 29 | -readability-identifier-length, 30 | -readability-function-cognitive-complexity, 31 | -readability-named-parameter, 32 | -readability-isolate-declaration, 33 | -readability-else-after-return, 34 | -readability-redundant-control-flow, 35 | -readability-suspicious-call-argument, 36 | -google-readability-casting, 37 | -google-readability-todo, 38 | -performance-no-int-to-ptr, 39 | # clang-analyzer-*, 40 | # clang-analyzer-deadcode.DeadStores, 41 | # clang-analyzer-optin.performance.Padding, 42 | # -clang-analyzer-security.insecureAPI.* 43 | 44 | # Turn all the warnings from the checks above into errors. 45 | FormatStyle: file 46 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 需求建议 3 | about: 需求建议描述 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **需求应用场景** 11 | 请描述需求应用的场景和方式。 12 | 13 | **建议的方案** 14 | 实现上述场景建议的方案。 15 | 16 | **设备信息** 17 | 1. 设备信息(CPU,厂家) 18 | 19 | 2. 固件信息 20 | 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 问题报告 3 | about: 问题现象描述 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **问题现象** 11 | 简要描述问题出现的现象 12 | 13 | **运行环境** 14 | 1. 固件型号 15 | 16 | 2. 运营商 17 | 18 | 3. smartdns来源以及版本 19 | 20 | 4. 涉及的配置(注意去除个人相关信息) 21 | 22 | 23 | **重现步骤** 24 | 1. 上游DNS配置。 25 | 26 | 2. 访问的域名。 27 | 28 | 29 | **信息收集** 30 | 1. 将/var/log/smrtdns.log日志作为附件上传(注意去除个人相关信息)。 31 | 2. 如进程异常,请将coredump功能开启,上传coredump信息文件,同时上传配套的smartdns进程文件。 32 | 在自定义界面,开启设置->自定义设置->生成coredump配置,重现问题后提交coredump文件 33 | coredump文件在/tmp目录下 34 | 35 | -------------------------------------------------------------------------------- /.github/workflows/c-cpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: prepare 17 | run: | 18 | sudo apt update 19 | sudo apt install libgtest-dev dnsperf 20 | - name: make 21 | run: | 22 | make all -j4 23 | make clean 24 | - name: test 25 | run: | 26 | make -C test test -j8 27 | -------------------------------------------------------------------------------- /.github/workflows/clean-cache.yml: -------------------------------------------------------------------------------- 1 | name: Clear Cache 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' # Runs once a day (https://crontab.guru/once-a-day) 6 | workflow_dispatch: 7 | 8 | jobs: 9 | clear: 10 | name: Clear cache 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Clear cache 14 | uses: MyAlbum/purge-cache@v2 15 | with: 16 | max-age: 86400 17 | token: ${{ secrets.TOKEN }} 18 | 19 | - name: Delete workflow runs 20 | uses: Mattraks/delete-workflow-runs@v2 21 | with: 22 | token: ${{ secrets.TOKEN }} 23 | repository: ${{ github.repository }} 24 | retain_days: 7 25 | keep_minimum_runs: 7 -------------------------------------------------------------------------------- /.github/workflows/docker.yml: -------------------------------------------------------------------------------- 1 | name: Publish Docker Image 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | version: 7 | description: 'new image tag(e.g. v1.1.0)' 8 | required: true 9 | default: 'latest' 10 | 11 | concurrency: 12 | group: ${{ github.workflow }}-${{ github.ref }} 13 | cancel-in-progress: true 14 | 15 | jobs: 16 | docker: 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Checkout repository 20 | uses: actions/checkout@v3 21 | - name: Set up QEMU 22 | uses: docker/setup-qemu-action@v2 23 | - name: Set up Docker Buildx 24 | uses: docker/setup-buildx-action@v2 25 | - name: Login to DockerHub 26 | uses: docker/login-action@v2 27 | with: 28 | username: ${{ secrets.DOCKERHUB_USERNAME }} 29 | password: ${{ secrets.DOCKERHUB_TOKEN }} 30 | - name: Build and push 31 | uses: docker/build-push-action@v3 32 | with: 33 | platforms: linux/amd64,linux/arm64 34 | push: true 35 | tags: ${{vars.DOCKERHUB_REPO}}:${{ github.event.inputs.version }} 36 | -------------------------------------------------------------------------------- /.github/workflows/fetch upstream.yml: -------------------------------------------------------------------------------- 1 | name: fetch upstream 2 | on: 3 | schedule: 4 | - cron: '0 */4 * * *' 5 | workflow_dispatch: # on button click 6 | 7 | jobs: 8 | sync: 9 | 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: fetch upstream 14 | uses: tgymnich/fork-sync@v1.3 15 | with: 16 | owner: pymumu 17 | base: master 18 | head: master 19 | auto_approve: true 20 | github_token: ${{ secrets.TOKEN }} 21 | 22 | - name: Delete workflow runs 23 | uses: Mattraks/delete-workflow-runs@v2 24 | with: 25 | token: ${{ secrets.TOKEN }} 26 | repository: ${{ github.repository }} 27 | retain_days: 7 28 | keep_minimum_runs: 7 -------------------------------------------------------------------------------- /.github/workflows/webui.yml: -------------------------------------------------------------------------------- 1 | name: WebUI CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: actions-rust-lang/setup-rust-toolchain@v1 17 | with: 18 | profile: minimal 19 | toolchain: stable 20 | - name: test 21 | run: | 22 | EXTRA_CFLAGS=-fPIC make -C plugin/smartdns-ui test -j8 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | *.o 3 | *.a 4 | *.pem 5 | .DS_Store 6 | *.swp. 7 | *.a 8 | systemd/smartdns.service 9 | test.bin 10 | -------------------------------------------------------------------------------- /Dockerfile.alpine: -------------------------------------------------------------------------------- 1 | FROM --platform=$TARGETPLATFORM alpine:3.21 as smartdns-builder 2 | LABEL previous-stage=smartdns 3 | # 添加标签,镜像生成后可使用 docker rmi `docker images --filter label=previous-stage=smartdns -q` 删除中间层 4 | COPY . /smartdns/ 5 | RUN apk update && \ 6 | apk add make gcc build-base linux-headers openssl-dev openssl-libs-static && \ 7 | chmod -R 0755 /smartdns && \ 8 | cd /smartdns && \ 9 | sh ./package/build-pkg.sh --platform linux --arch `uname -m` --static && \ 10 | strip /smartdns/src/smartdns && \ 11 | mkdir -p /release/usr/sbin/ && \ 12 | mkdir -p /release/etc/smartdns/ && \ 13 | cp /smartdns/src/smartdns /release/usr/sbin/ 14 | 15 | FROM --platform=$TARGETPLATFORM alpine:3.21 16 | # FROM scratch 17 | # 如果有进入镜像操作的必要,可以使用 busybox:musl 或 alpine。建议根据主机其他容器情况共用基础镜像 18 | ENV TZ="Asia/Shanghai" 19 | COPY --from=smartdns-builder /release/ / 20 | EXPOSE 53/udp 53/tcp 21 | VOLUME "/etc/smartdns/" 22 | HEALTHCHECK --interval=5m CMD test `nslookup dns.pub 127.0.0.1 |grep answer |wc -l` -gt 0 23 | CMD ["/usr/sbin/smartdns", "-f", "-x", "-p -"] 24 | -------------------------------------------------------------------------------- /doc/alipay_donate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PikuZheng/smartdns/3eb817461447619a240fc16b059d60c43ccf2541/doc/alipay_donate.jpg -------------------------------------------------------------------------------- /doc/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PikuZheng/smartdns/3eb817461447619a240fc16b059d60c43ccf2541/doc/architecture.png -------------------------------------------------------------------------------- /doc/architecture.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PikuZheng/smartdns/3eb817461447619a240fc16b059d60c43ccf2541/doc/architecture.vsdx -------------------------------------------------------------------------------- /doc/smartdns-banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PikuZheng/smartdns/3eb817461447619a240fc16b059d60c43ccf2541/doc/smartdns-banner.png -------------------------------------------------------------------------------- /doc/smartdns-webui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PikuZheng/smartdns/3eb817461447619a240fc16b059d60c43ccf2541/doc/smartdns-webui.png -------------------------------------------------------------------------------- /doc/smartdns.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PikuZheng/smartdns/3eb817461447619a240fc16b059d60c43ccf2541/doc/smartdns.png -------------------------------------------------------------------------------- /doc/wechat_donate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PikuZheng/smartdns/3eb817461447619a240fc16b059d60c43ccf2541/doc/wechat_donate.jpg -------------------------------------------------------------------------------- /etc/default/smartdns: -------------------------------------------------------------------------------- 1 | # Default settings for smartdns server. This file is sourced by /bin/sh from 2 | # /etc/init.d/smartdns. 3 | 4 | # Options to pass to smartdns 5 | SMART_DNS_OPTS= 6 | -------------------------------------------------------------------------------- /package/debian/DEBIAN/changelog: -------------------------------------------------------------------------------- 1 | smartdns (1:1.2022.04.05) stable; urgency=low 2 | 3 | * Initial build 4 | 5 | -- initial release. Mon, 9 jul 2018 21:20:28 +0800 6 | -------------------------------------------------------------------------------- /package/debian/DEBIAN/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /package/debian/DEBIAN/conffiles: -------------------------------------------------------------------------------- 1 | /etc/smartdns/smartdns.conf 2 | -------------------------------------------------------------------------------- /package/debian/DEBIAN/control: -------------------------------------------------------------------------------- 1 | Source: smartdns 2 | Maintainer: Nick Peng 3 | Build-Depends: debhelper (>= 8.0.0) 4 | Version: 5 | Section: net 6 | Package: smartdns 7 | Priority: extra 8 | Architecture: armhf 9 | Description: a smartdns server 10 | -------------------------------------------------------------------------------- /package/debian/DEBIAN/copyright: -------------------------------------------------------------------------------- 1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: smartdns 3 | Source: http://github.com/pymumu/smartdns 4 | 5 | Files: * 6 | Copyright: 2018-2025 Nick peng 7 | License: proprietary 8 | -------------------------------------------------------------------------------- /package/debian/DEBIAN/prerm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | systemctl stop smartdns 4 | systemctl disable smartdns 5 | -------------------------------------------------------------------------------- /package/debian/DEBIAN/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | %: 3 | dh $@ --with systemd --builddirectory=./target/ 4 | 5 | clean: 6 | make -C ../src clean 7 | 8 | build: 9 | make -C ../src 10 | 11 | override_dh_systemd_enable: 12 | dh_systemd_enable --name=smartdns 13 | 14 | override_dh_installinit: 15 | dh_installinit --name=smartdns 16 | 17 | override_dh_installdeb: 18 | dh_installdeb 19 | cp ../systemd/smartdns.service ${CURDIR}/debian/ 20 | 21 | 22 | -------------------------------------------------------------------------------- /package/luci-compat/control/control: -------------------------------------------------------------------------------- 1 | Package: luci-app-smartdns 2 | Version: git-18.201.27126-7bf0367-1 3 | Depends: libc, smartdns 4 | Source: feeds/luci/applications/luci-app-smartdns 5 | Section: luci 6 | Architecture: all 7 | Description: A smartdns server 8 | -------------------------------------------------------------------------------- /package/luci-compat/control/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | # 5 | # smartdns is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # smartdns is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | [ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0 19 | [ -e ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0 20 | . ${IPKG_INSTROOT}/lib/functions.sh 21 | default_postinst $0 $@ 22 | -------------------------------------------------------------------------------- /package/luci-compat/control/prerm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | # 5 | # smartdns is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # smartdns is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | [ -e ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0 19 | . ${IPKG_INSTROOT}/lib/functions.sh 20 | default_prerm $0 $@ 21 | -------------------------------------------------------------------------------- /package/luci-compat/debian-binary: -------------------------------------------------------------------------------- 1 | 2.0 2 | -------------------------------------------------------------------------------- /package/luci-compat/files/etc/uci-defaults/50_luci-smartdns: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | # 5 | # smartdns is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # smartdns is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | uci -q batch <<-EOF >/dev/null 19 | delete ucitrack.@smartdns[-1] 20 | add ucitrack smartdns 21 | set ucitrack.@smartdns[-1].init=smartdns 22 | commit ucitrack 23 | EOF 24 | 25 | rm -f /tmp/luci-indexcache 26 | exit 0 27 | -------------------------------------------------------------------------------- /package/luci-compat/files/luci/controller/smartdns.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright (C) 2018-2025 Ruilin Peng (Nick) . 3 | -- 4 | -- smartdns is free software: you can redistribute it and/or modify 5 | -- it under the terms of the GNU General Public License as published by 6 | -- the Free Software Foundation, either version 3 of the License, or 7 | -- (at your option) any later version. 8 | -- 9 | -- smartdns is distributed in the hope that it will be useful, 10 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | -- GNU General Public License for more details. 13 | -- 14 | -- You should have received a copy of the GNU General Public License 15 | -- along with this program. If not, see . 16 | 17 | module("luci.controller.smartdns", package.seeall) 18 | local smartdns = require "luci.model.smartdns" 19 | 20 | function index() 21 | if not nixio.fs.access("/etc/config/smartdns") then 22 | return 23 | end 24 | 25 | local page 26 | page = entry({"admin", "services", "smartdns"}, cbi("smartdns/smartdns"), _("SmartDNS"), 60) 27 | page.dependent = true 28 | page = entry({"admin", "services", "smartdns", "status"}, call("act_status")) 29 | page.leaf = true 30 | page = entry({"admin", "services", "smartdns", "upstream"}, cbi("smartdns/upstream"), nil) 31 | page.leaf = true 32 | end 33 | 34 | local function is_running() 35 | return luci.sys.call("pidof smartdns >/dev/null") == 0 36 | end 37 | 38 | function act_status() 39 | local e={} 40 | local ipv6_server; 41 | local dnsmasq_server = smartdns.get_config_option("dhcp", "dnsmasq", "server", {nil})[1] 42 | local auto_set_dnsmasq = smartdns.get_config_option("smartdns", "smartdns", "auto_set_dnsmasq", nil); 43 | 44 | e.auto_set_dnsmasq = auto_set_dnsmasq 45 | e.dnsmasq_server = dnsmasq_server 46 | e.local_port = smartdns.get_config_option("smartdns", "smartdns", "port", nil); 47 | if e.local_port ~= nil and e.local_port ~= "53" and auto_set_dnsmasq ~= nil and auto_set_dnsmasq == "1" then 48 | local str; 49 | str = "127.0.0.1#" .. e.local_port 50 | if dnsmasq_server ~= str then 51 | e.dnsmasq_redirect_failure = 1 52 | end 53 | end 54 | e.running = is_running() 55 | luci.http.prepare_content("application/json") 56 | luci.http.write_json(e) 57 | end 58 | -------------------------------------------------------------------------------- /package/luci-compat/files/luci/model/smartdns.lua: -------------------------------------------------------------------------------- 1 | -- 2 | -- Copyright (C) 2018-2025 Ruilin Peng (Nick) . 3 | -- 4 | -- smartdns is free software: you can redistribute it and/or modify 5 | -- it under the terms of the GNU General Public License as published by 6 | -- the Free Software Foundation, either version 3 of the License, or 7 | -- (at your option) any later version. 8 | -- 9 | -- smartdns is distributed in the hope that it will be useful, 10 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | -- GNU General Public License for more details. 13 | -- 14 | -- You should have received a copy of the GNU General Public License 15 | -- along with this program. If not, see . 16 | 17 | require ("nixio.fs") 18 | require ("luci.http") 19 | require ("luci.dispatcher") 20 | require ("nixio.fs") 21 | 22 | local uci = require "luci.model.uci".cursor() 23 | 24 | module("luci.model.smartdns", package.seeall) 25 | 26 | function get_config_option(module, section, option, default) 27 | return uci:get_first(module, section, option) or default 28 | end 29 | 30 | return m 31 | 32 | -------------------------------------------------------------------------------- /package/luci-compat/files/luci/view/smartdns/smartdns_status.htm: -------------------------------------------------------------------------------- 1 | 22 | 23 |
24 |

25 | <%:Collecting data...%> 26 |

27 |
28 | -------------------------------------------------------------------------------- /package/luci-compat/files/usr/share/rpcd/acl.d/luci-app-smartdns.json: -------------------------------------------------------------------------------- 1 | { 2 | "luci-app-smartdns": { 3 | "description": "Grant access to LuCI app smartdns", 4 | "read": { 5 | "file": { 6 | "/etc/smartdns/*": [ "read" ] 7 | }, 8 | "ubus": { 9 | "service": [ "list" ] 10 | }, 11 | "uci": [ "smartdns" ] 12 | }, 13 | "write": { 14 | "file": { 15 | "/etc/smartdns/*": [ "write" ], 16 | "/etc/init.d/smartdns restart": [ "exec" ], 17 | "/etc/init.d/smartdns updatefiles": [ "exec" ] 18 | }, 19 | "uci": [ "smartdns" ] 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /package/luci-lite/control/conffiles: -------------------------------------------------------------------------------- 1 | /etc/config/smartdns-lite 2 | -------------------------------------------------------------------------------- /package/luci-lite/control/control: -------------------------------------------------------------------------------- 1 | Package: luci-app-smartdns-lite 2 | Version: git-18.201.27126-7bf0367-1 3 | Depends: libc, smartdns 4 | Source: feeds/luci/applications/luci-app-smartdns-lite 5 | Section: luci 6 | Architecture: all 7 | Description: A smartdns server for china 8 | -------------------------------------------------------------------------------- /package/luci-lite/control/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | # 5 | # smartdns is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # smartdns is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | [ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0 19 | [ -e ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0 20 | . ${IPKG_INSTROOT}/lib/functions.sh 21 | default_postinst $0 $@ 22 | ret=$? 23 | /etc/init.d/smartdns-lite clear_rules 24 | /etc/init.d/smartdns-lite enable 25 | exit 0 -------------------------------------------------------------------------------- /package/luci-lite/control/prerm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | # 5 | # smartdns is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # smartdns is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | [ -e ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0 19 | . ${IPKG_INSTROOT}/lib/functions.sh 20 | default_prerm $0 $@ 21 | /etc/init.d/smartdns-lite clear_rules 22 | /etc/init.d/smartdns-lite disable 23 | rm /var/etc/smartdns-lite.conf -f 24 | exit 0 -------------------------------------------------------------------------------- /package/luci-lite/debian-binary: -------------------------------------------------------------------------------- 1 | 2.0 2 | -------------------------------------------------------------------------------- /package/luci-lite/files/root/etc/config/smartdns-lite: -------------------------------------------------------------------------------- 1 | config 'smartdns-lite' 2 | option 'enabled' '0' 3 | -------------------------------------------------------------------------------- /package/luci-lite/files/root/usr/share/luci/menu.d/luci-app-smartdns-lite.json: -------------------------------------------------------------------------------- 1 | { 2 | "admin/services/smartdns-lite": { 3 | "title": "SmartDNS Lite", 4 | "action": { 5 | "type": "view", 6 | "path": "smartdns-lite/smartdns-lite" 7 | }, 8 | "depends": { 9 | "acl": [ "luci-app-smartdns-lite" ], 10 | "uci": { "smartdns-lite": true } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /package/luci-lite/files/root/usr/share/rpcd/acl.d/luci-app-smartdns-lite.json: -------------------------------------------------------------------------------- 1 | { 2 | "luci-app-smartdns-lite": { 3 | "description": "Grant access to LuCI app smartdns", 4 | "read": { 5 | "file": { 6 | "/etc/smartdns/*": [ "read" ] 7 | }, 8 | "ubus": { 9 | "service": [ "list" ] 10 | }, 11 | "uci": [ "smartdns-lite", "smartdns" ] 12 | }, 13 | "write": { 14 | "file": { 15 | "/etc/smartdns/*": [ "write" ], 16 | "/etc/init.d/smartdns-lite restart": [ "exec" ], 17 | "/etc/init.d/smartdns-lite updatefiles": [ "exec" ] 18 | }, 19 | "uci": [ "smartdns-lite", "smartdns" ] 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /package/luci/control/control: -------------------------------------------------------------------------------- 1 | Package: luci-app-smartdns 2 | Version: git-18.201.27126-7bf0367-1 3 | Depends: libc, smartdns 4 | Source: feeds/luci/applications/luci-app-smartdns 5 | Section: luci 6 | Architecture: all 7 | Description: A smartdns server 8 | -------------------------------------------------------------------------------- /package/luci/control/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | # 5 | # smartdns is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # smartdns is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | [ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0 19 | [ -e ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0 20 | . ${IPKG_INSTROOT}/lib/functions.sh 21 | default_postinst $0 $@ 22 | -------------------------------------------------------------------------------- /package/luci/control/prerm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | # 5 | # smartdns is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # smartdns is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | [ -e ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0 19 | . ${IPKG_INSTROOT}/lib/functions.sh 20 | default_prerm $0 $@ 21 | -------------------------------------------------------------------------------- /package/luci/debian-binary: -------------------------------------------------------------------------------- 1 | 2.0 2 | -------------------------------------------------------------------------------- /package/luci/files/root/usr/share/luci/menu.d/luci-app-smartdns.json: -------------------------------------------------------------------------------- 1 | { 2 | "admin/services/smartdns": { 3 | "title": "SmartDNS", 4 | "action": { 5 | "type": "view", 6 | "path": "smartdns/smartdns" 7 | }, 8 | "depends": { 9 | "acl": [ "luci-app-smartdns" ], 10 | "uci": { "smartdns": true } 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /package/luci/files/root/usr/share/rpcd/acl.d/luci-app-smartdns.json: -------------------------------------------------------------------------------- 1 | { 2 | "luci-app-smartdns": { 3 | "description": "Grant access to LuCI app smartdns", 4 | "read": { 5 | "file": { 6 | "/etc/smartdns/*": [ "read" ] 7 | }, 8 | "ubus": { 9 | "service": [ "list" ] 10 | }, 11 | "uci": [ "smartdns" ] 12 | }, 13 | "write": { 14 | "file": { 15 | "/etc/smartdns/*": [ "write" ], 16 | "/etc/init.d/smartdns restart": [ "exec" ], 17 | "/etc/init.d/smartdns updatefiles": [ "exec" ] 18 | }, 19 | "uci": [ "smartdns" ] 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /package/openwrt/address.conf: -------------------------------------------------------------------------------- 1 | # Add domains which you want to force to an IP address here. 2 | # The example below send any host in example.com to a local webserver. 3 | # address /domain/[ip|-|-4|-6|#|#4|#6] 4 | # address /www.example.com/1.2.3.4, return ip 1.2.3.4 to client 5 | # address /www.example.com/-, ignore address, query from upstream, suffix 4, for ipv4, 6 for ipv6, none for all 6 | # address /www.example.com/#, return SOA to client, suffix 4, for ipv4, 6 for ipv6, none for all 7 | 8 | # specific ipset to domain 9 | # ipset /domain/[ipset|-] 10 | # ipset /www.example.com/block, set ipset with ipset name of block 11 | # ipset /www.example.com/-, ignore this domain 12 | 13 | # specific nameserver to domain 14 | # nameserver /domain/[group|-] 15 | # nameserver /www.example.com/office, Set the domain name to use the appropriate server group. 16 | # nameserver /www.example.com/-, ignore this domain 17 | -------------------------------------------------------------------------------- /package/openwrt/blacklist-ip.conf: -------------------------------------------------------------------------------- 1 | # Add IP blacklist which you want to filtering from some DNS server here. 2 | # The example below filtering ip from the result of DNS server which is configured with -blacklist-ip. 3 | # blacklist-ip [ip/subnet] 4 | # blacklist-ip 254.0.0.1/16 -------------------------------------------------------------------------------- /package/openwrt/control/conffiles: -------------------------------------------------------------------------------- 1 | /etc/config/smartdns 2 | /etc/smartdns/address.conf 3 | /etc/smartdns/blacklist-ip.conf 4 | /etc/smartdns/custom.conf 5 | /etc/smartdns/domain-block.list 6 | /etc/smartdns/domain-forwarding.list 7 | -------------------------------------------------------------------------------- /package/openwrt/control/control: -------------------------------------------------------------------------------- 1 | Package: smartdns 2 | Architecture: 3 | Priority: optional 4 | Section: net 5 | Version: 6 | Depends: libc, libopenssl, libpthread 7 | Maintainer: pymumu 8 | Source: http://127.0.0.1/ 9 | Description: A smart dns server 10 | Enabled: yes 11 | -------------------------------------------------------------------------------- /package/openwrt/control/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | # 5 | # smartdns is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # smartdns is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | chmod +x /usr/sbin/smartdns 19 | chmod +x /etc/init.d/smartdns 20 | mkdir -p /var/etc/smartdns/ 21 | 22 | [ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0 23 | . ${IPKG_INSTROOT}/lib/functions.sh 24 | default_postinst $0 $@ 25 | ret=$? 26 | /etc/init.d/smartdns enable 27 | exit 0 28 | 29 | -------------------------------------------------------------------------------- /package/openwrt/control/prerm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | # 5 | # smartdns is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # smartdns is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | . ${IPKG_INSTROOT}/lib/functions.sh 19 | default_prerm $0 $@ 20 | /etc/init.d/smartdns disable 21 | rm /var/etc/smartdns.conf -f 22 | rm /var/etc/smartdns/smartdns.conf -f 23 | rm /var/log/smartdns/ -fr 24 | rm /etc/smartdns/smartdns.cache -f 25 | exit 0 26 | -------------------------------------------------------------------------------- /package/openwrt/custom.conf: -------------------------------------------------------------------------------- 1 | # Add custom settings here. 2 | # please read https://pymumu.github.io/smartdns/config/basic-config/ 3 | -------------------------------------------------------------------------------- /package/openwrt/debian-binary: -------------------------------------------------------------------------------- 1 | 2.0 2 | -------------------------------------------------------------------------------- /package/openwrt/domain-block.list: -------------------------------------------------------------------------------- 1 | # domain block list, one domain name per line. 2 | # example: block a.com, and b.com 3 | # a.com 4 | # b.com -------------------------------------------------------------------------------- /package/openwrt/domain-forwarding.list: -------------------------------------------------------------------------------- 1 | # domain forwarding list, one domain name per line. 2 | # example: forwarding a.com, and b.com 3 | # a.com 4 | # b.com -------------------------------------------------------------------------------- /package/openwrt/files/etc/config/smartdns: -------------------------------------------------------------------------------- 1 | config 'smartdns' 2 | option 'enabled' '0' 3 | 4 | config 'domain-rule' -------------------------------------------------------------------------------- /package/optware/control/conffiles: -------------------------------------------------------------------------------- 1 | /opt/etc/smartdns/smartdns.conf 2 | /opt/etc/smartdns/smartdns-opt.conf 3 | -------------------------------------------------------------------------------- /package/optware/control/control: -------------------------------------------------------------------------------- 1 | Package: smartdns 2 | Architecture: mipsbig 3 | Priority: optional 4 | Section: net 5 | Version: 2018.7.6-1921 6 | Maintainer: pymumu 7 | Source: http://127.0.0.1/ 8 | Description: A smart dns server 9 | Suggests: 10 | Conflicts: 11 | Enabled: yes 12 | -------------------------------------------------------------------------------- /package/optware/control/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | # 5 | # smartdns is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # smartdns is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | chmod +x /opt/usr/sbin/smartdns 19 | chmod +x /opt/etc/init.d/S50smartdns 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /package/optware/control/prerm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | # 5 | # smartdns is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # smartdns is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | /opt/etc/init.d/S50smartdns stop 19 | -------------------------------------------------------------------------------- /package/optware/debian-binary: -------------------------------------------------------------------------------- 1 | 2.0 2 | -------------------------------------------------------------------------------- /package/optware/smartdns-opt.conf: -------------------------------------------------------------------------------- 1 | # workmode 2 | # 0: run as port only 3 | # 1: redirect port 4 | # 2: replace 5 | SMARTDNS_WORKMODE="1" 6 | 7 | # smartdns port 8 | SMARTDNS_PORT="535" 9 | 10 | # restart when crash 11 | SMARTDNS_CRASH_RESTART="1" -------------------------------------------------------------------------------- /package/redhat/smartdns.spec: -------------------------------------------------------------------------------- 1 | Name: smartdns 2 | Version: 1.2020.09.08 3 | Release: 2235%{?dist} 4 | Summary: smartdns 5 | 6 | License: GPL 3.0 7 | URL: https://github.com/pymumu/smartdns 8 | Source0: %{name}-%{version}.tar.gz 9 | 10 | BuildRequires: glibc 11 | BuildRequires: centos-release >= 7 12 | BuildRequires: openssl-devel 13 | Requires: glibc 14 | Requires: openssl 15 | Requires: systemd 16 | 17 | %description 18 | A local DNS server to obtain the fastest website IP for the best Internet experience. 19 | 20 | %prep 21 | %setup -q 22 | 23 | %build 24 | cd src 25 | make %{?_smp_mflags} 26 | 27 | %install 28 | rm -rf $RPM_BUILD_ROOT 29 | 30 | %{__install} -D -m 755 src/smartdns $RPM_BUILD_ROOT%{_sbindir}/smartdns 31 | %{__install} -D -m 644 etc/smartdns/smartdns.conf $RPM_BUILD_ROOT%{_sysconfdir}/smartdns/smartdns.conf 32 | %{__install} -D -m 644 systemd/smartdns.service.in $RPM_BUILD_ROOT%{_unitdir}/smartdns.service 33 | 34 | 35 | cat > $RPM_BUILD_ROOT%{_unitdir}/smartdns.service <. 3 | # 4 | # smartdns is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # smartdns is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | BIN=smartdns-demo.so 18 | OBJS_MAIN=$(patsubst %.c,%.o,$(wildcard *.c)) 19 | OBJS=$(OBJS_MAIN) 20 | 21 | # cflags 22 | ifndef CFLAGS 23 | ifdef DEBUG 24 | CFLAGS = -g -DDEBUG 25 | else 26 | CFLAGS = -O2 27 | endif 28 | CFLAGS +=-fPIC -Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing -funwind-tables -Wmissing-prototypes -Wshadow -Wextra -Wno-unused-parameter -Wno-implicit-fallthrough 29 | endif 30 | 31 | override CFLAGS +=-Iinclude -I../../src/include -I../../src 32 | override CFLAGS += -DBASE_FILE_NAME='"$(notdir $<)"' 33 | override CFLAGS += $(EXTRA_CFLAGS) 34 | 35 | override LDFLAGS += -lpthread -shared 36 | 37 | .PHONY: all clean 38 | 39 | all: $(BIN) 40 | 41 | $(BIN) : $(OBJS) 42 | $(CC) $(OBJS) -o $@ $(LDFLAGS) 43 | 44 | clean: 45 | $(RM) $(OBJS) $(BIN) 46 | -------------------------------------------------------------------------------- /plugin/demo/demo.c: -------------------------------------------------------------------------------- 1 | #include "demo.h" 2 | #include "smartdns/dns_server.h" 3 | #include "smartdns/tlog.h" 4 | #include "smartdns/util.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static int demo_server_recv(struct dns_packet *packet, unsigned char *inpacket, int inpacket_len, 11 | struct sockaddr_storage *local, socklen_t local_len, struct sockaddr_storage *from, 12 | socklen_t from_len) 13 | { 14 | char hostname[256] = {0}; 15 | tlog(TLOG_INFO, "recv packet from %s", get_host_by_addr(hostname, sizeof(hostname), (struct sockaddr *)from)); 16 | return 0; 17 | } 18 | 19 | static void demo_server_request_complete(struct dns_request *request) 20 | { 21 | tlog(TLOG_INFO, "server complete request, request domain is %s", dns_server_request_get_domain(request)); 22 | } 23 | 24 | struct smartdns_operations demo_ops = { 25 | .server_recv = demo_server_recv, 26 | .server_query_complete = demo_server_request_complete, 27 | }; 28 | 29 | int dns_plugin_init(struct dns_plugin *plugin) 30 | { 31 | char options[4096] = {0}; 32 | int argc = dns_plugin_get_argc(plugin); 33 | const char **argv = dns_plugin_get_argv(plugin); 34 | 35 | for (int i = 0; i < argc; i++) { 36 | snprintf(options + strlen(options), sizeof(options) - strlen(options), "%s ", argv[i]); 37 | } 38 | 39 | tlog(TLOG_INFO, "demo plugin init, options: %s", options); 40 | smartdns_operations_register(&demo_ops); 41 | return 0; 42 | } 43 | 44 | int dns_plugin_exit(struct dns_plugin *plugin) 45 | { 46 | tlog(TLOG_INFO, "demo plugin exit."); 47 | smartdns_operations_unregister(&demo_ops); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /plugin/demo/demo.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SMART_DNS_PLUGIN_DEMO_H 3 | #define SMART_DNS_PLUGIN_DEMO_H 4 | 5 | #include "smartdns/dns_plugin.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif /*__cplusplus */ 10 | 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif /*__cplusplus */ 15 | #endif 16 | -------------------------------------------------------------------------------- /plugin/smartdns-ui/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | Cargo.lock -------------------------------------------------------------------------------- /plugin/smartdns-ui/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "smartdns-ui" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [lib] 7 | crate-type = ["cdylib", "lib"] 8 | 9 | [dependencies] 10 | ctor = "0.2.9" 11 | bytes = "1.10.0" 12 | rusqlite = { version = "0.32.1", features = ["bundled"] } 13 | hyper = { version = "1.6.0", features = ["full"] } 14 | hyper-util = { version = "0.1.10", features = ["full"] } 15 | hyper-tungstenite = "0.14.0" 16 | tokio = { version = "1.43.0", features = ["full"] } 17 | serde = { version = "1.0.217", features = ["derive"] } 18 | tokio-rustls = { version = "0.26.1", optional = true} 19 | rustls-pemfile = { version = "2.2.0", optional = true} 20 | serde_json = "1.0.138" 21 | http-body-util = "0.1.2" 22 | getopts = "0.2.21" 23 | url = "2.5.4" 24 | jsonwebtoken = "9" 25 | matchit = "0.8.6" 26 | futures = "0.3.31" 27 | socket2 = "0.5.8" 28 | cfg-if = "1.0.0" 29 | urlencoding = "2.1.3" 30 | chrono = "0.4.39" 31 | nix = "0.29.0" 32 | tokio-fd = "0.3.0" 33 | pbkdf2 = { version = "0.12", features = ["simple"] } 34 | 35 | [features] 36 | build-release = [] 37 | https = ["tokio-rustls", "rustls-pemfile"] 38 | default = ["https"] 39 | 40 | [dev-dependencies] 41 | reqwest = {version = "0.12.12", features = ["blocking"]} 42 | tungstenite = "0.23.0" 43 | tokio-tungstenite = "0.23.1" 44 | tempfile = "3.16.0" 45 | 46 | [build-dependencies] 47 | bindgen = "0.69.5" 48 | 49 | [profile.release-optmize-size] 50 | inherits = "release" 51 | lto = true 52 | opt-level = "s" 53 | strip = true 54 | codegen-units = 1 55 | panic = "abort" -------------------------------------------------------------------------------- /plugin/smartdns-ui/src/lib.rs: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | pub mod data_server; 20 | pub mod data_stats; 21 | pub mod data_upstream_server; 22 | pub mod db; 23 | pub mod http_api_msg; 24 | pub mod http_error; 25 | pub mod http_jwt; 26 | pub mod http_server; 27 | pub mod http_server_api; 28 | pub mod http_server_stream; 29 | pub mod plugin; 30 | pub mod server_log; 31 | pub mod smartdns; 32 | pub mod utils; 33 | pub mod whois; 34 | 35 | use ctor::ctor; 36 | use ctor::dtor; 37 | #[cfg(not(test))] 38 | use plugin::*; 39 | use smartdns::*; 40 | 41 | #[cfg(not(test))] 42 | fn lib_init_ops() { 43 | let ops: Box = Box::new(SmartdnsPluginImpl::new()); 44 | unsafe { 45 | let plugin_addr = std::ptr::addr_of_mut!(PLUGIN); 46 | (*plugin_addr).set_operation(ops); 47 | } 48 | } 49 | 50 | #[cfg(not(test))] 51 | fn lib_deinit_ops() { 52 | unsafe { 53 | let plugin_addr = std::ptr::addr_of_mut!(PLUGIN); 54 | (*plugin_addr).clear_operation(); 55 | } 56 | } 57 | 58 | #[cfg(test)] 59 | fn lib_init_smartdns_lib() { 60 | smartdns::dns_log_set_level(LogLevel::DEBUG); 61 | } 62 | 63 | #[ctor] 64 | fn lib_init() { 65 | #[cfg(not(test))] 66 | lib_init_ops(); 67 | 68 | #[cfg(test)] 69 | lib_init_smartdns_lib(); 70 | } 71 | 72 | #[dtor] 73 | fn lib_deinit() { 74 | #[cfg(not(test))] 75 | lib_deinit_ops(); 76 | } 77 | -------------------------------------------------------------------------------- /plugin/smartdns-ui/tests/common/mod.rs: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | 20 | mod server; 21 | mod client; 22 | 23 | pub use server::*; 24 | pub use client::*; -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .o 3 | .DS_Store 4 | .swp. 5 | smartdns 6 | !smartdns/ 7 | -------------------------------------------------------------------------------- /src/dns_client/client_http3.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_HTTP3_H_ 20 | #define _DNS_CLIENT_HTTP3_H_ 21 | 22 | #include "dns_client.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_client_send_http3(struct dns_query_struct *query, struct dns_server_info *server_info, void *packet, 29 | unsigned short len); 30 | 31 | int _dns_client_process_recv_http3(struct dns_server_info *server_info, struct dns_conn_stream *conn_stream); 32 | #ifdef __cplusplus 33 | } 34 | #endif /*__cplusplus */ 35 | #endif 36 | -------------------------------------------------------------------------------- /src/dns_client/client_https.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_HTTPS_H_ 20 | #define _DNS_CLIENT_HTTPS_H_ 21 | 22 | #include "dns_client.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_client_send_https(struct dns_server_info *server_info, void *packet, unsigned short len); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif /*__cplusplus */ 33 | #endif 34 | -------------------------------------------------------------------------------- /src/dns_client/client_mdns.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_MDNS_ 20 | #define _DNS_CLIENT_MDNS_ 21 | 22 | #include "dns_client.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_client_create_socket_udp_mdns(struct dns_server_info *server_info); 29 | 30 | int _dns_client_send_udp_mdns(struct dns_server_info *server_info, void *packet, int len); 31 | 32 | int _dns_client_add_mdns_server(void); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif /*__cplusplus */ 37 | #endif 38 | -------------------------------------------------------------------------------- /src/dns_client/client_quic.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_QUIC_H_ 20 | #define _DNS_CLIENT_QUIC_H_ 21 | 22 | #include "dns_client.h" 23 | 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /*__cplusplus */ 29 | 30 | int _dns_client_create_socket_quic(struct dns_server_info *server_info, const char *hostname, const char *alpn); 31 | 32 | int _dns_client_send_quic(struct dns_query_struct *query, struct dns_server_info *server_info, void *packet, 33 | unsigned short len); 34 | 35 | int _dns_client_send_quic_data(struct dns_query_struct *query, struct dns_server_info *server_info, void *packet, 36 | unsigned short len); 37 | 38 | int _dns_client_process_quic(struct dns_server_info *server_info, struct epoll_event *event, unsigned long now); 39 | #ifdef __cplusplus 40 | } 41 | #endif /*__cplusplus */ 42 | #endif 43 | -------------------------------------------------------------------------------- /src/dns_client/client_socket.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_CLIENT_SOCKET_ 20 | #define _DNS_CLIENT_CLIENT_SOCKET_ 21 | 22 | #include "dns_client.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_client_send_data_to_buffer(struct dns_server_info *server_info, void *packet, int len); 29 | 30 | int _dns_client_copy_data_to_buffer(struct dns_server_info *server_info, void *packet, int len); 31 | 32 | int _dns_client_socket_send(struct dns_server_info *server_info); 33 | 34 | int _dns_client_socket_recv(struct dns_server_info *server_info); 35 | 36 | int _dns_client_create_socket(struct dns_server_info *server_info); 37 | 38 | void _dns_client_close_socket(struct dns_server_info *server_info); 39 | 40 | void _dns_client_close_socket_ext(struct dns_server_info *server_info, int no_del_conn_list); 41 | 42 | void _dns_client_shutdown_socket(struct dns_server_info *server_info); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif /*__cplusplus */ 47 | #endif 48 | -------------------------------------------------------------------------------- /src/dns_client/client_tcp.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_TCP_H_ 20 | #define _DNS_CLIENT_TCP_H_ 21 | 22 | #include "dns_client.h" 23 | 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /*__cplusplus */ 29 | 30 | int _dns_client_create_socket_tcp(struct dns_server_info *server_info); 31 | 32 | int _dns_client_process_tcp(struct dns_server_info *server_info, struct epoll_event *event, unsigned long now); 33 | 34 | int _dns_client_send_tcp(struct dns_server_info *server_info, void *packet, unsigned short len); 35 | 36 | void _dns_client_check_tcp(void); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif /*__cplusplus */ 41 | #endif 42 | -------------------------------------------------------------------------------- /src/dns_client/client_tls.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_TLS_H_ 20 | #define _DNS_CLIENT_TLS_H_ 21 | 22 | #include "dns_client.h" 23 | 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /*__cplusplus */ 29 | 30 | int _dns_client_socket_ssl_send(struct dns_server_info *server, const void *buf, int num); 31 | 32 | int _dns_client_socket_ssl_recv(struct dns_server_info *server, void *buf, int num); 33 | 34 | int _dns_client_socket_ssl_send_ext(struct dns_server_info *server, SSL *ssl, const void *buf, int num, uint64_t flags); 35 | 36 | int _dns_client_socket_ssl_recv_ext(struct dns_server_info *server, SSL *ssl, void *buf, int num); 37 | 38 | int _dns_client_create_socket_tls(struct dns_server_info *server_info, const char *hostname, const char *alpn); 39 | 40 | int _dns_client_ssl_poll_event(struct dns_server_info *server_info, int ssl_ret); 41 | 42 | int _dns_client_send_tls(struct dns_server_info *server_info, void *packet, unsigned short len); 43 | 44 | int _dns_client_process_tls(struct dns_server_info *server_info, struct epoll_event *event, unsigned long now); 45 | 46 | SSL_CTX *_ssl_ctx_get(int is_quic); 47 | 48 | int _ssl_shutdown(struct dns_server_info *server); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif /*__cplusplus */ 53 | #endif 54 | -------------------------------------------------------------------------------- /src/dns_client/client_udp.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_UDP_H_ 20 | #define _DNS_CLIENT_UDP_H_ 21 | 22 | #include "dns_client.h" 23 | 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /*__cplusplus */ 29 | 30 | int _dns_client_send_udp(struct dns_server_info *server_info, void *packet, int len); 31 | 32 | int _dns_client_create_socket_udp(struct dns_server_info *server_info); 33 | 34 | void _dns_client_check_udp_nat(struct dns_query_struct *query); 35 | 36 | int _dns_client_process_udp(struct dns_server_info *server_info, struct epoll_event *event, unsigned long now); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif /*__cplusplus */ 41 | #endif 42 | -------------------------------------------------------------------------------- /src/dns_client/conn_stream.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_CONN_STREAM_ 20 | #define _DNS_CLIENT_CONN_STREAM_ 21 | 22 | #include "dns_client.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void _dns_client_conn_stream_put(struct dns_conn_stream *stream); 29 | 30 | void _dns_client_conn_stream_get(struct dns_conn_stream *stream); 31 | 32 | struct dns_conn_stream *_dns_client_conn_stream_new(void); 33 | 34 | void _dns_client_conn_server_streams_free(struct dns_server_info *server_info, struct dns_query_struct *query); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif /*__cplusplus */ 39 | #endif 40 | -------------------------------------------------------------------------------- /src/dns_client/ecs.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_ECS_ 20 | #define _DNS_CLIENT_ECS_ 21 | 22 | #include "dns_client.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_client_query_setup_default_ecs(struct dns_query_struct *query); 29 | 30 | int _dns_client_dns_add_ecs(struct dns_query_struct *query, struct dns_packet *packet); 31 | 32 | int _dns_client_server_add_ecs(struct dns_server_info *server_info, struct client_dns_server_flags *flags); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif /*__cplusplus */ 37 | #endif 38 | -------------------------------------------------------------------------------- /src/dns_client/group.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_GROUP_ 20 | #define _DNS_CLIENT_GROUP_ 21 | 22 | #include "dns_client.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_client_remove_server_from_groups(struct dns_server_info *server_info); 29 | 30 | void _dns_client_group_remove_all(void); 31 | 32 | struct dns_server_group *_dns_client_get_dnsserver_group(const char *group_name); 33 | 34 | int _dns_client_add_to_group(const char *group_name, struct dns_server_info *server_info); 35 | 36 | struct dns_server_group *_dns_client_get_group(const char *group_name); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif /*__cplusplus */ 41 | #endif 42 | -------------------------------------------------------------------------------- /src/dns_client/packet.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_PACKET_ 20 | #define _DNS_CLIENT_PACKET_ 21 | 22 | #include "dns_client.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_client_setup_server_packet(struct dns_server_info *server_info, struct dns_query_struct *query, 29 | void *default_packet, int default_packet_len, unsigned char *packet_data_buffer, 30 | void **packet_data, int *packet_data_len); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif /*__cplusplus */ 35 | #endif 36 | -------------------------------------------------------------------------------- /src/dns_client/pending_server.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_PENDING_SERVER_ 20 | #define _DNS_CLIENT_PENDING_SERVER_ 21 | 22 | #include "dns_client.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | struct addrinfo *_dns_client_getaddr(const char *host, char *port, int type, int protocol); 29 | 30 | int _dns_client_add_server_pending(const char *server_ip, const char *server_host, int port, 31 | dns_server_type_t server_type, struct client_dns_server_flags *flags, 32 | int is_pending); 33 | 34 | int _dns_client_add_to_pending_group(const char *group_name, const char *server_ip, int port, 35 | dns_server_type_t server_type, const struct client_dns_server_flags *flags); 36 | 37 | int _dns_client_add_to_group_pending(const char *group_name, const char *server_ip, int port, 38 | dns_server_type_t server_type, const struct client_dns_server_flags *flags, 39 | int is_pending); 40 | 41 | void _dns_client_remove_all_pending_servers(void); 42 | 43 | void _dns_client_add_pending_servers(void); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif /*__cplusplus */ 48 | #endif 49 | -------------------------------------------------------------------------------- /src/dns_client/proxy.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_PROXY_ 20 | #define _DNS_CLIENT_PROXY_ 21 | 22 | #include "dns_client.h" 23 | 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /*__cplusplus */ 29 | 30 | int _dns_proxy_handshake(struct dns_server_info *server_info, struct epoll_event *event, unsigned long now); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif /*__cplusplus */ 35 | #endif 36 | -------------------------------------------------------------------------------- /src/dns_client/query.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_QUERY_ 20 | #define _DNS_CLIENT_QUERY_ 21 | 22 | #include "dns_client.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void _dns_client_retry_dns_query(struct dns_query_struct *query); 29 | 30 | void _dns_client_query_remove(struct dns_query_struct *query); 31 | 32 | void _dns_client_query_release(struct dns_query_struct *query); 33 | 34 | void _dns_client_query_get(struct dns_query_struct *query); 35 | 36 | void _dns_client_query_remove_all(void); 37 | 38 | int _dns_client_send_query(struct dns_query_struct *query); 39 | 40 | struct dns_query_struct *_dns_client_get_request(char *domain, int qtype, unsigned short sid); 41 | 42 | int _dns_replied_check_add(struct dns_query_struct *dns_query, struct sockaddr *addr, socklen_t addr_len); 43 | 44 | void _dns_replied_check_remove(struct dns_query_struct *dns_query, struct sockaddr *addr, socklen_t addr_len); 45 | 46 | int _dns_client_query_parser_options(struct dns_query_struct *query, struct dns_query_options *options); 47 | 48 | void _dns_client_retry_dns_query(struct dns_query_struct *query); 49 | 50 | int _dns_client_add_hashmap(struct dns_query_struct *query); 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif /*__cplusplus */ 55 | #endif 56 | -------------------------------------------------------------------------------- /src/dns_client/server_info.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_SERVER_INFO_ 20 | #define _DNS_CLIENT_SERVER_INFO_ 21 | 22 | #include "dns_client.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void _dns_server_inc_prohibit_server_num(struct dns_server_info *server_info); 29 | 30 | void _dns_server_dec_prohibit_server_num(struct dns_server_info *server_info); 31 | 32 | void _dns_client_server_close(struct dns_server_info *server_info); 33 | 34 | const char *_dns_server_get_type_string(dns_server_type_t type); 35 | 36 | void _dns_client_server_remove_all(void); 37 | 38 | struct dns_server_info *_dns_client_get_server(const char *server_ip, int port, dns_server_type_t server_type, 39 | const struct client_dns_server_flags *flags); 40 | 41 | int _dns_client_server_add(const char *server_ip, const char *server_host, int port, dns_server_type_t server_type, 42 | struct client_dns_server_flags *flags); 43 | 44 | void _dns_client_check_servers(void); 45 | #ifdef __cplusplus 46 | } 47 | #endif /*__cplusplus */ 48 | #endif 49 | -------------------------------------------------------------------------------- /src/dns_client/wake_event.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "wake_event.h" 20 | 21 | #include 22 | #include 23 | 24 | void _dns_client_close_wakeup_event(void) 25 | { 26 | if (client.fd_wakeup > 0) { 27 | close(client.fd_wakeup); 28 | client.fd_wakeup = -1; 29 | } 30 | } 31 | 32 | void _dns_client_clear_wakeup_event(void) 33 | { 34 | uint64_t val = 0; 35 | int unused __attribute__((unused)); 36 | 37 | if (client.fd_wakeup <= 0) { 38 | return; 39 | } 40 | 41 | unused = read(client.fd_wakeup, &val, sizeof(val)); 42 | } 43 | 44 | void _dns_client_do_wakeup_event(void) 45 | { 46 | uint64_t val = 1; 47 | int unused __attribute__((unused)); 48 | if (client.fd_wakeup <= 0) { 49 | return; 50 | } 51 | 52 | unused = write(client.fd_wakeup, &val, sizeof(val)); 53 | } 54 | 55 | int _dns_client_create_wakeup_event(void) 56 | { 57 | int fd_wakeup = -1; 58 | 59 | fd_wakeup = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); 60 | if (fd_wakeup < 0) { 61 | tlog(TLOG_ERROR, "create eventfd failed, %s\n", strerror(errno)); 62 | goto errout; 63 | } 64 | 65 | struct epoll_event event; 66 | memset(&event, 0, sizeof(event)); 67 | event.events = EPOLLIN; 68 | event.data.fd = fd_wakeup; 69 | if (epoll_ctl(client.epoll_fd, EPOLL_CTL_ADD, fd_wakeup, &event) < 0) { 70 | tlog(TLOG_ERROR, "add eventfd to epoll failed, %s\n", strerror(errno)); 71 | goto errout; 72 | } 73 | 74 | return fd_wakeup; 75 | 76 | errout: 77 | if (fd_wakeup > 0) { 78 | close(fd_wakeup); 79 | } 80 | 81 | return -1; 82 | } 83 | -------------------------------------------------------------------------------- /src/dns_client/wake_event.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CLIENT_WAKE_EVENT_ 20 | #define _DNS_CLIENT_WAKE_EVENT_ 21 | 22 | #include "dns_client.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void _dns_client_do_wakeup_event(void); 29 | 30 | int _dns_client_create_wakeup_event(void); 31 | 32 | void _dns_client_close_wakeup_event(void); 33 | 34 | void _dns_client_clear_wakeup_event(void); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif /*__cplusplus */ 39 | #endif 40 | -------------------------------------------------------------------------------- /src/dns_conf/address.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_ADDRESS_H_ 20 | #define _DNS_CONF_ADDRESS_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_address(void *data, int argc, char *argv[]); 30 | 31 | int _conf_domain_rule_address(char *domain, const char *domain_address); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif /*__cplusplus */ 36 | #endif 37 | -------------------------------------------------------------------------------- /src/dns_conf/bind.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_BIND_H_ 20 | #define _DNS_CONF_BIND_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_add_default_server_if_needed(void); 30 | int _config_bind_ip_udp(void *data, int argc, char *argv[]); 31 | int _config_bind_ip_tcp(void *data, int argc, char *argv[]); 32 | int _config_bind_ip_tls(void *data, int argc, char *argv[]); 33 | int _config_bind_ip_https(void *data, int argc, char *argv[]); 34 | 35 | void dns_server_bind_destroy(void); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif /*__cplusplus */ 40 | #endif 41 | -------------------------------------------------------------------------------- /src/dns_conf/bootstrap_dns.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "bootstrap_dns.h" 20 | #include "domain_rule.h" 21 | #include "nameserver.h" 22 | #include "smartdns/util.h" 23 | 24 | char dns_conf_exist_bootstrap_dns; 25 | 26 | int _config_update_bootstrap_dns_rule(void) 27 | { 28 | struct dns_servers *server = NULL; 29 | 30 | if (dns_conf_exist_bootstrap_dns == 0) { 31 | return 0; 32 | } 33 | 34 | for (int i = 0; i < dns_conf.server_num; i++) { 35 | server = &dns_conf.servers[i]; 36 | if (check_is_ipaddr(server->server) == 0) { 37 | continue; 38 | } 39 | 40 | _conf_domain_rule_nameserver(server->server, "bootstrap-dns"); 41 | } 42 | 43 | return 0; 44 | } -------------------------------------------------------------------------------- /src/dns_conf/bootstrap_dns.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_BOOTSTRAP_H_ 20 | #define _DNS_CONF_BOOTSTRAP_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_update_bootstrap_dns_rule(void); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif /*__cplusplus */ 34 | #endif 35 | -------------------------------------------------------------------------------- /src/dns_conf/client_rule.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_CLIENT_RULE_H_ 20 | #define _DNS_CONF_CLIENT_RULE_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_client_rule_flag_set(const char *ip_cidr, unsigned int flag, unsigned int is_clear); 30 | 31 | int _config_client_rule_group_add(const char *client, const char *group_name); 32 | 33 | int _config_client_rules(void *data, int argc, char *argv[]); 34 | 35 | void _config_client_rule_destroy(void); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif /*__cplusplus */ 40 | #endif 41 | -------------------------------------------------------------------------------- /src/dns_conf/client_subnet.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_CLIENT_SUBNET_H_ 20 | #define _DNS_CONF_CLIENT_SUBNET_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _conf_edns_client_subnet(void *data, int argc, char *argv[]); 30 | 31 | int _conf_client_subnet(char *subnet, struct dns_edns_client_subnet *ipv4_ecs, struct dns_edns_client_subnet *ipv6_ecs); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif /*__cplusplus */ 36 | #endif 37 | -------------------------------------------------------------------------------- /src/dns_conf/cname.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_CNAME_H_ 20 | #define _DNS_CONF_CNAME_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_cname(void *data, int argc, char *argv[]); 30 | 31 | int _conf_domain_rule_cname(const char *domain, const char *cname); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif /*__cplusplus */ 36 | #endif 37 | -------------------------------------------------------------------------------- /src/dns_conf/conf_file.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_CONF_FILE_H_ 20 | #define _DNS_CONF_CONF_FILE_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int conf_file_table_init(void); 30 | 31 | int config_additional_file(void *data, int argc, char *argv[]); 32 | 33 | void _config_file_hash_table_destroy(void); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif /*__cplusplus */ 38 | #endif 39 | -------------------------------------------------------------------------------- /src/dns_conf/ddns_domain.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "ddns_domain.h" 20 | #include "domain_rule.h" 21 | #include "smartdns/lib/stringutil.h" 22 | 23 | static char ddns_domain[DNS_MAX_CNAME_LEN] = {0}; 24 | 25 | const char *dns_conf_get_ddns_domain(void) 26 | { 27 | return ddns_domain; 28 | } 29 | 30 | int _config_ddns_domain(void *data, int argc, char *argv[]) 31 | { 32 | if (argc <= 1) { 33 | tlog(TLOG_ERROR, "invalid parameter."); 34 | return -1; 35 | } 36 | 37 | const char *domain = argv[1]; 38 | safe_strncpy(ddns_domain, domain, sizeof(ddns_domain)); 39 | _config_domain_rule_flag_set(domain, DOMAIN_FLAG_SMARTDNS_DOMAIN, 0); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /src/dns_conf/ddns_domain.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_DDNS_DOMAIN_H_ 20 | #define _DNS_CONF_DDNS_DOMAIN_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_ddns_domain(void *data, int argc, char *argv[]); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif /*__cplusplus */ 34 | #endif 35 | -------------------------------------------------------------------------------- /src/dns_conf/dhcp_lease_dnsmasq.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_DHCP_LEASE_DNSMASQ_H_ 20 | #define _DNS_CONF_DHCP_LEASE_DNSMASQ_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _conf_dhcp_lease_dnsmasq_file(void *data, int argc, char *argv[]); 30 | 31 | int dns_server_check_update_hosts(void); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif /*__cplusplus */ 36 | #endif 37 | -------------------------------------------------------------------------------- /src/dns_conf/dns64.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "dns64.h" 20 | #include "dns_conf_group.h" 21 | 22 | int _config_dns64(void *data, int argc, char *argv[]) 23 | { 24 | prefix_t prefix; 25 | char *subnet = NULL; 26 | const char *errmsg = NULL; 27 | void *p = NULL; 28 | 29 | if (argc <= 1) { 30 | return -1; 31 | } 32 | 33 | subnet = argv[1]; 34 | 35 | if (strncmp(subnet, "-", 2U) == 0) { 36 | memset(&_config_current_rule_group()->dns_dns64, 0, sizeof(struct dns_dns64)); 37 | return 0; 38 | } 39 | 40 | p = prefix_pton(subnet, -1, &prefix, &errmsg); 41 | if (p == NULL) { 42 | goto errout; 43 | } 44 | 45 | if (prefix.family != AF_INET6) { 46 | tlog(TLOG_ERROR, "dns64 subnet %s is not ipv6", subnet); 47 | goto errout; 48 | } 49 | 50 | if (prefix.bitlen <= 0 || prefix.bitlen > 96) { 51 | tlog(TLOG_ERROR, "dns64 subnet %s is not valid", subnet); 52 | goto errout; 53 | } 54 | 55 | struct dns_dns64 *dns64 = &(_config_current_rule_group()->dns_dns64); 56 | memcpy(&dns64->prefix, &prefix.add.sin6.s6_addr, sizeof(dns64->prefix)); 57 | dns64->prefix_len = prefix.bitlen; 58 | 59 | return 0; 60 | 61 | errout: 62 | return -1; 63 | } -------------------------------------------------------------------------------- /src/dns_conf/dns64.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_DNS64_H_ 20 | #define _DNS_CONF_DNS64_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_dns64(void *data, int argc, char *argv[]); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif /*__cplusplus */ 34 | #endif 35 | -------------------------------------------------------------------------------- /src/dns_conf/dns_conf.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_H_ 20 | #define _DNS_CONF_H_ 21 | 22 | #include "smartdns/dns_conf.h" 23 | #include "smartdns/tlog.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | const struct config_item *smartdns_config_item(void); 30 | 31 | int _conf_printf(const char *key, const char *value, const char *file, int lineno, int ret); 32 | 33 | struct config_enum_list *response_mode_list(void); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif /*__cplusplus */ 38 | #endif 39 | -------------------------------------------------------------------------------- /src/dns_conf/domain_rule.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_DOMAIN_RULE_H_ 20 | #define _DNS_CONF_DOMAIN_RULE_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_domain_iter_free(void *data, const unsigned char *key, uint32_t key_len, void *value); 30 | 31 | void *_new_dns_rule_ext(enum domain_rule domain_rule, int ext_size); 32 | void *_new_dns_rule(enum domain_rule domain_rule); 33 | void _dns_rule_get(struct dns_rule *rule); 34 | void _dns_rule_put(struct dns_rule *rule); 35 | 36 | int _config_domain_rule_add(const char *domain, enum domain_rule type, void *rule); 37 | int _config_domain_rule_flag_set(const char *domain, unsigned int flag, unsigned int is_clear); 38 | int _config_domain_rules(void *data, int argc, char *argv[]); 39 | int _config_domain_rule_delete(const char *domain); 40 | int _conf_domain_rule_group(const char *domain, const char *group_name); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif /*__cplusplus */ 45 | #endif 46 | -------------------------------------------------------------------------------- /src/dns_conf/domain_set.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_DOMAIN_SET_H_ 20 | #define _DNS_CONF_DOMAIN_SET_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_domain_set(void *data, int argc, char *argv[]); 30 | 31 | void _config_domain_set_name_table_init(void); 32 | 33 | void _config_domain_set_name_table_destroy(void); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif /*__cplusplus */ 38 | #endif 39 | -------------------------------------------------------------------------------- /src/dns_conf/get_domain.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_GET_DOMAIN_H_ 20 | #define _DNS_CONF_GET_DOMAIN_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _get_domain(char *value, char *domain, int max_domain_size, char **ptr_after_domain); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif /*__cplusplus */ 34 | #endif 35 | -------------------------------------------------------------------------------- /src/dns_conf/group.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_GROUP_H_ 20 | #define _DNS_CONF_GROUP_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_group_begin(void *data, int argc, char *argv[]); 30 | 31 | int _config_group_match(void *data, int argc, char *argv[]); 32 | 33 | int _config_group_end(void *data, int argc, char *argv[]); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif /*__cplusplus */ 38 | #endif 39 | -------------------------------------------------------------------------------- /src/dns_conf/host_file.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_HOST_FILE_H_ 20 | #define _DNS_CONF_HOST_FILE_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_hosts_file(void *data, int argc, char *argv[]); 30 | 31 | int _conf_host_add(const char *hostname, const char *ip, dns_hosts_type host_type, int is_dynamic); 32 | 33 | void _config_host_table_init(void); 34 | 35 | void _config_host_table_destroy(int only_dynamic); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif /*__cplusplus */ 40 | #endif 41 | -------------------------------------------------------------------------------- /src/dns_conf/https_record.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_HTTPS_RECORD_H_ 20 | #define _DNS_CONF_HTTPS_RECORD_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_https_record(void *data, int argc, char *argv[]); 30 | int _conf_domain_rule_https_record(const char *domain, const char *host); 31 | #ifdef __cplusplus 32 | } 33 | #endif /*__cplusplus */ 34 | #endif 35 | -------------------------------------------------------------------------------- /src/dns_conf/ip_alias.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_IP_ALIAS_H_ 20 | #define _DNS_CONF_IP_ALIAS_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _conf_ip_alias(const char *ip_cidr, const char *ips); 30 | 31 | int _config_ip_alias(void *data, int argc, char *argv[]); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif /*__cplusplus */ 36 | #endif 37 | -------------------------------------------------------------------------------- /src/dns_conf/ip_rule.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_IP_RULE_H_ 20 | #define _DNS_CONF_IP_RULE_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "set_file.h" 24 | #include "smartdns/dns_conf.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /*__cplusplus */ 29 | 30 | void _config_ip_iter_free(radix_node_t *node, void *cbctx); 31 | 32 | int _config_ip_rule_flag_set(const char *ip_cidr, unsigned int flag, unsigned int is_clear); 33 | int _config_ip_rule_set_each(const char *ip_set, set_rule_add_func callback, void *priv); 34 | 35 | int _config_blacklist_ip(void *data, int argc, char *argv[]); 36 | int _config_bogus_nxdomain(void *data, int argc, char *argv[]); 37 | int _config_ip_ignore(void *data, int argc, char *argv[]); 38 | int _config_whitelist_ip(void *data, int argc, char *argv[]); 39 | int _config_ip_rules(void *data, int argc, char *argv[]); 40 | 41 | int _config_ip_rule_alias_add_ip(const char *ip, struct ip_rule_alias *ip_alias); 42 | int _config_ip_rule_add(const char *ip_cidr, enum ip_rule type, void *rule); 43 | 44 | void *_new_dns_ip_rule(enum ip_rule ip_rule); 45 | void _dns_ip_rule_get(struct dns_ip_rule *rule); 46 | void _dns_ip_rule_put(struct dns_ip_rule *rule); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif /*__cplusplus */ 51 | #endif 52 | -------------------------------------------------------------------------------- /src/dns_conf/ip_set.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_IP_SET_H_ 20 | #define _DNS_CONF_IP_SET_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_ip_set(void *data, int argc, char *argv[]); 30 | 31 | void _config_ip_set_name_table_init(void); 32 | 33 | void _config_ip_set_name_table_destroy(void); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif /*__cplusplus */ 38 | #endif 39 | -------------------------------------------------------------------------------- /src/dns_conf/ipset.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_IPSET_H_ 20 | #define _DNS_CONF_IPSET_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | const char *_dns_conf_get_ipset(const char *ipsetname); 30 | int _config_ipset_init(void); 31 | void _config_ipset_table_destroy(void); 32 | 33 | int _conf_domain_rule_ipset(char *domain, const char *ipsetname); 34 | 35 | int _config_ipset_no_speed(void *data, int argc, char *argv[]); 36 | 37 | int _config_ipset(void *data, int argc, char *argv[]); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif /*__cplusplus */ 42 | #endif 43 | -------------------------------------------------------------------------------- /src/dns_conf/nameserver.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_NAMESERVER_H_ 20 | #define _DNS_CONF_NAMESERVER_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_nameserver(void *data, int argc, char *argv[]); 30 | 31 | int _conf_domain_rule_nameserver(const char *domain, const char *group_name); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif /*__cplusplus */ 36 | #endif 37 | -------------------------------------------------------------------------------- /src/dns_conf/nftset.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_NFTSET_H_ 20 | #define _DNS_CONF_NFTSET_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | const struct dns_nftset_name *_dns_conf_get_nftable(const char *familyname, const char *tablename, const char *setname); 30 | 31 | void _config_nftset_table_destroy(void); 32 | 33 | int _config_nftset(void *data, int argc, char *argv[]); 34 | 35 | int _config_nftset_no_speed(void *data, int argc, char *argv[]); 36 | 37 | int _conf_domain_rule_nftset(char *domain, const char *nftsetname); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif /*__cplusplus */ 42 | #endif 43 | -------------------------------------------------------------------------------- /src/dns_conf/plugin.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_PLUGIN_H_ 20 | #define _DNS_CONF_PLUGIN_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_plugin(void *data, int argc, char *argv[]); 30 | 31 | int _config_plugin_conf_add(const char *key, const char *value); 32 | 33 | void _config_plugin_table_init(void); 34 | 35 | void _config_plugin_table_destroy(void); 36 | 37 | void dns_conf_clear_all_plugin_conf(void); 38 | 39 | void _config_plugin_table_conf_destroy(void); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif /*__cplusplus */ 44 | #endif 45 | -------------------------------------------------------------------------------- /src/dns_conf/proxy_names.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_PROXY_NAMES_H_ 20 | #define _DNS_CONF_PROXY_NAMES_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _dns_conf_proxy_servers_add(const char *proxy_name, struct dns_proxy_servers *server); 30 | const char *_dns_conf_get_proxy_name(const char *proxy_name); 31 | 32 | void _config_proxy_table_destroy(void); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif /*__cplusplus */ 37 | #endif 38 | -------------------------------------------------------------------------------- /src/dns_conf/proxy_server.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_PROXY_SERVER_H_ 20 | #define _DNS_CONF_PROXY_SERVER_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_proxy_server(void *data, int argc, char *argv[]); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif /*__cplusplus */ 34 | #endif 35 | -------------------------------------------------------------------------------- /src/dns_conf/ptr.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_PTR_H_ 20 | #define _DNS_CONF_PTR_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _conf_ptr_add(const char *hostname, const char *ip, int is_dynamic); 30 | 31 | void _config_ptr_table_init(void); 32 | 33 | void _config_ptr_table_destroy(int only_dynamic); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif /*__cplusplus */ 38 | #endif 39 | -------------------------------------------------------------------------------- /src/dns_conf/qtype_soa.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_QTYPE_SOA_H_ 20 | #define _DNS_CONF_QTYPE_SOA_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_qtype_soa(void *data, int argc, char *argv[]); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif /*__cplusplus */ 34 | #endif 35 | -------------------------------------------------------------------------------- /src/dns_conf/server.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_SERVER_H_ 20 | #define _DNS_CONF_SERVER_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_server_udp(void *data, int argc, char *argv[]); 30 | int _config_server_tcp(void *data, int argc, char *argv[]); 31 | int _config_server_tls(void *data, int argc, char *argv[]); 32 | int _config_server_https(void *data, int argc, char *argv[]); 33 | int _config_server_quic(void *data, int argc, char *argv[]); 34 | int _config_server_http3(void *data, int argc, char *argv[]); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif /*__cplusplus */ 39 | #endif 40 | -------------------------------------------------------------------------------- /src/dns_conf/server_group.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_SERVER_GROUP_H_ 20 | #define _DNS_CONF_SERVER_GROUP_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _dns_conf_get_group_set(const char *group_name, struct dns_servers *server); 30 | 31 | struct dns_server_groups *_dns_conf_get_group(const char *group_name); 32 | 33 | const char *_dns_conf_get_group_name(const char *group_name); 34 | 35 | struct dns_conf_group *_config_rule_group_get(const char *group_name); 36 | 37 | struct dns_conf_group *dns_server_get_rule_group(const char *group_name); 38 | 39 | struct dns_conf_group *dns_server_get_default_rule_group(void); 40 | 41 | struct dns_conf_group *_config_rule_group_new(const char *group_name); 42 | 43 | void _config_group_table_init(void); 44 | 45 | void _config_group_table_destroy(void); 46 | 47 | void _config_rule_group_destroy(void); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif /*__cplusplus */ 52 | #endif 53 | -------------------------------------------------------------------------------- /src/dns_conf/set_file.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_SET_FILE_H_ 20 | #define _DNS_CONF_SET_FILE_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _get_domain(char *value, char *domain, int max_domain_size, char **ptr_after_domain); 30 | 31 | int _config_foreach_file(const char *file_pattern, int (*callback)(const char *file, void *priv), void *priv); 32 | 33 | typedef int (*set_rule_add_func)(const char *value, void *priv); 34 | int _config_set_rule_each_from_list(const char *file, set_rule_add_func callback, void *priv); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif /*__cplusplus */ 39 | #endif 40 | -------------------------------------------------------------------------------- /src/dns_conf/smartdns_domain.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_SMARTDNS_DOMAIN_H_ 20 | #define _DNS_CONF_SMARTDNS_DOMAIN_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | void _config_setup_smartdns_domain(void); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif /*__cplusplus */ 34 | #endif 35 | -------------------------------------------------------------------------------- /src/dns_conf/speed_check_mode.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_SPEED_CHECK_MODE_H_ 20 | #define _DNS_CONF_SPEED_CHECK_MODE_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _dns_ping_cap_check(void); 30 | 31 | int _config_speed_check_mode(void *data, int argc, char *argv[]); 32 | 33 | int _dns_conf_speed_check_mode_verify(void); 34 | 35 | int _config_speed_check_mode_parser(struct dns_domain_check_orders *check_orders, const char *mode); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif /*__cplusplus */ 40 | #endif 41 | -------------------------------------------------------------------------------- /src/dns_conf/srv_record.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_CONF_SRV_RECORD_H_ 20 | #define _DNS_CONF_SRV_RECORD_H_ 21 | 22 | #include "dns_conf.h" 23 | #include "smartdns/dns_conf.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _config_srv_record(void *data, int argc, char *argv[]); 30 | 31 | void _config_srv_record_table_init(void); 32 | void _config_srv_record_table_destroy(void); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif /*__cplusplus */ 37 | #endif 38 | -------------------------------------------------------------------------------- /src/dns_server/address.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_ADDRESS_ 20 | #define _DNS_SERVER_ADDRESS_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void _dns_server_select_possible_ipaddress(struct dns_request *request); 29 | 30 | int _dns_ip_address_check_add(struct dns_request *request, char *cname, unsigned char *addr, dns_type_t addr_type, 31 | int ping_time, struct dns_ip_address **out_addr_map); 32 | 33 | struct dns_ip_address *_dns_ip_address_get(struct dns_request *request, unsigned char *addr, dns_type_t addr_type); 34 | 35 | int _dns_server_process_address(struct dns_request *request); 36 | 37 | int _dns_server_is_adblock_ipv6(const unsigned char addr[16]); 38 | 39 | int _dns_server_address_generate_order(int orders[], int order_num, int max_order_count); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif /*__cplusplus */ 44 | #endif 45 | -------------------------------------------------------------------------------- /src/dns_server/answer.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_ANSWER_ 20 | #define _DNS_SERVER_ANSWER_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_server_process_answer(struct dns_request *request, const char *domain, struct dns_packet *packet, 29 | unsigned int result_flag, int *need_passthrouh); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif /*__cplusplus */ 34 | #endif 35 | -------------------------------------------------------------------------------- /src/dns_server/audit.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_AUDIT_ 20 | #define _DNS_SERVER_AUDIT_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void _dns_server_audit_log(struct dns_server_post_context *context); 29 | 30 | int _dns_server_audit_init(void); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif /*__cplusplus */ 35 | #endif 36 | -------------------------------------------------------------------------------- /src/dns_server/cache.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_CACHE_ 20 | #define _DNS_SERVER_CACHE_ 21 | 22 | #include "dns_server.h" 23 | #include "smartdns/dns_cache.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _dns_server_cache_save(int check_lock); 30 | 31 | void _dns_server_save_cache_to_file(void); 32 | 33 | int _dns_server_cache_init(void); 34 | 35 | int _dns_server_process_cache(struct dns_request *request); 36 | 37 | int _dns_cache_cname_packet(struct dns_server_post_context *context); 38 | 39 | int _dns_server_request_update_cache(struct dns_request *request, int speed, dns_type_t qtype, 40 | struct dns_cache_data *cache_data, int cache_ttl); 41 | 42 | int _dns_cache_packet(struct dns_server_post_context *context); 43 | 44 | int _dns_cache_try_keep_old_cache(struct dns_request *request); 45 | 46 | int _dns_cache_specify_packet(struct dns_server_post_context *context); 47 | 48 | int _dns_server_expired_cache_ttl(struct dns_cache *cache, int serve_expired_ttl); 49 | #ifdef __cplusplus 50 | } 51 | #endif /*__cplusplus */ 52 | #endif 53 | -------------------------------------------------------------------------------- /src/dns_server/client_rule.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "client_rule.h" 20 | #include "request.h" 21 | 22 | int _dns_server_request_set_client_rules(struct dns_request *request, struct dns_client_rules *client_rule) 23 | { 24 | if (client_rule == NULL) { 25 | if (_dns_server_has_bind_flag(request, BIND_FLAG_ACL) == 0 || dns_conf.acl_enable) { 26 | request->send_tick = get_tick_count(); 27 | request->rcode = DNS_RC_REFUSED; 28 | request->no_cache = 1; 29 | return -1; 30 | } 31 | return 0; 32 | } 33 | 34 | tlog(TLOG_DEBUG, "match client rule."); 35 | 36 | if (client_rule->rules[CLIENT_RULE_GROUP]) { 37 | struct client_rule_group *group = (struct client_rule_group *)client_rule->rules[CLIENT_RULE_GROUP]; 38 | if (group && group->group_name[0] != '\0') { 39 | safe_strncpy(request->dns_group_name, group->group_name, sizeof(request->dns_group_name)); 40 | } 41 | } 42 | 43 | if (client_rule->rules[CLIENT_RULE_FLAGS]) { 44 | struct client_rule_flags *flags = (struct client_rule_flags *)client_rule->rules[CLIENT_RULE_FLAGS]; 45 | if (flags) { 46 | request->server_flags = flags->flags; 47 | } 48 | } 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /src/dns_server/client_rule.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_CLIENT_RULE_ 20 | #define _DNS_SERVER_CLIENT_RULE_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_server_request_set_client_rules(struct dns_request *request, struct dns_client_rules *client_rule); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif /*__cplusplus */ 33 | #endif 34 | -------------------------------------------------------------------------------- /src/dns_server/cname.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_CNAME_ 20 | #define _DNS_SERVER_CNAME_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_server_process_cname_pre(struct dns_request *request); 29 | 30 | int _dns_server_process_cname(struct dns_request *request); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif /*__cplusplus */ 35 | #endif 36 | -------------------------------------------------------------------------------- /src/dns_server/connection.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_CONNECTION_ 20 | #define _DNS_SERVER_CONNECTION_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void _dns_server_close_socket_server(void); 29 | 30 | int _dns_server_client_close(struct dns_server_conn_head *conn); 31 | 32 | void _dns_server_client_touch(struct dns_server_conn_head *conn); 33 | 34 | int _dns_server_set_flags(struct dns_server_conn_head *head, struct dns_bind_ip *bind_ip); 35 | 36 | void _dns_server_conn_head_init(struct dns_server_conn_head *conn, int fd, int type); 37 | 38 | void _dns_server_conn_get(struct dns_server_conn_head *conn); 39 | 40 | void _dns_server_conn_release(struct dns_server_conn_head *conn); 41 | 42 | int _dns_server_epoll_ctl(struct dns_server_conn_head *head, int op, uint32_t events); 43 | 44 | void _dns_server_close_socket(void); 45 | 46 | int _dns_server_update_request_connection_timeout(struct dns_server_conn_head *conn, int timeout); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif /*__cplusplus */ 51 | #endif 52 | -------------------------------------------------------------------------------- /src/dns_server/context.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_CONTEXT_ 20 | #define _DNS_SERVER_CONTEXT_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_request_post(struct dns_server_post_context *context); 29 | 30 | void _dns_server_post_context_init(struct dns_server_post_context *context, struct dns_request *request); 31 | 32 | int _dns_server_reply_passthrough(struct dns_server_post_context *context); 33 | 34 | int _dns_cache_reply_packet(struct dns_server_post_context *context); 35 | 36 | int _dns_server_get_answer(struct dns_server_post_context *context); 37 | 38 | void _dns_server_post_context_init_from(struct dns_server_post_context *context, struct dns_request *request, 39 | struct dns_packet *packet, unsigned char *inpacket, int inpacket_len); 40 | #ifdef __cplusplus 41 | } 42 | #endif /*__cplusplus */ 43 | #endif 44 | -------------------------------------------------------------------------------- /src/dns_server/dualstack.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_DUALSTACK_ 20 | #define _DNS_SERVER_DUALSTACK_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | extern int is_ipv6_ready; 29 | 30 | int _dns_server_force_dualstack(struct dns_request *request); 31 | 32 | void _dns_server_set_dualstack_selection(struct dns_request *request); 33 | 34 | int _dns_server_query_dualstack(struct dns_request *request); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif /*__cplusplus */ 39 | #endif 40 | -------------------------------------------------------------------------------- /src/dns_server/ip_rule.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_IP_RULE_ 20 | #define _DNS_SERVER_IP_RULE_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_server_process_ip_rule(struct dns_request *request, unsigned char *addr, int addr_len, dns_type_t addr_type, 29 | int result_flag, struct dns_iplist_ip_addresses **alias); 30 | 31 | int _dns_server_process_ip_alias(struct dns_request *request, struct dns_iplist_ip_addresses *alias, 32 | unsigned char **paddrs, int *paddr_num, int max_paddr_num, int addr_len); 33 | 34 | struct dns_client_rules *_dns_server_get_client_rules(struct sockaddr_storage *addr, socklen_t addr_len); 35 | #ifdef __cplusplus 36 | } 37 | #endif /*__cplusplus */ 38 | #endif 39 | -------------------------------------------------------------------------------- /src/dns_server/ipset_nftset.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_IPSET_NFTSET_ 20 | #define _DNS_SERVER_IPSET_NFTSET_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void _dns_server_add_ipset_nftset(struct dns_request *request, struct dns_ipset_rule *ipset_rule, 29 | struct dns_nftset_rule *nftset_rule, const unsigned char addr[], int addr_len, 30 | int ipset_timeout_value, int nftset_timeout_value); 31 | 32 | void *_dns_server_get_bind_ipset_nftset_rule(struct dns_request *request, enum domain_rule type); 33 | #ifdef __cplusplus 34 | } 35 | #endif /*__cplusplus */ 36 | #endif 37 | -------------------------------------------------------------------------------- /src/dns_server/local_addr.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_LOCAL_ADDR_ 20 | #define _DNS_SERVER_LOCAL_ADDR_ 21 | 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_server_local_addr_cache_destroy(void); 29 | 30 | int _dns_server_local_addr_cache_init(void); 31 | 32 | void _dns_server_process_local_addr_cache(int fd_netlink, struct epoll_event *event, unsigned long now); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif /*__cplusplus */ 37 | #endif 38 | -------------------------------------------------------------------------------- /src/dns_server/mdns.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_MDNS_ 20 | #define _DNS_SERVER_MDNS_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void _dns_server_need_append_mdns_local_cname(struct dns_request *request); 29 | 30 | void _dns_server_mdns_query_setup_server_group(struct dns_request *request, const char **group_name); 31 | 32 | int _dns_server_mdns_query_setup(struct dns_request *request, const char *server_group_name, char **request_domain, 33 | char *domain_buffer, int domain_buffer_len); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif /*__cplusplus */ 38 | #endif 39 | -------------------------------------------------------------------------------- /src/dns_server/neighbor.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_NEIGHBOR_ 20 | #define _DNS_SERVER_NEIGHBOR_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | struct neighbor_cache_item *_dns_server_neighbor_cache_get_item(const uint8_t *net_addr, int net_addr_len); 29 | 30 | struct dns_client_rules *_dns_server_get_client_rules_by_mac(uint8_t *netaddr, int netaddr_len); 31 | 32 | int _dns_server_neighbor_cache_init(void); 33 | 34 | void _dns_server_neighbor_cache_remove_all(void); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif /*__cplusplus */ 39 | #endif 40 | -------------------------------------------------------------------------------- /src/dns_server/prefetch.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_PREFETCH_ 20 | #define _DNS_SERVER_PREFETCH_ 21 | 22 | #include "dns_server.h" 23 | #include "smartdns/dns_cache.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif /*__cplusplus */ 28 | 29 | int _dns_server_prefetch_request(char *domain, dns_type_t qtype, struct dns_server_query_option *server_query_option, 30 | int prefetch_flag); 31 | 32 | dns_cache_tmout_action_t _dns_server_prefetch_domain(struct dns_conf_group *conf_group, struct dns_cache *dns_cache); 33 | 34 | dns_cache_tmout_action_t _dns_server_prefetch_expired_domain(struct dns_conf_group *conf_group, 35 | struct dns_cache *dns_cache); 36 | #ifdef __cplusplus 37 | } 38 | #endif /*__cplusplus */ 39 | #endif 40 | -------------------------------------------------------------------------------- /src/dns_server/ptr.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_PTR_ 20 | #define _DNS_SERVER_PTR_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_server_get_local_ttl(struct dns_request *request); 29 | 30 | int _dns_server_process_local_ptr(struct dns_request *request); 31 | 32 | int _dns_server_process_ptrs(struct dns_request *request); 33 | 34 | int _dns_server_process_ptr(struct dns_request *request); 35 | 36 | int _dns_server_get_inet_by_addr(struct sockaddr_storage *localaddr, struct sockaddr_storage *addr, int family); 37 | 38 | int _dns_server_process_ptr_query(struct dns_request *request); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif /*__cplusplus */ 43 | #endif 44 | -------------------------------------------------------------------------------- /src/dns_server/request_pending.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_REQUEST_PENDING_ 20 | #define _DNS_SERVER_REQUEST_PENDING_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_server_reply_all_pending_list(struct dns_request *request, struct dns_server_post_context *context); 29 | 30 | int _dns_server_set_to_pending_list(struct dns_request *request); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif /*__cplusplus */ 35 | #endif 36 | -------------------------------------------------------------------------------- /src/dns_server/rules.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_RULES_ 20 | #define _DNS_SERVER_RULES_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void *_dns_server_get_dns_rule(struct dns_request *request, enum domain_rule rule); 29 | 30 | int _dns_server_get_conf_ttl(struct dns_request *request, int ttl); 31 | 32 | void *_dns_server_get_dns_rule_ext(struct dns_request_domain_rule *domain_rule, enum domain_rule rule); 33 | 34 | void _dns_server_get_domain_rule(struct dns_request *request); 35 | 36 | int _dns_server_pre_process_rule_flags(struct dns_request *request); 37 | 38 | int _dns_server_get_reply_ttl(struct dns_request *request, int ttl); 39 | 40 | int _dns_server_is_dns_rule_extract_match(struct dns_request *request, enum domain_rule rule); 41 | 42 | void _dns_server_get_domain_rule_by_domain_ext(struct dns_conf_group *conf, 43 | struct dns_request_domain_rule *request_domain_rule, int rule_index, 44 | const char *domain, int out_log); 45 | 46 | int _dns_server_passthrough_rule_check(struct dns_request *request, const char *domain, struct dns_packet *packet, 47 | unsigned int result_flag, int *pttl); 48 | 49 | void _dns_server_process_speed_rule(struct dns_request *request); 50 | 51 | void _dns_server_get_domain_rule_by_domain(struct dns_request *request, const char *domain, int out_log); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif /*__cplusplus */ 56 | #endif 57 | -------------------------------------------------------------------------------- /src/dns_server/server_https.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_HTTPS_ 20 | #define _DNS_SERVER_HTTPS_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_server_reply_http_error(struct dns_server_conn_tcp_client *tcpclient, int code, const char *code_msg, 29 | const char *message); 30 | 31 | int _dns_server_reply_https(struct dns_request *request, struct dns_server_conn_tcp_client *tcpclient, void *packet, 32 | unsigned short len); 33 | #ifdef __cplusplus 34 | } 35 | #endif /*__cplusplus */ 36 | #endif 37 | -------------------------------------------------------------------------------- /src/dns_server/server_socket.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_SOCKET_ 20 | #define _DNS_SERVER_SOCKET_ 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif /*__cplusplus */ 25 | 26 | int _dns_create_socket(const char *host_ip, int type); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif /*__cplusplus */ 31 | #endif 32 | -------------------------------------------------------------------------------- /src/dns_server/server_tcp.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_TCP_ 20 | #define _DNS_SERVER_TCP_ 21 | 22 | #include "dns_server.h" 23 | 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /*__cplusplus */ 29 | 30 | int _dns_server_reply_tcp_to_buffer(struct dns_server_conn_tcp_client *tcpclient, void *packet, int len); 31 | 32 | int _dns_server_tcp_socket_send(struct dns_server_conn_tcp_client *tcp_client, void *data, int data_len); 33 | 34 | int _dns_server_tcp_accept(struct dns_server_conn_tcp_server *tcpserver, struct epoll_event *event, unsigned long now); 35 | 36 | int _dns_server_tcp_socket_recv(struct dns_server_conn_tcp_client *tcp_client, void *data, int data_len); 37 | 38 | int _dns_server_tcp_process_requests(struct dns_server_conn_tcp_client *tcpclient); 39 | 40 | int _dns_server_process_tcp(struct dns_server_conn_tcp_client *dnsserver, struct epoll_event *event, unsigned long now); 41 | 42 | int _dns_server_reply_tcp(struct dns_request *request, struct dns_server_conn_tcp_client *tcpclient, void *packet, 43 | unsigned short len); 44 | 45 | void _dns_server_tcp_idle_check(void); 46 | 47 | int _dns_server_socket_tcp(struct dns_bind_ip *bind_ip); 48 | #ifdef __cplusplus 49 | } 50 | #endif /*__cplusplus */ 51 | #endif 52 | -------------------------------------------------------------------------------- /src/dns_server/server_tls.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_TLS_ 20 | #define _DNS_SERVER_TLS_ 21 | 22 | #include "dns_server.h" 23 | 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /*__cplusplus */ 29 | 30 | int _dns_server_ssl_poll_event(struct dns_server_conn_tls_client *tls_client, int ssl_ret); 31 | 32 | int _dns_server_tls_accept(struct dns_server_conn_tls_server *tls_server, struct epoll_event *event, unsigned long now); 33 | 34 | int _dns_server_socket_ssl_recv(struct dns_server_conn_tls_client *tls_client, void *buf, int num); 35 | 36 | int _dns_server_socket_ssl_send(struct dns_server_conn_tls_client *tls_client, const void *buf, int num); 37 | 38 | int _dns_server_process_tls(struct dns_server_conn_tls_client *tls_client, struct epoll_event *event, 39 | unsigned long now); 40 | 41 | int _dns_server_socket_tls(struct dns_bind_ip *bind_ip, DNS_CONN_TYPE conn_type); 42 | #ifdef __cplusplus 43 | } 44 | #endif /*__cplusplus */ 45 | #endif 46 | -------------------------------------------------------------------------------- /src/dns_server/server_udp.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_UDP_ 20 | #define _DNS_SERVER_UDP_ 21 | 22 | #include "dns_server.h" 23 | 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /*__cplusplus */ 29 | 30 | int _dns_server_process_udp(struct dns_server_conn_udp *udpconn, struct epoll_event *event, unsigned long now); 31 | 32 | int _dns_server_socket_udp(struct dns_bind_ip *bind_ip); 33 | 34 | int _dns_server_reply_udp(struct dns_request *request, struct dns_server_conn_udp *udpserver, unsigned char *inpacket, 35 | int inpacket_len); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif /*__cplusplus */ 40 | #endif 41 | -------------------------------------------------------------------------------- /src/dns_server/soa.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_SOA_ 20 | #define _DNS_SERVER_SOA_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_server_is_return_soa(struct dns_request *request); 29 | 30 | void _dns_server_setup_soa(struct dns_request *request); 31 | 32 | int _dns_server_is_return_soa_qtype(struct dns_request *request, dns_type_t qtype); 33 | 34 | int _dns_server_reply_SOA(int rcode, struct dns_request *request); 35 | 36 | int _dns_server_qtype_soa(struct dns_request *request); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif /*__cplusplus */ 41 | #endif 42 | -------------------------------------------------------------------------------- /src/dns_server/speed_check.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _DNS_SERVER_SPEED_CHECK_ 20 | #define _DNS_SERVER_SPEED_CHECK_ 21 | 22 | #include "dns_server.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _dns_server_second_ping_check(struct dns_request *request); 29 | 30 | int _dns_server_check_speed(struct dns_request *request, char *ip); 31 | #ifdef __cplusplus 32 | } 33 | #endif /*__cplusplus */ 34 | #endif 35 | -------------------------------------------------------------------------------- /src/fast_ping/notify_event.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _FAST_PING_NOTIFY_EVENT_H_ 20 | #define _FAST_PING_NOTIFY_EVENT_H_ 21 | 22 | #include "fast_ping.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void _fast_ping_remove_all_notify_event(void); 29 | 30 | void *_fast_ping_notify_worker(void *arg); 31 | 32 | int _fast_ping_send_notify_event(struct ping_host_struct *ping_host, FAST_PING_RESULT ping_result, unsigned int seq, 33 | int ttl, struct timeval *tvresult); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif /*__cplusplus */ 38 | #endif // !_FAST_PING_NOTIFY_EVENT_H_ 39 | -------------------------------------------------------------------------------- /src/fast_ping/ping_fake.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _FAST_PING_FAKE_H_ 20 | #define _FAST_PING_FAKE_H_ 21 | 22 | #include "fast_ping.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void _fast_ping_fake_put(struct fast_ping_fake_ip *fake); 29 | 30 | void _fast_ping_fake_remove(struct fast_ping_fake_ip *fake); 31 | 32 | void _fast_ping_fake_get(struct fast_ping_fake_ip *fake); 33 | 34 | struct fast_ping_fake_ip *_fast_ping_fake_find(FAST_PING_TYPE ping_type, struct sockaddr *addr, int addr_len); 35 | 36 | void _fast_ping_remove_all_fake_ip(void); 37 | 38 | int _fast_ping_process_fake(struct ping_host_struct *ping_host, struct timeval *now); 39 | 40 | int _fast_ping_send_fake(struct ping_host_struct *ping_host, struct fast_ping_fake_ip *fake); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif /*__cplusplus */ 45 | #endif // !_FAST_PING_H_ 46 | -------------------------------------------------------------------------------- /src/fast_ping/ping_host.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _FAST_PING_HOST_H_ 20 | #define _FAST_PING_HOST_H_ 21 | 22 | #include "fast_ping.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void _fast_ping_host_remove(struct ping_host_struct *ping_host); 29 | 30 | void _fast_ping_host_put(struct ping_host_struct *ping_host); 31 | 32 | void _fast_ping_host_get(struct ping_host_struct *ping_host); 33 | 34 | void _fast_ping_close_host_sock(struct ping_host_struct *ping_host); 35 | 36 | void _fast_ping_remove_all(void); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif /*__cplusplus */ 41 | #endif // !_FAST_PING_HOST_H_ 42 | -------------------------------------------------------------------------------- /src/fast_ping/ping_icmp.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _FAST_PING_ICMP_H_ 20 | #define _FAST_PING_ICMP_H_ 21 | 22 | #include "fast_ping.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _fast_ping_sendping_v4(struct ping_host_struct *ping_host); 29 | 30 | struct fast_ping_packet *_fast_ping_icmp_packet(struct ping_host_struct *ping_host, struct msghdr *msg, 31 | u_char *packet_data, int data_len); 32 | 33 | int _fast_ping_sockaddr_ip_cmp(struct sockaddr *first_addr, socklen_t first_addr_len, struct sockaddr *second_addr, 34 | socklen_t second_addr_len); 35 | 36 | uint16_t _fast_ping_checksum(uint16_t *header, size_t len); 37 | 38 | int _fast_ping_icmp_create_socket(struct ping_host_struct *ping_host); 39 | 40 | int _fast_ping_process_icmp(struct ping_host_struct *ping_host, struct timeval *now); 41 | 42 | int _fast_ping_get_addr_by_icmp(const char *ip_str, int port, struct addrinfo **out_gai, FAST_PING_TYPE *out_ping_type); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif /*__cplusplus */ 47 | #endif // !_FAST_PING_ICMP_H_ 48 | -------------------------------------------------------------------------------- /src/fast_ping/ping_icmp6.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _FAST_PING_ICMP6_H_ 20 | #define _FAST_PING_ICMP6_H_ 21 | 22 | #include "fast_ping.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | struct fast_ping_packet *_fast_ping_icmp6_packet(struct ping_host_struct *ping_host, struct msghdr *msg, 29 | u_char *packet_data, int data_len); 30 | 31 | void _fast_ping_install_filter_v6(int sock); 32 | 33 | int _fast_ping_sendping_v6(struct ping_host_struct *ping_host); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif /*__cplusplus */ 38 | #endif // !_FAST_PING_ICMP6_H_ 39 | -------------------------------------------------------------------------------- /src/fast_ping/ping_tcp.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _FAST_PING_TCP_H_ 20 | #define _FAST_PING_TCP_H_ 21 | 22 | #include "fast_ping.h" 23 | 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif /*__cplusplus */ 29 | 30 | int _fast_ping_process_tcp(struct ping_host_struct *ping_host, struct epoll_event *event, struct timeval *now); 31 | 32 | int _fast_ping_get_addr_by_tcp(const char *ip_str, int port, struct addrinfo **out_gai, FAST_PING_TYPE *out_ping_type); 33 | 34 | int _fast_ping_sendping_tcp(struct ping_host_struct *ping_host); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif /*__cplusplus */ 39 | #endif // !_FAST_PING_TCP_H_ 40 | -------------------------------------------------------------------------------- /src/fast_ping/ping_udp.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _FAST_PING_UDP_H_ 20 | #define _FAST_PING_UDP_H_ 21 | 22 | #include "fast_ping.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int _fast_ping_get_addr_by_dns(const char *ip_str, int port, struct addrinfo **out_gai, FAST_PING_TYPE *out_ping_type); 29 | 30 | int _fast_ping_sendping_udp(struct ping_host_struct *ping_host); 31 | 32 | int _fast_ping_process_udp(struct ping_host_struct *ping_host, struct timeval *now); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif /*__cplusplus */ 37 | #endif // !_FAST_PING_UDP_H_ 38 | -------------------------------------------------------------------------------- /src/fast_ping/wakeup_event.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | #define _GNU_SOURCE 19 | 20 | #include "wakeup_event.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | void _fast_ping_wakeup_thread(void) 28 | { 29 | uint64_t u = 1; 30 | int unused __attribute__((unused)); 31 | unused = write(ping.event_fd, &u, sizeof(u)); 32 | } 33 | 34 | int _fast_ping_init_wakeup_event(void) 35 | { 36 | int fdevent = -1; 37 | fdevent = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK); 38 | if (fdevent < 0) { 39 | tlog(TLOG_ERROR, "create eventfd failed, %s\n", strerror(errno)); 40 | goto errout; 41 | } 42 | 43 | struct epoll_event event; 44 | memset(&event, 0, sizeof(event)); 45 | event.events = EPOLLIN | EPOLLERR; 46 | event.data.fd = fdevent; 47 | if (epoll_ctl(ping.epoll_fd, EPOLL_CTL_ADD, fdevent, &event) != 0) { 48 | tlog(TLOG_ERROR, "set eventfd failed, %s\n", strerror(errno)); 49 | goto errout; 50 | } 51 | 52 | ping.event_fd = fdevent; 53 | 54 | return 0; 55 | errout: 56 | return -1; 57 | } 58 | -------------------------------------------------------------------------------- /src/fast_ping/wakeup_event.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _FAST_PING_WAKEUP_EVENT_H_ 20 | #define _FAST_PING_WAKEUP_EVENT_H_ 21 | 22 | #include "fast_ping.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | void _fast_ping_wakeup_thread(void); 29 | 30 | int _fast_ping_init_wakeup_event(void); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif /*__cplusplus */ 35 | #endif // !_FAST_PING_WAKEUP_EVENT_H_ 36 | -------------------------------------------------------------------------------- /src/http_parse/http1_parse.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _HTTP_PARSE_HTTP1_H_ 20 | #define _HTTP_PARSE_HTTP1_H_ 21 | 22 | #include "http_parse.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int http_head_serialize_http1_1(struct http_head *http_head, char *buffer, int buffer_len); 29 | 30 | int http_head_parse_http1_1(struct http_head *http_head, const uint8_t *data, int data_len); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif /*__cplusplus */ 35 | #endif 36 | -------------------------------------------------------------------------------- /src/http_parse/http2_parse.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "http2_parse.h" 20 | #include "http_parse.h" 21 | 22 | int http_head_parse_http2_0(struct http_head *http_head, const uint8_t *data, int data_len) 23 | { 24 | return -2; 25 | } 26 | 27 | int http_head_serialize_http2_0(struct http_head *http_head, uint8_t *buffer, int buffer_len) 28 | { 29 | return -2; 30 | } -------------------------------------------------------------------------------- /src/http_parse/http2_parse.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _HTTP_PARSE_HTTP2_H_ 20 | #define _HTTP_PARSE_HTTP2_H_ 21 | 22 | #include "http_parse.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int http_head_parse_http2_0(struct http_head *http_head, const uint8_t *data, int data_len); 29 | 30 | int http_head_serialize_http2_0(struct http_head *http_head, uint8_t *buffer, int buffer_len); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif /*__cplusplus */ 35 | #endif 36 | -------------------------------------------------------------------------------- /src/http_parse/http3_parse.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _HTTP_PARSE_HTTP3_H_ 20 | #define _HTTP_PARSE_HTTP3_H_ 21 | 22 | #include "http_parse.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int http_head_parse_http3_0(struct http_head *http_head, const uint8_t *data, int data_len); 29 | 30 | int http_head_serialize_http3_0(struct http_head *http_head, uint8_t *buffer, int buffer_len); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif /*__cplusplus */ 35 | #endif 36 | -------------------------------------------------------------------------------- /src/http_parse/qpack.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _QPACK_H 20 | #define _QPACK_H 21 | 22 | #include 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | struct qpack_header_field { 30 | const char *name; 31 | const char *value; 32 | }; 33 | 34 | struct qpack_header_field *qpack_get_static_header_field(int index); 35 | 36 | int qpack_huffman_decode(const uint8_t *bytes, const uint8_t *bytes_max, uint8_t *decoded, size_t max_decoded, 37 | size_t *nb_decoded); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif // !_QPACK_H 44 | -------------------------------------------------------------------------------- /src/include/smartdns/fast_ping.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef FAST_PING_H 20 | #define FAST_PING_H 21 | 22 | #include 23 | #include 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | typedef enum { 29 | PING_TYPE_ICMP = 1, 30 | PING_TYPE_TCP = 2, 31 | PING_TYPE_DNS = 3, 32 | } PING_TYPE; 33 | 34 | typedef enum { 35 | PING_RESULT_RESPONSE = 1, 36 | PING_RESULT_TIMEOUT = 2, 37 | PING_RESULT_ERROR = 3, 38 | PING_RESULT_END = 4, 39 | } FAST_PING_RESULT; 40 | 41 | struct ping_host_struct; 42 | typedef void (*fast_ping_result)(struct ping_host_struct *ping_host, const char *host, FAST_PING_RESULT result, 43 | struct sockaddr *addr, socklen_t addr_len, int seqno, int ttl, struct timeval *tv, 44 | int error, void *userptr); 45 | 46 | /* start ping */ 47 | struct ping_host_struct *fast_ping_start(PING_TYPE type, const char *host, int count, int interval, int timeout, 48 | fast_ping_result ping_callback, void *userptr); 49 | 50 | int fast_ping_fake_ip_add(PING_TYPE type, const char *host, int ttl, float time); 51 | 52 | int fast_ping_fake_ip_remove(PING_TYPE type, const char *host); 53 | 54 | /* stop ping */ 55 | int fast_ping_stop(struct ping_host_struct *ping_host); 56 | 57 | int fast_ping_init(void); 58 | 59 | void fast_ping_exit(void); 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif /*__cplusplus */ 64 | 65 | #endif // !FAST_PING_H 66 | -------------------------------------------------------------------------------- /src/include/smartdns/lib/idna.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _SMARTDNS_IDNA_H 20 | #define _SMARTDNS_IDNA_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | int utf8_to_punycode(const char *src, int src_len, char *dst, int dst_len); 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | 32 | #endif // !_SMARTDNS_IDNA_H 33 | -------------------------------------------------------------------------------- /src/include/smartdns/lib/nftset.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2022 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _NFTSET_H 20 | #define _NFTSET_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | int nftset_add(const char *familyname, const char *tablename, const char *setname, const unsigned char addr[], 27 | int addr_len, unsigned long timeout); 28 | 29 | int nftset_del(const char *familyname, const char *tablename, const char *setname, const unsigned char addr[], 30 | int addr_len); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif // !_NFTSET_H 37 | -------------------------------------------------------------------------------- /src/include/smartdns/lib/stringutil.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef _GENERIC_STRING_UITL_H 20 | #define _GENERIC_STRING_UITL_H 21 | 22 | #include 23 | #include 24 | 25 | static inline char *safe_strncpy(char *dest, const char *src, size_t n) 26 | { 27 | if (src == NULL) { 28 | dest[0] = '\0'; 29 | return dest; 30 | } 31 | 32 | if (n <= 0) { 33 | return NULL; 34 | } 35 | 36 | #if __GNUC__ > 7 37 | #pragma GCC diagnostic push 38 | #pragma GCC diagnostic ignored "-Wstringop-truncation" 39 | #endif 40 | char *ret = strncpy(dest, src, n - 1); 41 | if (n > 0) { 42 | dest[n - 1] = '\0'; 43 | } 44 | #if __GNUC__ > 7 45 | #pragma GCC diagnostic pop 46 | #endif 47 | return ret; 48 | } 49 | 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/include/smartdns/lib/timer_wheel.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __TIMER_WHEEL_H 20 | #define __TIMER_WHEEL_H 21 | 22 | #include "list.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | struct tw_base; 29 | struct tw_timer_list; 30 | 31 | typedef void (*tw_func)(struct tw_base *, struct tw_timer_list *, void *, unsigned long); 32 | typedef void (*tw_del_func)(struct tw_base *, struct tw_timer_list *, void *); 33 | 34 | struct tw_timer_list { 35 | void *data; 36 | unsigned long expires; 37 | tw_func function; 38 | tw_del_func del_function; 39 | struct list_head entry; 40 | }; 41 | 42 | struct tw_base *tw_init_timers(void); 43 | 44 | int tw_cleanup_timers(struct tw_base *); 45 | 46 | void tw_add_timer(struct tw_base *, struct tw_timer_list *); 47 | 48 | int tw_del_timer(struct tw_base *, struct tw_timer_list *); 49 | 50 | int tw_mod_timer_pending(struct tw_base *, struct tw_timer_list *, unsigned long); 51 | 52 | int tw_mod_timer(struct tw_base *, struct tw_timer_list *, unsigned long); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | #endif 58 | -------------------------------------------------------------------------------- /src/include/smartdns/smartdns.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef SMART_DNS_H 20 | #define SMART_DNS_H 21 | 22 | #include "smartdns/dns_cache.h" 23 | #include "smartdns/dns_client.h" 24 | #include "smartdns/dns_conf.h" 25 | #include "smartdns/dns_plugin.h" 26 | #include "smartdns/dns_server.h" 27 | #include "smartdns/dns_stats.h" 28 | #include "smartdns/fast_ping.h" 29 | #include "smartdns/util.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif /*__cplusplus */ 34 | 35 | void smartdns_exit(int status); 36 | 37 | void smartdns_restart(void); 38 | 39 | int smartdns_get_cert(char *key, char *cert); 40 | 41 | int smartdns_main(int argc, char *argv[]); 42 | 43 | int smartdns_server_run(const char *config_file); 44 | 45 | int smartdns_server_stop(void); 46 | 47 | const char *smartdns_version(void); 48 | 49 | #ifdef TEST 50 | 51 | typedef void (*smartdns_post_func)(void *arg); 52 | 53 | int smartdns_reg_post_func(smartdns_post_func func, void *arg); 54 | 55 | int smartdns_test_main(int argc, char *argv[], int fd_notify, int no_close_allfds); 56 | 57 | #endif 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif /*__cplusplus */ 62 | #endif 63 | -------------------------------------------------------------------------------- /src/include/smartdns/timer.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef SMART_DNS_TIMER_H 20 | #define SMART_DNS_TIMER_H 21 | 22 | #include "smartdns/lib/timer_wheel.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif /*__cplusplus */ 27 | 28 | int dns_timer_init(void); 29 | 30 | void dns_timer_add(struct tw_timer_list *timer); 31 | 32 | int dns_timer_del(struct tw_timer_list *timer); 33 | 34 | int dns_timer_mod(struct tw_timer_list *timer, unsigned long expires); 35 | 36 | void dns_timer_destroy(void); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif /*__cplusplus */ 41 | #endif 42 | -------------------------------------------------------------------------------- /src/lib/stringutil.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "smartdns/smartdns.h" 20 | #include 21 | #include 22 | #include 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | const char *smartdns_workdir = getenv("SMARTDNS_WORKDIR"); 27 | if (smartdns_workdir != NULL) { 28 | if (chdir(smartdns_workdir) != 0) { 29 | fprintf(stderr, "chdir to %s failed: %s\n", smartdns_workdir, strerror(errno)); 30 | return 1; 31 | } 32 | } 33 | 34 | return smartdns_main(argc, argv); 35 | } 36 | -------------------------------------------------------------------------------- /src/timer.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "smartdns/timer.h" 20 | #include "smartdns/lib/timer_wheel.h" 21 | 22 | static struct tw_base *dns_timer_base = NULL; 23 | 24 | int dns_timer_init(void) 25 | { 26 | struct tw_base *tw = tw_init_timers(); 27 | if (tw == NULL) { 28 | return -1; 29 | } 30 | 31 | dns_timer_base = tw; 32 | 33 | return 0; 34 | } 35 | 36 | void dns_timer_destroy(void) 37 | { 38 | if (dns_timer_base != NULL) { 39 | tw_cleanup_timers(dns_timer_base); 40 | dns_timer_base = NULL; 41 | } 42 | } 43 | 44 | void dns_timer_add(struct tw_timer_list *timer) 45 | { 46 | if (dns_timer_base == NULL) { 47 | return; 48 | } 49 | 50 | tw_add_timer(dns_timer_base, timer); 51 | } 52 | 53 | int dns_timer_del(struct tw_timer_list *timer) 54 | { 55 | if (dns_timer_base == NULL) { 56 | return 0; 57 | } 58 | 59 | return tw_del_timer(dns_timer_base, timer); 60 | } 61 | 62 | int dns_timer_mod(struct tw_timer_list *timer, unsigned long expires) 63 | { 64 | if (dns_timer_base == NULL) { 65 | return 0; 66 | } 67 | 68 | return tw_mod_timer(dns_timer_base, timer, expires); 69 | } 70 | -------------------------------------------------------------------------------- /systemd/smartdns.service.in: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=SmartDNS Server 3 | After=network.target 4 | Before=network-online.target 5 | Before=nss-lookup.target 6 | Wants=nss-lookup.target 7 | StartLimitBurst=0 8 | StartLimitIntervalSec=60 9 | 10 | [Service] 11 | Type=forking 12 | PIDFile=@RUNSTATEDIR@/smartdns.pid 13 | EnvironmentFile=@SYSCONFDIR@/default/smartdns 14 | ExecStart=@SBINDIR@/smartdns -p @RUNSTATEDIR@/smartdns.pid $SMART_DNS_OPTS 15 | Restart=always 16 | RestartSec=2 17 | TimeoutStopSec=15 18 | 19 | [Install] 20 | WantedBy=multi-user.target 21 | Alias=smartdns.service 22 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | 2 | # Copyright (C) 2018-2025 Ruilin Peng (Nick) . 3 | # 4 | # smartdns is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # smartdns is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | SMARTDNS_SRC_DIR=../src 18 | 19 | BIN=test.bin 20 | SMARTDNS_TEST_LIB=$(SMARTDNS_SRC_DIR)/libsmartdns-test.a 21 | 22 | CXXFLAGS += -g 23 | CXXFLAGS += -DTEST 24 | CXXFLAGS += -I./ -I../src -I../src/include 25 | 26 | TEST_SOURCES := $(wildcard *.cc) $(wildcard */*.cc) $(wildcard */*/*.cc) 27 | TEST_OBJECTS := $(patsubst %.cc, %.o, $(TEST_SOURCES)) 28 | OBJS += $(TEST_OBJECTS) 29 | 30 | SMARTDNS_SRC_FILES := $(wildcard $(SMARTDNS_SRC_DIR)/*.c) $(wildcard $(SMARTDNS_SRC_DIR)/*.h) $(wildcard $(SMARTDNS_SRC_DIR)/lib/*.c) 31 | 32 | 33 | LDFLAGS += -lssl -lcrypto -lpthread -ldl -lgtest -lstdc++ -lm 34 | LDFLAGS += $(EXTRA_LDFLAGS) 35 | 36 | .PHONY: all clean test $(SMARTDNS_TEST_LIB) 37 | 38 | all: $(BIN) 39 | 40 | $(BIN) : $(OBJS) $(SMARTDNS_TEST_LIB) 41 | $(CC) $^ -o $@ $(LDFLAGS) 42 | 43 | test: $(BIN) 44 | ./$(BIN) 45 | 46 | $(SMARTDNS_TEST_LIB): 47 | $(MAKE) -C $(SMARTDNS_SRC_DIR) libsmartdns-test.a 48 | 49 | clean: 50 | $(RM) $(OBJS) $(BIN) 51 | $(MAKE) -C $(SMARTDNS_SRC_DIR) clean 52 | -------------------------------------------------------------------------------- /test/cases/test-mock-server.cc: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "client.h" 20 | #include "include/utils.h" 21 | #include "server.h" 22 | #include "gtest/gtest.h" 23 | 24 | TEST(MockServer, query_fail) 25 | { 26 | smartdns::MockServer server; 27 | smartdns::Client client; 28 | server.Start("udp://0.0.0.0:61053", [](struct smartdns::ServerRequestContext *request) { 29 | request->response_data_len = 0; 30 | return smartdns::SERVER_REQUEST_ERROR; 31 | }); 32 | 33 | ASSERT_TRUE(client.Query("example.com", 61053)); 34 | std::cout << client.GetResult() << std::endl; 35 | EXPECT_EQ(client.GetStatus(), "SERVFAIL"); 36 | } 37 | 38 | TEST(MockServer, soa) 39 | { 40 | smartdns::MockServer server; 41 | smartdns::Client client; 42 | server.Start("udp://0.0.0.0:61053", 43 | [](struct smartdns::ServerRequestContext *request) { return smartdns::SERVER_REQUEST_SOA; }); 44 | 45 | ASSERT_TRUE(client.Query("example.com", 61053)); 46 | std::cout << client.GetResult() << std::endl; 47 | EXPECT_EQ(client.GetStatus(), "NXDOMAIN"); 48 | } 49 | 50 | TEST(MockServer, noerror) 51 | { 52 | smartdns::MockServer server; 53 | smartdns::Client client; 54 | server.Start("udp://0.0.0.0:61053", 55 | [](struct smartdns::ServerRequestContext *request) { return smartdns::SERVER_REQUEST_OK; }); 56 | 57 | ASSERT_TRUE(client.Query("example.com", 61053)); 58 | std::cout << client.GetResult() << std::endl; 59 | EXPECT_EQ(client.GetStatus(), "NOERROR"); 60 | } 61 | -------------------------------------------------------------------------------- /test/test.cc: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | * 3 | * Copyright (C) 2018-2025 Ruilin Peng (Nick) . 4 | * 5 | * smartdns is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * smartdns is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include "gtest/gtest.h" 20 | 21 | int main(int argc, char **argv) 22 | { 23 | if (WEXITSTATUS(system("which dig >/dev/null 2>&1")) != 0) { 24 | std::cerr << "dig not found, please install it first." << std::endl; 25 | return 1; 26 | } 27 | 28 | ::testing::InitGoogleTest(&argc, argv); 29 | return RUN_ALL_TESTS(); 30 | } --------------------------------------------------------------------------------