confd: fix mDNS CNAME conflict by flipping the table

Instead of publishing A/AAAA records for $(hostname).loocal with a CNAME
infix.local, we flip it around to take advantage of the mDNS conflict
resolution rules.  This gives us infix.local for one device ont the LAN
and infix-2.local for the next.

Update all service records to *not* advertise hostname, but instead to
let Avahi imply that from the advertised A/AAAA and CNAME records.

Fixes #1387

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2026-03-09 19:24:36 +01:00
parent e2c29cb1a7
commit e255828418
4 changed files with 20 additions and 22 deletions
@@ -62,8 +62,8 @@ if ! runlevel >/dev/null 2>&1; then
fi
initctl -bq status lldpd && lldpcli configure system hostname "$new_hostname" 2>/dev/null
initctl -bq status mdns && avahi-set-host-name "$new_hostname" 2>/dev/null
initctl -bq touch netbrowse 2>/dev/null
initctl -bq touch mdns-alias 2>/dev/null
initctl -bq touch netbrowse 2>/dev/null
# If called from dhcp script we need to reload to activate new name in syslogd
# Otherwise we're called from confd, which does the reload when all is done.
+5 -2
View File
@@ -1,2 +1,5 @@
service <!service/mdns/running> env:-/etc/default/mdns-alias log:prio:daemon.debug,tag:mdns \
[2345] mdns-alias $MDNS_ALIAS_ARGS -- mDNS alias advertiser
# Avahi advertises the system default hostname, this service advertises
# /etc/hostname (-H) and, optionally, network.local as CNAMEs. Changes
# to /etc/default/mdns-alias will cause Finit to restart not reload.
service <service/mdns/running> env:-/etc/default/mdns-alias \
[2345] mdns-alias -H $MDNS_ALIAS_ARGS --
-1
View File
@@ -33,7 +33,6 @@ cat <<EOF >"$file"
<service>
<type>$type</type>
<port>$port</port>
<host-name>$host.local</host-name>
<txt-record>vv=1</txt-record>
<txt-record>vendor=$(jq -r .vendor /run/system.json)</txt-record>
<txt-record>product=$(jq -r '."product-name"' /run/system.json)</txt-record>
+13 -17
View File
@@ -206,6 +206,7 @@ static void fput_list(FILE *fp, struct lyd_node *cfg, const char *list, const ch
static void mdns_conf(struct lyd_node *cfg)
{
const char *hostname = fgetkey("/etc/os-release", "DEFAULT_HOSTNAME");
struct lyd_node *ctx;
FILE *fp;
@@ -217,9 +218,10 @@ static void mdns_conf(struct lyd_node *cfg)
fprintf(fp, "# Generated by Infix confd\n"
"[server]\n"
"host-name=%s\n"
"domain-name=%s\n"
"use-ipv4=yes\n"
"use-ipv6=yes\n", lydx_get_cattr(cfg, "domain"));
"use-ipv6=yes\n", hostname, lydx_get_cattr(cfg, "domain"));
ctx = lydx_get_descendant(lyd_child(cfg), "interfaces", NULL);
if (ctx) {
@@ -254,23 +256,17 @@ static void mdns_cname(sr_session_ctx_t *session)
if (ena) {
int www = srx_enabled(session, "/infix-services:web/netbrowse/enabled");
const char *hostname = fgetkey("/etc/os-release", "DEFAULT_HOSTNAME");
FILE *fp;
if (hostname || www) {
FILE *fp;
fp = fopen("/etc/default/mdns-alias", "w");
if (fp) {
fprintf(fp, "MDNS_ALIAS_ARGS=\"%s%s %s\"\n",
hostname ?: "", hostname ? ".local" : "",
www ? "network.local" : "");
fclose(fp);
} else {
ERRNO("failed updating mDNS aliases");
ena = 0;
}
} else
ena = 0; /* nothing to advertise */
fp = fopen("/etc/default/mdns-alias", "w");
if (fp) {
fprintf(fp, "MDNS_ALIAS_ARGS=\"%s\"\n",
www ? "network.local" : "");
fclose(fp);
} else {
ERRNO("failed updating mDNS aliases");
ena = 0;
}
}
svc_enadis(ena, none, "mdns-alias");