Skip to content

Commit 29029bb

Browse files
committed
netlink: enumerate existing interfaces at startup
The netlink plugin only receives RTM_NEWLINK events for interfaces that appear after the plugin starts. Interfaces that already exist at boot (e.g., virtio-net in QEMU) never generate events, so their conditions like net/eth0/exist were never set. Moving enumeration to PLUGIN_INIT doesn't work because it runs before cond_init(), so the condition filesystem isn't ready yet. Fix by registering an HOOK_SVC_PLUGIN callback that queries existing interfaces and routes. This hook runs during conf_init(), after the condition system is initialized.
1 parent bbe588a commit 29029bb

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

plugins/netlink.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,29 @@ static void nl_reconf(void *arg)
406406
cond_reassert("net/");
407407
}
408408

409+
/*
410+
* Initial enumeration of existing interfaces and routes. Called from
411+
* HOOK_SVC_PLUGIN which runs after the condition system is initialized.
412+
* Interfaces that exist before finit starts (e.g., virtio-net in QEMU)
413+
* won't generate RTM_NEWLINK events, so we must query for them.
414+
*/
415+
static void nl_enumerate(void *arg)
416+
{
417+
int sd;
418+
419+
sd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
420+
if (sd < 0)
421+
return;
422+
423+
nl_resync_ifaces(sd, 0);
424+
nl_resync_routes(sd, 1);
425+
close(sd);
426+
}
427+
409428
static plugin_t plugin = {
410429
.name = __FILE__,
411-
.hook[HOOK_SVC_RECONF] = { .cb = nl_reconf },
430+
.hook[HOOK_SVC_RECONF] = { .cb = nl_reconf },
431+
.hook[HOOK_SVC_PLUGIN] = { .cb = nl_enumerate },
412432
.io = {
413433
.cb = nl_callback,
414434
.flags = PLUGIN_IO_READ,

0 commit comments

Comments
 (0)