pancheri/rule.go

86 lines
1.4 KiB
Go
Raw Normal View History

2023-10-02 01:38:23 +00:00
package pancheri
2023-10-02 14:24:01 +00:00
import (
"github.com/miekg/dns"
"net"
)
2023-10-02 14:21:08 +00:00
2023-10-02 01:38:23 +00:00
const (
RuleTypeA = "A"
RuleTypeAAAA = "AAAA"
RuleTypeCNAME = "CNAME"
RuleTypeTXT = "TXT"
)
2023-10-02 14:21:08 +00:00
type RecordA struct {
In string `yaml:"i"`
Ip net.IP `yaml:"v4"`
TTL uint `yaml:"t"`
2023-10-02 14:21:08 +00:00
}
2023-10-02 14:24:01 +00:00
func (record *RecordA) Render() *dns.A {
r := new(dns.A)
r.Hdr = dns.RR_Header{
Name: record.In,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: uint32(record.TTL),
}
r.A = record.Ip
return r
}
2023-10-02 14:21:08 +00:00
type RecordAAAA struct {
In string `yaml:"i"`
Ip net.IP `yaml:"v6"`
TTL uint `yaml:"t"`
2023-10-02 14:21:08 +00:00
}
2023-10-02 14:24:01 +00:00
func (record *RecordAAAA) Render() *dns.AAAA {
r := new(dns.AAAA)
r.Hdr = dns.RR_Header{
Name: record.In,
Rrtype: dns.TypeAAAA,
Class: dns.ClassINET,
Ttl: uint32(record.TTL),
}
r.AAAA = record.Ip
return r
}
2023-10-02 14:21:08 +00:00
type RecordCNAME struct {
In string `yaml:"i"`
Target string `yaml:"tr"`
TTL uint `yaml:"t"`
2023-10-02 14:21:08 +00:00
}
2023-10-02 14:24:01 +00:00
func (record *RecordCNAME) Render() *dns.CNAME {
r := new(dns.CNAME)
r.Hdr = dns.RR_Header{
Name: record.In,
Rrtype: dns.TypeCNAME,
Class: dns.ClassINET,
Ttl: uint32(record.TTL),
}
r.Target = record.Target
return r
}
2023-10-02 14:21:08 +00:00
type RecordTXT struct {
In string `yaml:"i"`
Content []string `yaml:"c"`
TTL uint `yaml:"t"`
2023-10-02 01:38:23 +00:00
}
2023-10-02 14:24:01 +00:00
func (record *RecordTXT) Render() *dns.TXT {
r := new(dns.TXT)
r.Hdr = dns.RR_Header{
Name: record.In,
Rrtype: dns.TypeTXT,
Class: dns.ClassINET,
Ttl: uint32(record.TTL),
}
r.Txt = record.Content
return r
}