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    async fn add_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
18    async fn delete_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
19}
20
21/// DNS provider that does not deduplicate record additions
22/// Sending add/dels from multiple rrdnsd nodes is not supported
23pub trait StackProvider {
24    async fn add_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
25    async fn delete_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
26}
27
28/// DNS provider that can only update an A/AAAA record e.g. FreeDNS (without add/delete)
29pub trait UpdatingProvider {
30    async fn update_record(token: &str, fqdn: &str, zone: &str, ipaddr: IpAddr) -> Result<()>;
31}
32
33pub const fn record_type(ipaddr: IpAddr) -> &'static str {
34    if ipaddr.is_ipv4() {
35        "A"
36    } else {
37        "AAAA"
38    }
39}
40
41pub fn new_reqw() -> Result<Reqw> {
42    let r = Reqw::builder()
43        .user_agent("rrdnsd")
44        .timeout(Duration::from_secs(30))
45        .pool_max_idle_per_host(0)
46        .build()?;
47    Ok(r)
48}