Skip to content

Commit 72c2d49

Browse files
committed
confd: expose more avahi-daemon settings in mdns service context
Fix #678 Signed-off-by: Joachim Wiberg <[email protected]>
1 parent 9cc9006 commit 72c2d49

File tree

4 files changed

+117
-1
lines changed

4 files changed

+117
-1
lines changed

src/confd/src/infix-services.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,59 @@ static int hostname_change(sr_session_ctx_t *session, uint32_t sub_id, const cha
176176
return mdns_records("update", all);
177177
}
178178

179+
static void fput_list(FILE *fp, struct lyd_node *cfg, const char *list, const char *heading)
180+
{
181+
const char *prefix = heading;
182+
struct lyd_node *node;
183+
184+
LYX_LIST_FOR_EACH(lyd_child(cfg), node, list) {
185+
fprintf(fp, "%s%s", prefix, lyd_get_value(node));
186+
prefix = ",";
187+
}
188+
189+
if (prefix != heading)
190+
fprintf(fp, "\n");
191+
}
192+
193+
#define AVAHI_CONF "/etc/avahi/avahi-daemon.conf"
194+
195+
static void mdns_conf(struct lyd_node *cfg)
196+
{
197+
FILE *fp;
198+
199+
fp = fopen(AVAHI_CONF, "w");
200+
if (!fp) {
201+
ERRNO("failed creating %s", AVAHI_CONF);
202+
return;
203+
}
204+
205+
fprintf(fp, "# Generated by Infix confd\n"
206+
"[server]\n"
207+
"domain-name=%s\n"
208+
"use-ipv4=yes\n"
209+
"use-ipv6=yes\n", lydx_get_cattr(cfg, "domain"));
210+
211+
fput_list(fp, cfg, "allow-interfaces", "allow-interfaces=");
212+
fput_list(fp, cfg, "deny-interfaces", "deny-interfaces=");
213+
214+
fprintf(fp,
215+
"ratelimit-interval-usec=1000000\n"
216+
"ratelimit-burst=1000\n");
217+
218+
fprintf(fp, "\n[wide-area]\n");
219+
/* nop */
220+
fprintf(fp, "\n[publish]\n");
221+
/* nop */
222+
fprintf(fp, "\n[reflector]\n");
223+
fprintf(fp, "enable-reflector=%s\n", lydx_is_enabled(cfg, "reflector") ? "yes" : "no");
224+
fput_list(fp, cfg, "reflect-filter", "reflect-filters=");
225+
226+
fprintf(fp, "\n[rlimits]\n");
227+
/* nop */
228+
229+
fclose(fp);
230+
}
231+
179232
static void mdns_cname(sr_session_ctx_t *session)
180233
{
181234
int ena = srx_enabled(session, "/infix-services:mdns/enabled");
@@ -217,6 +270,9 @@ static int mdns_change(sr_session_ctx_t *session, uint32_t sub_id, const char *m
217270

218271
ena = lydx_is_enabled(srv, "enabled");
219272
if (ena) {
273+
/* Generate/update avahi-daemon.conf */
274+
mdns_conf(srv);
275+
220276
/* Generate/update basic mDNS service records */
221277
mdns_records("update", all);
222278
}

src/confd/yang/confd.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ MODULES=(
3333
3434
3535
36-
"infix-services@2024-05-30.yang"
36+
"infix-services@2024-11-21.yang"
3737
3838
3939

src/confd/yang/infix-services.yang

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,21 @@ module infix-services {
33
namespace "urn:ietf:params:xml:ns:yang:infix-services";
44
prefix infix-svc;
55

6+
import ietf-interfaces {
7+
prefix if;
8+
}
9+
import ietf-inet-types {
10+
prefix inet;
11+
}
12+
613
organization "KernelKit";
714
contact "[email protected]";
815
description "Infix services, generic.";
916

17+
revision 2024-11-21 {
18+
description "Expand mdns options: domain, allow/deny interfaces.";
19+
reference "internal";
20+
}
1021
revision 2024-05-30 {
1122
description "Add support for RESTCONF enable/disable as a web service.";
1223
reference "internal";
@@ -35,6 +46,55 @@ module infix-services {
3546
description "Globally enable or disable mDNS/SD on all interfaces.";
3647
type boolean;
3748
}
49+
50+
leaf domain {
51+
description "LAN domain name to register host name and services in.
52+
53+
Most common is .local, but some also use .lan, or .office,
54+
usually this setting can be left as-is.";
55+
default "local";
56+
type inet:domain-name;
57+
}
58+
59+
leaf-list allow-interfaces {
60+
description "Interfaces to act on, can be combined with deny-interfaces.
61+
62+
By defaullt all, except loopback and point-to-pint links.";
63+
type if:interface-ref;
64+
}
65+
66+
leaf-list deny-interfaces {
67+
description "Interfaces to ignore.
68+
69+
Other not specified interfaces will be used, except loopback
70+
and point-to-point, unless combined with allow-interfaces.
71+
72+
This option takes precedence over allow-interfaces.";
73+
type if:interface-ref;
74+
}
75+
76+
leaf reflector {
77+
description "Reflect incoming mDNS requests to local interfaces.";
78+
type boolean;
79+
}
80+
81+
leaf-list reflect-filter {
82+
description "Filter mDNS service names to reflect.
83+
84+
Example, for AirPlay and AirTunes, use:
85+
86+
- _airplay._tcp.local
87+
- _raop._tcp.local
88+
89+
For AirPrint use:
90+
91+
- _printer._tcp.local
92+
- _ipp._tcp.local
93+
- _pdl-datastream._tcp.local
94+
95+
By defaullt all services are reflected.";
96+
type string;
97+
}
3898
}
3999

40100
container web {

0 commit comments

Comments
 (0)