Refactor confd deps#1511
Merged
Merged
Conversation
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.
There was a problem hiding this comment.
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_*) insrc/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.cand remove the hostname-specific loop fromdhcp-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
ifnameis used to build dependency XPaths without a NULL check. If the interface node does not carry thenamekey,snprintf()will receive NULL and can crash. Addif (!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 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 on lines
+388
to
391
| ifname = lydx_get_cattr(dif, "name"); | ||
|
|
||
| cif = lydx_get_xpathf(config, "/ietf-interfaces:interfaces/interface[name='%s']", ifname); | ||
|
|
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 on lines
+442
to
+443
| if (strcmp(class, "infix-hardware:wifi")) | ||
| continue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Checklist
Tick relevant boxes, this PR is-a or has-a: