Add mDNS IP/interface configuration and NetUtils enhancements#331
Add mDNS IP/interface configuration and NetUtils enhancements#331thimo-seitz wants to merge 25 commits intosdeigm:mainfrom
Conversation
Add support for configuring the IP address or network interface to use for Avahi/mDNS publishing. NetUtils: introduce detectIpAddressFromInterface() and listNetworkInterfaceNames() helpers to resolve IPv4 addresses and enumerate interfaces. MDnsAvahi: add config-driven resolution (ip-address, ip-interface), fall back to the service-provided IP, and log warnings when an interface is missing or has no IPv4 address. Update reference.conf to expose new mdns.ip-address and mdns.ip-interface settings.
Bump templating-maven-plugin from 1.0.0 to 3.1.0 in pom.xml. Rename/move Version.java into src/main/java-templates/com/deigmueller/uni_meter/application/ so the template file resides in the package directory (no content changes). Fixes compile failure in eclipse
|
Hi Thimo, thanks for providing this PR. It generally looks great and I will include it when I will find some time (I am currently on vacation). But I think I will move the configuration/detection of the IP-Interface/IP-Address to the basic OutputDevice class instead of MDnsAvahi. The reason for this is, that a) devices like the EcoTracker additionally announce the IP address in the TXT records of the mDNS information. Therefor the OutputDevice has to know the announced IP Address b) configuring the IP Address also makes sense for the MDnsHomeAssistant (ZeroConf) But anyhow thanks for this good input!! |
Hi Stefan, I'm not finished yet, but I'll only be able to work on it at weekends. |
Remove @{argLine}
Centralize announced IP resolution logic into OutputDevice (resolveAnnouncedIpAddress) and remove the old resolvePublishIpAddress from MDnsAvahi. Devices (EcoTracker, ShellyPro3EM) now use getAnnouncedIpAddress() instead of calling NetUtils.detectPrimaryIpAddress() directly. MDnsAvahi no longer keeps configured ip/interface fields and uses the RegisterService IP when publishing; avahi resolution logic was consolidated and NetUtils usage is mocked in updated tests. This reduces duplication and provides a consistent fallback order: configured ip-address -> ip-interface (if valid) -> primary detected IP.
Refactor how the announced mDNS IP is resolved: introduce a new static overload resolveAnnouncedIpAddress(..., fallbackIpAddress) and an instance helper resolveMdnsFallbackIpAddress() that prefers a configured bind interface (if not wildcard) before falling back to NetUtils.detectPrimaryIpAddress(). The instance method now passes that fallback into the static resolver. Also adjust the log text when interface resolution fails. This ensures a configurable and deterministic fallback IP for mDNS announcements.
Move and rename the test from mdns/MDnsAvahiTest to output/OutputDeviceTest (package changed to com.deigmueller.uni_meter.output).
Add a class-level static LOGGER and centralize warning logs to it. Simplify resolveAnnouncedIpAddress API by removing the Logger parameter and switching the instance resolver to call the new static signature; make the instance resolver protected. Update log calls to use the static LOGGER and adjust unit tests to use the new method signature (pass the fallback Supplier instead of a Logger). This centralizes logging and reduces parameter passing for IP-address resolution.
Move mDNS address selection from the global mdns config to the output-device `interface` setting and update docs accordingly. OutputDevice.resolveAnnouncedIpAddress now reads the device `interface`, treats literal IPs as addresses, resolves interface names via NetUtils.detectIpAddressFromInterface, and falls back to NetUtils.detectPrimaryIpAddress. NetUtils was adjusted to prefer IPv4 addresses but return any address if no IPv4 is found. Updated reference.conf, installation and output docs, and adapted unit tests to the new config layout and behavior.
This pull request adds support for explicitly configuring which IPv4 address is announced via mDNS.