log:
  level: info

plugins:
  - tag: lazy_cache
    type: cache
    args:
      size: 20000
      lazy_cache_ttl: 86400

  - tag: geosite_cn
    type: domain_set
    args:
      files:
          - "/var/etc/bypass/domains_cn.txt"
          - "/etc/bypass/white.list"

  - tag: geoip_cn
    type: ip_set
    args:
      files:
          - "/var/etc/bypass/china.txt"
          - "/var/etc/bypass/china_v6.txt"

  - tag: geosite_no_cn
    type: domain_set
    args:
      files:
          - "/var/etc/bypass/gfw.list"
          - "/etc/bypass/black.list"

  - tag: adlist
    type: domain_set
    args:
      files:
          - "adfile"

  - tag: forward_local
    type: forward
    args:
      concurrent: 2
      upstreams:
        - addr: local_dns
  - tag: forward_remote
    type: forward
    args:
      concurrent: 2
      upstreams:
        - addr: remote_dns
  - tag: local_sequence
    type: sequence
    args:
      - exec: $forward_local

  - tag: remote_sequence_IPv6
    type: sequence
    args:
      - exec: prefer_ipv4
      - exec: $forward_remote
  - tag: remote_sequence
    type: sequence
    args:
      - exec: prefer_ipv4
      - exec: $forward_remote
      - matches: 
        - qtype 28 65
        exec: reject 0

  - tag: has_resp_sequence
    type: sequence
    args:
      - matches: has_resp
        exec: accept

  - tag: query_is_local_ip
    type: sequence
    args:
      - exec: $local_sequence
      - matches: "!resp_ip $geoip_cn"
        exec: drop_resp


  - tag: query_is_remote
    type: sequence
    args:
      - exec: $IPV6MODE

  - tag: fallback
    type: fallback
    args:
      primary: POLLUTION
      secondary: query_is_remote
      threshold: 500
      always_standby: true

  - tag: query_is_local_domain
    type: sequence
    args:
      - matches: qname $geosite_cn
        exec: $local_sequence

  - tag: query_is_no_local_domain
    type: sequence
    args:
      - matches: qname $geosite_no_cn
        exec: $remote_sequence
  - tag: query_is_reject_domain
    type: sequence
    args:
      - matches: qname $adlist
        exec: reject 3
  - tag: main_sequence
    type: sequence
    args:
      - exec: $lazy_cache
      - exec: jump has_resp_sequence
      - exec: $query_is_reject_domain
      - exec: jump has_resp_sequence
      - exec: $query_is_local_domain
      - exec: jump has_resp_sequence
      - exec: $query_is_no_local_domain
      - exec: jump has_resp_sequence
      - exec: $fallback

  - tag: udp_server
    type: udp_server
    args:
      entry: main_sequence
      listen: ":DNS_PORT"

  - tag: tcp_server
    type: tcp_server
    args:
      entry: main_sequence
      listen: ":DNS_PORT"
