[net-firewall/iptables] long overdue sync with tree
This commit is contained in:
parent
782f9c4872
commit
629024c08f
@ -1,16 +1,24 @@
|
|||||||
# /etc/conf.d/ip6tables
|
# /etc/conf.d/ip6tables
|
||||||
|
|
||||||
# Location in which iptables initscript will save set rules on
|
# Set wait option for xtables lock in seconds
|
||||||
|
# DEFAULT: 60
|
||||||
|
#IPTABLES_LOCK_WAIT_TIME="60"
|
||||||
|
|
||||||
|
# Set wait interval option for xtables lock in microseconds
|
||||||
|
# DEFAULT: 1000
|
||||||
|
#IPTABLES_LOCK_WAIT_INTERVAL="1000"
|
||||||
|
|
||||||
|
# Location in which ip6tables initscript will save set rules on
|
||||||
# service shutdown
|
# service shutdown
|
||||||
IP6TABLES_SAVE="/var/lib/ip6tables/rules-save"
|
IP6TABLES_SAVE="/var/lib/ip6tables/rules-save"
|
||||||
|
|
||||||
# Options to pass to iptables-save and iptables-restore
|
# Options to pass to ip6tables-save and ip6tables-restore
|
||||||
SAVE_RESTORE_OPTIONS="-c"
|
SAVE_RESTORE_OPTIONS="-c"
|
||||||
|
|
||||||
# Save state on stopping iptables
|
# Save state on stopping ip6tables
|
||||||
SAVE_ON_STOP="yes"
|
SAVE_ON_STOP="yes"
|
||||||
|
|
||||||
# If you need to log iptables messages as soon as iptables starts,
|
# If you need to log ip6tables messages as soon as ip6tables starts,
|
||||||
# AND your logger does NOT depend on the network, then you may wish
|
# AND your logger does NOT depend on the network, then you may wish
|
||||||
# to uncomment the next line.
|
# to uncomment the next line.
|
||||||
# If your logger depends on the network, and you uncomment this line
|
# If your logger depends on the network, and you uncomment this line
|
@ -1,6 +1,14 @@
|
|||||||
# /etc/conf.d/iptables
|
# /etc/conf.d/iptables
|
||||||
|
|
||||||
# Location in which iptables initscript will save set rules on
|
# Set wait option for xtables lock in seconds
|
||||||
|
# DEFAULT: 60
|
||||||
|
#IPTABLES_LOCK_WAIT_TIME="60"
|
||||||
|
|
||||||
|
# Set wait interval option for xtables lock in microseconds
|
||||||
|
# DEFAULT: 1000
|
||||||
|
#IPTABLES_LOCK_WAIT_INTERVAL="1000"
|
||||||
|
|
||||||
|
# Location in which iptables initscript will save set rules on
|
||||||
# service shutdown
|
# service shutdown
|
||||||
IPTABLES_SAVE="/var/lib/iptables/rules-save"
|
IPTABLES_SAVE="/var/lib/iptables/rules-save"
|
||||||
|
|
@ -1,15 +1,17 @@
|
|||||||
#!/sbin/openrc-run
|
#!/sbin/openrc-run
|
||||||
# Copyright 1999-2013 Gentoo Foundation
|
# Copyright 1999-2018 Gentoo Authors
|
||||||
# Distributed under the terms of the GNU General Public License v2
|
# Distributed under the terms of the GNU General Public License v2
|
||||||
# $Id$
|
|
||||||
|
|
||||||
extra_commands="check save panic"
|
extra_commands="check save panic"
|
||||||
extra_started_commands="reload"
|
extra_started_commands="reload"
|
||||||
|
|
||||||
|
iptables_lock_wait_time=${IPTABLES_LOCK_WAIT_TIME:-"60"}
|
||||||
|
iptables_lock_wait_interval=${IPTABLES_LOCK_WAIT_INTERVAL:-"1000"}
|
||||||
|
|
||||||
iptables_name=${SVCNAME}
|
iptables_name=${SVCNAME}
|
||||||
case ${iptables_name} in
|
case ${iptables_name} in
|
||||||
iptables|ip6tables) ;;
|
iptables|ip6tables) ;;
|
||||||
*) iptables_name="iptables" ;;
|
*) iptables_name="iptables" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
iptables_bin="/sbin/${iptables_name}"
|
iptables_bin="/sbin/${iptables_name}"
|
||||||
@ -26,17 +28,21 @@ depend() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set_table_policy() {
|
set_table_policy() {
|
||||||
local chains table=$1 policy=$2
|
local has_errors=0 chains table=$1 policy=$2
|
||||||
case ${table} in
|
case ${table} in
|
||||||
nat) chains="PREROUTING POSTROUTING OUTPUT";;
|
nat) chains="PREROUTING POSTROUTING OUTPUT";;
|
||||||
mangle) chains="PREROUTING INPUT FORWARD OUTPUT POSTROUTING";;
|
mangle) chains="PREROUTING INPUT FORWARD OUTPUT POSTROUTING";;
|
||||||
filter) chains="INPUT FORWARD OUTPUT";;
|
filter) chains="INPUT FORWARD OUTPUT";;
|
||||||
*) chains="";;
|
*) chains="";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
local chain
|
local chain
|
||||||
for chain in ${chains} ; do
|
for chain in ${chains} ; do
|
||||||
${iptables_bin} -w -t ${table} -P ${chain} ${policy}
|
${iptables_bin} --wait ${iptables_lock_wait_time} --wait-interval ${iptables_lock_wait_interval} -t ${table} -P ${chain} ${policy}
|
||||||
|
[ $? -ne 0 ] && has_errors=1
|
||||||
done
|
done
|
||||||
|
|
||||||
|
return ${has_errors}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkkernel() {
|
checkkernel() {
|
||||||
@ -47,8 +53,9 @@ checkkernel() {
|
|||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
checkconfig() {
|
checkconfig() {
|
||||||
if [ ! -f ${iptables_save} ] ; then
|
if [ -z "${iptables_save}" -o ! -f "${iptables_save}" ] ; then
|
||||||
eerror "Not starting ${iptables_name}. First create some rules then run:"
|
eerror "Not starting ${iptables_name}. First create some rules then run:"
|
||||||
eerror "/etc/init.d/${iptables_name} save"
|
eerror "/etc/init.d/${iptables_name} save"
|
||||||
return 1
|
return 1
|
||||||
@ -56,39 +63,53 @@ checkconfig() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start_pre() {
|
||||||
checkconfig || return 1
|
checkconfig || return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
start() {
|
||||||
ebegin "Loading ${iptables_name} state and starting firewall"
|
ebegin "Loading ${iptables_name} state and starting firewall"
|
||||||
${iptables_bin}-restore ${SAVE_RESTORE_OPTIONS} < "${iptables_save}"
|
${iptables_bin}-restore --wait ${iptables_lock_wait_time} --wait-interval ${iptables_lock_wait_interval} ${SAVE_RESTORE_OPTIONS} < "${iptables_save}"
|
||||||
eend $?
|
eend $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stop_pre() {
|
||||||
|
checkkernel || return 1
|
||||||
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
if [ "${SAVE_ON_STOP}" = "yes" ] ; then
|
if [ "${SAVE_ON_STOP}" = "yes" ] ; then
|
||||||
save || return 1
|
save || return 1
|
||||||
fi
|
fi
|
||||||
checkkernel || return 1
|
|
||||||
ebegin "Stopping firewall"
|
ebegin "Stopping firewall"
|
||||||
local a
|
local has_errors=0 a
|
||||||
for a in $(cat ${iptables_proc}) ; do
|
for a in $(cat ${iptables_proc}) ; do
|
||||||
set_table_policy $a ACCEPT
|
set_table_policy $a ACCEPT
|
||||||
|
[ $? -ne 0 ] && has_errors=1
|
||||||
|
|
||||||
${iptables_bin} -w -F -t $a
|
${iptables_bin} --wait ${iptables_lock_wait_time} --wait-interval ${iptables_lock_wait_interval} -F -t $a
|
||||||
${iptables_bin} -w -X -t $a
|
[ $? -ne 0 ] && has_errors=1
|
||||||
|
|
||||||
|
${iptables_bin} --wait ${iptables_lock_wait_time} --wait-interval ${iptables_lock_wait_interval} -X -t $a
|
||||||
|
[ $? -ne 0 ] && has_errors=1
|
||||||
done
|
done
|
||||||
eend $?
|
eend ${has_errors}
|
||||||
}
|
}
|
||||||
|
|
||||||
reload() {
|
reload() {
|
||||||
checkkernel || return 1
|
checkkernel || return 1
|
||||||
checkrules || return 1
|
checkrules || return 1
|
||||||
ebegin "Flushing firewall"
|
ebegin "Flushing firewall"
|
||||||
local a
|
local has_errors=0 a
|
||||||
for a in $(cat ${iptables_proc}) ; do
|
for a in $(cat ${iptables_proc}) ; do
|
||||||
${iptables_bin} -w -F -t $a
|
${iptables_bin} --wait ${iptables_lock_wait_time} --wait-interval ${iptables_lock_wait_interval} -F -t $a
|
||||||
${iptables_bin} -w -X -t $a
|
[ $? -ne 0 ] && has_errors=1
|
||||||
|
|
||||||
|
${iptables_bin} --wait ${iptables_lock_wait_time} --wait-interval ${iptables_lock_wait_interval} -X -t $a
|
||||||
|
[ $? -ne 0 ] && has_errors=1
|
||||||
done
|
done
|
||||||
eend $?
|
eend ${has_errors}
|
||||||
|
|
||||||
start
|
start
|
||||||
}
|
}
|
||||||
@ -113,18 +134,32 @@ save() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
panic() {
|
panic() {
|
||||||
checkkernel || return 1
|
# use iptables autoload capability to load at least all required
|
||||||
|
# modules and filter table
|
||||||
|
${iptables_bin} --wait ${iptables_lock_wait_time} --wait-interval ${iptables_lock_wait_interval} -S >/dev/null
|
||||||
|
if [ $? -ne 0 ] ; then
|
||||||
|
eerror "${iptables_bin} failed to load"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
if service_started ${iptables_name}; then
|
if service_started ${iptables_name}; then
|
||||||
rc-service ${iptables_name} stop
|
rc-service ${iptables_name} stop
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local a
|
local has_errors=0 a
|
||||||
ebegin "Dropping all packets"
|
ebegin "Dropping all packets"
|
||||||
for a in $(cat ${iptables_proc}) ; do
|
for a in $(cat ${iptables_proc}) ; do
|
||||||
${iptables_bin} -w -F -t $a
|
${iptables_bin} --wait ${iptables_lock_wait_time} --wait-interval ${iptables_lock_wait_interval} -F -t $a
|
||||||
${iptables_bin} -w -X -t $a
|
[ $? -ne 0 ] && has_errors=1
|
||||||
|
|
||||||
set_table_policy $a DROP
|
${iptables_bin} --wait ${iptables_lock_wait_time} --wait-interval ${iptables_lock_wait_interval} -X -t $a
|
||||||
|
[ $? -ne 0 ] && has_errors=1
|
||||||
|
|
||||||
|
if [ "${a}" != "nat" ]; then
|
||||||
|
# The "nat" table is not intended for filtering, the use of DROP is therefore inhibited.
|
||||||
|
set_table_policy $a DROP
|
||||||
|
[ $? -ne 0 ] && has_errors=1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
eend $?
|
eend ${has_errors}
|
||||||
}
|
}
|
@ -3,12 +3,12 @@ Description=Restore ip6tables firewall rules
|
|||||||
# if both are queued for some reason, don't store before restoring :)
|
# if both are queued for some reason, don't store before restoring :)
|
||||||
Before=ip6tables-store.service
|
Before=ip6tables-store.service
|
||||||
# sounds reasonable to have firewall up before any of the services go up
|
# sounds reasonable to have firewall up before any of the services go up
|
||||||
Before=network.target
|
Before=network-pre.target
|
||||||
Conflicts=shutdown.target
|
Wants=network-pre.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=/sbin/ip6tables-restore /var/lib/ip6tables/rules-save
|
ExecStart=/sbin/ip6tables-restore -w -- /var/lib/ip6tables/rules-save
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=basic.target
|
WantedBy=basic.target
|
||||||
|
6
net-firewall/iptables/files/systemd/ip6tables.service
Normal file
6
net-firewall/iptables/files/systemd/ip6tables.service
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Store and restore ip6tables firewall rules
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
Also=ip6tables-store.service
|
||||||
|
Also=ip6tables-restore.service
|
@ -3,12 +3,12 @@ Description=Restore iptables firewall rules
|
|||||||
# if both are queued for some reason, don't store before restoring :)
|
# if both are queued for some reason, don't store before restoring :)
|
||||||
Before=iptables-store.service
|
Before=iptables-store.service
|
||||||
# sounds reasonable to have firewall up before any of the services go up
|
# sounds reasonable to have firewall up before any of the services go up
|
||||||
Before=network.target
|
Before=network-pre.target
|
||||||
Conflicts=shutdown.target
|
Wants=network-pre.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=/sbin/iptables-restore /var/lib/iptables/rules-save
|
ExecStart=/sbin/iptables-restore -w -- /var/lib/iptables/rules-save
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=basic.target
|
WantedBy=basic.target
|
||||||
|
6
net-firewall/iptables/files/systemd/iptables.service
Normal file
6
net-firewall/iptables/files/systemd/iptables.service
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Store and restore iptables firewall rules
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
Also=iptables-store.service
|
||||||
|
Also=iptables-restore.service
|
@ -1,21 +1,21 @@
|
|||||||
# Copyright 1999-2018 Gentoo Foundation
|
# Copyright 1999-2019 Gentoo Authors
|
||||||
# Distributed under the terms of the GNU General Public License v2
|
# Distributed under the terms of the GNU General Public License v2
|
||||||
|
|
||||||
EAPI=6
|
EAPI=7
|
||||||
|
|
||||||
# Force users doing their own patches to install their own tools
|
# Force users doing their own patches to install their own tools
|
||||||
AUTOTOOLS_AUTO_DEPEND=no
|
AUTOTOOLS_AUTO_DEPEND=no
|
||||||
|
|
||||||
inherit ltprune multilib systemd toolchain-funcs autotools flag-o-matic git-r3
|
inherit multilib systemd toolchain-funcs autotools flag-o-matic usr-ldscript git-r3
|
||||||
|
|
||||||
DESCRIPTION="Linux kernel (2.4+) firewall, NAT and packet mangling tools"
|
DESCRIPTION="Linux kernel (2.4+) firewall, NAT and packet mangling tools"
|
||||||
HOMEPAGE="http://www.netfilter.org/projects/iptables/"
|
HOMEPAGE="https://www.netfilter.org/projects/iptables/"
|
||||||
EGIT_REPO_URI="git://git.netfilter.org/iptables.git"
|
EGIT_REPO_URI="git://git.netfilter.org/iptables.git"
|
||||||
|
|
||||||
LICENSE="GPL-2"
|
LICENSE="GPL-2"
|
||||||
# Subslot tracks libxtables as that's the one other packages generally link
|
# Subslot reflects PV when libxtables and/or libip*tc was changed
|
||||||
# against and iptables changes. Will have to revisit if other sonames change.
|
# the last time.
|
||||||
SLOT="0/12"
|
SLOT="0/1.8.3"
|
||||||
KEYWORDS=""
|
KEYWORDS=""
|
||||||
IUSE="conntrack ipv6 netlink nftables pcap static-libs"
|
IUSE="conntrack ipv6 netlink nftables pcap static-libs"
|
||||||
|
|
||||||
@ -24,13 +24,15 @@ COMMON_DEPEND="
|
|||||||
netlink? ( net-libs/libnfnetlink )
|
netlink? ( net-libs/libnfnetlink )
|
||||||
nftables? (
|
nftables? (
|
||||||
>=net-libs/libmnl-1.0:0=
|
>=net-libs/libmnl-1.0:0=
|
||||||
>=net-libs/libnftnl-1.0.5:0=
|
>=net-libs/libnftnl-1.1.3:0=
|
||||||
)
|
)
|
||||||
pcap? ( net-libs/libpcap )
|
pcap? ( net-libs/libpcap )
|
||||||
"
|
"
|
||||||
|
|
||||||
DEPEND="${COMMON_DEPEND}
|
DEPEND="${COMMON_DEPEND}
|
||||||
virtual/os-headers
|
virtual/os-headers
|
||||||
|
>=sys-kernel/linux-headers-4.4:0
|
||||||
|
"
|
||||||
|
BDEPEND="
|
||||||
virtual/pkgconfig
|
virtual/pkgconfig
|
||||||
nftables? (
|
nftables? (
|
||||||
sys-devel/flex
|
sys-devel/flex
|
||||||
@ -43,7 +45,7 @@ RDEPEND="${COMMON_DEPEND}
|
|||||||
|
|
||||||
src_prepare() {
|
src_prepare() {
|
||||||
# use the saner headers from the kernel
|
# use the saner headers from the kernel
|
||||||
rm -f include/linux/{kernel,types}.h
|
rm include/linux/{kernel,types}.h || die
|
||||||
|
|
||||||
eautoreconf
|
eautoreconf
|
||||||
}
|
}
|
||||||
@ -97,19 +99,25 @@ src_install() {
|
|||||||
doins include/iptables/internal.h
|
doins include/iptables/internal.h
|
||||||
|
|
||||||
keepdir /var/lib/iptables
|
keepdir /var/lib/iptables
|
||||||
newinitd "${FILESDIR}"/${PN}.init iptables
|
newinitd "${FILESDIR}"/${PN}-r2.init iptables
|
||||||
newconfd "${FILESDIR}"/${PN}-1.4.13.confd iptables
|
newconfd "${FILESDIR}"/${PN}-r1.confd iptables
|
||||||
if use ipv6 ; then
|
if use ipv6 ; then
|
||||||
keepdir /var/lib/ip6tables
|
keepdir /var/lib/ip6tables
|
||||||
newinitd "${FILESDIR}"/iptables.init ip6tables
|
dosym iptables /etc/init.d/ip6tables
|
||||||
newconfd "${FILESDIR}"/ip6tables-1.4.13.confd ip6tables
|
newconfd "${FILESDIR}"/ip6tables-r1.confd ip6tables
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if use nftables; then
|
if use nftables; then
|
||||||
# Bug 647458
|
# Bug 647458
|
||||||
rm "${ED%/}"/etc/ethertypes || die
|
rm "${ED}"/etc/ethertypes || die
|
||||||
|
|
||||||
|
# Bug 660886
|
||||||
|
rm "${ED}"/sbin/{arptables,ebtables} || die
|
||||||
|
|
||||||
|
# Bug 669894
|
||||||
|
rm "${ED}"/sbin/ebtables-{save,restore} || die
|
||||||
fi
|
fi
|
||||||
|
|
||||||
systemd_dounit "${FILESDIR}"/systemd/iptables-{re,}store.service
|
systemd_dounit "${FILESDIR}"/systemd/iptables-{re,}store.service
|
||||||
if use ipv6 ; then
|
if use ipv6 ; then
|
||||||
systemd_dounit "${FILESDIR}"/systemd/ip6tables-{re,}store.service
|
systemd_dounit "${FILESDIR}"/systemd/ip6tables-{re,}store.service
|
||||||
@ -118,5 +126,5 @@ src_install() {
|
|||||||
# Move important libs to /lib #332175
|
# Move important libs to /lib #332175
|
||||||
gen_usr_ldscript -a ip{4,6}tc iptc xtables
|
gen_usr_ldscript -a ip{4,6}tc iptc xtables
|
||||||
|
|
||||||
prune_libtool_files
|
find "${ED}" -type f -name "*.la" -delete || die
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user