Skip to content

[dhcpmon] Clean up source include dependencies#88

Open
Xichen96 wants to merge 1 commit into
sonic-net:masterfrom
Xichen96:dev/xichenlin/include-cleanup
Open

[dhcpmon] Clean up source include dependencies#88
Xichen96 wants to merge 1 commit into
sonic-net:masterfrom
Xichen96:dev/xichenlin/include-cleanup

Conversation

@Xichen96

@Xichen96 Xichen96 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Description of PR

Summary:

Make source dependencies explicit and keep public headers self-contained. The change removes unused or redundant includes, moves implementation-only dependencies into .cpp files, and adds direct includes where code previously relied on transitive imports.

Dependencies: None.

Work item tracking
  • Microsoft ADO (number only): 38919307
  • Child Task: 38919308

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Documentation update
  • Test improvement

Approach

What is the motivation for this PR?

Several files rely on unrelated headers to expose declarations such as errno, smart pointers, fixed-width integers, and size_t. Other files retain imports they do not use. This makes compilation dependencies fragile and increases header coupling.

How did you do it?

  • Added direct implementation includes for symbols used by each source file.
  • Made public headers include the declarations required by their own APIs and inline templates.
  • Moved smart-pointer dependencies out of util.h and into their implementation users.
  • Removed unused and redundant system, SWSS, libevent, and standard-library includes.

How did you verify/test it?

  • Reviewed all 19 C++ source and header files for direct symbol ownership and header self-containment.
  • Focused diff review found no semantic or dependency issues.
  • PR CI build 1173128 passed for amd64, arm64, and armhf; DCO passed.

Any platform specific information?

No. This is a compile-dependency cleanup with no runtime or platform-specific behavior change.

Back port request

None.

Tested branch

  • 202605

Test result

PR CI passed on amd64, arm64, and armhf.

Documentation

Not applicable; there is no user-facing behavior or interface change.

Make headers self-contained, move implementation-only dependencies into source files, and remove unused or redundant imports. This keeps compile dependencies explicit without changing runtime behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: be978a4b-32ee-4a29-bd1c-3699552d52d0
Signed-off-by: Xichen96 <lukelin0907@gmail.com>
Copilot AI review requested due to automatic review settings July 23, 2026 18:08
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown

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 the C++ include structure to make dependencies explicit, reduce transitive-include reliance, and keep public headers self-contained—helping keep compilation dependencies stable as the codebase evolves.

Changes:

  • Updated public headers to directly include standard/library headers required by their exposed APIs and inline helpers.
  • Moved implementation-only dependencies (e.g., <memory>, <vector>, <errno.h>) into .cpp files where the symbols are actually used.
  • Removed unused/redundant includes across multiple translation units to reduce coupling.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/util.h Makes the header self-contained for its inline helpers and exported APIs (adds required C/stdlib and <utility> includes; drops transitive deps like <memory>).
src/util.cpp Adds direct implementation includes required for exceptions, smart pointers, and stdio/stdlib usage.
src/sock_mgr.h Adds <stddef.h> so size_t usage in the header doesn’t rely on transitive includes.
src/sock_mgr.cpp Adds direct includes (<arpa/inet.h>, <memory>) used by the implementation.
src/packet_handler.h Switches to <string> for the public interface types and drops unused <string.h> from the header.
src/packet_handler.cpp Adds direct includes used by the implementation (<errno.h>, <string.h>, <vector>).
src/main.cpp Removes unused headers and adds direct includes required by the file’s usage (stdint/stdio).
src/dhcp_mon.h Adds <stddef.h> to make the size_t API self-contained.
src/dhcp_mon.cpp Moves implementation-only includes into the .cpp and removes unused ones.
src/dhcp_devman.h Removes unused <stdint.h> from the header.
src/dhcp_devman.cpp Adds <memory> to cover smart pointer declarations used in the implementation.
src/dhcp_device.cpp Adds direct includes for errno/stdlib/socket and unordered containers used in the implementation.

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