Skip to content

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

Merged
SJrX merged 1 commit into
242.xfrom
af-enumerate-restrict-address-families
Jun 25, 2026
Merged

fix: enumerate RestrictAddressFamilies= AF_ names instead of loose regex#492
SJrX merged 1 commit into
242.xfrom
af-enumerate-restrict-address-families

Conversation

@SJrX

@SJrX SJrX commented Jun 25, 2026

Copy link
Copy Markdown
Owner

What

RestrictAddressFamilies= validated names with the loose RegexTerminal("AF_[A-Z0-9_]+"), so any AF_-prefixed token slipped through — AF_BOGUS, AF_INETZ, AF_DECNET (wrong case for the real AF_DECnet) all passed. systemd's config_parse_address_families resolves each name through af_from_name, whose set is generated from the AF_* macros in <sys/socket.h> (minus AF_UNSPEC/AF_MAX).

This replaces the loose regex with a FlexibleLiteralChoiceTerminal enumerating the real names: it still matches the shape leniently (so coloring and error localization keep working on a typo) but is semantically valid only for an exact name.

Why it's the right shape

This is the "generous RegexTerminal → enumerated choice" cleanup we flagged: an enumerated terminal gives correct validation and sets up grammar-based completion (the names become suggestions) and the valid-but-kernel-removed deprecation annotator (AF_DECnet, AF_IRDA, AF_ECONET, AF_WANPIPE) — all for free.

Scope / behavior

  • Default-path correctness fix — affects both engines (the original SemanticMatch and the new parse()), since the change is in the grammar, not the machinery.
  • Behavior change: previously-accepted bogus AF_* tokens are now flagged (well-formed but invalid).

Tests

  • Adds testValidEnumeratedFamilies (aliases / mixed-case / newest names / inverted list still accepted) and testUnknownFamiliesAreNowRejected (the regression guard) to the validator test.
  • Now that AF_BOGUS is honestly invalid, the grammar-engine e2e test (GrammarParseEngineInspectionTest) uses it to cover the SemanticError → highlight path, replacing the 242.x-safe workaround introduced in feat: opt-in list-of-successes grammar engine + dual-engine test infra #490.

Verification

./gradlew test and ./gradlew test -Dsystemd.unit.grammarParseEngine=true both pass.

Unblocks the deprecation annotator (#484), which needs the names enumerated rather than a loose regex.

🤖 Generated with Claude Code

config_parse_address_families resolves each name through af_from_name, whose set
is generated from the AF_* macros in <sys/socket.h> (minus AF_UNSPEC/AF_MAX). The
validator matched the loose RegexTerminal("AF_[A-Z0-9_]+"), so any AF_-prefixed
token (AF_BOGUS, AF_INETZ, AF_DECNET) passed validation incorrectly.

Replace it with a FlexibleLiteralChoiceTerminal enumerating the real names: it
still matches the shape leniently (so coloring / error localization keep working)
but is semantically valid only for an exact name. This is a correctness fix on
the default path (both engines), and it sets up grammar-based completion and the
valid-but-kernel-removed deprecation annotator (AF_DECnet, AF_IRDA, ...).

Tests: adds enumerated-valid and unknown-rejected cases to the validator test;
now that AF_BOGUS is honestly invalid, the grammar-engine e2e test uses it to
cover the SemanticError -> highlight mapping (replacing a 242.x-safe workaround).

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

Copy link
Copy Markdown

Unit Test Results (grammar engine true)

1 137 tests   1 137 ✅  48s ⏱️
  297 suites      0 💤
  297 files        0 ❌

Results for commit 78999e2.

@github-actions

Copy link
Copy Markdown

Unit Test Results (grammar engine false)

1 137 tests   1 137 ✅  46s ⏱️
  297 suites      0 💤
  297 files        0 ❌

Results for commit 78999e2.

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