mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-04 04:17:39 +03:00
Fix generate empty sets
This commit is contained in:
parent
1048b277ea
commit
086271ef29
1 changed files with 18 additions and 9 deletions
|
@ -79,17 +79,9 @@ func nftablesCreateIPSet(
|
||||||
) (*nftables.Set, error) {
|
) (*nftables.Set, error) {
|
||||||
if len(prefixList) > 0 {
|
if len(prefixList) > 0 {
|
||||||
var builder netipx.IPSetBuilder
|
var builder netipx.IPSetBuilder
|
||||||
if appendDefault && len(setList) == 0 {
|
|
||||||
if family == nftables.TableFamilyIPv4 {
|
|
||||||
prefixList = append(prefixList, netip.PrefixFrom(netip.IPv4Unspecified(), 0))
|
|
||||||
} else {
|
|
||||||
prefixList = append(prefixList, netip.PrefixFrom(netip.IPv6Unspecified(), 0))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _, prefix := range prefixList {
|
for _, prefix := range prefixList {
|
||||||
builder.AddPrefix(prefix)
|
builder.AddPrefix(prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
ipSet, err := builder.IPSet()
|
ipSet, err := builder.IPSet()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -103,7 +95,7 @@ func nftablesCreateIPSet(
|
||||||
ipSets = append(ipSets, mySet)
|
ipSets = append(ipSets, mySet)
|
||||||
rangeLen += len(mySet.rr)
|
rangeLen += len(mySet.rr)
|
||||||
}
|
}
|
||||||
setElements := make([]nftables.SetElement, 0, len(prefixList)+rangeLen)
|
setElements := make([]nftables.SetElement, 0, rangeLen)
|
||||||
for _, mySet := range ipSets {
|
for _, mySet := range ipSets {
|
||||||
for _, rr := range mySet.rr {
|
for _, rr := range mySet.rr {
|
||||||
if (family == nftables.TableFamilyIPv4) != rr.from.Is4() {
|
if (family == nftables.TableFamilyIPv4) != rr.from.Is4() {
|
||||||
|
@ -122,6 +114,23 @@ func nftablesCreateIPSet(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(prefixList) == 0 && appendDefault {
|
||||||
|
if family == nftables.TableFamilyIPv4 {
|
||||||
|
setElements = append(setElements, nftables.SetElement{
|
||||||
|
Key: netip.IPv4Unspecified().AsSlice(),
|
||||||
|
}, nftables.SetElement{
|
||||||
|
Key: netip.IPv4Unspecified().AsSlice(),
|
||||||
|
IntervalEnd: true,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
setElements = append(setElements, nftables.SetElement{
|
||||||
|
Key: netip.IPv6Unspecified().AsSlice(),
|
||||||
|
}, nftables.SetElement{
|
||||||
|
Key: netip.IPv6Unspecified().AsSlice(),
|
||||||
|
IntervalEnd: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
var keyType nftables.SetDatatype
|
var keyType nftables.SetDatatype
|
||||||
if family == nftables.TableFamilyIPv4 {
|
if family == nftables.TableFamilyIPv4 {
|
||||||
keyType = nftables.TypeIPAddr
|
keyType = nftables.TypeIPAddr
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue