Skip to content

fix(parser): accept prefix delegation size none on DHCPv6 interfaces - #1072

Open
intigenesis wants to merge 1 commit into
EvilBit-Labs:mainfrom
intigenesis:fix/dhcp6-ia-pd-len-none
Open

intigenesis wants to merge 1 commit into
EvilBit-Labs:mainfrom
intigenesis:fix/dhcp6-ia-pd-len-none

Conversation

@intigenesis

Copy link
Copy Markdown
Collaborator

Pull Request

Description

Both GUIs store the DHCPv6 prefix delegation size in <dhcp6-ia-pd-len> as a bit count from 0 to 16 or as none. Interface.DHCP6IaPdLen was a strict int in pkg/schema/opnsense and pkg/schema/pfsense, so none raised a strconv error that ended the decode of the whole config, and convert, display, audit, validate and diff exited 1 with no report. Both vendors were affected. This PR makes the field a string in both schemas.

none requests no prefix delegation at all; it is not a missing size hint. Both vendors' interfaces.inc gate the prefix delegation request on is_numeric(): OPNsense 26.7.9 at L2932 and L2981, pfSense at L5030 and L5052. OPNsense offers none beside the bit counts (interfaces.php L1731-1752, NetworkInterface.xml L149-172). pfSense lists it first (interfaces.php L2814, the same in RELENG_2_7_2 L2504) and preselects it when a DHCPv6 interface has no value (L305-306), so saving such an interface without picking a size writes it.

Nothing outside pkg/schema reads the field, so no converter, validator or pkg/model change is needed, and convert output for every config fixture under testdata/ is unchanged. The value is kept as written and is still not mapped into CommonDevice. #834 tracks that, so until it lands diff reports nothing for a change from 0 to none.

A string also keeps <dhcp6-ia-pd-len>0</dhcp6-ia-pd-len> when the schema struct is marshaled. The int with omitempty dropped it, and an absent element fails the same is_numeric() test, so the marshaled config requested no prefix delegation where the original requested it.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (changes to documentation only)
  • Refactoring (no functional changes, code improvements)
  • Performance improvement (improves performance without changing functionality)
  • Test addition/update (adding or updating tests)
  • Build/CI change (changes to build system or CI configuration)

Related Issues

Testing

Pre-submission Checklist

  • Code Quality: golangci-lint run ./pkg/schema/... ./pkg/parser/... reports 0 issues, formatters included
  • Linting: as above
  • Tests: go test ./pkg/schema/... ./pkg/parser/... ./internal/cfgparser/... ./internal/validator/... passes
  • Error Handling: not applicable, no error path changes
  • Logging: not applicable
  • Documentation: the schema doc comments, GOTCHAS 15.0, the API snapshots and the model reference row are updated
  • Dependencies: none added or changed
  • Security: no secrets or credentials involved
  • Input Validation: not applicable

Test Commands Executed

go test ./pkg/schema/... ./pkg/parser/... ./internal/cfgparser/... ./internal/validator/...
golangci-lint run ./pkg/schema/... ./pkg/parser/...
go test ./pkg/parser -run TestPublicAPISnapshot -update
pre-commit run --files docs/templates/model-reference.md GOTCHAS.md

Test Results

The same inputs through opndossier-main, built from main, and opndossier, built from this branch, each with go build -o <name> .. The inputs are two shipped fixtures with their one <dhcp6-ia-pd-len>0</dhcp6-ia-pd-len> changed to none:

sed 's|<dhcp6-ia-pd-len>0</dhcp6-ia-pd-len>|<dhcp6-ia-pd-len>none</dhcp6-ia-pd-len>|' testdata/config.xml.sample > pdlen-none.xml
sed 's|<dhcp6-ia-pd-len>0</dhcp6-ia-pd-len>|<dhcp6-ia-pd-len>none</dhcp6-ia-pd-len>|' testdata/pfsense/config-pfSense.xml > pf-pdlen-none.xml
for bin in ./opndossier-main ./opndossier; do
  echo "== $bin"
  for f in pdlen-none.xml pf-pdlen-none.xml; do for cmd in "convert --format json" "display" "validate" "audit --mode blue --format json" "audit --mode red --format json"; do $bin $cmd "$f" > /dev/null 2>&1; echo "$f $cmd: exit=$?"; done; done
  $bin diff testdata/config.xml.sample pdlen-none.xml; echo "diff exit=$?"
  $bin diff testdata/pfsense/config-pfSense.xml pf-pdlen-none.xml; echo "diff exit=$?"
