mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-04 10:05:42 +00:00
config: add DNS import/export policies
config: move ID generation to ZoneConfig config: serde fixes
This commit is contained in:
+2
-1
@@ -167,7 +167,8 @@ network-interface = "2.0"
|
||||
# for ospf route
|
||||
petgraph = "0.8.1"
|
||||
hashbrown = "0.15.3"
|
||||
ordered_hash_map = "0.5.0"
|
||||
ordered_hash_map = "0.5.0"# TODO: REPLACE THIS
|
||||
indexmap = "2.13.0"
|
||||
|
||||
# for wireguard
|
||||
boringtun = { package = "boringtun-easytier", version = "0.6.1", optional = true }
|
||||
|
||||
+64
-26
@@ -1,11 +1,14 @@
|
||||
use crate::dns::utils::{sanitize, NameServerAddr};
|
||||
use crate::proto::dns::{DnsConfigKind, DnsConfigPb, ZoneConfigPb};
|
||||
use crate::proto::dns::{DnsConfigPb, ZoneConfigPb};
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use gethostname::gethostname;
|
||||
use hickory_proto::rr::LowerName;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||
use std::str::FromStr;
|
||||
use std::sync::LazyLock;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub const DNS_DEFAULT_ADDRESS: SocketAddr =
|
||||
SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(100, 100, 100, 101), 53));
|
||||
@@ -17,6 +20,8 @@ pub static DNS_DEFAULT_TLD: LazyLock<LowerName> =
|
||||
pub struct DnsConfig {
|
||||
#[serde(rename = "zone")]
|
||||
pub zones: Vec<ZoneConfig>,
|
||||
#[serde(flatten)]
|
||||
pub policies: HashMap<LowerName, DnsPolicyConfig>,
|
||||
name: LowerName,
|
||||
pub domain: LowerName,
|
||||
pub addresses: Vec<SocketAddr>,
|
||||
@@ -43,34 +48,17 @@ impl DnsConfig {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn to_pb(&self, kind: DnsConfigKind) -> DnsConfigPb {
|
||||
let pb = DnsConfigPb {
|
||||
kind: kind.into(),
|
||||
name: self.get_name(),
|
||||
domain: self.domain.to_string(),
|
||||
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
match kind {
|
||||
DnsConfigKind::Local => DnsConfigPb {
|
||||
zones: self.zones.iter().map(Into::into).collect(),
|
||||
addresses: self.addresses.clone().into_iter().map(Into::into).collect(),
|
||||
listeners: self.listeners.iter().map(ToString::to_string).collect(),
|
||||
|
||||
..pb
|
||||
},
|
||||
|
||||
DnsConfigKind::Remote => DnsConfigPb {
|
||||
pub fn export(&self) -> DnsConfigPb {
|
||||
DnsConfigPb {
|
||||
zones: self
|
||||
.zones
|
||||
.iter()
|
||||
.filter(|z| z.broadcast)
|
||||
.filter(|z| z.policy.export.is_some()) // TODO: check policies of parent zones
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
|
||||
..pb
|
||||
},
|
||||
name: self.get_name(),
|
||||
domain: self.domain.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,19 +66,21 @@ impl DnsConfig {
|
||||
impl Default for DnsConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
zones: Vec::new(),
|
||||
policies: HashMap::new(),
|
||||
name: LowerName::default(),
|
||||
domain: DNS_DEFAULT_TLD.clone(),
|
||||
addresses: vec![DNS_DEFAULT_ADDRESS],
|
||||
listeners: vec![],
|
||||
zones: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
|
||||
pub struct ZoneConfig {
|
||||
#[serde(default)]
|
||||
pub broadcast: bool,
|
||||
#[serde(default = "Uuid::new_v4")]
|
||||
#[serde(skip_serializing)]
|
||||
id: Uuid,
|
||||
pub origin: LowerName,
|
||||
#[serde(default)]
|
||||
pub ttl: u32,
|
||||
@@ -98,11 +88,14 @@ pub struct ZoneConfig {
|
||||
pub records: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub forwarders: Vec<NameServerAddr>,
|
||||
#[serde(flatten)]
|
||||
pub policy: ZonePolicyConfig,
|
||||
}
|
||||
|
||||
impl From<&ZoneConfig> for ZoneConfigPb {
|
||||
fn from(value: &ZoneConfig) -> Self {
|
||||
Self {
|
||||
id: Some(value.id.into()),
|
||||
origin: value.origin.to_string(),
|
||||
ttl: value.ttl,
|
||||
records: value.records.clone(),
|
||||
@@ -110,3 +103,48 @@ impl From<&ZoneConfig> for ZoneConfigPb {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
|
||||
#[serde(default)]
|
||||
pub struct AclPolicy {
|
||||
pub whitelist: Option<Vec<String>>,
|
||||
pub blacklist: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default, Deref, DerefMut)]
|
||||
#[serde(default)]
|
||||
pub struct FunctionalityPolicy {
|
||||
#[serde(flatten)]
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
acl: AclPolicy, // TODO
|
||||
pub disabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default, Deref, DerefMut)]
|
||||
#[serde(default)]
|
||||
pub struct DnsPolicy<P = FunctionalityPolicy> {
|
||||
#[serde(flatten)]
|
||||
#[deref]
|
||||
#[deref_mut]
|
||||
policy: P,
|
||||
pub recursive: bool, // TODO
|
||||
}
|
||||
|
||||
pub type ZoneExportPolicy = FunctionalityPolicy;
|
||||
pub type DnsExportPolicy = DnsPolicy<ZoneExportPolicy>;
|
||||
pub type DnsImportPolicy = DnsPolicy<FunctionalityPolicy>;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
|
||||
#[serde(default)]
|
||||
pub struct DnsPolicyConfig {
|
||||
pub import: DnsImportPolicy,
|
||||
pub export: Option<DnsExportPolicy>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
|
||||
#[serde(default)]
|
||||
pub struct ZonePolicyConfig {
|
||||
#[serde(default)]
|
||||
pub export: Option<DnsExportPolicy>,
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ use super::{
|
||||
PeerPacketFilter,
|
||||
};
|
||||
use crate::common::config::ConfigLoader;
|
||||
use crate::proto::dns::DnsConfigKind;
|
||||
use crate::{
|
||||
common::{
|
||||
config::NetworkIdentity,
|
||||
@@ -261,7 +260,7 @@ impl RoutePeerInfo {
|
||||
ipv6_addr: global_ctx.get_ipv6().map(|x| x.into()),
|
||||
|
||||
groups: global_ctx.get_acl_groups(my_peer_id),
|
||||
dns: Some(global_ctx.config.get_dns().to_pb(DnsConfigKind::Remote)),
|
||||
dns: Some(global_ctx.config.get_dns().export()),
|
||||
|
||||
noise_static_pubkey,
|
||||
|
||||
|
||||
@@ -4,23 +4,16 @@ import "common.proto";
|
||||
|
||||
package dns;
|
||||
|
||||
enum DnsConfigKind {
|
||||
LOCAL = 0;
|
||||
REMOTE = 1;
|
||||
}
|
||||
|
||||
message DnsConfigPb {
|
||||
DnsConfigKind kind = 1;
|
||||
repeated ZoneConfigPb zones = 2;
|
||||
string name = 3;
|
||||
string domain = 4;
|
||||
repeated common.SocketAddr addresses = 5;
|
||||
repeated string listeners = 6;
|
||||
repeated ZoneConfigPb zones = 1;
|
||||
string name = 2;
|
||||
string domain = 3;
|
||||
}
|
||||
|
||||
message ZoneConfigPb {
|
||||
string origin = 1;
|
||||
uint32 ttl = 2;
|
||||
repeated string records = 3;
|
||||
repeated string forwarders = 4;
|
||||
common.UUID id = 1;
|
||||
string origin = 2;
|
||||
uint32 ttl = 3;
|
||||
repeated string records = 4;
|
||||
repeated string forwarders = 5;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user