Skip to content

update consts and add discrete types for enums - #46

Open
thaJeztah wants to merge 6 commits into
moby:mainfrom
thaJeztah:update_consts
Open

thaJeztah wants to merge 6 commits into
moby:mainfrom
thaJeztah:update_consts

Conversation

@thaJeztah

@thaJeztah thaJeztah commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

document IPVS netlink constants and use explicit values

Replace iota-based constant definitions with explicit values matching
the Linux kernel's IPVS generic netlink interface.

Add comments identifying the corresponding kernel constants and links
to their definitions in the Linux UAPI headers.

This makes it easier to verify the values against the kernel and
prevents accidental changes to protocol values when constants are
added or reordered.

define a distinct type for IPVS netlink commands

Introduce an ipvsCmd type for IPVS generic netlink commands and
update the command helpers to use it.

This groups the command constants under a distinct type, allowing
linters such as exhaustive to detect missing cases in switches and
providing stronger type checking.

Keep the generic netlink request helper accepting uint8, as it is
also used for commands outside the IPVS family.

define distinct types for IPVS netlink attributes

Introduce dedicated types for IPVS command, service, destination,
and statistics attributes, using int as the underlying type to
match the netlink package's API.

Update the encoding and decoding paths to use these types, with
explicit conversions at the netlink API boundaries.

This improves type safety and allows linters such as exhaustive
to detect missing attribute cases in switch statements.

The attribute values and wire format remain unchanged.

deduplicate IPVS forwarding method constants

Use the ConnFwd* constants as the canonical names for IPVS
forwarding methods, and deprecate the duplicate ConnectionFlag*
constants while retaining them as aliases for compatibility.

Update internal references to use ConnFwd* and document their
corresponding Linux kernel definitions.

Simplify lookupFwMethod by returning string literals directly
instead of indexing into a separate slice, and handle the
previously missing LocalNode and Bypass methods.

document IPVS scheduler name constants

Add a reference to the Linux kernel's IPVS scheduler implementations
to clarify where the scheduler names originate.

Unlike the netlink attributes and forwarding flags, these names
are registered as strings by the individual kernel schedulers,
rather than defined as UAPI constants.

use unix address family constants directly

Replace nl.FAMILY_* constants with their corresponding unix.AF_*
constants.

The netlink package aliases these constants to the Linux address
family values, so using golang.org/x/sys/unix directly avoids an
unnecessary layer of indirection and makes their origin explicit.

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.

🟢 Approval recommended

The type-safety changes preserve protocol values and consistently update all affected call sites.

0 open findings

What changed in this PR

Introduces type-safe IPVS netlink enums while preserving existing wire values.

Changes:

  • Replaces iota constants with documented kernel values.
  • Adds distinct command and attribute types.
  • Converts typed values at netlink API boundaries.
File Description
constants_linux.go Defines documented, typed netlink constants.
netlink_linux.go Applies typed constants in encoding and decoding.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Replace iota-based constant definitions with explicit values matching
the Linux kernel's IPVS generic netlink interface.

Add comments identifying the corresponding kernel constants and links
to their definitions in the Linux UAPI headers.

This makes it easier to verify the values against the kernel and
prevents accidental changes to protocol values when constants are
added or reordered.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Introduce an ipvsCmd type for IPVS generic netlink commands and
update the command helpers to use it.

This groups the command constants under a distinct type, allowing
linters such as exhaustive to detect missing cases in switches and
providing stronger type checking.

Keep the generic netlink request helper accepting uint8, as it is
also used for commands outside the IPVS family.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Introduce dedicated types for IPVS command, service, destination,
and statistics attributes, using int as the underlying type to
match the netlink package's API.

Update the encoding and decoding paths to use these types, with
explicit conversions at the netlink API boundaries.

This improves type safety and allows linters such as exhaustive
to detect missing attribute cases in switch statements.

The attribute values and wire format remain unchanged.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Use the ConnFwd* constants as the canonical names for IPVS
forwarding methods, and deprecate the duplicate ConnectionFlag*
constants while retaining them as aliases for compatibility.

Update internal references to use ConnFwd* and document their
corresponding Linux kernel definitions.

Simplify lookupFwMethod by returning string literals directly
instead of indexing into a separate slice, and handle the
previously missing LocalNode and Bypass methods.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Add a reference to the Linux kernel's IPVS scheduler implementations
to clarify where the scheduler names originate.

Unlike the netlink attributes and forwarding flags, these names
are registered as strings by the individual kernel schedulers,
rather than defined as UAPI constants.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Replace nl.FAMILY_* constants with their corresponding unix.AF_*
constants.

The netlink package aliases these constants to the Linux address
family values, so using golang.org/x/sys/unix directly avoids an
unnecessary layer of indirection and makes their origin explicit.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
thaJeztah marked this pull request as ready for review October 9, 2026 12:57
@thaJeztah
thaJeztah requested a balanced review from Copilot October 9, 2026 14:07

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.

🟡 Changes recommended

Several linked UAPI enum members are omitted, undermining the intended exhaustive checking.

1 open finding

🧠 Review effort: Balanced

Comment thread constants_linux.go
Comment on lines +80 to +81
ipvsSvcAttrStats ipvsSvcAttr = 10 // IPVS_SVC_ATTR_STATS
ipvsSvcAttrPEName ipvsSvcAttr = 11 // IPVS_SVC_ATTR_PE_NAME

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yup; back-filling missing ones is on my list for a follow-up. This PR is just cleaning up the current definitions and correlating them with the upstream (Linux kernel)

@thaJeztah
thaJeztah requested review from robmry and vvoland October 9, 2026 14:19
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.

2 participants