mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-08 03:00:27 +08:00
自动将同集群节点IP加入白名单/尝试使用本地防火墙提升黑名单连接封锁效率
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
package iplibrary
|
package iplibrary
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
"github.com/TeaOSLab/EdgeNode/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -14,6 +15,12 @@ func AllowIP(ip string, serverId int64) (canGoNext bool, inAllowList bool) {
|
|||||||
return false, false
|
return false, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check node
|
||||||
|
nodeConfig, err := nodeconfigs.SharedNodeConfig()
|
||||||
|
if err == nil && nodeConfig.IPIsAutoAllowed(ip) {
|
||||||
|
return true, true
|
||||||
|
}
|
||||||
|
|
||||||
// check white lists
|
// check white lists
|
||||||
if GlobalWhiteIPList.Contains(ipLong) {
|
if GlobalWhiteIPList.Contains(ipLong) {
|
||||||
return true, true
|
return true, true
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ package nodes
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeNode/internal/firewalls"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/iplibrary"
|
"github.com/TeaOSLab/EdgeNode/internal/iplibrary"
|
||||||
"github.com/TeaOSLab/EdgeNode/internal/waf"
|
"github.com/TeaOSLab/EdgeNode/internal/waf"
|
||||||
"net"
|
"net"
|
||||||
@@ -51,6 +52,13 @@ func (this *ClientListener) Accept() (net.Conn, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_ = conn.Close()
|
_ = conn.Close()
|
||||||
|
|
||||||
|
// 使用本地防火墙延长封禁
|
||||||
|
var fw = firewalls.Firewall()
|
||||||
|
if fw != nil && !fw.IsMock() {
|
||||||
|
_ = fw.DropSourceIP(ip, 60)
|
||||||
|
}
|
||||||
|
|
||||||
return this.Accept()
|
return this.Accept()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ func (this *Node) Start() {
|
|||||||
this.checkDisk()
|
this.checkDisk()
|
||||||
|
|
||||||
// 读取API配置
|
// 读取API配置
|
||||||
|
remotelogs.Println("NODE", "init config ...")
|
||||||
err = this.syncConfig(0)
|
err = this.syncConfig(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, err := nodeconfigs.SharedNodeConfig()
|
_, err := nodeconfigs.SharedNodeConfig()
|
||||||
@@ -429,7 +430,7 @@ func (this *Node) syncConfig(taskVersion int64) error {
|
|||||||
clusterErr := this.checkClusterConfig()
|
clusterErr := this.checkClusterConfig()
|
||||||
if clusterErr != nil {
|
if clusterErr != nil {
|
||||||
if os.IsNotExist(clusterErr) {
|
if os.IsNotExist(clusterErr) {
|
||||||
return err
|
return errors.New("can not find config file 'configs/api.yaml'")
|
||||||
}
|
}
|
||||||
return errors.New("check cluster config failed: " + clusterErr.Error())
|
return errors.New("check cluster config failed: " + clusterErr.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,8 +130,8 @@ func (this *IPList) Contains(ipType string, scope firewallconfigs.FirewallScope,
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.locker.RLock()
|
this.locker.RLock()
|
||||||
defer this.locker.RUnlock()
|
|
||||||
_, ok := this.ipMap[ip]
|
_, ok := this.ipMap[ip]
|
||||||
|
this.locker.RUnlock()
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user