MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Firewall

Function Firewall

internal/firewalls/firewall.go:33–85  ·  view source on GitHub ↗

Firewall 查找当前系统中最适合的防火墙

()

Source from the content-addressed store, hash-verified

31
32// Firewall 查找当前系统中最适合的防火墙
33func Firewall() FirewallInterface {
34 firewallLocker.Lock()
35 defer firewallLocker.Unlock()
36 if currentFirewall != nil {
37 return currentFirewall
38 }
39
40 // http firewall
41 {
42 endpoint, _ := os.LookupEnv("EDGE_HTTP_FIREWALL_ENDPOINT")
43 if len(endpoint) > 0 {
44 var httpFirewall = NewHTTPFirewall(endpoint)
45 for i := 0; i < 10; i++ {
46 if httpFirewall.IsReady() {
47 currentFirewall = httpFirewall
48 remotelogs.Println("FIREWALL", "using http firewall '"+endpoint+"'")
49 break
50 }
51 time.Sleep(1 * time.Second)
52 }
53 return httpFirewall
54 }
55 }
56
57 // nftables
58 if runtime.GOOS == "linux" {
59 nftables, err := NewNFTablesFirewall()
60 if err != nil {
61 remotelogs.Warn("FIREWALL", "'nftables' should be installed on the system to enhance security (init failed: "+err.Error()+")")
62 } else {
63 if nftables.IsReady() {
64 currentFirewall = nftables
65 events.Notify(events.EventNFTablesReady)
66 return nftables
67 } else {
68 remotelogs.Warn("FIREWALL", "'nftables' should be enabled on the system to enhance security")
69 }
70 }
71 }
72
73 // firewalld
74 if runtime.GOOS == "linux" {
75 var firewalld = NewFirewalld()
76 if firewalld.IsReady() {
77 currentFirewall = firewalld
78 return currentFirewall
79 }
80 }
81
82 // 至少返回一个
83 currentFirewall = NewMockFirewall()
84 return currentFirewall
85}

Callers 5

updateMethod · 0.92
listenSockMethod · 0.92
RemoveIPMethod · 0.92
initFunction · 0.85
DropTemporaryToFunction · 0.85

Calls 12

IsReadyMethod · 0.95
PrintlnFunction · 0.92
WarnFunction · 0.92
NotifyFunction · 0.92
NewHTTPFirewallFunction · 0.85
NewFirewalldFunction · 0.85
NewMockFirewallFunction · 0.85
NewNFTablesFirewallFunction · 0.70
IsReadyMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected