Skip to content

Commit

Permalink
auto-redirect: Fix uid rules
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Aug 25, 2024
1 parent aecfc19 commit c836de6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
12 changes: 7 additions & 5 deletions redirect_iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ func (r *autoRedirect) setupIPTablesForFamily(iptablesPath string) error {
return err
}
}
for _, uid := range r.tunOptions.ExcludeUID {
err = r.runShell(iptablesPath, "-t nat -A", tableNamePreRouteing,
"-m owner --uid-owner", uid, "-j RETURN")
if err != nil {
return err
for _, uidRange := range r.tunOptions.ExcludeUID {
for uid := uidRange.Start; uid <= uidRange.End; uid++ {
err = r.runShell(iptablesPath, "-t nat -A", tableNamePreRouteing,
"-m owner --uid-owner", uid, "-j RETURN")
if err != nil {
return err
}
}
}
if !r.tunOptions.EXP_DisableDNSHijack {
Expand Down
30 changes: 12 additions & 18 deletions redirect_nftables_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,16 @@ func (r *autoRedirect) nftablesCreateExcludeRules(nft *nftables.Conn, table *nft
Table: table,
Anonymous: true,
Constant: true,
Interval: true,
KeyType: nftables.TypeUID,
}
err := nft.AddSet(includeUID, common.FlatMap(r.tunOptions.IncludeUID, func(it ranges.Range[uint32]) []nftables.SetElement {
return []nftables.SetElement{
{
Key: binaryutil.BigEndian.PutUint32(it.Start),
},
{
Key: binaryutil.BigEndian.PutUint32(it.End + 1),
IntervalEnd: true,
},
var elements []nftables.SetElement
for uid := it.Start; uid <= it.End; uid++ {
elements = append(elements, nftables.SetElement{
Key: binaryutil.BigEndian.PutUint32(uid),
})
}
return elements
}))
if err != nil {
return err
Expand Down Expand Up @@ -290,19 +287,16 @@ func (r *autoRedirect) nftablesCreateExcludeRules(nft *nftables.Conn, table *nft
Table: table,
Anonymous: true,
Constant: true,
Interval: true,
KeyType: nftables.TypeUID,
}
err := nft.AddSet(excludeUID, common.FlatMap(r.tunOptions.ExcludeUID, func(it ranges.Range[uint32]) []nftables.SetElement {
return []nftables.SetElement{
{
Key: binaryutil.BigEndian.PutUint32(it.Start),
},
{
Key: binaryutil.BigEndian.PutUint32(it.End + 1),
IntervalEnd: true,
},
var elements []nftables.SetElement
for uid := it.Start; uid <= it.End; uid++ {
elements = append(elements, nftables.SetElement{
Key: binaryutil.BigEndian.PutUint32(uid),
})
}
return elements
}))
if err != nil {
return err
Expand Down

0 comments on commit c836de6

Please sign in to comment.