[net-firewall/iptables] import of iptables scm junk, needs cleanup
This commit is contained in:
19
net-firewall/iptables/files/ip6tables-1.4.13.confd
Normal file
19
net-firewall/iptables/files/ip6tables-1.4.13.confd
Normal file
@@ -0,0 +1,19 @@
|
||||
# /etc/conf.d/ip6tables
|
||||
|
||||
# Location in which iptables initscript will save set rules on
|
||||
# service shutdown
|
||||
IP6TABLES_SAVE="/var/lib/ip6tables/rules-save"
|
||||
|
||||
# Options to pass to iptables-save and iptables-restore
|
||||
SAVE_RESTORE_OPTIONS="-c"
|
||||
|
||||
# Save state on stopping iptables
|
||||
SAVE_ON_STOP="yes"
|
||||
|
||||
# If you need to log iptables messages as soon as iptables starts,
|
||||
# AND your logger does NOT depend on the network, then you may wish
|
||||
# to uncomment the next line.
|
||||
# If your logger depends on the network, and you uncomment this line
|
||||
# you will create an unresolvable circular dependency during startup.
|
||||
# After commenting or uncommenting this line, you must run 'rc-update -u'.
|
||||
#rc_use="logger"
|
||||
130
net-firewall/iptables/files/iptables-1.4.13-r1.init
Normal file
130
net-firewall/iptables/files/iptables-1.4.13-r1.init
Normal file
@@ -0,0 +1,130 @@
|
||||
#!/sbin/runscript
|
||||
# Copyright 1999-2013 Gentoo Foundation
|
||||
# Distributed under the terms of the GNU General Public License v2
|
||||
# $Header: /var/cvsroot/gentoo-x86/net-firewall/iptables/files/iptables-1.4.13-r1.init,v 1.3 2013/04/27 17:29:09 vapier Exp $
|
||||
|
||||
extra_commands="check save panic"
|
||||
extra_started_commands="reload"
|
||||
|
||||
iptables_name=${SVCNAME}
|
||||
case ${iptables_name} in
|
||||
iptables|ip6tables) ;;
|
||||
*) iptables_name="iptables" ;;
|
||||
esac
|
||||
|
||||
iptables_bin="/sbin/${iptables_name}"
|
||||
case ${iptables_name} in
|
||||
iptables) iptables_proc="/proc/net/ip_tables_names"
|
||||
iptables_save=${IPTABLES_SAVE};;
|
||||
ip6tables) iptables_proc="/proc/net/ip6_tables_names"
|
||||
iptables_save=${IP6TABLES_SAVE};;
|
||||
esac
|
||||
|
||||
depend() {
|
||||
need localmount #434774
|
||||
before net
|
||||
}
|
||||
|
||||
set_table_policy() {
|
||||
local chains table=$1 policy=$2
|
||||
case ${table} in
|
||||
nat) chains="PREROUTING POSTROUTING OUTPUT";;
|
||||
mangle) chains="PREROUTING INPUT FORWARD OUTPUT POSTROUTING";;
|
||||
filter) chains="INPUT FORWARD OUTPUT";;
|
||||
*) chains="";;
|
||||
esac
|
||||
local chain
|
||||
for chain in ${chains} ; do
|
||||
${iptables_bin} -t ${table} -P ${chain} ${policy}
|
||||
done
|
||||
}
|
||||
|
||||
checkkernel() {
|
||||
if [ ! -e ${iptables_proc} ] ; then
|
||||
eerror "Your kernel lacks ${iptables_name} support, please load"
|
||||
eerror "appropriate modules and try again."
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
checkconfig() {
|
||||
if [ ! -f ${iptables_save} ] ; then
|
||||
eerror "Not starting ${iptables_name}. First create some rules then run:"
|
||||
eerror "/etc/init.d/${iptables_name} save"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
start() {
|
||||
checkconfig || return 1
|
||||
ebegin "Loading ${iptables_name} state and starting firewall"
|
||||
${iptables_bin}-restore ${SAVE_RESTORE_OPTIONS} < "${iptables_save}"
|
||||
eend $?
|
||||
}
|
||||
|
||||
stop() {
|
||||
if [ "${SAVE_ON_STOP}" = "yes" ] ; then
|
||||
save || return 1
|
||||
fi
|
||||
checkkernel || return 1
|
||||
ebegin "Stopping firewall"
|
||||
local a
|
||||
for a in $(cat ${iptables_proc}) ; do
|
||||
set_table_policy $a ACCEPT
|
||||
|
||||
${iptables_bin} -F -t $a
|
||||
${iptables_bin} -X -t $a
|
||||
done
|
||||
eend $?
|
||||
}
|
||||
|
||||
reload() {
|
||||
checkkernel || return 1
|
||||
checkrules || return 1
|
||||
ebegin "Flushing firewall"
|
||||
local a
|
||||
for a in $(cat ${iptables_proc}) ; do
|
||||
${iptables_bin} -F -t $a
|
||||
${iptables_bin} -X -t $a
|
||||
done
|
||||
eend $?
|
||||
|
||||
start
|
||||
}
|
||||
|
||||
checkrules() {
|
||||
ebegin "Checking rules"
|
||||
${iptables_bin}-restore --test ${SAVE_RESTORE_OPTIONS} < "${iptables_save}"
|
||||
eend $?
|
||||
}
|
||||
|
||||
check() {
|
||||
# Short name for users of init.d script.
|
||||
checkrules
|
||||
}
|
||||
|
||||
save() {
|
||||
ebegin "Saving ${iptables_name} state"
|
||||
checkpath -q -d "$(dirname "${iptables_save}")"
|
||||
checkpath -q -m 0600 -f "${iptables_save}"
|
||||
${iptables_bin}-save ${SAVE_RESTORE_OPTIONS} > "${iptables_save}"
|
||||
eend $?
|
||||
}
|
||||
|
||||
panic() {
|
||||
checkkernel || return 1
|
||||
if service_started ${iptables_name}; then
|
||||
rc-service ${iptables_name} stop
|
||||
fi
|
||||
|
||||
local a
|
||||
ebegin "Dropping all packets"
|
||||
for a in $(cat ${iptables_proc}) ; do
|
||||
${iptables_bin} -F -t $a
|
||||
${iptables_bin} -X -t $a
|
||||
|
||||
set_table_policy $a DROP
|
||||
done
|
||||
eend $?
|
||||
}
|
||||
19
net-firewall/iptables/files/iptables-1.4.13.confd
Normal file
19
net-firewall/iptables/files/iptables-1.4.13.confd
Normal file
@@ -0,0 +1,19 @@
|
||||
# /etc/conf.d/iptables
|
||||
|
||||
# Location in which iptables initscript will save set rules on
|
||||
# service shutdown
|
||||
IPTABLES_SAVE="/var/lib/iptables/rules-save"
|
||||
|
||||
# Options to pass to iptables-save and iptables-restore
|
||||
SAVE_RESTORE_OPTIONS="-c"
|
||||
|
||||
# Save state on stopping iptables
|
||||
SAVE_ON_STOP="yes"
|
||||
|
||||
# If you need to log iptables messages as soon as iptables starts,
|
||||
# AND your logger does NOT depend on the network, then you may wish
|
||||
# to uncomment the next line.
|
||||
# If your logger depends on the network, and you uncomment this line
|
||||
# you will create an unresolvable circular dependency during startup.
|
||||
# After commenting or uncommenting this line, you must run 'rc-update -u'.
|
||||
#rc_use="logger"
|
||||
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=Restore ip6tables firewall rules
|
||||
# if both are queued for some reason, don't store before restoring :)
|
||||
Before=ip6tables-store.service
|
||||
# sounds reasonable to have firewall up before any of the services go up
|
||||
Before=network.target
|
||||
Conflicts=shutdown.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/sbin/ip6tables-restore /var/lib/ip6tables/rules-save
|
||||
|
||||
[Install]
|
||||
WantedBy=basic.target
|
||||
11
net-firewall/iptables/files/systemd/ip6tables-store.service
Normal file
11
net-firewall/iptables/files/systemd/ip6tables-store.service
Normal file
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Store ip6tables firewall rules
|
||||
Before=shutdown.target
|
||||
DefaultDependencies=No
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/sh -c "/sbin/ip6tables-save --counters > /var/lib/ip6tables/rules-save"
|
||||
|
||||
[Install]
|
||||
WantedBy=shutdown.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
|
||||
14
net-firewall/iptables/files/systemd/iptables-restore.service
Normal file
14
net-firewall/iptables/files/systemd/iptables-restore.service
Normal file
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=Restore iptables firewall rules
|
||||
# if both are queued for some reason, don't store before restoring :)
|
||||
Before=iptables-store.service
|
||||
# sounds reasonable to have firewall up before any of the services go up
|
||||
Before=network.target
|
||||
Conflicts=shutdown.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/sbin/iptables-restore /var/lib/iptables/rules-save
|
||||
|
||||
[Install]
|
||||
WantedBy=basic.target
|
||||
11
net-firewall/iptables/files/systemd/iptables-store.service
Normal file
11
net-firewall/iptables/files/systemd/iptables-store.service
Normal file
@@ -0,0 +1,11 @@
|
||||
[Unit]
|
||||
Description=Store iptables firewall rules
|
||||
Before=shutdown.target
|
||||
DefaultDependencies=No
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/sh -c "/sbin/iptables-save --counters > /var/lib/iptables/rules-save"
|
||||
|
||||
[Install]
|
||||
WantedBy=shutdown.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
|
||||
Reference in New Issue
Block a user