diff --git a/config/config.toml b/config/config.toml index bd198ea..ec73445 100644 --- a/config/config.toml +++ b/config/config.toml @@ -15,7 +15,10 @@ caa_records = [ "0 issue \"letsencrypt.org\"", ] mx_records = [ - "10 inbound-smtp.us-west-2.amazonaws.com", + # mydomain.org + ["@", "10 inbound-smtp.us-west-2.amazonaws.com"], + # mail.mydomain.org + ["mail", "10 mail.inbound-smtp.us-west-2.amazonaws.com"], ] ns_records = [ [ "ns1.mydomain.org.", "5.6.7.8" ], diff --git a/src/args.rs b/src/args.rs index f11c39d..c9ac4b1 100644 --- a/src/args.rs +++ b/src/args.rs @@ -98,7 +98,10 @@ fn test_args() { assert_eq!(args.pdns.caa_records, ["0 issue \"letsencrypt.org\"",]); assert_eq!( args.pdns.mx_records, - ["10 inbound-smtp.us-west-2.amazonaws.com"] + [ + ("@".to_owned(), "10 inbound-smtp.us-west-2.amazonaws.com".to_owned()), + ("mail".to_owned(), "10 mail.inbound-smtp.us-west-2.amazonaws.com".to_owned()) + ] ); assert_eq!( args.pdns.ns_records, diff --git a/src/config.rs b/src/config.rs index e08d814..8d075d2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -38,7 +38,7 @@ pub struct PdnsOptions { pub tunnel_ttl: u32, pub api_ttl: u32, pub caa_records: Vec, - pub mx_records: Vec, + pub mx_records: Vec<(String,String)>, pub ns_records: Vec>, pub txt_records: Vec>, pub cname_records: Vec>, diff --git a/src/pdns.rs b/src/pdns.rs index 9f0d6c7..964a3b3 100644 --- a/src/pdns.rs +++ b/src/pdns.rs @@ -217,18 +217,20 @@ fn build_ns_response(qname: &str, config: &Config) -> Vec { } // Returns an MX record for a given qname. -fn build_mx_response(qname: &str, config: &Config) -> Vec { +fn build_mx_response(qname: &str, is_bare_domain: bool, subdomain: &str, config: &Config) -> Vec { let mut records = vec![]; - for mx in &config.options.pdns.mx_records { - records.push(PdnsLookupResponse { - qtype: "MX".to_owned(), - qname: qname.to_owned(), - content: mx.to_owned(), - ttl: config.options.pdns.dns_ttl, - domain_id: None, - scope_mask: None, - auth: None, - }); + for (domain, mx) in &config.options.pdns.mx_records { + if domain == subdomain || (domain == "@" && is_bare_domain) { + records.push(PdnsLookupResponse { + qtype: "MX".to_owned(), + qname: qname.to_owned(), + content: mx.to_owned(), + ttl: config.options.pdns.dns_ttl, + domain_id: None, + scope_mask: None, + auth: None, + }); + } } records @@ -452,6 +454,7 @@ fn handle_lookup(req: PdnsRequest, config: &Config) -> Result Result