Skip to content

fix: enumerate RestrictAddressFamilies= AF_ names instead of loose regex#468

Open
SJrX wants to merge 1 commit into
242.xfrom
issue-345
Open

fix: enumerate RestrictAddressFamilies= AF_ names instead of loose regex#468
SJrX wants to merge 1 commit into
242.xfrom
issue-345

Conversation

@SJrX

@SJrX SJrX commented Jun 21, 2026

Copy link
Copy Markdown
Owner

What

Replace the loose RegexTerminal("AF_[A-Z0-9_]+") in the RestrictAddressFamilies= validator with a FlexibleLiteralChoiceTerminal enumerating the 48 address families systemd's af_from_name actually accepts — the AF_* macros from <sys/socket.h>, minus AF_UNSPEC/AF_MAX (the same set systemd generates via generate-af-list.sh).

Why

The old regex accepted any AF_-prefixed token, so bogus names like AF_BOGUS passed validation. Enumerating the real names:

  • makes validation correct (AF_BOGUS, AF_INETZ, wrong-case AF_DECNET are now flagged);
  • keeps good error localization — FlexibleLiteralChoiceTerminal matches loosely for syntax (so the offending token is highlighted, not the whole line) but requires an exact choice to be semantically valid;
  • is the foundation for grammar-based completion and a future deprecation annotator for kernel-removed-but-still-resolvable families (AF_DECnet, AF_IRDA, AF_ECONET, AF_WANPIPE).

Tests

Adds a golden test suite that anchors the upcoming grammar-engine rework:

  • testValidValues / testInvalidValues — existing behavior preserved.
  • testValidEnumeratedFamilies — alias (AF_LOCAL), mixed-case real name (AF_DECnet), newest families (AF_VSOCK AF_XDP AF_MCTP), and a ~-inverted multi-family list.
  • testUnknownFamiliesAreNowRejected — raw-value regression guard that unknown AF_ names are flagged (raw values so it doesn't depend on test-framework <error> markup stripping).

This is step 1 of the grammar-engine rework tracked in #467, and the canary suite the new parse() engine must keep green.

Refs #467 #345 #343

🤖 Generated with Claude Code

Replace RegexTerminal("AF_[A-Z0-9_]+") with a FlexibleLiteralChoiceTerminal of
the 48 address families systemd's af_from_name accepts (the AF_* macros from
<sys/socket.h>, minus AF_UNSPEC/AF_MAX). Unknown names like AF_BOGUS are now
correctly rejected, and the exact name set is the foundation for grammar-based
completion and a future deprecation annotator for kernel-removed families
(AF_DECnet, AF_IRDA, AF_ECONET, AF_WANPIPE).

FlexibleLiteralChoiceTerminal keeps loose syntactic matching (so error
localization still highlights the offending token) but requires an exact choice
to be semantically valid.

Adds a golden test suite (valid families incl. alias/mixed-case/~-inversion,
plus a raw-value regression guard that unknown AF_ names are flagged) to anchor
the upcoming grammar-engine rework.

Refs #467 #345 #343

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Test Results

1 112 tests   1 112 ✅  48s ⏱️
  294 suites      0 💤
  294 files        0 ❌

Results for commit 8b48357.

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.

1 participant