Skip to content

Commit

Permalink
confd: expose more avahi-daemon settings in mdns service context
Browse files Browse the repository at this point in the history
Fix #678

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
  • Loading branch information
troglobit committed Nov 24, 2024
1 parent 9cc9006 commit 72c2d49
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 1 deletion.
56 changes: 56 additions & 0 deletions src/confd/src/infix-services.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,59 @@ static int hostname_change(sr_session_ctx_t *session, uint32_t sub_id, const cha
return mdns_records("update", all);
}

static void fput_list(FILE *fp, struct lyd_node *cfg, const char *list, const char *heading)
{
const char *prefix = heading;
struct lyd_node *node;

LYX_LIST_FOR_EACH(lyd_child(cfg), node, list) {
fprintf(fp, "%s%s", prefix, lyd_get_value(node));
prefix = ",";
}

if (prefix != heading)
fprintf(fp, "\n");
}

#define AVAHI_CONF "/etc/avahi/avahi-daemon.conf"

static void mdns_conf(struct lyd_node *cfg)
{
FILE *fp;

fp = fopen(AVAHI_CONF, "w");
if (!fp) {
ERRNO("failed creating %s", AVAHI_CONF);
return;
}

fprintf(fp, "# Generated by Infix confd\n"
"[server]\n"
"domain-name=%s\n"
"use-ipv4=yes\n"
"use-ipv6=yes\n", lydx_get_cattr(cfg, "domain"));

fput_list(fp, cfg, "allow-interfaces", "allow-interfaces=");
fput_list(fp, cfg, "deny-interfaces", "deny-interfaces=");

fprintf(fp,
"ratelimit-interval-usec=1000000\n"
"ratelimit-burst=1000\n");

fprintf(fp, "\n[wide-area]\n");
/* nop */
fprintf(fp, "\n[publish]\n");
/* nop */
fprintf(fp, "\n[reflector]\n");
fprintf(fp, "enable-reflector=%s\n", lydx_is_enabled(cfg, "reflector") ? "yes" : "no");
fput_list(fp, cfg, "reflect-filter", "reflect-filters=");

fprintf(fp, "\n[rlimits]\n");
/* nop */

fclose(fp);
}

static void mdns_cname(sr_session_ctx_t *session)
{
int ena = srx_enabled(session, "/infix-services:mdns/enabled");
Expand Down Expand Up @@ -217,6 +270,9 @@ static int mdns_change(sr_session_ctx_t *session, uint32_t sub_id, const char *m

ena = lydx_is_enabled(srv, "enabled");
if (ena) {
/* Generate/update avahi-daemon.conf */
mdns_conf(srv);

/* Generate/update basic mDNS service records */
mdns_records("update", all);
}
Expand Down
2 changes: 1 addition & 1 deletion src/confd/yang/confd.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ MODULES=(
"infix-dhcp-client@2024-09-20.yang"
"infix-meta@2024-10-18.yang"
"infix-system@2024-09-13.yang"
"infix-services@2024-05-30.yang"
"infix-services@2024-11-21.yang"
"ieee802-ethernet-interface@2019-06-21.yang"
"infix-ethernet-interface@2024-02-27.yang"
"infix-factory-default@2023-06-28.yang"
Expand Down
60 changes: 60 additions & 0 deletions src/confd/yang/infix-services.yang
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@ module infix-services {
namespace "urn:ietf:params:xml:ns:yang:infix-services";
prefix infix-svc;

import ietf-interfaces {
prefix if;
}
import ietf-inet-types {
prefix inet;
}

organization "KernelKit";
contact "kernelkit@googlegroups.com";
description "Infix services, generic.";

revision 2024-11-21 {
description "Expand mdns options: domain, allow/deny interfaces.";
reference "internal";
}
revision 2024-05-30 {
description "Add support for RESTCONF enable/disable as a web service.";
reference "internal";
Expand Down Expand Up @@ -35,6 +46,55 @@ module infix-services {
description "Globally enable or disable mDNS/SD on all interfaces.";
type boolean;
}

leaf domain {
description "LAN domain name to register host name and services in.
Most common is .local, but some also use .lan, or .office,
usually this setting can be left as-is.";
default "local";
type inet:domain-name;
}

leaf-list allow-interfaces {
description "Interfaces to act on, can be combined with deny-interfaces.
By defaullt all, except loopback and point-to-pint links.";
type if:interface-ref;
}

leaf-list deny-interfaces {
description "Interfaces to ignore.
Other not specified interfaces will be used, except loopback
and point-to-point, unless combined with allow-interfaces.
This option takes precedence over allow-interfaces.";
type if:interface-ref;
}

leaf reflector {
description "Reflect incoming mDNS requests to local interfaces.";
type boolean;
}

leaf-list reflect-filter {
description "Filter mDNS service names to reflect.
Example, for AirPlay and AirTunes, use:
- _airplay._tcp.local
- _raop._tcp.local
For AirPrint use:
- _printer._tcp.local
- _ipp._tcp.local
- _pdl-datastream._tcp.local
By defaullt all services are reflected.";
type string;
}
}

container web {
Expand Down

0 comments on commit 72c2d49

Please sign in to comment.