Fix nftables interval end when range hits max address

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
This commit is contained in:
H-TTTTT 2026-07-22 11:56:24 +08:00 committed by 世界
parent 8048acde1e
commit 7954dd6e20
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -149,18 +149,17 @@ func nftablesCreateIPSet(
if (family == nftables.TableFamilyIPv4) != rr.From().Is4() { if (family == nftables.TableFamilyIPv4) != rr.From().Is4() {
continue continue
} }
endAddr := rr.To().Next()
if !endAddr.IsValid() {
endAddr = rr.From()
}
setElements = append(setElements, nftables.SetElement{ setElements = append(setElements, nftables.SetElement{
Key: rr.From().AsSlice(), Key: rr.From().AsSlice(),
}) })
endAddr := rr.To().Next()
if endAddr.IsValid() {
setElements = append(setElements, nftables.SetElement{ setElements = append(setElements, nftables.SetElement{
Key: endAddr.AsSlice(), Key: endAddr.AsSlice(),
IntervalEnd: true, IntervalEnd: true,
}) })
} }
}
if appendDefault && len(setElements) == 0 { if appendDefault && len(setElements) == 0 {
if family == nftables.TableFamilyIPv4 { if family == nftables.TableFamilyIPv4 {
setElements = append(setElements, nftables.SetElement{ setElements = append(setElements, nftables.SetElement{