mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
feat: add mdns hostname metadata variant and fix vhost routing
- Add HostnameMetadata::Mdns variant to distinguish mDNS from private domains - Mark mDNS addresses as private (public: false) since mDNS is local-only - Fall back to null SNI entry when hostname not found in vhost mapping - Simplify public detection in ProxyTarget filter - Pass hostname to update_addresses for mDNS domain name generation
This commit is contained in:
@@ -1005,9 +1005,10 @@ impl NetworkInterfaceController {
|
||||
.as_network_mut()
|
||||
.as_gateways_mut()
|
||||
.ser(info)?;
|
||||
let hostname = crate::hostname::Hostname(db.as_public().as_server_info().as_hostname().de()?);
|
||||
let ports = db.as_private().as_available_ports().de()?;
|
||||
for host in all_hosts(db) {
|
||||
host?.update_addresses(info, &ports)?;
|
||||
host?.update_addresses(&hostname, info, &ports)?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
|
||||
@@ -10,6 +10,7 @@ use ts_rs::TS;
|
||||
use crate::GatewayId;
|
||||
use crate::context::{CliContext, RpcContext};
|
||||
use crate::db::model::DatabaseModel;
|
||||
use crate::hostname::Hostname;
|
||||
use crate::net::acme::AcmeProvider;
|
||||
use crate::net::host::{HostApiKind, all_hosts};
|
||||
use crate::prelude::*;
|
||||
@@ -194,9 +195,10 @@ pub async fn add_public_domain<Kind: HostApiKind>(
|
||||
.as_public_domains_mut()
|
||||
.insert(&fqdn, &PublicDomainConfig { acme, gateway })?;
|
||||
handle_duplicates(db)?;
|
||||
let hostname = Hostname(db.as_public().as_server_info().as_hostname().de()?);
|
||||
let gateways = db.as_public().as_server_info().as_network().as_gateways().de()?;
|
||||
let ports = db.as_private().as_available_ports().de()?;
|
||||
Kind::host_for(&inheritance, db)?.update_addresses(&gateways, &ports)
|
||||
Kind::host_for(&inheritance, db)?.update_addresses(&hostname, &gateways, &ports)
|
||||
})
|
||||
.await
|
||||
.result?;
|
||||
@@ -225,9 +227,10 @@ pub async fn remove_public_domain<Kind: HostApiKind>(
|
||||
Kind::host_for(&inheritance, db)?
|
||||
.as_public_domains_mut()
|
||||
.remove(&fqdn)?;
|
||||
let hostname = Hostname(db.as_public().as_server_info().as_hostname().de()?);
|
||||
let gateways = db.as_public().as_server_info().as_network().as_gateways().de()?;
|
||||
let ports = db.as_private().as_available_ports().de()?;
|
||||
Kind::host_for(&inheritance, db)?.update_addresses(&gateways, &ports)
|
||||
Kind::host_for(&inheritance, db)?.update_addresses(&hostname, &gateways, &ports)
|
||||
})
|
||||
.await
|
||||
.result?;
|
||||
@@ -255,9 +258,10 @@ pub async fn add_private_domain<Kind: HostApiKind>(
|
||||
.upsert(&fqdn, || Ok(BTreeSet::new()))?
|
||||
.mutate(|d| Ok(d.insert(gateway)))?;
|
||||
handle_duplicates(db)?;
|
||||
let hostname = Hostname(db.as_public().as_server_info().as_hostname().de()?);
|
||||
let gateways = db.as_public().as_server_info().as_network().as_gateways().de()?;
|
||||
let ports = db.as_private().as_available_ports().de()?;
|
||||
Kind::host_for(&inheritance, db)?.update_addresses(&gateways, &ports)
|
||||
Kind::host_for(&inheritance, db)?.update_addresses(&hostname, &gateways, &ports)
|
||||
})
|
||||
.await
|
||||
.result?;
|
||||
@@ -276,9 +280,10 @@ pub async fn remove_private_domain<Kind: HostApiKind>(
|
||||
Kind::host_for(&inheritance, db)?
|
||||
.as_private_domains_mut()
|
||||
.mutate(|d| Ok(d.remove(&domain)))?;
|
||||
let hostname = Hostname(db.as_public().as_server_info().as_hostname().de()?);
|
||||
let gateways = db.as_public().as_server_info().as_network().as_gateways().de()?;
|
||||
let ports = db.as_private().as_available_ports().de()?;
|
||||
Kind::host_for(&inheritance, db)?.update_addresses(&gateways, &ports)
|
||||
Kind::host_for(&inheritance, db)?.update_addresses(&hostname, &gateways, &ports)
|
||||
})
|
||||
.await
|
||||
.result?;
|
||||
|
||||
@@ -13,7 +13,8 @@ use ts_rs::TS;
|
||||
|
||||
use crate::context::RpcContext;
|
||||
use crate::db::model::DatabaseModel;
|
||||
use crate::db::model::public::NetworkInterfaceInfo;
|
||||
use crate::db::model::public::{NetworkInterfaceInfo, NetworkInterfaceType};
|
||||
use crate::hostname::Hostname;
|
||||
use crate::net::forward::AvailablePorts;
|
||||
use crate::net::host::address::{HostAddress, PublicDomainConfig, address_api};
|
||||
use crate::net::host::binding::{BindInfo, BindOptions, Bindings, binding};
|
||||
@@ -66,10 +67,13 @@ impl Host {
|
||||
impl Model<Host> {
|
||||
pub fn update_addresses(
|
||||
&mut self,
|
||||
mdns: &Hostname,
|
||||
gateways: &OrdMap<GatewayId, NetworkInterfaceInfo>,
|
||||
available_ports: &AvailablePorts,
|
||||
) -> Result<(), Error> {
|
||||
let this = self.destructure_mut();
|
||||
|
||||
// ips
|
||||
for (_, bind) in this.bindings.as_entries_mut()? {
|
||||
let net = bind.as_net().de()?;
|
||||
let opt = bind.as_options().de()?;
|
||||
@@ -143,6 +147,46 @@ impl Model<Host> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// mdns
|
||||
let mdns_host = mdns.local_domain_name();
|
||||
let mdns_gateways: BTreeSet<GatewayId> = gateways
|
||||
.iter()
|
||||
.filter(|(_, g)| {
|
||||
matches!(
|
||||
g.ip_info.as_ref().and_then(|i| i.device_type),
|
||||
Some(NetworkInterfaceType::Ethernet | NetworkInterfaceType::Wireless)
|
||||
)
|
||||
})
|
||||
.map(|(id, _)| id.clone())
|
||||
.collect();
|
||||
if let Some(port) = net.assigned_port.filter(|_| {
|
||||
opt.secure
|
||||
.map_or(true, |s| !(s.ssl && opt.add_ssl.is_some()))
|
||||
}) {
|
||||
available.insert(HostnameInfo {
|
||||
ssl: opt.secure.map_or(false, |s| s.ssl),
|
||||
public: false,
|
||||
host: mdns_host.clone(),
|
||||
port: Some(port),
|
||||
metadata: HostnameMetadata::Mdns {
|
||||
gateways: mdns_gateways.clone(),
|
||||
},
|
||||
});
|
||||
}
|
||||
if let Some(mut port) = net.assigned_ssl_port {
|
||||
available.insert(HostnameInfo {
|
||||
ssl: true,
|
||||
public: false,
|
||||
host: mdns_host,
|
||||
port: Some(port),
|
||||
metadata: HostnameMetadata::Mdns {
|
||||
gateways: mdns_gateways,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// public domains
|
||||
for (domain, info) in this.public_domains.de()? {
|
||||
let metadata = HostnameMetadata::PublicDomain {
|
||||
gateway: info.gateway.clone(),
|
||||
@@ -173,12 +217,14 @@ impl Model<Host> {
|
||||
available.insert(HostnameInfo {
|
||||
ssl: true,
|
||||
public: true,
|
||||
host: domain.clone(),
|
||||
host: domain,
|
||||
port: Some(port),
|
||||
metadata,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// private domains
|
||||
for (domain, domain_gateways) in this.private_domains.de()? {
|
||||
if let Some(port) = net.assigned_port.filter(|_| {
|
||||
opt.secure
|
||||
@@ -213,7 +259,7 @@ impl Model<Host> {
|
||||
available.insert(HostnameInfo {
|
||||
ssl: true,
|
||||
public: true,
|
||||
host: domain.clone(),
|
||||
host: domain,
|
||||
port: Some(port),
|
||||
metadata: HostnameMetadata::PrivateDomain {
|
||||
gateways: domain_gateways,
|
||||
|
||||
@@ -539,10 +539,11 @@ impl NetService {
|
||||
.as_network()
|
||||
.as_gateways()
|
||||
.de()?;
|
||||
let hostname = Hostname(db.as_public().as_server_info().as_hostname().de()?);
|
||||
let mut ports = db.as_private().as_available_ports().de()?;
|
||||
let host = host_for(db, pkg_id.as_ref(), &id)?;
|
||||
host.add_binding(&mut ports, internal_port, options)?;
|
||||
host.update_addresses(&gateways, &ports)?;
|
||||
host.update_addresses(&hostname, &gateways, &ports)?;
|
||||
db.as_private_mut().as_available_ports_mut().ser(&ports)?;
|
||||
Ok(())
|
||||
})
|
||||
@@ -563,6 +564,7 @@ impl NetService {
|
||||
.as_network()
|
||||
.as_gateways()
|
||||
.de()?;
|
||||
let hostname = Hostname(db.as_public().as_server_info().as_hostname().de()?);
|
||||
let ports = db.as_private().as_available_ports().de()?;
|
||||
if let Some(ref pkg_id) = pkg_id {
|
||||
for (host_id, host) in db
|
||||
@@ -584,7 +586,7 @@ impl NetService {
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
host.update_addresses(&gateways, &ports)?;
|
||||
host.update_addresses(&hostname, &gateways, &ports)?;
|
||||
}
|
||||
} else {
|
||||
let host = db
|
||||
@@ -603,7 +605,7 @@ impl NetService {
|
||||
}
|
||||
Ok(())
|
||||
})?;
|
||||
host.update_addresses(&gateways, &ports)?;
|
||||
host.update_addresses(&hostname, &gateways, &ports)?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
|
||||
@@ -32,6 +32,9 @@ pub enum HostnameMetadata {
|
||||
gateway: GatewayId,
|
||||
scope_id: u32,
|
||||
},
|
||||
Mdns {
|
||||
gateways: BTreeSet<GatewayId>,
|
||||
},
|
||||
PrivateDomain {
|
||||
gateways: BTreeSet<GatewayId>,
|
||||
},
|
||||
@@ -67,7 +70,9 @@ impl HostnameMetadata {
|
||||
Self::Ipv4 { gateway }
|
||||
| Self::Ipv6 { gateway, .. }
|
||||
| Self::PublicDomain { gateway } => Box::new(std::iter::once(gateway)),
|
||||
Self::PrivateDomain { gateways } => Box::new(gateways.iter()),
|
||||
Self::PrivateDomain { gateways } | Self::Mdns { gateways } => {
|
||||
Box::new(gateways.iter())
|
||||
}
|
||||
Self::Plugin { .. } => Box::new(std::iter::empty()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,13 +175,14 @@ pub async fn remove_tunnel(
|
||||
|
||||
ctx.db
|
||||
.mutate(|db| {
|
||||
let hostname = crate::hostname::Hostname(db.as_public().as_server_info().as_hostname().de()?);
|
||||
let gateways = db.as_public().as_server_info().as_network().as_gateways().de()?;
|
||||
let ports = db.as_private().as_available_ports().de()?;
|
||||
for host in all_hosts(db) {
|
||||
let host = host?;
|
||||
host.as_public_domains_mut()
|
||||
.mutate(|p| Ok(p.retain(|_, v| v.gateway != id)))?;
|
||||
host.update_addresses(&gateways, &ports)?;
|
||||
host.update_addresses(&hostname, &gateways, &ports)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -193,6 +194,7 @@ pub async fn remove_tunnel(
|
||||
|
||||
ctx.db
|
||||
.mutate(|db| {
|
||||
let hostname = crate::hostname::Hostname(db.as_public().as_server_info().as_hostname().de()?);
|
||||
let gateways = db.as_public().as_server_info().as_network().as_gateways().de()?;
|
||||
let ports = db.as_private().as_available_ports().de()?;
|
||||
for host in all_hosts(db) {
|
||||
@@ -204,7 +206,7 @@ pub async fn remove_tunnel(
|
||||
d.retain(|_, gateways| !gateways.is_empty());
|
||||
Ok(())
|
||||
})?;
|
||||
host.update_addresses(&gateways, &ports)?;
|
||||
host.update_addresses(&hostname, &gateways, &ports)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -278,8 +278,7 @@ impl Accept for VHostBindListener {
|
||||
cx: &mut std::task::Context<'_>,
|
||||
) -> Poll<Result<(Self::Metadata, AcceptStream), Error>> {
|
||||
// Update listeners when ip_info or bind_reqs change
|
||||
while self.ip_info.poll_changed(cx).is_ready()
|
||||
|| self.bind_reqs.poll_changed(cx).is_ready()
|
||||
while self.ip_info.poll_changed(cx).is_ready() || self.bind_reqs.poll_changed(cx).is_ready()
|
||||
{
|
||||
let reqs = self.bind_reqs.read_and_mark_seen();
|
||||
let listeners = &mut self.listeners;
|
||||
@@ -506,10 +505,8 @@ where
|
||||
};
|
||||
|
||||
let src = tcp.peer_addr.ip();
|
||||
// Public if: source is a gateway/router IP (NAT'd internet),
|
||||
// or source is outside all known subnets (direct internet)
|
||||
let is_public = ip_info.lan_ip.contains(&src)
|
||||
|| !ip_info.subnets.iter().any(|s| s.contains(&src));
|
||||
// Public: source is outside all known subnets (direct internet)
|
||||
let is_public = !ip_info.subnets.iter().any(|s| s.contains(&src));
|
||||
|
||||
if is_public {
|
||||
self.public.contains(&gw.id)
|
||||
@@ -695,6 +692,7 @@ where
|
||||
|
||||
let (target, rc) = self.0.peek(|m| {
|
||||
m.get(&hello.server_name().map(InternedString::from))
|
||||
.or_else(|| m.get(&None))
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter(|(_, rc)| rc.strong_count() > 0)
|
||||
|
||||
@@ -240,7 +240,7 @@ impl LocaleString {
|
||||
pub fn localize(&mut self) {
|
||||
self.localize_for(&*rust_i18n::locale());
|
||||
}
|
||||
pub fn localized(mut self) -> String {
|
||||
pub fn localized(self) -> String {
|
||||
self.localized_for(&*rust_i18n::locale())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user