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:
parent
8048acde1e
commit
7954dd6e20
1 changed files with 7 additions and 8 deletions
|
|
@ -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{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue