Skip to content

fix: omit nftables interval end when range hits max address - #83

Merged
nekohasekai merged 1 commit into
SagerNet:devfrom
H-TTTTT:fix/nftables-interval-end-overflow
Jul 22, 2026
Merged

fix: omit nftables interval end when range hits max address#83
nekohasekai merged 1 commit into
SagerNet:devfrom
H-TTTTT:fix/nftables-interval-end-overflow

Conversation

@H-TTTTT

@H-TTTTT H-TTTTT commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • When building nftables interval sets, ranges whose upper bound is the address-family maximum (255.255.255.255 / ffff:...:ffff) made To().Next() invalid.
  • The old fallback set the interval end equal to the start, so nftables rejected the duplicate key with EEXIST (file exists).
  • Omit the end element in that case so the half-open interval extends through the max address (same convention as other nftables consumers).

Test plan

  • route_exclude_address: ["ff00::/8"] with auto_redirect: true starts without EEXIST
  • IPv4 240.0.0.0/4 / 224.0.0.0/3 exclude addresses also work
  • Normal non-max ranges still encode start + exclusive end

Fixes SagerNet/sing-box#4316

When To() is 255.255.255.255 / ffff:...:ffff, Next() is invalid. Using
From() as the end key duplicated the start element and caused EEXIST.
Omit the end element so the half-open interval covers through max.

Fixes SagerNet/sing-box#4316
@H-TTTTT
H-TTTTT force-pushed the fix/nftables-interval-end-overflow branch from 8775818 to 7e3a2d4 Compare July 22, 2026 03:43
@nekohasekai
nekohasekai merged commit 8cededc into SagerNet:dev Jul 22, 2026
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.

TUN auto_redirect: nftables EEXIST for excluded CIDRs reaching the max address (ff00::/8, 240.0.0.0/4)

2 participants