done
Check main This PR
The loop, all ten lines exit=1 exit=0
diff, both vendors exit 1, Failed to parse new config exit 0, No changes detected between configurations.

On this branch each none file converts to the same JSON as its unmodified fixture:

cmp <(./opndossier convert testdata/config.xml.sample --format json 2>/dev/null) <(./opndossier convert pdlen-none.xml --format json 2>/dev/null) && echo "opnsense: identical"
cmp <(./opndossier convert testdata/pfsense/config-pfSense.xml --format json 2>/dev/null) <(./opndossier convert pf-pdlen-none.xml --format json 2>/dev/null) && echo "pfsense: identical"

Both lines print. convert output for all 19 config fixtures under testdata/ is byte-identical between the two binaries; this loop prints nothing:

for f in testdata/*.xml testdata/config.xml.sample testdata/pfsense/*.xml; do cmp -s <(./opndossier-main convert "$f" --format json 2>/dev/null) <(./opndossier convert "$f" --format json 2>/dev/null) || echo "differs: $f"; done

With the two schema files reverted and the new tests kept, the tests fail on both vendors. 0a3f0fe4 is this PR's base:

git checkout 0a3f0fe4 -- pkg/schema/opnsense/interfaces.go pkg/schema/pfsense/interfaces.go
go test ./pkg/schema/opnsense ./pkg/schema/pfsense ./pkg/parser/opnsense ./pkg/parser/pfsense -run DHCP6IaPdLen -v
git checkout HEAD -- pkg/schema/opnsense/interfaces.go pkg/schema/pfsense/interfaces.go
  • TestParser_DHCP6IaPdLen_EndToEnd, in both parser packages, fails on the none cases in both validate modes with the strconv error and passes on every bit count from 0 to 16, the empty element and the absent element.
  • TestInterfaces_DHCP6IaPdLen_DecodesEveryGUIValue, in both schema packages, fails on every case: none with the strconv error, and the rest because the field decodes to an int where the test expects the string as written. 0 also fails because the marshal drops <dhcp6-ia-pd-len>0</dhcp6-ia-pd-len>.

Changes Made

Files Modified

  • pkg/schema/opnsense/interfaces.go, pkg/schema/pfsense/interfaces.go
  • pkg/schema/opnsense/interface_dhcp6_pd_len_test.go, pkg/schema/pfsense/interface_dhcp6_pd_len_test.go (new)
  • pkg/parser/opnsense/converter_dhcp6_pd_len_test.go, pkg/parser/pfsense/converter_dhcp6_pd_len_test.go (new)
  • pkg/parser/testdata/api-snapshots/pkg-schema-opnsense.golden, pkg-schema-pfsense.golden
  • docs/templates/model-reference.md
  • GOTCHAS.md

Key Changes

  • Interface.DHCP6IaPdLen is a string in both schemas, with the tags and column alignment unchanged. Each Interface doc comment says why.
  • The schema tests decode an <interfaces> block with the value on the second of three interfaces, for none, every bit count from 0 to 16, an empty element and an absent element, and marshal it back.
  • The end-to-end tests drive a config with a DHCPv6 WAN and a track6 LAN through parser.Factory.CreateDevice in both validate modes, for the same values, and check that both interfaces and a filter rule after <interfaces> are converted. They do not check the stored value, which is not mapped into CommonDevice.
  • GOTCHAS 15.0 gains a paragraph on why a strict int failed the whole parse.

Review Checklist

For Reviewers

  • Code Quality: Code follows project conventions and Go standards
  • Architecture: Changes align with project architecture patterns
  • Security: No security vulnerabilities introduced
  • Performance: No performance regressions
  • Documentation: Documentation updated if needed
  • Testing: Adequate test coverage provided
  • Breaking Changes: Breaking changes properly documented

For Contributors

  • Self Review: Code has been self-reviewed
  • Commit Messages: Follow conventional commit format
  • Branch Naming: Branch follows naming convention (feat/, fix/, docs/, etc.)
  • Scope: Changes are focused and not too broad
  • Dependencies: No unnecessary dependencies added

Documentation

Documentation Updates

  • README.md
  • CONTRIBUTING.md
  • docs/development/standards.md
  • docs/development/architecture.md
  • Project specification files

None of the above. GOTCHAS 15.0, the two Interface doc comments, the API snapshots and the DHCP6IaPdLen row of docs/templates/model-reference.md are updated.

API Changes

Interface.DHCP6IaPdLen in pkg/schema/opnsense and pkg/schema/pfsense changes from int to string, so its JSON and YAML key dhcp6IaPdLen holds a string instead of a number. docs/development/public-api.md treats pkg/schema/* as vendor-tracking, so this follows the vendors rather than making a semver commitment. pkg/model does not change.

Breaking Changes

None in pkg/model or in CLI output. A pkg/schema caller that read DHCP6IaPdLen as an int will need to read a string: "0" to "16", "none", or "" for an empty or absent element. Released versions through v1.10.0 expose the field as an int.

Migration Guide

None needed for the model or the CLI. A pkg/schema caller can use strconv.Atoi on the string and treat a failure as no prefix delegation, as the vendors' is_numeric() test does.

Security Considerations

None. The field holds no secret.

Performance Impact

None.

Acceptance Criteria

  • A config with <dhcp6-ia-pd-len>none</dhcp6-ia-pd-len> parses on both vendors, and convert, display, audit, validate and diff complete
  • 0, 16, an empty element and an absent element still decode
  • convert output for every config fixture under testdata/ is unchanged
  • The new tests fail on main's schema types for both vendors

Additional Notes

The shipped fixtures that carry the element all hold 0, which is why no test caught this.

go run tools/docgen/main.go also refreshes rows of docs/templates/model-reference.md that earlier changes left stale: Floating, Quick and Disabled in the OPNsense filter rule table (now *string) and a DisableFilter row in the system table. Those changes are unrelated to this fix and are left out.

Labels

  • bug-fix

AI disclosure

Used Claude Code (claude-opus-5-5) to trace the vendor source and write the change, the tests and this description. All changes reviewed locally before push. Followed process per AI_POLICY.md.


By submitting this pull request, I confirm that:

  • I have read and followed the Contributing Guide
  • I have read and followed the Development Standards
  • My code follows the project's coding standards
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings
  • I have checked my code and corrected any misspellings

Both GUIs store the DHCPv6 prefix delegation size in <dhcp6-ia-pd-len>
as a bit count from 0 to 16 or as "none", which requests no prefix
delegation at all. OPNsense 26.7.9 offers none beside the bit counts
(interfaces.php L1731-1752). pfSense lists it first and selects it when
a DHCPv6 interface has no value (interfaces.php L305-306, L2814). Both
interfaces.inc files gate the prefix delegation request on is_numeric().

Interface.DHCP6IaPdLen was a strict int in both schemas, so "none"
raised a strconv error that failed the parse of the whole config, and
convert, display, audit, validate and diff exited 1 with no report. The
field is now a string in pkg/schema/opnsense and pkg/schema/pfsense.
Nothing outside pkg/schema reads it, so no converter, validator or
model change is needed, and convert output for every testdata fixture is
unchanged. A string also keeps <dhcp6-ia-pd-len>0</dhcp6-ia-pd-len> on
marshal, which the int with omitempty dropped.

The tests decode every size the GUIs offer through the schema and the
parsers. The API snapshots, the model reference row and GOTCHAS 15.0
are updated.

Signed-off-by: intigenesis <313311150+intigenesis@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed configuration parsing for DHCPv6 prefix-delegation lengths in OPNsense and pfSense. Values such as none, empty or missing entries, and numeric lengths from 0 to 16 are now handled without causing the configuration decode to fail.
    • Preserved prefix-delegation values when reading and writing configuration files, including nonnumeric values such as none.

Walkthrough

Both OPNsense and pfSense now represent DHCPv6 prefix-delegation length as a string. Schema round-trip tests and end-to-end parser tests cover none, empty and absent elements, and numeric values from 0 to 16.

Changes

DHCPv6 Prefix-Length Parsing

Layer / File(s) Summary
String schema contract and XML round-trip coverage
pkg/schema/opnsense/interfaces.go, pkg/schema/pfsense/interfaces.go, pkg/schema/opnsense/interface_dhcp6_pd_len_test.go, pkg/schema/pfsense/interface_dhcp6_pd_len_test.go, pkg/parser/testdata/api-snapshots/*, docs/templates/model-reference.md, GOTCHAS.md
Both schema fields change from int to string; their serialization tags remain unchanged. Schema tests cover decoding and marshal-round-trip behavior for GUI values. API snapshots and documentation describe the field and its values.
End-to-end parser coverage
pkg/parser/opnsense/converter_dhcp6_pd_len_test.go, pkg/parser/pfsense/converter_dhcp6_pd_len_test.go
Parser tests cover none, empty and absent elements, and values from 0 to 16 with validation enabled and disabled. They check device creation, WAN and LAN interfaces, and firewall rules.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • Issue 834 tracks mapping DHCP6IaPdLen into CommonDevice. This change updates schema parsing but leaves that mapping out of scope.

Suggested labels: type:bug, go, testing, breaking_change

Merge Risk: Minimal · up to cdbb6

This change lets configurations with a "none" DHCPv6 prefix-delegation length parse in both OPNsense and pfSense. Tests cover the affected values. Library callers that read the field must now handle a string instead of an int. The merge risk is minimal.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title "fix(parser): accept prefix delegation size none on DHCPv6 interfaces" follows the conventional commit format (type fix, scope parser, description). It matches the main change: the DHCP6IaPd…
Description check Passed The description covers the problem, the fix, the vendor evidence, and the test results. It follows the template's main sections, including Description, Type of Change, Related Issues, Testing, Changes…
Linked Issues check Passed [#1071] Requirement: a config with none must parse on OPNsense and pfSense, and the commands must not exit on a parse error. The head diff changes Interface.DHCP6IaP…
Out of Scope Changes check Passed The whole-PR changes against merge base 0a3f0fe are: the two schema field type changes with doc comments, new schema and parser regression tests, API snapshot golden updates for the changed field, a …
Go Exported-Symbol Godoc Passed The check applies to exported identifiers in non-test production .go files. The PR's changed .go files are pkg/schema/opnsense/interfaces.go and pkg/schema/pfsense/interfaces.go (modified), plus sever…
Full details: Title check

Explanation

The title "fix(parser): accept prefix delegation size none on DHCPv6 interfaces" follows the conventional commit format (type fix, scope parser, description). It matches the main change: the DHCP6IaPdLen field changes from int to string so that the value none parses in both the OPNsense and pfSense schemas.

Full details: Description check

Explanation

The description covers the problem, the fix, the vendor evidence, and the test results. It follows the template's main sections, including Description, Type of Change, Related Issues, Testing, Changes Made, Documentation, API Changes, Breaking Changes, and Acceptance Criteria. Some template items remain unchecked or unfilled, such as the Review Checklist, the Documentation checklist, and the Performance and Security sections. These gaps are non-critical, since the description is mostly complete.

Full details: Linked Issues check

Explanation

[#1071] Requirement: a config with <dhcp6-ia-pd-len>none</dhcp6-ia-pd-len> must parse on OPNsense and pfSense, and the commands must not exit on a parse error. The head diff changes Interface.DHCP6IaPdLen from int to string in pkg/schema/opnsense/interfaces.go and pkg/schema/pfsense/interfaces.go. The XML tag is unchanged, so encoding/xml no longer calls strconv on the element body. This removes the strconv error that ended the decode. The 0-16 values, the empty element and the absent element are all valid strings, so they still decode. A non-empty string such as "0" survives marshal under omitempty, which meets the marshal-preservation requirement. The new tests in pkg/schema//interface_dhcp6_pd_len_test.go and pkg/parser//converter_dhcp6_pd_len_test.go cover these values, per the PR description. I did not run these tests. Related #834 is a separate mapping task and is not a requirement of #1071.

Full details: Out of Scope Changes check

Explanation

The whole-PR changes against merge base 0a3f0fe are: the two schema field type changes with doc comments, new schema and parser regression tests, API snapshot golden updates for the changed field, a model-reference doc row for the field, and a GOTCHAS 15.0 paragraph. Each supports the #1071 fix or documents it. The PR description states that unrelated stale rows in docs/templates/model-reference.md were regenerated but left out. No converter, validator, or pkg/model change is present in the PR description's file list. The claim that convert output is byte-identical for the 19 fixtures is author-reported evidence; I did not re-run it.

Full details: Go Exported-Symbol Godoc

Explanation

The check applies to exported identifiers in non-test production .go files. The PR's changed .go files are pkg/schema/opnsense/interfaces.go and pkg/schema/pfsense/interfaces.go (modified), plus several new *_test.go files (exempt). The other changed files are GOTCHAS.md, a markdown doc, and .golden snapshots, which are not Go source. The diff for the two production files adds no new exported identifier. It changes only the type of the existing exported field DHCP6IaPdLen from int to string and adds prose to the existing Interface type doc comments. Struct fields are outside the listed identifier kinds (functions, methods, types, constants, variables). The Interface type comments already start with the identifier name: "Interface represents a single network interface..." (opnsense) and "Interface represents a pfSense network interface..." (pfsense). Both directly precede the declaration with no blank line. No qualifying identifier lacks a conforming doc comment, so there are no hits to report.

Finishing Touches

Simplify code

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A length may arrive as none
Or numbers in the GUI’s range
The schemas keep the value as text
Round trips check what XML exchanged
Two parsers read the tested cases

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: EvilBit-Labs/opnDossier
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 0a3f0fe
  • Layers: Repository YAML (base), Repository UI (inherited), Organization UI (inherited)
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: c5e5b18d-4391-4269-95ea-61a78f767555
Commits

Reviewing files that changed from the base of the PR and between 0a3f0fe and cdbb6df.

Files selected for processing: 10

  • GOTCHAS.md
  • docs/templates/model-reference.md
  • pkg/parser/opnsense/converter_dhcp6_pd_len_test.go
  • pkg/parser/pfsense/converter_dhcp6_pd_len_test.go
  • pkg/parser/testdata/api-snapshots/pkg-schema-opnsense.golden
  • pkg/parser/testdata/api-snapshots/pkg-schema-pfsense.golden
  • pkg/schema/opnsense/interface_dhcp6_pd_len_test.go
  • pkg/schema/opnsense/interfaces.go
  • pkg/schema/pfsense/interface_dhcp6_pd_len_test.go
  • pkg/schema/pfsense/interfaces.go
Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@mergify

mergify Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 4 protections blocking · waiting on 🙋 you

Protection Waiting on
🔴 🚦 Auto-queue 🙋 you
🟢 Enforce conventional commit —
🟢 Full CI must pass —
🟢 Do not merge outdated PRs —

🔴 🚦 Auto-queue

This rule is failing.

When all merge protections are satisfied and these conditions match, this pull request will be queued automatically.

  • any of:
    • all of:
      • author = dosubot[bot]
      • base = main
      • label != do-not-merge
    • all of:
      • -files ~= ^(?!\.github/workflows/)
      • author = dependabot[bot]
      • base = main
      • label != do-not-merge
    • all of:
      • author = dependabot[bot]
      • base = main
      • label != do-not-merge

Show 3 satisfied protections

🟢 Enforce conventional commit

Require conventional commit format per https://www.conventionalcommits.org/en/v1.0.0/. Skipped for dependabot and dosubot.

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?!?:

🟢 Full CI must pass

All CI checks must pass. Activates for non-bot authors, or dependabot when files exist outside .github/workflows/.

  • check-success = Build
  • check-success = Coverage
  • check-success = Integration Tests
  • check-success = Lint
  • check-success = Test (macos-latest, stable)
  • check-success = Test (ubuntu-latest, stable)
  • check-success = Test (windows-latest, stable)

🟢 Do not merge outdated PRs

Make sure PRs are within 10 commits of the base branch before merging

  • #commits-behind <= 10

@mergify

mergify Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@coderabbitai coderabbitai Bot added breaking_change Significant changes that disrupt backward compatibility. go Pull requests that update go code testing Test infrastructure and test-related issues type:bug Bug or defect that needs fixing labels Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking_change Significant changes that disrupt backward compatibility. go Pull requests that update go code testing Test infrastructure and test-related issues type:bug Bug or defect that needs fixing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Config fails to parse when a DHCPv6 interface has prefix delegation size None

1 participant