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

Method RejectSourceIP

internal/firewalls/firewall_firewalld.go:145–166  ·  view source on GitHub ↗
(ip string, timeoutSeconds int)

Source from the content-addressed store, hash-verified

143}
144
145func (this *Firewalld) RejectSourceIP(ip string, timeoutSeconds int) error {
146 if !this.isReady {
147 return nil
148 }
149
150 // 避免短时间内重复添加
151 if this.checkLatestIP(ip) {
152 return nil
153 }
154
155 var family = "ipv4"
156 if strings.Contains(ip, ":") {
157 family = "ipv6"
158 }
159 var args = []string{"--add-rich-rule=rule family='" + family + "' source address='" + ip + "' reject"}
160 if timeoutSeconds > 0 {
161 args = append(args, "--timeout="+types.String(timeoutSeconds)+"s")
162 }
163 var cmd = executils.NewTimeoutCmd(10*time.Second, this.exe, args...)
164 this.pushCmd(cmd, ip)
165 return nil
166}
167
168func (this *Firewalld) DropSourceIP(ip string, timeoutSeconds int, async bool) error {
169 if !this.isReady {

Callers

nothing calls this directly

Calls 4

pushCmdMethod · 0.95
checkLatestIPMethod · 0.80
ContainsMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected