mirror of
https://github.com/SunBK201/UA3F.git
synced 2025-12-17 01:06:13 +00:00
fix: ensure firewall setup netlink helper behind nfqueue server
This commit is contained in:
parent
a3cd2cbef8
commit
16a08cb5a3
@ -4,6 +4,7 @@ package nfqueue
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/coreos/go-iptables/iptables"
|
"github.com/coreos/go-iptables/iptables"
|
||||||
"github.com/sunbk201/ua3f/internal/netfilter"
|
"github.com/sunbk201/ua3f/internal/netfilter"
|
||||||
@ -36,7 +37,13 @@ func (s *Server) iptSetup() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ipt.Append(table, jumpPoint, JumpChain...)
|
// ensure netlink helper behind nfqueue server
|
||||||
|
pos, exists := s.detectNfqueue(ipt)
|
||||||
|
if !exists {
|
||||||
|
err = ipt.Append(table, jumpPoint, JumpChain...)
|
||||||
|
} else {
|
||||||
|
err = ipt.Insert(table, jumpPoint, pos-1, JumpChain...)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -97,3 +104,17 @@ func (s *Server) IptSetNfqueue(ipt *iptables.IPTables) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// detect if iptables nfqueue rule exists and return nfqueue rule position
|
||||||
|
func (s *Server) detectNfqueue(ipt *iptables.IPTables) (pos int, exists bool) {
|
||||||
|
rules, err := ipt.List(table, jumpPoint)
|
||||||
|
if err != nil {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
for i, rule := range rules {
|
||||||
|
if strings.Contains(rule, "NFQUEUE") {
|
||||||
|
return i + 1, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user