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

Method DropSourceIP

internal/firewalls/firewall_firewalld.go:168–200  ·  view source on GitHub ↗
(ip string, timeoutSeconds int, async bool)

Source from the content-addressed store, hash-verified

166}
167
168func (this *Firewalld) DropSourceIP(ip string, timeoutSeconds int, async bool) error {
169 if !this.isReady {
170 return nil
171 }
172
173 // 避免短时间内重复添加
174 if async && this.checkLatestIP(ip) {
175 return nil
176 }
177
178 var family = "ipv4"
179 if strings.Contains(ip, ":") {
180 family = "ipv6"
181 }
182 var args = []string{"--add-rich-rule=rule family='" + family + "' source address='" + ip + "' drop"}
183 if timeoutSeconds > 0 {
184 args = append(args, "--timeout="+types.String(timeoutSeconds)+"s")
185 }
186 var cmd = executils.NewTimeoutCmd(10*time.Second, this.exe, args...)
187 if async {
188 this.pushCmd(cmd, ip)
189 return nil
190 }
191
192 // 关闭连接
193 defer conns.SharedMap.CloseIPConns(ip)
194
195 err := cmd.Run()
196 if err != nil {
197 return fmt.Errorf("run command failed '%s': %w", cmd.String(), err)
198 }
199 return nil
200}
201
202func (this *Firewalld) RemoveSourceIP(ip string) error {
203 if !this.isReady {

Callers

nothing calls this directly

Calls 7

pushCmdMethod · 0.95
checkLatestIPMethod · 0.80
CloseIPConnsMethod · 0.80
ErrorfMethod · 0.80
ContainsMethod · 0.45
StringMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected