[dhcpmon] Start only available address families - #111
Conversation
|
/azp run |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR updates dhcpmon to start monitoring only for the IP address families that are actually available on the downstream VLAN, instead of requiring both IPv4 and IPv6 on every monitored interface. This aligns socket creation, health checks, and DB/state publishing with the enabled families to support IPv4-only or IPv6-only VLAN deployments.
Changes:
- Add
dhcpv4_enabled/dhcpv6_enabledas device-manager-derived feature flags and use them to gate socket-pair initialization and registration. - Gate health-check execution, counter DB initialization/cleanup, and state publishing to only run for enabled families.
- Allow interfaces to have IPv4-only, IPv6-only (GUA or LLA), or dual-stack addressing; zero out missing address fields to avoid stale/uninitialized data.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/sock_mgr.h | Document “disabled family” sockets as -1. |
| src/sock_mgr.cpp | Initialize sockets to -1; open/close/register only enabled-family socket pairs; compile/attach BPF only for sockets in sock_map. |
| src/health_check.h | Add is_v6 to health-check state to support family gating. |
| src/health_check.cpp | Skip health checks for disabled families based on dhcpv4_enabled/dhcpv6_enabled. |
| src/dhcp_mon.cpp | Gate COUNTERS_DB init/checks, stale cleanup, debug printing, and STATE_DB updates to enabled families; remove inactive-family DB/state entries. |
| src/dhcp_devman.h | Export enabled-family flags for downstream VLAN. |
| src/dhcp_devman.cpp | Derive enabled families from downstream VLAN addressing; enforce Loopback0 requirements only for enabled families. |
| src/dhcp_device.h | Clarify that per-interface address fields can be “zero/unavailable”. |
| src/dhcp_device.cpp | Zero address fields before discovery; relax address requirements to “at least one family, at most one primary per type”. |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/dhcp_mon.cpp:183
- cleanup_stale_db_counters() still iterates both families and only deletes entries for interfaces that are no longer tracked. When an address family is disabled (dhcpv4_enabled/dhcpv6_enabled false), the inactive-family COUNTERS_DB tables for tracked interfaces are not removed, which contradicts the PR goal of removing stale inactive-family counter entries.
* @code cleanup_stale_db_counters();
* @brief Clean up stale counter entries for interfaces that are no longer present
* @param none
* @return none
*/
src/dhcp_mon.cpp:113
- PR description says only enabled address families should have COUNTERS_DB tables initialized, but initialize_db_counters() still unconditionally creates both IPv4 and IPv6 tables. This leaves inactive-family tables present (and can confuse consumers that interpret presence as enabled). Consider initializing only the enabled-family tables here.
This issue also appears on line 179 of the same file.
table_name = construct_counter_db_table_key(ifname, false);
init_value = generate_json_string(NULL, DHCP_MESSAGE_TYPE_COUNT, db_counter_name);
mCountersDbPtr->hset(table_name, "RX", init_value);
mCountersDbPtr->hset(table_name, "TX", init_value);
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
317b542 to
f300a1e
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/dhcp_device.cpp:530
- The new LOG_ALERT message is ambiguous: it fires both when an interface has no addresses and when it has too many (e.g., multiple primary IPv4s / multiple GUAs/LLAs). Including the observed counts in the alert makes diagnosis much easier, especially since this condition makes dhcpmon exit for that interface context.
syslog(LOG_ALERT, "Interface %s has no usable IPv4 or IPv6 address", context->intf);
f300a1e to
7de55cb
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
7de55cb to
d3e8741
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
37083fc to
a07e86c
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
1 similar comment
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azpw run |
|
Retrying failed(or canceled) jobs... |
|
/azpw retry |
|
Retrying failed(or canceled) jobs... |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Validate IPv4 and IPv6 prerequisites independently, log and skip unavailable families, and start only their sockets, cache counters, state coordination, debug output, and health checks while resetting both database counter families at startup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0dc64b79-c313-4ee3-81f0-dbcb8daf1681 Signed-off-by: Xichen96 <lukelin0907@gmail.com>
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/dhcp_mon.cpp:229
- update_disabled_cache_counter() writes to STATE_DB without taking db_sync_mutex. Other clear-counter synchronization writes (e.g., update_cache_counter_callback and the SIGUSR1 handler) perform STATE_DB writes under db_sync_mutex, so this new unlocked path can race concurrent DB operations from per-socket event threads during a clear-counter sync.
static void update_disabled_cache_counter()
{
if (!dhcpv4_enabled) {
std::string state_key = STATE_DB_COUNTER_UPDATE_PREFIX + downstream_ifname;
mStateDbPtr->hset(state_key, "rx_cache_update", "done");
Why I did it
dhcpmoncurrently requires every non-management interface to have both a primary IPv4 address and an IPv6 GUA or link-local address. It also opens IPv4 and IPv6 socket pairs and initializes both protocol families unconditionally.That makes the whole monitor exit when a VLAN or uplink is truly IPv4-only or IPv6-only, even though packet capture, counters, and health checks are already implemented independently for each family.
This change is a prerequisite for sonic-net/sonic-buildimage#27277 to generate monitors for DHCPv4-only and DHCPv6-only VLANs.
Work item tracking
How I did it
dhcp6relay.Loopback0relay address is unavailable.COUNTERS_DBtables to zero at every startup so disabled families cannot expose stale counts.Expected startup matrix:
How to verify it
6b69a12ac2.1180642passed on amd64, arm64, and armhf; replacement checks are pending.Which release branch to backport (provide reason below if selected)
Tested branch (Please provide the tested image version)
6b69a12ac2Description for the changelog
Start dhcpmon monitoring only for address families available on the downstream VLAN.
Link to config_db schema for YANG module changes
N/A - no schema change.
A picture of a cute animal (not mandatory but encouraged)
N/A