OpenGFW
OpenGFW copied to clipboard
feat: add multiple addresses support for DNS modifier
Completes #137 . The DNS modifier now takes a list of addresses. One of the addresses is picked by the hash of the DNS query.
This PR forces a change to the rule.yaml file. Existing rule file will break as following:
2000-01-01T00:00:00+00:00 FATAL failed to load rules {"error": "yaml: unmarshal errors:\n line 22: cannot unmarshal !!str `1.1.1.1` into []interface {}"}
An example new modifier file
- name: v2ex dns poisoning
action: modify
modifier:
name: dns
args:
a:
- "192.0.2.1"
- "192.0.2.2"
- "192.0.2.3"
- "198.51.100.1"
- "198.51.100.2"
aaaa:
- "2001:db8::1234:5678"
- "2001:db8::abcd:ef12"
expr: dns != nil && dns.qr && any(dns.questions, {.name endsWith "v2ex.com"})
Loading the list from an external file might be better.
And I think it is possible to determine the IP family when parsing, so splitting the options to "a" and "aaaa" would not be necessary.
- name: ...
action: modify
modifier:
name: dns
args:
a: "192.0.2.33"
aaaa: "2001:db8::abc:123"
file: "./ipslist.txt"
list:
- "192.0.2.66"
- "192.0.2.67"
- "2001:db8::ccc:ddd"
- "2001:db8::abcd:1234"
expr: ...
Hi @haruue ! I've updated the PR to support exactly this format. Let me know what do you think about this :)
- name: ...
action: modify
modifier:
name: dns
args:
a: "192.0.2.33"
aaaa: "2001:db8::abc:123"
file: "./ipslist.txt"
list:
- "192.0.2.66"
- "192.0.2.67"
- "2001:db8::ccc:ddd"
- "2001:db8::abcd:1234"
expr: ...
Added a and aaaa back for backward compat.