mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 10:21:52 +00:00
add more gateway info to hostnameInfo (#3019)
This commit is contained in:
@@ -14,12 +14,14 @@ impl GatewayId {
|
||||
&*self.0
|
||||
}
|
||||
}
|
||||
impl<T> From<T> for GatewayId
|
||||
where
|
||||
T: Into<InternedString>,
|
||||
{
|
||||
fn from(value: T) -> Self {
|
||||
Self(value.into())
|
||||
impl From<InternedString> for GatewayId {
|
||||
fn from(value: InternedString) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
impl From<GatewayId> for InternedString {
|
||||
fn from(value: GatewayId) -> Self {
|
||||
value.0
|
||||
}
|
||||
}
|
||||
impl FromStr for GatewayId {
|
||||
|
||||
@@ -219,7 +219,7 @@ pub struct NetworkInterfaceInfo {
|
||||
impl NetworkInterfaceInfo {
|
||||
pub fn loopback() -> (&'static GatewayId, &'static Self) {
|
||||
lazy_static! {
|
||||
static ref LO: GatewayId = GatewayId::from("lo");
|
||||
static ref LO: GatewayId = GatewayId::from(InternedString::intern("lo"));
|
||||
static ref LOOPBACK: NetworkInterfaceInfo = NetworkInterfaceInfo {
|
||||
name: Some(InternedString::from_static("Loopback")),
|
||||
public: Some(false),
|
||||
@@ -250,7 +250,8 @@ impl NetworkInterfaceInfo {
|
||||
}
|
||||
pub fn lxc_bridge() -> (&'static GatewayId, &'static Self) {
|
||||
lazy_static! {
|
||||
static ref LXCBR0: GatewayId = GatewayId::from(START9_BRIDGE_IFACE);
|
||||
static ref LXCBR0: GatewayId =
|
||||
GatewayId::from(InternedString::intern(START9_BRIDGE_IFACE));
|
||||
static ref LXC_BRIDGE: NetworkInterfaceInfo = NetworkInterfaceInfo {
|
||||
name: Some(InternedString::from_static("LXC Bridge Interface")),
|
||||
public: Some(false),
|
||||
|
||||
@@ -982,7 +982,7 @@ impl NetworkInterfaceController {
|
||||
info
|
||||
}
|
||||
},
|
||||
[START9_BRIDGE_IFACE.into()],
|
||||
[InternedString::from_static(START9_BRIDGE_IFACE).into()],
|
||||
);
|
||||
let mut ip_info_watch = watcher.subscribe();
|
||||
ip_info_watch.mark_seen();
|
||||
|
||||
@@ -24,7 +24,7 @@ use crate::net::gateway::{
|
||||
use crate::net::host::address::HostAddress;
|
||||
use crate::net::host::binding::{AddSslOptions, BindId, BindOptions};
|
||||
use crate::net::host::{host_for, Host, Hosts};
|
||||
use crate::net::service_interface::{HostnameInfo, IpHostname, OnionHostname};
|
||||
use crate::net::service_interface::{GatewayInfo, HostnameInfo, IpHostname, OnionHostname};
|
||||
use crate::net::socks::SocksController;
|
||||
use crate::net::tor::{OnionAddress, TorController, TorSecretKey};
|
||||
use crate::net::utils::ipv6_is_local;
|
||||
@@ -427,10 +427,19 @@ impl NetServiceData {
|
||||
}
|
||||
let mut bind_hostname_info: Vec<HostnameInfo> =
|
||||
hostname_info.remove(port).unwrap_or_default();
|
||||
for (interface, info) in net_ifaces
|
||||
for (gateway_id, info) in net_ifaces
|
||||
.iter()
|
||||
.filter(|(id, info)| bind.net.filter(id, info))
|
||||
{
|
||||
let gateway = GatewayInfo {
|
||||
id: gateway_id.clone(),
|
||||
name: info
|
||||
.name
|
||||
.clone()
|
||||
.or_else(|| info.ip_info.as_ref().map(|i| i.name.clone()))
|
||||
.unwrap_or_else(|| gateway_id.clone().into()),
|
||||
public: info.public(),
|
||||
};
|
||||
let port = bind.net.assigned_port.filter(|_| {
|
||||
bind.options.secure.map_or(false, |s| {
|
||||
!(s.ssl && bind.options.add_ssl.is_some()) || info.secure()
|
||||
@@ -442,7 +451,7 @@ impl NetServiceData {
|
||||
})
|
||||
{
|
||||
bind_hostname_info.push(HostnameInfo::Ip {
|
||||
gateway_id: interface.clone(),
|
||||
gateway: gateway.clone(),
|
||||
public: false,
|
||||
hostname: IpHostname::Local {
|
||||
value: InternedString::from_display(&{
|
||||
@@ -462,7 +471,8 @@ impl NetServiceData {
|
||||
} = address
|
||||
{
|
||||
let private = private && !info.public();
|
||||
let public = public.as_ref().map_or(false, |p| &p.gateway == interface);
|
||||
let public =
|
||||
public.as_ref().map_or(false, |p| &p.gateway == gateway_id);
|
||||
if public || private {
|
||||
if bind
|
||||
.options
|
||||
@@ -471,7 +481,7 @@ impl NetServiceData {
|
||||
.map_or(false, |ssl| ssl.preferred_external_port == 443)
|
||||
{
|
||||
bind_hostname_info.push(HostnameInfo::Ip {
|
||||
gateway_id: interface.clone(),
|
||||
gateway: gateway.clone(),
|
||||
public,
|
||||
hostname: IpHostname::Domain {
|
||||
value: address.clone(),
|
||||
@@ -481,7 +491,7 @@ impl NetServiceData {
|
||||
});
|
||||
} else {
|
||||
bind_hostname_info.push(HostnameInfo::Ip {
|
||||
gateway_id: interface.clone(),
|
||||
gateway: gateway.clone(),
|
||||
public,
|
||||
hostname: IpHostname::Domain {
|
||||
value: address.clone(),
|
||||
@@ -497,7 +507,7 @@ impl NetServiceData {
|
||||
let public = info.public();
|
||||
if let Some(wan_ip) = ip_info.wan_ip {
|
||||
bind_hostname_info.push(HostnameInfo::Ip {
|
||||
gateway_id: interface.clone(),
|
||||
gateway: gateway.clone(),
|
||||
public: true,
|
||||
hostname: IpHostname::Ipv4 {
|
||||
value: wan_ip,
|
||||
@@ -511,7 +521,7 @@ impl NetServiceData {
|
||||
IpNet::V4(net) => {
|
||||
if !public {
|
||||
bind_hostname_info.push(HostnameInfo::Ip {
|
||||
gateway_id: interface.clone(),
|
||||
gateway: gateway.clone(),
|
||||
public,
|
||||
hostname: IpHostname::Ipv4 {
|
||||
value: net.addr(),
|
||||
@@ -523,7 +533,7 @@ impl NetServiceData {
|
||||
}
|
||||
IpNet::V6(net) => {
|
||||
bind_hostname_info.push(HostnameInfo::Ip {
|
||||
gateway_id: interface.clone(),
|
||||
gateway: gateway.clone(),
|
||||
public: public && !ipv6_is_local(net.addr()),
|
||||
hostname: IpHostname::Ipv6 {
|
||||
value: net.addr(),
|
||||
|
||||
@@ -12,8 +12,7 @@ use ts_rs::TS;
|
||||
#[serde(tag = "kind")]
|
||||
pub enum HostnameInfo {
|
||||
Ip {
|
||||
#[ts(type = "string")]
|
||||
gateway_id: GatewayId,
|
||||
gateway: GatewayInfo,
|
||||
public: bool,
|
||||
hostname: IpHostname,
|
||||
},
|
||||
@@ -30,6 +29,15 @@ impl HostnameInfo {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, TS)]
|
||||
#[ts(export)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GatewayInfo {
|
||||
pub id: GatewayId,
|
||||
pub name: InternedString,
|
||||
pub public: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, TS)]
|
||||
#[ts(export)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
|
||||
@@ -47,7 +47,7 @@ pub async fn add_tunnel(
|
||||
}: AddTunnelParams,
|
||||
) -> Result<GatewayId, Error> {
|
||||
let ifaces = ctx.net_controller.net_iface.watcher.subscribe();
|
||||
let mut iface = GatewayId::from("wg0");
|
||||
let mut iface = GatewayId::from(InternedString::intern("wg0"));
|
||||
if !ifaces.send_if_modified(|i| {
|
||||
for id in 1..256 {
|
||||
if !i.contains_key(&iface) {
|
||||
|
||||
@@ -6,7 +6,7 @@ use models::GatewayId;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::v0_3_5::V0_3_0_COMPAT;
|
||||
use super::{VersionT, v0_3_6_alpha_9};
|
||||
use super::{v0_3_6_alpha_9, VersionT};
|
||||
use crate::net::host::address::PublicDomainConfig;
|
||||
use crate::net::tor::OnionAddress;
|
||||
use crate::prelude::*;
|
||||
@@ -75,7 +75,7 @@ impl VersionT for Version {
|
||||
domains.insert(
|
||||
address.clone(),
|
||||
PublicDomainConfig {
|
||||
gateway: GatewayId::from("lo"),
|
||||
gateway: GatewayId::from(InternedString::intern("lo")),
|
||||
acme: None,
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user