rrdnsd/providers/
mod.rs

1// rrdnsd - DNS provider API clients
2
3use anyhow::Result;
4use reqwest::Client as Reqw;
5use std::net::IpAddr;
6use std::time::Duration;
7
8pub mod dynu;
9pub mod dynv6;
10// pub mod freedns;
11
12pub use dynu::Dynu;
13pub use dynv6::Dynv6;
14
15/// DNS provider that deduplicates record additions as per RFC2136
16pub trait SetProvider {
17    const DEDUPLICATES_RECORDS: bool = true;
18    async fn add_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
19    async fn delete_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
20}
21
22/// DNS provider that does not deduplicate record additions
23/// Sending add/dels from multiple rrdnsd nodes is not supported
24pub trait StackProvider {
25    const DEDUPLICATES_RECORDS: bool = false;
26    async fn add_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
27    async fn delete_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
28}
29
30/// DNS provider that can only update an A/AAAA record e.g. FreeDNS (without add/delete)
31pub trait UpdatingProvider {
32    async fn update_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
33}
34
35pub const fn record_type(ipaddr: IpAddr) -> &'static str {
36    if ipaddr.is_ipv4() {
37        "A"
38    } else {
39        "AAAA"
40    }
41}
42
43pub fn new_reqw() -> Result<Reqw> {
44    let r = Reqw::builder()
45        .user_agent("rrdnsd")
46        .timeout(Duration::from_secs(30))
47        .pool_max_idle_per_host(0)
48        .build()?;
49    Ok(r)
50}