aboutsummaryrefslogtreecommitdiffstats
path: root/main/iptables
diff options
context:
space:
mode:
Diffstat (limited to 'main/iptables')
-rw-r--r--main/iptables/APKBUILD66
-rw-r--r--main/iptables/iptables-1.4.2-include-in.patch12
-rw-r--r--main/iptables/iptables.confd11
-rwxr-xr-xmain/iptables/iptables.initd114
4 files changed, 203 insertions, 0 deletions
diff --git a/main/iptables/APKBUILD b/main/iptables/APKBUILD
new file mode 100644
index 0000000000..2a503aca77
--- /dev/null
+++ b/main/iptables/APKBUILD
@@ -0,0 +1,66 @@
+#!/bin/sh
+# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
+
+pkgname=iptables
+pkgver=1.4.4
+pkgrel=0
+pkgdesc="Linux kernel firewall, NAT and packet mangling tools"
+url="http://www.iptables.org/"
+license=GPL-2
+source="http://iptables.org/projects/iptables/files/$pkgname-$pkgver.tar.bz2
+ iptables-1.4.2-include-in.patch
+ iptables.initd
+ iptables.confd
+ "
+
+makedepends="linux-headers"
+subpackages="ip6tables $pkgname-doc $pkgname-dev"
+
+build() {
+ local i
+ cd "$srcdir/$pkgname-$pkgver"
+ for i in ../*.patch; do
+ msg "Applying $i..."
+ patch -p1 -i $i || return 1
+ done
+
+ ./configure --prefix=/usr \
+ --mandir=/usr/share/man \
+ --sbindir=/sbin \
+ --without-kernel \
+ --enable-devel \
+ --enable-libipq \
+ --enable-shared
+ make || return 1
+ make install DESTDIR="$pkgdir"
+
+ mkdir -p "$pkgdir"/usr/include/libiptc \
+ "$pkgdir"/usr/lib \
+ "$pkgdir"/var/lib/iptables \
+ "$pkgdir"/etc/init.d \
+ "$pkgdir"/etc/conf.d
+ install -m644 include/iptables.h include/ip6tables.h \
+ "$pkgdir"/usr/include/
+ install include/libiptc/*.h "$pkgdir"/usr/include/libiptc/
+ install -m644 libiptc/libiptc.a "$pkgdir"/usr/lib
+ install -m755 "$startdir"/iptables.initd "$pkgdir"/etc/init.d/iptables
+ install -m644 "$startdir"/iptables.confd "$pkgdir"/etc/conf.d/iptables
+}
+
+ip6tables() {
+ mkdir -p "$subpkgdir"/sbin \
+ "$subpkgdir"/etc/init.d/ \
+ "$subpkgdir"/var/lib/ip6tables \
+ "$subpkgdir"/usr/libexec/xtables
+
+ mv "$pkgdir"/sbin/ip6* "$subpkgdir"/sbin/
+ mv "$pkgdir"/usr/libexec/xtables/libip6* \
+ "$subpkgdir"/usr/libexec/xtables/
+ install -m755 "$startdir"/iptables.initd \
+ "$subpkgdir"/etc/init.d/ip6tables
+}
+
+md5sums="08cd9196881657ea0615d926334cb7e9 iptables-1.4.4.tar.bz2
+ec3e80a1b0ea3e13e4e60824b7ebd1b9 iptables-1.4.2-include-in.patch
+2202ac150a5dfe32a8363b0ad565ee1d iptables.initd
+956ebf5ab69e5a1e1d3983541eab643b iptables.confd"
diff --git a/main/iptables/iptables-1.4.2-include-in.patch b/main/iptables/iptables-1.4.2-include-in.patch
new file mode 100644
index 0000000000..138fa564ca
--- /dev/null
+++ b/main/iptables/iptables-1.4.2-include-in.patch
@@ -0,0 +1,12 @@
+pull in in.h as it sets up some proto defines that iptables relies on
+
+--- a/include/xtables.h.in
++++ b/include/xtables.h.in
+@@ -5,6 +5,7 @@
+ #include <sys/types.h>
+ #include <stdbool.h>
+ #include <net/if.h>
++#include <netinet/in.h>
+ #include <linux/types.h>
+ #include <linux/netfilter/x_tables.h>
+
diff --git a/main/iptables/iptables.confd b/main/iptables/iptables.confd
new file mode 100644
index 0000000000..91287debdb
--- /dev/null
+++ b/main/iptables/iptables.confd
@@ -0,0 +1,11 @@
+# /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"
diff --git a/main/iptables/iptables.initd b/main/iptables/iptables.initd
new file mode 100755
index 0000000000..e63d8ea9e2
--- /dev/null
+++ b/main/iptables/iptables.initd
@@ -0,0 +1,114 @@
+#!/sbin/runscript
+# Copyright 1999-2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/net-firewall/iptables/files/iptables-1.3.2.init,v 1.6 2007/03/12 21:49:04 vapier Exp $
+
+opts="save reload panic"
+
+iptables_name=${SVCNAME}
+if [ "${iptables_name}" != "iptables" -a "${iptables_name}" != "ip6tables" ] ; then
+ iptables_name="iptables"
+fi
+
+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() {
+ before net
+ use logger
+}
+
+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
+ 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
+}
+
+save() {
+ ebegin "Saving ${iptables_name} state"
+ touch "${iptables_save}"
+ chmod 0600 "${iptables_save}"
+ ${iptables_bin}-save ${SAVE_RESTORE_OPTIONS} > "${iptables_save}"
+ eend $?
+}
+
+panic() {
+ checkkernel || return 1
+ service_started ${iptables_name} && svc_stop
+
+ 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 $?
+}