From 97b5751a347c114ea5d75ffb6a58b44ee7d81e91 Mon Sep 17 00:00:00 2001 From: m5r Date: Sat, 29 Oct 2022 15:25:40 +0200 Subject: [PATCH] handle MX for emails --- xip/xip.go | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/xip/xip.go b/xip/xip.go index 48a5b40..b07cd24 100644 --- a/xip/xip.go +++ b/xip/xip.go @@ -21,6 +21,7 @@ type Xip struct { type HardcodedRecord struct { A net.IP TXT []string + MX []dns.MX } var ( @@ -32,8 +33,15 @@ var ( A: net.IPv4(137, 66, 38, 214), }, "local-ip.sh.": { - A: net.IPv4(137, 66, 53, 22), - TXT: []string{"sl-verification=frudknyqpqlpgzbglkqnsmorfcvxrf"}, + A: net.IPv4(137, 66, 53, 22), + TXT: []string{ + "sl-verification=frudknyqpqlpgzbglkqnsmorfcvxrf", + "v=spf1 include:simplelogin.co ~all", + }, + MX: []dns.MX{ + {Preference: 10, Mx: "mx1.simplelogin.co."}, + {Preference: 20, Mx: "mx2.simplelogin.co."}, + }, }, } ) @@ -129,6 +137,27 @@ func (xip *Xip) handleTXT(question dns.Question, message *dns.Msg) { }) } +func (xip *Xip) handleMX(question dns.Question, message *dns.Msg) { + fqdn := question.Name + if hardcodedRecords[strings.ToLower(fqdn)].MX == nil { + return + } + + for _, record := range hardcodedRecords[strings.ToLower(fqdn)].MX { + message.Answer = append(message.Answer, &dns.MX{ + Hdr: dns.RR_Header{ + // Ttl: uint32((time.Hour * 24 * 7).Seconds()), + Ttl: uint32((time.Second * 10).Seconds()), + Name: fqdn, + Rrtype: dns.TypeMX, + Class: dns.ClassINET, + }, + Mx: record.Mx, + Preference: record.Preference, + }) + } +} + func (xip *Xip) SOARecord(question dns.Question) *dns.SOA { soa := new(dns.SOA) soa.Hdr = dns.RR_Header{ @@ -166,6 +195,8 @@ func (xip *Xip) handleQuery(message *dns.Msg) { xip.handleNS(question, message) case dns.TypeTXT: xip.handleTXT(question, message) + case dns.TypeMX: + xip.handleMX(question, message) } } }