diff --git a/internal/firewalls/firewall_firewalld.go b/internal/firewalls/firewall_firewalld.go index 6ec1a15..81146bc 100644 --- a/internal/firewalls/firewall_firewalld.go +++ b/internal/firewalls/firewall_firewalld.go @@ -170,7 +170,7 @@ func (this *Firewalld) DropSourceIP(ip string, timeoutSeconds int, async bool) e } // 避免短时间内重复添加 - if this.checkLatestIP(ip) { + if async && this.checkLatestIP(ip) { return nil } diff --git a/internal/firewalls/firewall_nftables.go b/internal/firewalls/firewall_nftables.go index 33517a0..3632b39 100644 --- a/internal/firewalls/firewall_nftables.go +++ b/internal/firewalls/firewall_nftables.go @@ -347,14 +347,14 @@ func (this *NFTablesFirewall) DropSourceIP(ip string, timeoutSeconds int, async return errors.New("invalid ip '" + ip + "'") } - // 避免短时间内重复添加 - if this.checkLatestIP(ip) { - return nil - } - // 尝试关闭连接 conns.SharedMap.CloseIPConns(ip) + // 避免短时间内重复添加 + if async && this.checkLatestIP(ip) { + return nil + } + if async { select { case this.dropIPQueue <- &blockIPItem{