[dhcpmon] Apply small packet and C++ hardening fixes - #96
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 improves sonic-dhcpmon’s raw-socket packet receive path to keep the libevent loop responsive under bursty traffic, while also correcting recvfrom() address-length handling.
Changes:
- Limit each libevent read callback to processing at most 64 packets, leaving remaining packets queued so other events can run.
- Reset the
socklen_taddress length tosizeof(sockaddr_ll)before eachrecvfrom()call to avoid reusing a modified length.
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
faa1813 to
7f6f687
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. |
There was a problem hiding this comment.
🟢 Ready to approve
The change is small, self-contained, and corrects a concrete fairness issue (bounded draining) plus a correctness issue (socklen_t reuse) without introducing new risky behavior.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
| while ((buffer_sz = recvfrom(fd, sock_info.buffer, sock_info.snaplen, MSG_DONTWAIT, (struct sockaddr *)&sll, &slen)) > 0) | ||
| { | ||
| for (int packet_count = 0; packet_count < MAX_PACKETS_PER_CALLBACK; packet_count++) { | ||
| slen = sizeof(sll); |
There was a problem hiding this comment.
Moved the declaration and initialization into the loop. The per-iteration initialization remains necessary because recvfrom() treats socklen_t as a value-result parameter and may modify it.
| for (int packet_count = 0; packet_count < MAX_PACKETS_PER_CALLBACK; packet_count++) { | ||
| slen = sizeof(sll); | ||
| buffer_sz = recvfrom(fd, sock_info.buffer, sock_info.snaplen, MSG_DONTWAIT, | ||
| (struct sockaddr *)&sll, &slen); |
There was a problem hiding this comment.
the following lines can be shortened, like the previous version
There was a problem hiding this comment.
Updated to assign recvfrom() inside the break condition, matching the previous compact form.
7f6f687 to
1ee6d6a
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
🟢 Ready to approve
The change is small, locally scoped to the callback loop, aligns with libevent EV_READ|EV_PERSIST behavior, and matches the stated goal without introducing observable correctness issues.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Bound each raw-socket callback to 64 packets and reset the recvfrom address length for every receive attempt. Rename three file-scope helpers that begin with underscores because C++ reserves those identifiers in the global namespace; static linkage already marks them as internal. Replace four nullptr comparisons with NULL to match the daemon's established style. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 39f979be-d826-4d5c-949a-f20abb58bb83 Signed-off-by: Xichen96 <lukelin0907@gmail.com>
1ee6d6a to
076df9a
Compare
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
🟡 Not ready to approve
The updated addr_is_primary_impl() documentation claims “false if … not found” but the implementation returns true on “not found,” which is misleading for future maintenance.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
Suppressed comments (1)
src/util.cpp:40
- The
@returndocumentation doesn’t match the function behavior: addr_is_primary_impl() returns true when the address is not found in ConfigDB (falls through toreturn true;). Please update the comment to reflect the actual semantics so callers aren’t misled.
* @return true if the address is primary, false if secondary or not found
- Files reviewed: 4/4 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Description of PR
Collect the small packet-path and C++ consistency fixes found during the F2
review:
recvfrom()address length before every receive._.nullptrcomparisons with the daemon's establishedNULLstyle.
These changes are independent of CONFIG_DB listening and do not add or remove
command-line options.
Work item tracking
Type of change
Approach
What is the motivation for this PR?
Draining an unbounded packet backlog in one callback can monopolize its socket
event loop. Reinitializing the value-result
socklen_tfollows therecvfrom()contract.C++ reserves names beginning with
_in the global namespace for theimplementation. The three affected helpers already use
staticlinkage, sodescriptive names identify their purpose without relying on reserved
identifiers.
The four
nullptrcomparisons were the remaining pointer-style outliers frommerged PR #62.
How did you do it?
socklen_ttosizeof(sockaddr_ll)before eachrecvfrom()._increase_cache_counter()toincrease_single_cache_counter()._addr_is_primary()toaddr_is_primary_impl()._compile_bpf_prog()tocompile_bpf_prog().nullptrcomparisons withNULL.How did you verify/test it?
Azure PR CI will validate the consolidated head on amd64, arm64, and armhf.
No local compilation is used.
Any platform specific information?
No.
Back port request
None. This targets master only.
Tested branch
master
Test result
The earlier behavioral stack passed regular master DHCPv4/DHCPv6 regression
and F2 traffic, convergence, and counter-clear scenarios without a dhcpmon
restart. Exact-head acceptance awaits the consolidated PR build.
Documentation
Not applicable.
Review
Review the single commit:
076df9a [dhcpmon]: Apply small packet and C++ hardening fixes