Skip to content

Refactor confd deps#1511

Merged
troglobit merged 3 commits into
mainfrom
refactor-confd-deps
May 23, 2026
Merged

Refactor confd deps#1511
troglobit merged 3 commits into
mainfrom
refactor-confd-deps

Conversation

@mattiaswal
Copy link
Copy Markdown
Contributor

@mattiaswal mattiaswal commented May 22, 2026

  • Refactor dependency tracking in confd/core.c
  • Add dependecy tracking for wireguard keys
  • Move dependency checking for hostname changes from dhcp-client to the dependency tracker

Description

Checklist

Tick relevant boxes, this PR is-a or has-a:

  • Bugfix
    • Regression tests
    • ChangeLog updates (for next release)
  • Feature
    • YANG model change => revision updated?
    • Regression tests added?
    • ChangeLog updates (for next release)
    • Documentation added?
  • Test changes
    • Checked in changed Readme.adoc (make test-spec)
    • Added new test to group Readme.adoc and yaml file
  • Code style update (formatting, renaming)
  • Refactoring (please detail in commit messages)
  • Build related changes
  • Documentation content changes
    • ChangeLog updated (for major changes)
  • Other (please describe):

Extract the monolithic handle_dependencies() into five smaller
functions, each handling one dependency type:

 - dep_symmetric_keys()    - key -> wifi secret
 - dep_asymmetric_keys()   - key -> ssh hostkey/web cert
 - dep_hostname()          - hostname -> dhcp-server/mdns
 - dep_wifi_interfaces()   - interface wifi -> radio hardware
 - dep_radio_components()  - radio hardware -> interface wifi

Also fixes a potential NULL dereference of dwifi before accessing
its access-point child, and removes redundant NULL checks for
YANG-guaranteed mandatory leaves (list keys, mandatory true).
When keystore keys change, trigger regeneration of wireguard
interfaces that reference them:

 - Asymmetric key change: triggers interfaces using it as private-key
 - Symmetric key change: triggers interfaces using it as preshared-key
   (both at peers bag-level and individual peer-level)
Move the hostname-triggers-dhcp-client logic from dhcp-client.c into
the centralized dep_hostname() dependency tracker.  When the hostname
changes, all interfaces with DHCP client configured are now added to
the diff by the core dependency resolver, so dhcp_client_change() picks
them up through its normal diff-based interface iteration.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors confd’s dependency-tracking logic in core.c to make dependency expansion more modular, extends dependency tracking to cover WireGuard key references, and moves hostname-change-triggered DHCP client updates out of dhcp-client.c into the central dependency tracker.

Changes:

  • Split the previous monolithic dependency handler into targeted helpers (dep_*) in src/confd/src/core.c.
  • Add dependency expansion for WireGuard private keys and preshared keys referenced from interfaces.
  • Move hostname-change dependency handling (DHCP client, mDNS, DHCP server) into core.c and remove the hostname-specific loop from dhcp-client.c.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/confd/src/core.c Refactors dependency tracking into helper functions; adds hostname and WireGuard key dependency expansion.
src/confd/src/dhcp-client.c Removes hostname-change special-casing so hostname dependencies are handled centrally.
Comments suppressed due to low confidence (1)

src/confd/src/core.c:463

  • ifname is used to build dependency XPaths without a NULL check. If the interface node does not carry the name key, snprintf() will receive NULL and can crash. Add if (!ifname) continue; after reading the attribute.
			struct lyd_node *wifi_node = lyd_parent(ifaces->dnodes[j]);
			struct lyd_node *iface_node = lyd_parent(wifi_node);
			const char *ifname;
			char xpath[256];

			ifname = lydx_get_cattr(iface_node, "name");

			snprintf(xpath, sizeof(xpath),
				 "/ietf-interfaces:interfaces/interface[name='%s']/infix-interfaces:wifi", ifname);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/confd/src/core.c
Comment on lines 274 to 276
hostkeys = lydx_find_xpathf(config, "/infix-services:ssh/hostkey[.='%s']", key_name);
if (hostkeys && hostkeys->count > 0) {
for (i = 0; i < hostkeys->count; i++) {
Comment thread src/confd/src/core.c
Comment on lines +388 to 391
ifname = lydx_get_cattr(dif, "name");

cif = lydx_get_xpathf(config, "/ietf-interfaces:interfaces/interface[name='%s']", ifname);

Comment thread src/confd/src/core.c
Comment on lines 432 to +437
name = lydx_get_cattr(dcomponent, "name");
if (!name)
continue;

class = lydx_get_cattr(dcomponent, "class");
if (!class) {
struct lyd_node *class_node = lydx_get_xpathf(config, "/ietf-hardware:hardware/component[name='%s']/class", name);
struct lyd_node *class_node = lydx_get_xpathf(config,
"/ietf-hardware:hardware/component[name='%s']/class", name);
Comment thread src/confd/src/core.c
Comment on lines +442 to +443
if (strcmp(class, "infix-hardware:wifi"))
continue;
Copy link
Copy Markdown
Contributor

@troglobit troglobit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@troglobit troglobit merged commit 6618bcd into main May 23, 2026
13 checks passed
@troglobit troglobit deleted the refactor-confd-deps branch May 23, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants