mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-28 11:36:32 +00:00
Merge bbb361fead9cced0c6db3f23353822e995a16047 into 606db3585cb07a7e04a309fbfd540403da1a4e86
This commit is contained in:
commit
90d9ff4040
@ -24,7 +24,9 @@ from ..const import (
|
||||
ATTR_INTERFACES,
|
||||
ATTR_IPV4,
|
||||
ATTR_IPV6,
|
||||
ATTR_LLMNR,
|
||||
ATTR_MAC,
|
||||
ATTR_MDNS,
|
||||
ATTR_METHOD,
|
||||
ATTR_MODE,
|
||||
ATTR_NAMESERVERS,
|
||||
@ -49,6 +51,7 @@ from ..host.configuration import (
|
||||
InterfaceMethod,
|
||||
IpConfig,
|
||||
IpSetting,
|
||||
MulticastDnsMode,
|
||||
VlanConfig,
|
||||
WifiConfig,
|
||||
)
|
||||
@ -90,6 +93,8 @@ SCHEMA_UPDATE = vol.Schema(
|
||||
vol.Optional(ATTR_IPV6): _SCHEMA_IPV6_CONFIG,
|
||||
vol.Optional(ATTR_WIFI): _SCHEMA_WIFI_CONFIG,
|
||||
vol.Optional(ATTR_ENABLED): vol.Boolean(),
|
||||
vol.Optional(ATTR_MDNS): vol.Coerce(MulticastDnsMode),
|
||||
vol.Optional(ATTR_LLMNR): vol.Coerce(MulticastDnsMode),
|
||||
}
|
||||
)
|
||||
|
||||
@ -136,6 +141,8 @@ def interface_struct(interface: Interface) -> dict[str, Any]:
|
||||
ATTR_IPV6: ipconfig_struct(interface.ipv6, interface.ipv6setting),
|
||||
ATTR_WIFI: wifi_struct(interface.wifi) if interface.wifi else None,
|
||||
ATTR_VLAN: vlan_struct(interface.vlan) if interface.vlan else None,
|
||||
ATTR_MDNS: interface.mdns,
|
||||
ATTR_LLMNR: interface.llmnr,
|
||||
}
|
||||
|
||||
|
||||
@ -230,6 +237,10 @@ class APINetwork(CoreSysAttributes):
|
||||
)
|
||||
elif key == ATTR_ENABLED:
|
||||
interface.enabled = config
|
||||
elif key == ATTR_MDNS:
|
||||
interface.mdns = config
|
||||
elif key == ATTR_LLMNR:
|
||||
interface.llmnr = config
|
||||
|
||||
await asyncio.shield(self.sys_host.network.apply_changes(interface))
|
||||
|
||||
|
@ -228,6 +228,7 @@ ATTR_KERNEL_MODULES = "kernel_modules"
|
||||
ATTR_LABELS = "labels"
|
||||
ATTR_LAST_BOOT = "last_boot"
|
||||
ATTR_LEGACY = "legacy"
|
||||
ATTR_LLMNR = "llmnr"
|
||||
ATTR_LOCALS = "locals"
|
||||
ATTR_LOCATION = "location"
|
||||
ATTR_LOGGING = "logging"
|
||||
@ -237,6 +238,7 @@ ATTR_MAC = "mac"
|
||||
ATTR_MACHINE = "machine"
|
||||
ATTR_MAINTAINER = "maintainer"
|
||||
ATTR_MAP = "map"
|
||||
ATTR_MDNS = "mdns"
|
||||
ATTR_MEMORY_LIMIT = "memory_limit"
|
||||
ATTR_MEMORY_PERCENT = "memory_percent"
|
||||
ATTR_MEMORY_USAGE = "memory_usage"
|
||||
|
@ -296,6 +296,14 @@ class MulticastProtocolEnabled(StrEnum):
|
||||
RESOLVE = "resolve"
|
||||
|
||||
|
||||
class MulticastDnsValue(IntEnum):
|
||||
"""Connection MulticastDNS (mdns/llmnr) values."""
|
||||
|
||||
OFF = 0
|
||||
RESOLVE = 1
|
||||
ANNOUNCE = 2
|
||||
|
||||
|
||||
class DNSOverTLSEnabled(StrEnum):
|
||||
"""DNS over TLS enabled."""
|
||||
|
||||
|
@ -23,6 +23,8 @@ class ConnectionProperties:
|
||||
uuid: str | None
|
||||
type: str | None
|
||||
interface_name: str | None
|
||||
mdns: int | None
|
||||
llmnr: int | None
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
|
@ -219,6 +219,8 @@ class NetworkSetting(DBusInterface):
|
||||
data[CONF_ATTR_CONNECTION].get(CONF_ATTR_CONNECTION_UUID),
|
||||
data[CONF_ATTR_CONNECTION].get(CONF_ATTR_CONNECTION_TYPE),
|
||||
data[CONF_ATTR_CONNECTION].get(CONF_ATTR_CONNECTION_INTERFACE_NAME),
|
||||
data[CONF_ATTR_CONNECTION].get(CONF_ATTR_CONNECTION_MDNS),
|
||||
data[CONF_ATTR_CONNECTION].get(CONF_ATTR_CONNECTION_LLMNR),
|
||||
)
|
||||
|
||||
if CONF_ATTR_802_ETHERNET in data:
|
||||
|
@ -8,7 +8,8 @@ from uuid import uuid4
|
||||
|
||||
from dbus_fast import Variant
|
||||
|
||||
from ....host.const import InterfaceMethod, InterfaceType
|
||||
from ....host.const import InterfaceMethod, InterfaceType, MulticastDnsMode
|
||||
from ...const import MulticastDnsValue
|
||||
from .. import NetworkManager
|
||||
from . import (
|
||||
CONF_ATTR_802_ETHERNET,
|
||||
@ -133,6 +134,16 @@ def _get_ipv6_connection_settings(ipv6setting) -> dict:
|
||||
return ipv6
|
||||
|
||||
|
||||
def _map_mdns_setting(mode: MulticastDnsMode | None) -> int:
|
||||
mapping = {
|
||||
MulticastDnsMode.OFF: MulticastDnsValue.OFF,
|
||||
MulticastDnsMode.RESOLVE: MulticastDnsValue.RESOLVE,
|
||||
MulticastDnsMode.ANNOUNCE: MulticastDnsValue.ANNOUNCE,
|
||||
}
|
||||
|
||||
return int(mapping[mode] if mode else MulticastDnsValue.ANNOUNCE)
|
||||
|
||||
|
||||
def get_connection_from_interface(
|
||||
interface: Interface,
|
||||
network_manager: NetworkManager,
|
||||
@ -158,13 +169,16 @@ def get_connection_from_interface(
|
||||
if not uuid:
|
||||
uuid = str(uuid4())
|
||||
|
||||
llmnr = _map_mdns_setting(interface.llmnr)
|
||||
mdns = _map_mdns_setting(interface.mdns)
|
||||
|
||||
conn: dict[str, dict[str, Variant]] = {
|
||||
CONF_ATTR_CONNECTION: {
|
||||
CONF_ATTR_CONNECTION_ID: Variant("s", name),
|
||||
CONF_ATTR_CONNECTION_UUID: Variant("s", uuid),
|
||||
CONF_ATTR_CONNECTION_TYPE: Variant("s", iftype),
|
||||
CONF_ATTR_CONNECTION_LLMNR: Variant("i", 2),
|
||||
CONF_ATTR_CONNECTION_MDNS: Variant("i", 2),
|
||||
CONF_ATTR_CONNECTION_LLMNR: Variant("i", llmnr),
|
||||
CONF_ATTR_CONNECTION_MDNS: Variant("i", mdns),
|
||||
CONF_ATTR_CONNECTION_AUTOCONNECT: Variant("b", True),
|
||||
},
|
||||
}
|
||||
|
@ -9,10 +9,17 @@ from ..dbus.const import (
|
||||
ConnectionStateType,
|
||||
DeviceType,
|
||||
InterfaceMethod as NMInterfaceMethod,
|
||||
MulticastDnsValue,
|
||||
)
|
||||
from ..dbus.network.connection import NetworkConnection
|
||||
from ..dbus.network.interface import NetworkInterface
|
||||
from .const import AuthMethod, InterfaceMethod, InterfaceType, WifiMode
|
||||
from .const import (
|
||||
AuthMethod,
|
||||
InterfaceMethod,
|
||||
InterfaceType,
|
||||
MulticastDnsMode,
|
||||
WifiMode,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
@ -82,6 +89,8 @@ class Interface:
|
||||
ipv6setting: IpSetting | None
|
||||
wifi: WifiConfig | None
|
||||
vlan: VlanConfig | None
|
||||
mdns: MulticastDnsMode | None
|
||||
llmnr: MulticastDnsMode | None
|
||||
|
||||
def equals_dbus_interface(self, inet: NetworkInterface) -> bool:
|
||||
"""Return true if this represents the dbus interface."""
|
||||
@ -145,6 +154,13 @@ class Interface:
|
||||
and ConnectionStateFlags.IP6_READY in inet.connection.state_flags
|
||||
)
|
||||
|
||||
if inet.settings and inet.settings.connection:
|
||||
mdns = inet.settings.connection.mdns
|
||||
llmnr = inet.settings.connection.llmnr
|
||||
else:
|
||||
mdns = None
|
||||
llmnr = None
|
||||
|
||||
return Interface(
|
||||
inet.name,
|
||||
inet.hw_address,
|
||||
@ -181,6 +197,8 @@ class Interface:
|
||||
ipv6_setting,
|
||||
Interface._map_nm_wifi(inet),
|
||||
Interface._map_nm_vlan(inet),
|
||||
Interface._map_nm_multicast_dns(mdns),
|
||||
Interface._map_nm_multicast_dns(llmnr),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
@ -258,3 +276,13 @@ class Interface:
|
||||
return None
|
||||
|
||||
return VlanConfig(inet.settings.vlan.id, inet.settings.vlan.parent)
|
||||
|
||||
@staticmethod
|
||||
def _map_nm_multicast_dns(mode: int | None) -> MulticastDnsMode | None:
|
||||
mapping = {
|
||||
MulticastDnsValue.OFF: MulticastDnsMode.OFF,
|
||||
MulticastDnsValue.RESOLVE: MulticastDnsMode.RESOLVE,
|
||||
MulticastDnsValue.ANNOUNCE: MulticastDnsMode.ANNOUNCE,
|
||||
}
|
||||
|
||||
return mapping[mode]
|
||||
|
@ -70,3 +70,11 @@ class LogFormatter(StrEnum):
|
||||
|
||||
PLAIN = "plain"
|
||||
VERBOSE = "verbose"
|
||||
|
||||
|
||||
class MulticastDnsMode(StrEnum):
|
||||
"""Multicast DNS (MDNS/LLMNR) mode."""
|
||||
|
||||
OFF = "off"
|
||||
RESOLVE = "resolve"
|
||||
ANNOUNCE = "announce"
|
||||
|
Loading…
x
Reference in New Issue
Block a user