gistfile1.txt
· 558 B · Text
Ham
function fw::has_rule() {
# Generic rule existence check
# fw::has_rule <target> <client_ip> <dest> [port] [proto]
local action="${1:-DROP}" client_ip="${2:-}" target="${3:-}" \
port="${4:-}" proto="${5:-}"
if [[ -n "$port" ]]; then
fw::_forward_exists -s "$client_ip" -d "$target" \
-p "$proto" --dport "$port" -j "$action"
else
fw::_forward_exists -s "$client_ip" -d "$target" -j "$action"
fi
}
function fw::has_block_rule() {
fw::has_rule "DROP" "$@"
}
function fw::has_allow_rule() {
fw::has_rule "ACCEPT" "$@"
}
| 1 | function fw::has_rule() { |
| 2 | # Generic rule existence check |
| 3 | # fw::has_rule <target> <client_ip> <dest> [port] [proto] |
| 4 | local action="${1:-DROP}" client_ip="${2:-}" target="${3:-}" \ |
| 5 | port="${4:-}" proto="${5:-}" |
| 6 | if [[ -n "$port" ]]; then |
| 7 | fw::_forward_exists -s "$client_ip" -d "$target" \ |
| 8 | -p "$proto" --dport "$port" -j "$action" |
| 9 | else |
| 10 | fw::_forward_exists -s "$client_ip" -d "$target" -j "$action" |
| 11 | fi |
| 12 | } |
| 13 | |
| 14 | function fw::has_block_rule() { |
| 15 | fw::has_rule "DROP" "$@" |
| 16 | } |
| 17 | |
| 18 | function fw::has_allow_rule() { |
| 19 | fw::has_rule "ACCEPT" "$@" |
| 20 | } |