-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from thibault-cne/issue/23
Fix tsig support issue
- Loading branch information
Showing
9 changed files
with
417 additions
and
168 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use std::sync::{Arc, RwLock}; | ||
|
||
use domain::base::iana::{Class, Rcode}; | ||
use domain::base::ToName; | ||
|
||
use domain::zonetree::{Answer, ReadableZone, Zone}; | ||
|
||
use crate::config::Config; | ||
use crate::error::Error; | ||
use crate::key::KeyStore; | ||
use crate::zone::ZoneTree; | ||
|
||
pub use service::dns; | ||
|
||
mod service; | ||
|
||
type Zones = Arc<RwLock<ZoneTree>>; | ||
|
||
pub struct State { | ||
pub config: Config, | ||
pub zones: Zones, | ||
pub keystore: Arc<RwLock<KeyStore>>, | ||
} | ||
|
||
impl State { | ||
pub fn config(&self) -> &Config { | ||
&self.config | ||
} | ||
|
||
fn find_zone<N, F>(&self, qname: &N, class: Class, f: F) -> Answer | ||
where | ||
N: ToName, | ||
F: FnOnce(Option<Box<dyn ReadableZone>>) -> Answer, | ||
{ | ||
if class != Class::IN { | ||
return Answer::new(Rcode::NXDOMAIN); | ||
} | ||
|
||
let zones = self.zones.read().unwrap(); | ||
f(zones.find_zone(qname).map(|z| z.read())) | ||
} | ||
|
||
pub fn insert_zone(&self, zone: Zone) -> Result<(), Error> { | ||
log::info!(target: "zone_change", "adding zone {}", zone.apex_name()); | ||
let mut zones = self.zones.write().unwrap(); | ||
zones.insert_zone(zone) | ||
} | ||
|
||
pub fn remove_zone<N>(&self, name: &N, class: Class) -> Result<(), Error> | ||
where | ||
N: ToName, | ||
{ | ||
log::info!(target: "zone_change", "removing zone {} {}", name.to_bytes(), class); | ||
|
||
let mut zones = self.zones.write().unwrap(); | ||
|
||
for z in zones.iter_zones() { | ||
log::debug!(target: "zone", "zone {:?}", z); | ||
} | ||
|
||
zones.remove_zone(name)?; | ||
|
||
for z in zones.iter_zones() { | ||
log::debug!(target: "zone", "zone {}", z.apex_name()); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl From<Config> for State { | ||
fn from(config: Config) -> Self { | ||
let zones = Arc::new(RwLock::new(ZoneTree::new())); | ||
State { | ||
config, | ||
zones, | ||
keystore: KeyStore::new_shared(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.