Files
bpfire/config/firewall/ipsec-block
Michael Tremer 80fbd89949 ipsec: Add block rules to avoid conntrack entries
If an IPsec VPN connections is not established, there are
rare cases when packets are supposed to be sent through
that said tunnel and incorrectly handled.

Those packets are sent to the default gateway an entry
for this connection is created in the connection tracking
table (usually only happens to UDP). All following packets
are sent the same route even after the tunnel has been
brought up. That leads to SIP phones not being able to
register among other things.

This patch adds firewall rules that these packets are
rejected. That will sent a notification to the client
that the tunnel is not up and avoid the connection to
be added to the connection tracking table.

Apart from a small performance penalty there should
be no other side-effects.

Fixes: #10908

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Cc: tomvend@rymes.com
Cc: daniel.weismueller@ipfire.org
Cc: morlix@morlix.de
Reviewed-by: Timo Eissler <timo.eissler@ipfire.org>
2015-10-15 22:44:47 +01:00

60 lines
2.5 KiB
Bash

#!/bin/bash
###############################################################################
# #
# IPFire.org - A linux based firewall #
# Copyright (C) 2015 IPFire Team #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
###############################################################################
VPN_CONFIG="/var/ipfire/vpn/config"
block_subnet() {
local subnet="${1}"
# Don't block a wildcard subnet
if [ "${subnet}" = "0.0.0.0/0" ] || [ "${subnet}" = "0.0.0.0/0.0.0.0" ]; then
return 0
fi
iptables -A IPSECBLOCK -d "${subnet}" -j REJECT --reject-with icmp-net-unreachable
}
block_ipsec() {
# Flush all exists rules
iptables -F IPSECBLOCK
local id status name lefthost type ctype unknown1 unknown2 unknown3
local leftsubnets unknown4 righthost rightsubnets rest
while IFS="," read -r id status name lefthost type ctype unkown1 unknown2 unknown3 \
leftsubnets unknown4 righthost rightsubnets rest; do
# Check if the connection is enabled
[ "${status}" = "on" ] || continue
# Check if this a net-to-net connection
[ "${type}" = "net" ] || continue
# Split multiple subnets
rightsubnets="${rightsubnets//\|/ }"
local rightsubnet
for rightsubnet in ${rightsubnets}; do
block_subnet "${rightsubnet}"
done
done < "${VPN_CONFIG}"
}
block_ipsec || exit $?