fix: replace netfilter reset tcp option timestamp with nfqueue way

This commit is contained in:
SunBK201 2025-11-23 15:53:32 +08:00
parent 43d95183d9
commit 82c9d7ebc8
2 changed files with 10 additions and 24 deletions

View File

@ -87,12 +87,7 @@ func (s *Server) IptSetTTL(ipt *iptables.IPTables) error {
} }
func (s *Server) IptDelTCPTS(ipt *iptables.IPTables) error { func (s *Server) IptDelTCPTS(ipt *iptables.IPTables) error {
err := ipt.Append(table, chain, RuleRstTimestamp...) err := ipt.Append(table, chain, RuleDelTCPTS...)
if err == nil {
return nil
}
err = ipt.Append(table, chain, RuleDelTCPTS...)
if err != nil { if err != nil {
return err return err
} }

View File

@ -83,22 +83,12 @@ func (s *Server) NftDelTCPTS(tx *knftables.Transaction, table *knftables.Table)
} }
tx.Add(chain) tx.Add(chain)
var rule *knftables.Rule var rule *knftables.Rule
if resetOptionAvailable() { rule = &knftables.Rule{
rule = &knftables.Rule{ Chain: chain.Name,
Chain: chain.Name, Rule: knftables.Concat(
Rule: knftables.Concat( "tcp flags syn",
"tcp option timestamp exists", fmt.Sprintf("counter queue num %d bypass", s.nfqServer.QueueNum),
"counter reset tcp option timestamp", ),
),
}
} else {
rule = &knftables.Rule{
Chain: chain.Name,
Rule: knftables.Concat(
"tcp flags syn",
fmt.Sprintf("counter queue num %d bypass", s.nfqServer.QueueNum),
),
}
} }
tx.Add(rule) tx.Add(rule)
} }
@ -122,7 +112,8 @@ func (s *Server) NftSetIP(tx *knftables.Transaction, table *knftables.Table) {
tx.Add(rule) tx.Add(rule)
} }
func resetOptionAvailable() bool { // unused currently
func ResetOptionAvailable() bool {
const TestName = "UA3F_TEST_RESET" const TestName = "UA3F_TEST_RESET"
table := &knftables.Table{ table := &knftables.Table{
Name: TestName, Name: TestName,
@ -130,7 +121,7 @@ func resetOptionAvailable() bool {
} }
nft, err := knftables.New(table.Family, table.Name) nft, err := knftables.New(table.Family, table.Name)
if err != nil { if err != nil {
slog.Error("resetOptionAvailable knftables.New", slog.Any("error", err)) slog.Error("ResetOptionAvailable knftables.New", slog.Any("error", err))
return false return false
} }
tx := nft.NewTransaction() tx := nft.NewTransaction()