commit
9b14f0b507
1 file changed
+30
-19
+30
-19
@@ -47,6 +47,32 @@ check_command_and_run() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_iptables() {
|
||||||
|
# -w is recent addition to iptables
|
||||||
|
if [ -z "$CHECKED_IPTABLES_W" ] ; then
|
||||||
|
if iptables -S -w >/dev/null 2>&1 ; then
|
||||||
|
IPTABLES_W=-w
|
||||||
|
fi
|
||||||
|
CHECKED_IPTABLES_W=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
iptables $IPTABLES_W "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add a rule to iptables, if it doesn't exist already
|
||||||
|
add_iptables_rule() {
|
||||||
|
IPTABLES_TABLE="$1"
|
||||||
|
shift 1
|
||||||
|
if ! run_iptables -t $IPTABLES_TABLE -C "$@" >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
run_iptables -t $IPTABLES_TABLE -A "$@" >/dev/null
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
add_nat_rule() {
|
||||||
|
add_iptables_rule nat "$@"
|
||||||
|
}
|
||||||
|
|
||||||
create_bridge() {
|
create_bridge() {
|
||||||
[ ! -d /sys/class/net/$BRIDGE ] && {
|
[ ! -d /sys/class/net/$BRIDGE ] && {
|
||||||
ip link add dev $BRIDGE type bridge
|
ip link add dev $BRIDGE type bridge
|
||||||
@@ -60,6 +86,9 @@ create_bridge() {
|
|||||||
ip link del dev v${CONTAINER_IFNAME}du
|
ip link del dev v${CONTAINER_IFNAME}du
|
||||||
# disable offloading
|
# disable offloading
|
||||||
check_command_and_run ethtool ethtool -K $BRIDGE tx off >/dev/null
|
check_command_and_run ethtool ethtool -K $BRIDGE tx off >/dev/null
|
||||||
|
# Work around the situation where there are no rules allowing traffic
|
||||||
|
# across our bridge. E.g. ufw
|
||||||
|
add_iptables_rule filter FORWARD -i $BRIDGE -o $BRIDGE -j ACCEPT
|
||||||
}
|
}
|
||||||
ip link set dev $BRIDGE up
|
ip link set dev $BRIDGE up
|
||||||
}
|
}
|
||||||
@@ -68,25 +97,7 @@ destroy_bridge() {
|
|||||||
if [ -d /sys/class/net/$BRIDGE ] ; then
|
if [ -d /sys/class/net/$BRIDGE ] ; then
|
||||||
ip link del dev $BRIDGE
|
ip link del dev $BRIDGE
|
||||||
fi
|
fi
|
||||||
}
|
run_iptables -t filter -D FORWARD -i $BRIDGE -o $BRIDGE -j ACCEPT 2>/dev/null || true
|
||||||
|
|
||||||
run_iptables() {
|
|
||||||
# -w is recent addition to iptables
|
|
||||||
if [ -z "$CHECKED_IPTABLES_W" ] ; then
|
|
||||||
if iptables -S -w >/dev/null 2>&1 ; then
|
|
||||||
IPTABLES_W=-w
|
|
||||||
fi
|
|
||||||
CHECKED_IPTABLES_W=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
iptables $IPTABLES_W "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
add_nat_rule() {
|
|
||||||
if ! run_iptables -t nat -C "$@" >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
run_iptables -t nat -A "$@" >/dev/null
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_masquerading() {
|
setup_masquerading() {
|
||||||
|
|||||||
Reference in new issue
Block a user