mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
fix .local service resolution
This commit is contained in:
@@ -29,6 +29,7 @@ pub struct PreInitNetController {
|
|||||||
tor: TorController,
|
tor: TorController,
|
||||||
vhost: VHostController,
|
vhost: VHostController,
|
||||||
os_bindings: Vec<Arc<()>>,
|
os_bindings: Vec<Arc<()>>,
|
||||||
|
server_hostnames: Vec<Option<InternedString>>,
|
||||||
}
|
}
|
||||||
impl PreInitNetController {
|
impl PreInitNetController {
|
||||||
#[instrument(skip_all)]
|
#[instrument(skip_all)]
|
||||||
@@ -44,6 +45,7 @@ impl PreInitNetController {
|
|||||||
tor: TorController::new(tor_control, tor_socks),
|
tor: TorController::new(tor_control, tor_socks),
|
||||||
vhost: VHostController::new(db),
|
vhost: VHostController::new(db),
|
||||||
os_bindings: Vec::new(),
|
os_bindings: Vec::new(),
|
||||||
|
server_hostnames: Vec::new(),
|
||||||
};
|
};
|
||||||
res.add_os_bindings(hostname, os_tor_key).await?;
|
res.add_os_bindings(hostname, os_tor_key).await?;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
@@ -59,64 +61,26 @@ impl PreInitNetController {
|
|||||||
MaybeUtf8String("h2".into()),
|
MaybeUtf8String("h2".into()),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
// Internal DNS
|
self.server_hostnames = vec![
|
||||||
self.vhost
|
// LAN IP
|
||||||
.add(
|
None,
|
||||||
Some("embassy".into()),
|
// Internal DNS
|
||||||
443,
|
Some("embassy".into()),
|
||||||
([127, 0, 0, 1], 80).into(),
|
Some("startos".into()),
|
||||||
alpn.clone(),
|
// localhost
|
||||||
)
|
Some("localhost".into()),
|
||||||
.await?;
|
Some(hostname.no_dot_host_name()),
|
||||||
self.vhost
|
// LAN mDNS
|
||||||
.add(
|
Some(hostname.local_domain_name()),
|
||||||
Some("startos".into()),
|
];
|
||||||
443,
|
|
||||||
([127, 0, 0, 1], 80).into(),
|
|
||||||
alpn.clone(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
// LAN IP
|
for hostname in self.server_hostnames.iter().cloned() {
|
||||||
self.os_bindings.push(
|
self.os_bindings.push(
|
||||||
self.vhost
|
self.vhost
|
||||||
.add(None, 443, ([127, 0, 0, 1], 80).into(), alpn.clone())
|
.add(hostname, 443, ([127, 0, 0, 1], 80).into(), alpn.clone())
|
||||||
.await?,
|
.await?,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
// localhost
|
|
||||||
self.os_bindings.push(
|
|
||||||
self.vhost
|
|
||||||
.add(
|
|
||||||
Some("localhost".into()),
|
|
||||||
443,
|
|
||||||
([127, 0, 0, 1], 80).into(),
|
|
||||||
alpn.clone(),
|
|
||||||
)
|
|
||||||
.await?,
|
|
||||||
);
|
|
||||||
self.os_bindings.push(
|
|
||||||
self.vhost
|
|
||||||
.add(
|
|
||||||
Some(hostname.no_dot_host_name()),
|
|
||||||
443,
|
|
||||||
([127, 0, 0, 1], 80).into(),
|
|
||||||
alpn.clone(),
|
|
||||||
)
|
|
||||||
.await?,
|
|
||||||
);
|
|
||||||
|
|
||||||
// LAN mDNS
|
|
||||||
self.os_bindings.push(
|
|
||||||
self.vhost
|
|
||||||
.add(
|
|
||||||
Some(hostname.local_domain_name()),
|
|
||||||
443,
|
|
||||||
([127, 0, 0, 1], 80).into(),
|
|
||||||
alpn.clone(),
|
|
||||||
)
|
|
||||||
.await?,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Tor
|
// Tor
|
||||||
self.os_bindings.push(
|
self.os_bindings.push(
|
||||||
@@ -154,6 +118,7 @@ pub struct NetController {
|
|||||||
pub(super) dns: DnsController,
|
pub(super) dns: DnsController,
|
||||||
pub(super) forward: LanPortForwardController,
|
pub(super) forward: LanPortForwardController,
|
||||||
pub(super) os_bindings: Vec<Arc<()>>,
|
pub(super) os_bindings: Vec<Arc<()>>,
|
||||||
|
pub(super) server_hostnames: Vec<Option<InternedString>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NetController {
|
impl NetController {
|
||||||
@@ -163,6 +128,7 @@ impl NetController {
|
|||||||
tor,
|
tor,
|
||||||
vhost,
|
vhost,
|
||||||
os_bindings,
|
os_bindings,
|
||||||
|
server_hostnames,
|
||||||
}: PreInitNetController,
|
}: PreInitNetController,
|
||||||
dns_bind: &[SocketAddr],
|
dns_bind: &[SocketAddr],
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
@@ -173,6 +139,7 @@ impl NetController {
|
|||||||
dns: DnsController::init(dns_bind).await?,
|
dns: DnsController::init(dns_bind).await?,
|
||||||
forward: LanPortForwardController::new(),
|
forward: LanPortForwardController::new(),
|
||||||
os_bindings,
|
os_bindings,
|
||||||
|
server_hostnames,
|
||||||
};
|
};
|
||||||
res.os_bindings
|
res.os_bindings
|
||||||
.push(res.dns.add(None, HOST_IP.into()).await?);
|
.push(res.dns.add(None, HOST_IP.into()).await?);
|
||||||
@@ -258,10 +225,15 @@ impl NetService {
|
|||||||
let ctrl = self.net_controller()?;
|
let ctrl = self.net_controller()?;
|
||||||
let mut errors = ErrorCollection::new();
|
let mut errors = ErrorCollection::new();
|
||||||
for (_, binds) in std::mem::take(&mut self.binds) {
|
for (_, binds) in std::mem::take(&mut self.binds) {
|
||||||
for (_, (lan, _, _, rc)) in binds.lan {
|
for (_, (lan, _, hostnames, rc)) in binds.lan {
|
||||||
drop(rc);
|
drop(rc);
|
||||||
if let Some(external) = lan.assigned_ssl_port {
|
if let Some(external) = lan.assigned_ssl_port {
|
||||||
ctrl.vhost.gc(None, external).await?;
|
for hostname in ctrl.server_hostnames.iter().cloned() {
|
||||||
|
ctrl.vhost.gc(hostname, external).await?;
|
||||||
|
}
|
||||||
|
for hostname in hostnames {
|
||||||
|
ctrl.vhost.gc(Some(hostname), external).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(external) = lan.assigned_port {
|
if let Some(external) = lan.assigned_port {
|
||||||
ctrl.forward.gc(external).await?;
|
ctrl.forward.gc(external).await?;
|
||||||
@@ -317,11 +289,13 @@ impl NetService {
|
|||||||
Err(AlpnInfo::Reflect)
|
Err(AlpnInfo::Reflect)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
rcs.push(
|
for hostname in ctrl.server_hostnames.iter().cloned() {
|
||||||
ctrl.vhost
|
rcs.push(
|
||||||
.add(None, external, target, connect_ssl.clone())
|
ctrl.vhost
|
||||||
.await?,
|
.add(hostname, external, target, connect_ssl.clone())
|
||||||
);
|
.await?,
|
||||||
|
);
|
||||||
|
}
|
||||||
for address in host.addresses() {
|
for address in host.addresses() {
|
||||||
match address {
|
match address {
|
||||||
HostAddress::Onion { address } => {
|
HostAddress::Onion { address } => {
|
||||||
@@ -407,7 +381,9 @@ impl NetService {
|
|||||||
}
|
}
|
||||||
if let Some((lan, _, hostnames, _)) = old_lan_bind {
|
if let Some((lan, _, hostnames, _)) = old_lan_bind {
|
||||||
if let Some(external) = lan.assigned_ssl_port {
|
if let Some(external) = lan.assigned_ssl_port {
|
||||||
ctrl.vhost.gc(None, external).await?;
|
for hostname in ctrl.server_hostnames.iter().cloned() {
|
||||||
|
ctrl.vhost.gc(hostname, external).await?;
|
||||||
|
}
|
||||||
for hostname in hostnames {
|
for hostname in hostnames {
|
||||||
ctrl.vhost.gc(Some(hostname), external).await?;
|
ctrl.vhost.gc(Some(hostname), external).await?;
|
||||||
}
|
}
|
||||||
@@ -429,7 +405,9 @@ impl NetService {
|
|||||||
});
|
});
|
||||||
for (lan, hostnames) in removed {
|
for (lan, hostnames) in removed {
|
||||||
if let Some(external) = lan.assigned_ssl_port {
|
if let Some(external) = lan.assigned_ssl_port {
|
||||||
ctrl.vhost.gc(None, external).await?;
|
for hostname in ctrl.server_hostnames.iter().cloned() {
|
||||||
|
ctrl.vhost.gc(hostname, external).await?;
|
||||||
|
}
|
||||||
for hostname in hostnames {
|
for hostname in hostnames {
|
||||||
ctrl.vhost.gc(Some(hostname), external).await?;
|
ctrl.vhost.gc(Some(hostname), external).await?;
|
||||||
}
|
}
|
||||||
@@ -533,7 +511,9 @@ impl NetService {
|
|||||||
pub async fn remove_all(mut self) -> Result<(), Error> {
|
pub async fn remove_all(mut self) -> Result<(), Error> {
|
||||||
self.shutdown = true;
|
self.shutdown = true;
|
||||||
if let Some(ctrl) = Weak::upgrade(&self.controller) {
|
if let Some(ctrl) = Weak::upgrade(&self.controller) {
|
||||||
self.clear_bindings().await
|
self.clear_bindings().await?;
|
||||||
|
drop(ctrl);
|
||||||
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
tracing::warn!("NetService dropped after NetController is shutdown");
|
tracing::warn!("NetService dropped after NetController is shutdown");
|
||||||
Err(Error::new(
|
Err(Error::new(
|
||||||
|
|||||||
Reference in New Issue
Block a user