(ip string, timeoutSeconds int)
| 143 | } |
| 144 | |
| 145 | func (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 | |
| 168 | func (this *Firewalld) DropSourceIP(ip string, timeoutSeconds int, async bool) error { |
| 169 | if !this.isReady { |
nothing calls this directly
no test coverage detected