statd: avahi: rename avahi subsystem to mdns

The operator sees Infix through YANG models and should not need to know
which library implements a given feature.  Rename the public-facing
parts of the avahi module to use the mdns vocabulary:

- Log strings: "avahi: ..." → "mdns: ..."
- Public API:  avahi_ctx_init/exit → mdns_ctx_init/exit
- Main type:   struct avahi_ctx → struct mdns_ctx
- statd field: statd.avahi → statd.mdns

Internal types (struct avahi_neighbor, avahi_service, …) and file names
(avahi.c, avahi.h) are kept as-is — developers debugging at the C level
benefit from knowing the underlying implementation.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2026-03-20 16:18:12 +01:00
parent fee552196a
commit 7f2fbc8bbf
3 changed files with 46 additions and 46 deletions
+40 -40
View File
@@ -43,14 +43,14 @@ struct AvahiWatch {
AvahiWatchEvent last_event;
AvahiWatchCallback callback;
void *userdata;
struct avahi_ctx *ctx;
struct mdns_ctx *ctx;
};
struct AvahiTimeout {
ev_timer timer; /* MUST be first */
AvahiTimeoutCallback callback;
void *userdata;
struct avahi_ctx *ctx;
struct mdns_ctx *ctx;
};
/* --------------------------------------------------------------------------
@@ -73,7 +73,7 @@ static void watch_io_cb(struct ev_loop *loop, ev_io *w, int events)
static AvahiWatch *watch_new(const AvahiPoll *api, int fd, AvahiWatchEvent event,
AvahiWatchCallback callback, void *userdata)
{
struct avahi_ctx *ctx = api->userdata;
struct mdns_ctx *ctx = api->userdata;
struct AvahiWatch *w;
int ev_events = 0;
@@ -130,7 +130,7 @@ static void timeout_cb(struct ev_loop *loop, ev_timer *t, int events)
static AvahiTimeout *timeout_new(const AvahiPoll *api, const struct timeval *tv,
AvahiTimeoutCallback callback, void *userdata)
{
struct avahi_ctx *ctx = api->userdata;
struct mdns_ctx *ctx = api->userdata;
struct AvahiTimeout *t;
t = calloc(1, sizeof(*t));
@@ -188,7 +188,7 @@ static void timeout_free(AvahiTimeout *t)
* In-memory state helpers
* -------------------------------------------------------------------------- */
static struct avahi_neighbor *find_neighbor(struct avahi_ctx *ctx, const char *hostname)
static struct avahi_neighbor *find_neighbor(struct mdns_ctx *ctx, const char *hostname)
{
struct avahi_neighbor *n;
@@ -199,7 +199,7 @@ static struct avahi_neighbor *find_neighbor(struct avahi_ctx *ctx, const char *h
return NULL;
}
static struct avahi_neighbor *get_neighbor(struct avahi_ctx *ctx, const char *hostname)
static struct avahi_neighbor *get_neighbor(struct mdns_ctx *ctx, const char *hostname)
{
struct avahi_neighbor *n = find_neighbor(ctx, hostname);
@@ -241,7 +241,7 @@ static void add_addr(struct avahi_neighbor *n, const char *addr)
/*
* Find service in flat list by 5-tuple (ifindex, proto, name, type, domain).
*/
static struct avahi_service *find_service(struct avahi_ctx *ctx,
static struct avahi_service *find_service(struct mdns_ctx *ctx,
int ifindex, AvahiProtocol proto,
const char *name, const char *type,
const char *domain)
@@ -262,7 +262,7 @@ static struct avahi_service *find_service(struct avahi_ctx *ctx,
* used after removing one 5-tuple entry to decide if the DS entry should
* be removed too (another interface may still have the same service).
*/
static int svc_ds_entry_exists(struct avahi_ctx *ctx, const char *hostname, const char *name)
static int svc_ds_entry_exists(struct mdns_ctx *ctx, const char *hostname, const char *name)
{
struct avahi_service *s;
@@ -273,7 +273,7 @@ static int svc_ds_entry_exists(struct avahi_ctx *ctx, const char *hostname, cons
return 0;
}
static int neighbor_has_services(struct avahi_ctx *ctx, const char *hostname)
static int neighbor_has_services(struct mdns_ctx *ctx, const char *hostname)
{
struct avahi_service *s;
@@ -315,7 +315,7 @@ static void free_neighbor(struct avahi_neighbor *n)
free(n);
}
static void free_all(struct avahi_ctx *ctx)
static void free_all(struct mdns_ctx *ctx)
{
struct avahi_service *s;
struct avahi_neighbor *n;
@@ -350,7 +350,7 @@ static int sr_setstr(sr_session_ctx_t *ses, const char *xpath, const char *val)
int err = sr_set_item_str(ses, xpath, val, NULL, 0);
if (err)
ERROR("avahi: sr_set_item_str(%s): %s", xpath, sr_strerror(err));
ERROR("mdns: sr_set_item_str(%s): %s", xpath, sr_strerror(err));
return err;
}
@@ -372,7 +372,7 @@ static const char *xpath_str(char *buf, size_t sz, const char *val)
* Push a resolver result to the operational DS.
* new_addr is non-NULL only when a new address was just added in memory.
*/
static void ds_push_resolver(struct avahi_ctx *ctx, struct avahi_service *svc,
static void ds_push_resolver(struct mdns_ctx *ctx, struct avahi_service *svc,
const char *new_addr)
{
char qname[258]; /* quoted svc->name for safe XPath predicates */
@@ -443,10 +443,10 @@ static void ds_push_resolver(struct avahi_ctx *ctx, struct avahi_service *svc,
err = sr_apply_changes(ctx->sr_ses, 0);
if (err)
ERROR("avahi: sr_apply_changes: %s", sr_strerror(err));
ERROR("mdns: sr_apply_changes: %s", sr_strerror(err));
}
static void ds_delete_service(struct avahi_ctx *ctx, const char *hostname, const char *name)
static void ds_delete_service(struct mdns_ctx *ctx, const char *hostname, const char *name)
{
char qname[258];
char xpath[512];
@@ -458,7 +458,7 @@ static void ds_delete_service(struct avahi_ctx *ctx, const char *hostname, const
sr_delete_item(ctx->sr_ses, xpath, 0);
}
static void ds_delete_neighbor(struct avahi_ctx *ctx, const char *hostname)
static void ds_delete_neighbor(struct mdns_ctx *ctx, const char *hostname)
{
char xpath[512];
@@ -467,7 +467,7 @@ static void ds_delete_neighbor(struct avahi_ctx *ctx, const char *hostname)
sr_delete_item(ctx->sr_ses, xpath, 0);
}
static void ds_clear_all(struct avahi_ctx *ctx)
static void ds_clear_all(struct mdns_ctx *ctx)
{
sr_delete_item(ctx->sr_ses, XPATH_BASE, 0);
sr_apply_changes(ctx->sr_ses, 0);
@@ -486,7 +486,7 @@ static void resolver_cb(AvahiServiceResolver *r,
AvahiLookupResultFlags flags,
void *userdata)
{
struct avahi_ctx *ctx = userdata;
struct mdns_ctx *ctx = userdata;
char addrstr[AVAHI_ADDRESS_STR_MAX] = "";
struct avahi_neighbor *n;
struct avahi_service *svc;
@@ -510,7 +510,7 @@ static void resolver_cb(AvahiServiceResolver *r,
/* Find or create neighbor (tracks addresses) */
n = get_neighbor(ctx, hostname);
if (!n) {
ERROR("avahi: out of memory for neighbor '%s'", hostname);
ERROR("mdns: out of memory for neighbor '%s'", hostname);
goto done;
}
@@ -525,7 +525,7 @@ static void resolver_cb(AvahiServiceResolver *r,
if (!svc) {
svc = calloc(1, sizeof(*svc));
if (!svc) {
ERROR("avahi: out of memory for service '%s'", name);
ERROR("mdns: out of memory for service '%s'", name);
goto done;
}
svc->ifindex = iface;
@@ -567,7 +567,7 @@ static void service_browser_cb(AvahiServiceBrowser *b,
AvahiLookupResultFlags flags,
void *userdata)
{
struct avahi_ctx *ctx = userdata;
struct mdns_ctx *ctx = userdata;
(void)b;
(void)flags;
@@ -578,7 +578,7 @@ static void service_browser_cb(AvahiServiceBrowser *b,
name, type, domain,
AVAHI_PROTO_UNSPEC, 0,
resolver_cb, ctx))
DEBUG("avahi: resolver_new(%s) failed: %s", name,
DEBUG("mdns: resolver_new(%s) failed: %s", name,
avahi_strerror(avahi_client_errno(ctx->client)));
break;
@@ -626,7 +626,7 @@ static void type_browser_cb(AvahiServiceTypeBrowser *b,
AvahiLookupResultFlags flags,
void *userdata)
{
struct avahi_ctx *ctx = userdata;
struct mdns_ctx *ctx = userdata;
(void)b;
(void)flags;
@@ -653,14 +653,14 @@ static void type_browser_cb(AvahiServiceTypeBrowser *b,
0,
service_browser_cb, ctx);
if (!te->browser) {
DEBUG("avahi: service_browser_new(%s) failed: %s", type,
DEBUG("mdns: service_browser_new(%s) failed: %s", type,
avahi_strerror(avahi_client_errno(ctx->client)));
free(te);
return;
}
LIST_INSERT_HEAD(&ctx->type_entries, te, link);
DEBUG("avahi: browsing service type %s", type);
DEBUG("mdns: browsing service type %s", type);
break;
}
@@ -690,7 +690,7 @@ static void type_browser_cb(AvahiServiceTypeBrowser *b,
* Opens a temporary session to avoid disturbing the operational-DS session.
* Returns true if enabled or if the check cannot be performed (fail-safe).
*/
static bool mdns_is_enabled(struct avahi_ctx *ctx)
static bool mdns_is_enabled(struct mdns_ctx *ctx)
{
sr_session_ctx_t *sess = NULL;
sr_data_t *data = NULL;
@@ -724,10 +724,10 @@ static bool mdns_is_enabled(struct avahi_ctx *ctx)
* avahi: mDNS daemon not responding (attempt 3/3) — check that the mdns
* service is running
*/
static void avahi_retry_cb(struct ev_loop *loop, ev_timer *w, int revents)
static void mdns_retry_cb(struct ev_loop *loop, ev_timer *w, int revents)
{
struct avahi_ctx *ctx = (struct avahi_ctx *)
((char *)w - offsetof(struct avahi_ctx, retry_timer));
struct mdns_ctx *ctx = (struct mdns_ctx *)
((char *)w - offsetof(struct mdns_ctx, retry_timer));
ctx->fail_count++;
if (ctx->fail_count < 3) {
@@ -737,13 +737,13 @@ static void avahi_retry_cb(struct ev_loop *loop, ev_timer *w, int revents)
}
if (mdns_is_enabled(ctx))
ERROR("avahi: mDNS daemon not responding (attempt %d/3) — "
ERROR("mdns: mDNS daemon not responding (attempt %d/3) — "
"check that the mdns service is running", ctx->fail_count);
}
static void client_cb(AvahiClient *c, AvahiClientState state, void *userdata)
{
struct avahi_ctx *ctx = userdata;
struct mdns_ctx *ctx = userdata;
ctx->client = c;
@@ -751,10 +751,10 @@ static void client_cb(AvahiClient *c, AvahiClientState state, void *userdata)
case AVAHI_CLIENT_S_RUNNING:
if (ctx->fail_count > 0) {
ev_timer_stop(ctx->loop, &ctx->retry_timer);
NOTE("avahi: mDNS daemon reconnected");
NOTE("mdns: mDNS daemon reconnected");
ctx->fail_count = 0;
}
INFO("avahi: client running");
INFO("mdns: client running");
if (ctx->type_browser)
break; /* Already browsing */
@@ -765,7 +765,7 @@ static void client_cb(AvahiClient *c, AvahiClientState state, void *userdata)
0,
type_browser_cb, ctx);
if (!ctx->type_browser)
ERROR("avahi: service_type_browser_new failed: %s",
ERROR("mdns: service_type_browser_new failed: %s",
avahi_strerror(avahi_client_errno(ctx->client)));
break;
@@ -780,7 +780,7 @@ static void client_cb(AvahiClient *c, AvahiClientState state, void *userdata)
* and mDNS is enabled in the running config.
*/
if (!ev_is_active(&ctx->retry_timer)) {
ev_timer_init(&ctx->retry_timer, avahi_retry_cb, 2.0, 0.0);
ev_timer_init(&ctx->retry_timer, mdns_retry_cb, 2.0, 0.0);
ev_timer_start(ctx->loop, &ctx->retry_timer);
}
@@ -814,7 +814,7 @@ static void client_cb(AvahiClient *c, AvahiClientState state, void *userdata)
* Public interface
* -------------------------------------------------------------------------- */
int avahi_ctx_init(struct avahi_ctx *ctx, struct ev_loop *loop, sr_conn_ctx_t *sr_conn)
int mdns_ctx_init(struct mdns_ctx *ctx, struct ev_loop *loop, sr_conn_ctx_t *sr_conn)
{
int avahi_err;
@@ -828,7 +828,7 @@ int avahi_ctx_init(struct avahi_ctx *ctx, struct ev_loop *loop, sr_conn_ctx_t *s
/* Dedicated operational session for push writes (avoids sharing
* sr_query_ses which the journal thread also uses). */
if (sr_session_start(sr_conn, SR_DS_OPERATIONAL, &ctx->sr_ses)) {
ERROR("avahi: failed to start sysrepo session");
ERROR("mdns: failed to start sysrepo session");
return -1;
}
@@ -847,17 +847,17 @@ int avahi_ctx_init(struct avahi_ctx *ctx, struct ev_loop *loop, sr_conn_ctx_t *s
client_cb, ctx,
&avahi_err);
if (!ctx->client) {
ERROR("avahi: client_new failed: %s", avahi_strerror(avahi_err));
ERROR("mdns: client_new failed: %s", avahi_strerror(avahi_err));
sr_session_stop(ctx->sr_ses);
ctx->sr_ses = NULL;
return -1;
}
INFO("avahi: mDNS neighbor monitor initialized");
INFO("mdns: mDNS neighbor monitor initialized");
return 0;
}
void avahi_ctx_exit(struct avahi_ctx *ctx)
void mdns_ctx_exit(struct mdns_ctx *ctx)
{
struct avahi_type_entry *te;
@@ -887,5 +887,5 @@ void avahi_ctx_exit(struct avahi_ctx *ctx)
}
free_all(ctx);
INFO("avahi: mDNS neighbor monitor stopped");
INFO("mdns: mDNS neighbor monitor stopped");
}
+3 -3
View File
@@ -51,7 +51,7 @@ struct avahi_type_entry {
LIST_ENTRY(avahi_type_entry) link;
};
struct avahi_ctx {
struct mdns_ctx {
struct ev_loop *loop;
sr_conn_ctx_t *sr_conn; /* Connection for running-DS config queries */
sr_session_ctx_t *sr_ses; /* Dedicated operational DS write session */
@@ -65,7 +65,7 @@ struct avahi_ctx {
LIST_HEAD(, avahi_type_entry) type_entries;
};
int avahi_ctx_init(struct avahi_ctx *ctx, struct ev_loop *loop, sr_conn_ctx_t *sr_conn);
void avahi_ctx_exit(struct avahi_ctx *ctx);
int mdns_ctx_init(struct mdns_ctx *ctx, struct ev_loop *loop, sr_conn_ctx_t *sr_conn);
void mdns_ctx_exit(struct mdns_ctx *ctx);
#endif
+3 -3
View File
@@ -70,7 +70,7 @@ struct statd {
sr_conn_ctx_t *sr_conn; /* Connection (owns YANG context) */
struct ev_loop *ev_loop;
struct journal_ctx journal; /* Journal thread context */
struct avahi_ctx avahi; /* mDNS neighbor monitor */
struct mdns_ctx mdns; /* mDNS neighbor monitor */
};
static int ly_add_yanger_data(const struct ly_ctx *ctx, struct lyd_node **parent,
@@ -524,7 +524,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
if (avahi_ctx_init(&statd.avahi, statd.ev_loop, statd.sr_conn))
if (mdns_ctx_init(&statd.mdns, statd.ev_loop, statd.sr_conn))
INFO("mDNS neighbor monitoring not available");
/* Signal readiness to Finit */
@@ -536,7 +536,7 @@ int main(int argc, char *argv[])
/* We should never get here during normal operation */
INFO("Status daemon shutting down");
avahi_ctx_exit(&statd.avahi);
mdns_ctx_exit(&statd.mdns);
journal_stop(&statd.journal);
unsub_to_all(&statd);