| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | |
| 6 | "codeberg.org/miekg/dns" |
| 7 | ) |
| 8 | |
| 9 | type PluginBlockIPv6 struct{} |
| 10 | |
| 11 | func (plugin *PluginBlockIPv6) Name() string { |
| 12 | return "block_ipv6" |
| 13 | } |
| 14 | |
| 15 | func (plugin *PluginBlockIPv6) Description() string { |
| 16 | return "Immediately return a synthetic response to AAAA queries." |
| 17 | } |
| 18 | |
| 19 | func (plugin *PluginBlockIPv6) Init(proxy *Proxy) error { |
| 20 | return nil |
| 21 | } |
| 22 | |
| 23 | func (plugin *PluginBlockIPv6) Drop() error { |
| 24 | return nil |
| 25 | } |
| 26 | |
| 27 | func (plugin *PluginBlockIPv6) Reload() error { |
| 28 | return nil |
| 29 | } |
| 30 | |
| 31 | func (plugin *PluginBlockIPv6) Eval(pluginsState *PluginsState, msg *dns.Msg) error { |
| 32 | question := msg.Question[0] |
| 33 | if question.Header().Class != dns.ClassINET || dns.RRToType(question) != dns.TypeAAAA { |
| 34 | return nil |
| 35 | } |
| 36 | synth := EmptyResponseFromMessage(msg) |
| 37 | hinfo := new(dns.HINFO) |
| 38 | hinfo.Hdr = dns.Header{ |
| 39 | Name: question.Header().Name, Class: dns.ClassINET, TTL: 86400, |
| 40 | } |
| 41 | hinfo.Cpu = "AAAA queries have been locally blocked by dnscrypt-proxy" |
| 42 | hinfo.Os = "Set block_ipv6 to false to disable this feature" |
| 43 | synth.Answer = []dns.RR{hinfo} |
| 44 | qName := question.Header().Name |
| 45 | i := strings.Index(qName, ".") |
| 46 | parentZone := "." |
| 47 | if !(i < 0 || i+1 >= len(qName)) { |
| 48 | parentZone = qName[i+1:] |
| 49 | } |
| 50 | soa := new(dns.SOA) |
| 51 | soa.Mbox = "h.invalid." |
| 52 | soa.Ns = "a.root-servers.net." |
| 53 | soa.Serial = 1 |
| 54 | soa.Refresh = 10000 |
| 55 | soa.Minttl = 2400 |
| 56 | soa.Expire = 604800 |
| 57 | soa.Retry = 300 |
| 58 | soa.Hdr = dns.Header{ |
| 59 | Name: parentZone, Class: dns.ClassINET, TTL: 60, |
| 60 | } |
| 61 | synth.Ns = []dns.RR{soa} |
| 62 | pluginsState.synthResponse = synth |
| 63 | pluginsState.action = PluginsActionSynth |
| 64 | pluginsState.returnCode = PluginsReturnCodeSynth |
| 65 | return nil |
| 66 | } |