From 415856bdd4f48ab4f2732996f0bae58595092bbe Mon Sep 17 00:00:00 2001 From: Parabola Date: Tue, 5 Apr 2011 14:26:38 +0000 Subject: Tue Apr 5 14:26:38 UTC 2011 --- core/iptables/PKGBUILD | 53 ++++++++++++++++++++ core/iptables/empty.rules | 6 +++ core/iptables/ip6tables | 97 +++++++++++++++++++++++++++++++++++++ core/iptables/iptables | 95 ++++++++++++++++++++++++++++++++++++ core/iptables/iptables.conf.d | 8 +++ core/iptables/simple_firewall.rules | 11 +++++ 6 files changed, 270 insertions(+) create mode 100644 core/iptables/PKGBUILD create mode 100644 core/iptables/empty.rules create mode 100755 core/iptables/ip6tables create mode 100755 core/iptables/iptables create mode 100644 core/iptables/iptables.conf.d create mode 100644 core/iptables/simple_firewall.rules (limited to 'core/iptables') diff --git a/core/iptables/PKGBUILD b/core/iptables/PKGBUILD new file mode 100644 index 000000000..c2b812f85 --- /dev/null +++ b/core/iptables/PKGBUILD @@ -0,0 +1,53 @@ +# $Id: PKGBUILD 102057 2010-12-04 09:52:03Z allan $ +# Maintainer: Ronald van Haren +# Contributor: Thomas Baechler + +pkgname=iptables +pkgver=1.4.10 +pkgrel=1 +pkgdesc="A Linux kernel packet control tool" +arch=('i686' 'x86_64') +license=('GPL2') +url="http://www.netfilter.org/" +depends=('glibc' 'bash') +options=('!libtool') +source=(http://www.iptables.org/projects/iptables/files/${pkgname}-${pkgver}.tar.bz2 + iptables + ip6tables + empty.rules + simple_firewall.rules + iptables.conf.d) +backup=(etc/conf.d/iptables) +sha1sums=('8190b8c9714a3eec825317e8ac1deeb3d11c6d29' + 'd7540316581bb66c5594885882a14ba394e95098' + '70d70113e3a23f0fe99404c5536507a887a4ca5c' + '83b3363878e3660ce23b2ad325b53cbd6c796ecf' + '9907f9e815592837abc7fa3264a401567b7606ab' + '1c52444ffbecc09f56bb325db49e924dd32f9213') + +build() { + cd ${srcdir}/${pkgname}-${pkgver} + + # http://bugs.archlinux.org/task/17046 + sed -i '87 i libxt_RATEEST.so: libxt_RATEEST.oo' extensions/GNUmakefile.in + sed -i '88 i \\t${AM_VERBOSE_CCLD} ${CCLD} ${AM_LDFLAGS} -lm -shared ${LDFLAGS} -o $@ $<;\n' extensions/GNUmakefile.in + + ./configure --prefix=/usr --with-kernel=usr/src/linux-$(uname -r) \ + --libexecdir=/usr/lib/iptables --sysconfdir=/etc \ + --with-xtlibdir=/usr/lib/iptables \ + --enable-devel --enable-libipq + + make +} + +package() { + cd ${srcdir}/${pkgname}-${pkgver} + + make DESTDIR=${pkgdir} install + + install -D -m755 ../iptables ${pkgdir}/etc/rc.d/iptables + install -D -m755 ../ip6tables ${pkgdir}/etc/rc.d/ip6tables + install -D -m644 ../empty.rules ${pkgdir}/etc/iptables/empty.rules + install -D -m644 ../simple_firewall.rules ${pkgdir}/etc/iptables/simple_firewall.rules + install -D -m644 ../iptables.conf.d ${pkgdir}/etc/conf.d/iptables +} diff --git a/core/iptables/empty.rules b/core/iptables/empty.rules new file mode 100644 index 000000000..e24e1aa30 --- /dev/null +++ b/core/iptables/empty.rules @@ -0,0 +1,6 @@ +# Empty iptables rule file +*filter +:INPUT ACCEPT [0:0] +:FORWARD ACCEPT [0:0] +:OUTPUT ACCEPT [0:0] +COMMIT diff --git a/core/iptables/ip6tables b/core/iptables/ip6tables new file mode 100755 index 000000000..1733db281 --- /dev/null +++ b/core/iptables/ip6tables @@ -0,0 +1,97 @@ +#!/bin/bash + +# source application-specific settings +[ -f /etc/conf.d/iptables ] && . /etc/conf.d/iptables + +# Set defaults if settings are missing +[ -z "$IP6TABLES" ] && IP6TABLES=/usr/sbin/ip6tables +[ -z "$IP6TABLES_CONF" ] && IP6TABLES_CONF=/etc/iptables/ip6tables.rules + +. /etc/rc.conf +. /etc/rc.d/functions + +case "$1" in + start) + if [ ! -f $IP6TABLES_CONF ]; then + echo "Cannot load iptables rules: $IP6TABLES_CONF is missing!" >&2 + exit 1 + fi + stat_busy "Starting IP6 Tables" + if [ "$IPTABLES_FORWARD" = "1" ]; then + echo 1 >/proc/sys/net/ipv6/conf/default/forwarding + echo 1 >/proc/sys/net/ipv6/conf/all/forwarding + fi + if ck_daemon ip6tables; then + /usr/sbin/ip6tables-restore < $IP6TABLES_CONF + if [ $? -gt 0 ]; then + stat_fail + else + add_daemon ip6tables + stat_done + fi + else + stat_fail + fi + ;; + stop) + stat_busy "Stopping IP6 Tables" + echo 0 >/proc/sys/net/ipv6/conf/all/forwarding + echo 0 >/proc/sys/net/ipv6/conf/default/forwarding + if ! ck_daemon ip6tables; then + fail=0 + for table in $(cat /proc/net/ip6_tables_names); do + $IP6TABLES -t $table -F &>/dev/null && \ + $IP6TABLES -t $table -X &>/dev/null && \ + $IP6TABLES -t $table -Z &>/dev/null + [ $? -gt 0 ] && fail=1 + done + if [ $fail -gt 0 ]; then + stat_fail + else + rm_daemon ip6tables + # reset policies + for table in filter mangle raw; do + if grep -qw $table /proc/net/ip6_tables_names; then + $IP6TABLES -t $table -P OUTPUT ACCEPT + fi + done + for table in filter mangle; do + if grep -qw $table /proc/net/ip6_tables_names; then + $IP6TABLES -t $table -P INPUT ACCEPT + $IP6TABLES -t $table -P FORWARD ACCEPT + fi + done + for table in mangle raw; do + if grep -qw $table /proc/net/ip6_tables_names; then + $IP6TABLES -t $table -P PREROUTING ACCEPT + fi + done + for table in mangle; do + if grep -qw $table /proc/net/ip6_tables_names; then + $IP6TABLES -t $table -P POSTROUTING ACCEPT + fi + done + stat_done + fi + else + stat_fail + fi + ;; + restart) + $0 stop + sleep 2 + $0 start + ;; + save) + stat_busy "Saving IP6 Tables" + /usr/sbin/ip6tables-save >$IP6TABLES_CONF + if [ $? -gt 0 ]; then + stat_fail + else + stat_done + fi + ;; + *) + echo "usage: $0 {start|stop|restart|save}" +esac +exit 0 diff --git a/core/iptables/iptables b/core/iptables/iptables new file mode 100755 index 000000000..50c13d5c1 --- /dev/null +++ b/core/iptables/iptables @@ -0,0 +1,95 @@ +#!/bin/bash + +# source application-specific settings +[ -f /etc/conf.d/iptables ] && . /etc/conf.d/iptables + +# Set defaults if settings are missing +[ -z "$IPTABLES" ] && IPTABLES=/usr/sbin/iptables +[ -z "$IPTABLES_CONF" ] && IPTABLES_CONF=/etc/iptables/iptables.rules + +. /etc/rc.conf +. /etc/rc.d/functions + +case "$1" in + start) + if [ ! -f $IPTABLES_CONF ]; then + echo "Cannot load iptables rules: $IPTABLES_CONF is missing!" >&2 + exit 1 + fi + stat_busy "Starting IP Tables" + if [ "$IPTABLES_FORWARD" = "1" ]; then + echo 1 >/proc/sys/net/ipv4/ip_forward + fi + if ck_daemon iptables; then + /usr/sbin/iptables-restore < $IPTABLES_CONF + if [ $? -gt 0 ]; then + stat_fail + else + add_daemon iptables + stat_done + fi + else + stat_fail + fi + ;; + stop) + stat_busy "Stopping IP Tables" + echo 0 >/proc/sys/net/ipv4/ip_forward + if ! ck_daemon iptables; then + fail=0 + for table in $(cat /proc/net/ip_tables_names); do + $IPTABLES -t $table -F &>/dev/null && \ + $IPTABLES -t $table -X &>/dev/null && \ + $IPTABLES -t $table -Z &>/dev/null + [ $? -gt 0 ] && fail=1 + done + if [ $fail -gt 0 ]; then + stat_fail + else + rm_daemon iptables + # reset policies + for table in filter nat mangle raw; do + if grep -qw $table /proc/net/ip_tables_names; then + $IPTABLES -t $table -P OUTPUT ACCEPT + fi + done + for table in filter mangle; do + if grep -qw $table /proc/net/ip_tables_names; then + $IPTABLES -t $table -P INPUT ACCEPT + $IPTABLES -t $table -P FORWARD ACCEPT + fi + done + for table in nat mangle raw; do + if grep -qw $table /proc/net/ip_tables_names; then + $IPTABLES -t $table -P PREROUTING ACCEPT + fi + done + for table in nat mangle; do + if grep -qw $table /proc/net/ip_tables_names; then + $IPTABLES -t $table -P POSTROUTING ACCEPT + fi + done + stat_done + fi + else + stat_fail + fi + ;; + restart) + $0 stop + sleep 2 + $0 start + ;; + save) + stat_busy "Saving IP Tables" + /usr/sbin/iptables-save >$IPTABLES_CONF + if [ $? -gt 0 ]; then + stat_fail + else + stat_done + fi + ;; + *) + echo "usage: $0 {start|stop|restart|save}" +esac +exit 0 diff --git a/core/iptables/iptables.conf.d b/core/iptables/iptables.conf.d new file mode 100644 index 000000000..07bc11aa1 --- /dev/null +++ b/core/iptables/iptables.conf.d @@ -0,0 +1,8 @@ +# Configuration for iptables rules + +IPTABLES=/usr/sbin/iptables +IP6TABLES=/usr/sbin/ip6tables + +IPTABLES_CONF=/etc/iptables/iptables.rules +IP6TABLES_CONF=/etc/iptables/ip6tables.rules +IPTABLES_FORWARD=0 # enable IP forwarding? diff --git a/core/iptables/simple_firewall.rules b/core/iptables/simple_firewall.rules new file mode 100644 index 000000000..e1604cc36 --- /dev/null +++ b/core/iptables/simple_firewall.rules @@ -0,0 +1,11 @@ +*filter +:INPUT DROP [0:0] +:FORWARD DROP [0:0] +:OUTPUT ACCEPT [0:0] +-A INPUT -p icmp -j ACCEPT +-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT +-A INPUT -i lo -j ACCEPT +-A INPUT -p tcp -j REJECT --reject-with tcp-reset +-A INPUT -p udp -j REJECT --reject-with icmp-port-unreachable +-A INPUT -j REJECT --reject-with icmp-proto-unreachable +COMMIT -- cgit v1.2.3-54-g00ecf