Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
876 changes: 621 additions & 255 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ resolver = "2"
# default-members = ["bin"]

[workspace.dependencies]
trust-dns-proto = { version = "0.22.0", default-features = false, features = [
"dnssec",
"serde-config",
hickory-proto = { version = "0.25.2", default-features = false, features = [
"dnssec-ring",
"serde",
] }
socket2 = { version = "0.5.6", features = [
"all",
Expand All @@ -27,7 +27,8 @@ anyhow = { version = "1.0", features = ["backtrace"] }
async-trait = "0.1"
bytes = "1.1"
clap = { version = "4.5.4", features = ["derive", "env"] }
dhcproto = "0.11.0"
base64 = "0.22.1"
dhcproto = "0.14.0"
futures = { version = "0.3", default-features = false, features = ["std"] }
ipnet = { features = ["serde"], version = "2.4.0" }
pnet = { features = ["serde", "std"], version = "0.34.0" }
Expand All @@ -43,3 +44,4 @@ rand = "0.8.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.8"
rustls-pki-types = "1.13.1"
2 changes: 1 addition & 1 deletion docs/ddns.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ There are a few config values that can change the behavior of the update. These

The logic for client FQDN flag handling is largely in the `handle_flags` function, and was translated from [Keas flag handling](https://github.com/isc-projects/kea/blob/9c76b9a9e55b49ea407531b64783f6ec12546f42/src/lib/dhcpsrv/d2_client_mgr.cc#L115)

As for the content of the DNS updates themselves, here is an example of a forward update created by trust-dns-client
As for the content of the DNS updates themselves, here is an example of a forward update created by hickory-dns-client

![fwd_update](https://user-images.githubusercontent.com/1128302/210460131-97bcf7f1-09aa-4c82-807f-7d5eb19542d3.png)

Expand Down
3 changes: 1 addition & 2 deletions dora-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ tokio-util = { workspace = true }
tracing = { workspace = true }
tracing-futures = { workspace = true }
tracing-subscriber = { workspace = true }
thiserror = { workspace = true }
trust-dns-proto = { workspace = true }
hickory-proto = { workspace = true }
pin-project = "1.0"
prometheus = { workspace = true }
prometheus-static-metric = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion dora-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ pub use async_trait::async_trait;
pub use chrono;
pub use chrono_tz;
pub use dhcproto;
pub use hickory_proto;
pub use pnet;
pub use tokio;
pub use tokio_stream;
pub use tracing;
pub use trust_dns_proto;
pub use unix_udp_sock;

pub use crate::server::Server;
Expand Down
31 changes: 16 additions & 15 deletions dora-core/src/server/context.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
//! context of current server message
use chrono::{DateTime, Utc};
use dhcproto::{Decodable, Decoder, Encodable, v4, v6};
use pnet::ipnetwork::{IpNetwork, Ipv4Network, Ipv6Network};
use tracing::{error, trace};
use unix_udp_sock::RecvMeta;

use std::{
fmt,
io::{self, Error, ErrorKind},
Expand All @@ -13,6 +7,12 @@ use std::{
time::Duration,
};

use chrono::{DateTime, Utc};
use dhcproto::{Decodable, Decoder, Encodable, v4, v6};
use pnet::ipnetwork::{IpNetwork, Ipv4Network, Ipv6Network};
use tracing::{error, trace};
use unix_udp_sock::RecvMeta;

use crate::{
metrics::{self, RECV_TYPE_COUNT, SENT_TYPE_COUNT, V6_RECV_TYPE_COUNT, V6_SENT_TYPE_COUNT},
server::{State, msg::SerialMsg, typemap::TypeMap},
Expand Down Expand Up @@ -552,10 +552,10 @@ impl MsgContext<v4::Message> {
.opts()
.get(OptionCode::RelayAgentInformation)
.and_then(|opt| {
if let DhcpOption::RelayAgentInformation(info) = opt {
if let Some(RelayInfo::LinkSelection(ip)) = info.get(RelayCode::LinkSelection) {
return Some(ip);
}
if let DhcpOption::RelayAgentInformation(info) = opt
&& let Some(RelayInfo::LinkSelection(ip)) = info.get(RelayCode::LinkSelection)
{
return Some(ip);
}
None
})
Expand Down Expand Up @@ -644,11 +644,12 @@ impl MsgContext<v4::Message> {
self.msg.opts().get(OptionCode::ParameterRequestList)
{
// if broadcast addr is requested, try to fill from interface
if let Some(IpNetwork::V4(interface)) = self.interface {
if requested.contains(&v4::OptionCode::BroadcastAddr) && interface_match {
resp.opts_mut()
.insert(DhcpOption::BroadcastAddr(interface.broadcast()));
}
if let Some(IpNetwork::V4(interface)) = self.interface
&& requested.contains(&v4::OptionCode::BroadcastAddr)
&& interface_match
{
resp.opts_mut()
.insert(DhcpOption::BroadcastAddr(interface.broadcast()));
}
// look in the requested list of params
for code in requested {
Expand Down
2 changes: 1 addition & 1 deletion external-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ipnet = { workspace = true }


[dev-dependencies]
reqwest = { version = "0.12", default-features = false, features = [
reqwest = { version = "0.12.4", default-features = false, features = [
"json",
"rustls-tls",
] }
4 changes: 2 additions & 2 deletions libs/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ license = "MPL-2.0"

[dependencies]
anyhow = { workspace = true }
base64 = { workspace = true }
ipnet = { workspace = true }
tracing = { workspace = true }
serde_yaml = { workspace = true }
serde_json = { workspace = true }
serde = { workspace = true }
trust-dns-proto = { workspace = true }
base64 = "0.21.0"
hex = "0.4"
phf = { version = "0.11", features = ["macros"] }
rand = "0.8"
rustls-pki-types = { workspace = true }

dora-core = { path = "../../dora-core" }
client-classification = { path = "../client-classification" }
Expand Down
8 changes: 4 additions & 4 deletions libs/config/src/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,10 @@ impl Network {
// skip matching on message type
continue;
}
if let Some(res) = self.get_reserved_opt(opt) {
if res.match_class(classes) {
return Some(res);
}
if let Some(res) = self.get_reserved_opt(opt)
&& res.match_class(classes)
{
return Some(res);
}
}
None
Expand Down
8 changes: 2 additions & 6 deletions libs/config/src/v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use std::{
use anyhow::{Context, bail};
use dora_core::{
anyhow::Result,
dhcproto::{
v4::HType,
v6::{DhcpOptions, duid::Duid},
},
dhcproto::v6::{DhcpOptions, HType, duid::Duid},
pnet::ipnetwork::{IpNetwork, Ipv6Network},
pnet::{self, datalink::NetworkInterface},
};
Expand Down Expand Up @@ -194,8 +191,7 @@ pub fn generate_duid_from_config(server_id: &ServerDuidInfo, link_layer: Ipv6Add
if htype == 0 {
HType::Eth
} else {
//TODO: This is a compromise of v4 HType. Should be changed to v6 HType after dhcproto is updated.
HType::from(htype as u8)
HType::from(htype)
}
}
match server_id {
Expand Down
15 changes: 7 additions & 8 deletions libs/config/src/wire/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ use dora_core::{
Decodable, Decoder, Encodable, Encoder,
v4::{self, DhcpOption, DhcpOptions, OptionCode},
},
hickory_proto::{
rr::Name,
serialize::binary::{BinEncodable, BinEncoder},
},
pnet::util::MacAddr,
};
use serde::{Deserialize, Deserializer, Serialize, de};
use tracing::warn;
use trust_dns_proto::{
rr,
serialize::binary::{BinEncodable, BinEncoder},
};

use crate::wire::{MaybeList, MinMax};

Expand Down Expand Up @@ -263,7 +263,7 @@ fn write_opt(enc: &mut Encoder<'_>, code: u8, opt: Opt) -> anyhow::Result<()> {
Opt::Domain(MaybeList::Val(domain)) => {
let mut buf = Vec::new();
let mut name_encoder = BinEncoder::new(&mut buf);
let name = domain.parse::<rr::Name>()?;
let name = domain.parse::<Name>()?;
name.emit(&mut name_encoder)?;
v4::encode_long_opt_bytes(OptionCode::from(code), &buf, enc)?;
}
Expand All @@ -272,7 +272,7 @@ fn write_opt(enc: &mut Encoder<'_>, code: u8, opt: Opt) -> anyhow::Result<()> {
let mut buf = Vec::new();
let mut name_encoder = BinEncoder::new(&mut buf);
for name in list {
let name = name.parse::<rr::Name>()?;
let name = name.parse::<Name>()?;
name.emit(&mut name_encoder)?;
}
v4::encode_long_opt_bytes(OptionCode::from(code), &buf, enc)?;
Expand Down Expand Up @@ -498,8 +498,7 @@ pub mod ddns {

use super::*;

use dora_core::dhcproto::Name;
pub use dora_core::trust_dns_proto::rr::dnssec::rdata::tsig::TsigAlgorithm;
use dora_core::{dhcproto::Name, hickory_proto::dnssec::rdata::tsig::TsigAlgorithm};

fn default_true() -> bool {
true
Expand Down
9 changes: 2 additions & 7 deletions libs/config/src/wire/v6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,15 @@ pub struct Net {
pub authoritative: bool,
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone, Default)]
pub enum DuidType {
#[default]
LLT,
LL,
EN,
UUID,
}

impl Default for DuidType {
fn default() -> Self {
Self::LLT
}
}

#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(tag = "type")]
pub enum ServerDuidInfo {
Expand Down
5 changes: 1 addition & 4 deletions libs/ddns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ edition = "2024"
[dependencies]
dora-core = { path = "../../dora-core" }
config = { path = "../config" }
trust-dns-client = { version = "0.22.0", features = ["dnssec-ring"] }
base64 = { workspace = true }
thiserror = { workspace = true }
ring = "0.16.20"
hex = "0.4"
rand = { workspace = true }
ipnet = { workspace = true }

[dev-dependencies]
base64 = "0.20"

[[example]]
name = "tsig"
Expand Down
3 changes: 1 addition & 2 deletions libs/ddns/examples/tsig.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{fs::File, io::Read, str::FromStr};

use config::wire::v4::ddns::TsigAlgorithm;
use ddns::{
dhcid::{self, IdType},
update::Updater,
Expand All @@ -9,10 +8,10 @@ use dora_core::{
anyhow::{self, Result},
config::trace,
dhcproto::Name,
hickory_proto::dnssec::{rdata::tsig::TsigAlgorithm, tsig::TSigner},
tokio::{self},
tracing::{debug, error},
};
use trust_dns_client::rr::dnssec::tsig::TSigner;

#[tokio::main]
async fn main() -> Result<()> {
Expand Down
20 changes: 17 additions & 3 deletions libs/ddns/src/dhcid.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
use std::fmt;

use base64::{Engine, prelude::BASE64_STANDARD};
use dora_core::dhcproto::{Name, NameError, v4::HType};
use dora_core::hickory_proto::serialize::binary::BinEncoder;
use ring::digest::{Context, SHA256};
use trust_dns_client::serialize::binary::BinEncoder;

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct DhcId {
ty: IdType,
id: Vec<u8>,
}

impl fmt::Display for DhcId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DhcId")
.field("type", &self.ty)
.field("id", &BASE64_STANDARD.encode(&self.id))
.finish()
}
}

impl DhcId {
/// if created with type Chaddr, only significant bytes (up to hlen) should be provided
pub fn new<T: Into<Vec<u8>>>(ty: IdType, id: T) -> Self {
Expand Down Expand Up @@ -98,6 +110,8 @@ pub enum IdType {
mod tests {
use std::str::FromStr;

use base64::{Engine, prelude::BASE64_STANDARD};

use super::*;

// A DHCP server allocates the IPv4 address 192.0.2.2 to a client that
Expand All @@ -120,7 +134,7 @@ mod tests {
.rdata(&Name::from_str("chi.example.com.").unwrap())
.unwrap();
assert_eq!(
base64::encode(out),
BASE64_STANDARD.encode(out),
"AAEBOSD+XR3Os/0LozeXVqcNc7FwCfQdWL3b/NaiUDlW2No=".to_owned()
);
}
Expand All @@ -145,7 +159,7 @@ mod tests {
.rdata(&Name::from_str("client.example.com.").unwrap())
.unwrap();
assert_eq!(
base64::encode(out),
BASE64_STANDARD.encode(out),
"AAABxLmlskllE0MVjd57zHcWmEH3pCQ6VytcKD//7es/deY=".to_owned()
);
}
Expand Down
Loading
Loading