add option to select packet filtering command (ipchains, pf, ipfilter)

This commit is contained in:
OBATA Akio 2005-04-21 13:04:57 +00:00 committed by Thomas Klausner
parent 3868974433
commit 5512eccaf1
4 changed files with 37 additions and 7 deletions

View file

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.2 2005/03/31 03:01:15 obache Exp $
# $NetBSD: Makefile,v 1.3 2005/04/21 13:04:57 obache Exp $
#
DISTNAME= linuxigd-0.92
@ -14,6 +14,8 @@ USE_LANGUAGES= c c++
USE_PKGINSTALL= yes
USE_GNU_TOOLS+= make
.include "options.mk"
WRKSRC= ${WRKDIR}/linux-igd
PKG_SYSCONFSUBDIR?= linuxigd

View file

@ -1,4 +1,4 @@
$NetBSD: distinfo,v 1.1.1.1 2005/03/13 12:48:21 obache Exp $
$NetBSD: distinfo,v 1.2 2005/04/21 13:04:58 obache Exp $
SHA1 (linuxigd-0.92.tgz) = 38a6684914e9db747cde3e3cf21270e06d417b7e
RMD160 (linuxigd-0.92.tgz) = ded0fdbe38c55cbc3f524ebcc83d0fd61a5759bc
@ -8,4 +8,4 @@ SHA1 (patch-ab) = 69d80c970b840d641a070569c326223cd0b950ab
SHA1 (patch-ac) = 1ebc48d947dc4e56326ad1a7cbc4898df81ac3b6
SHA1 (patch-ad) = 7bc5741089502595143d986af28de1bd8e724d61
SHA1 (patch-ae) = d594034ab39e9c4dc3218d5b91885632851e2380
SHA1 (patch-af) = 89af067bdbdf0468705dfcef8ccbed00f7bb01cd
SHA1 (patch-af) = 23877ea6a9f58ce3d3556516bb20ff8d664e51b4

28
linuxigd/options.mk Normal file
View file

@ -0,0 +1,28 @@
# $NetBSD: options.mk,v 1.1 2005/04/21 13:04:58 obache Exp $
PKG_OPTIONS_VAR= PKG_OPTIONS.linuxigd
PKG_SUPPORTED_OPTIONS= iptables pf ipfilter
.include "../../mk/bsd.prefs.mk"
.if ${OPSYS} == "Linux"
PKG_DEFAULT_OPTIONS= iptables
.elif ${OPSYS} == "OpenBSD"
PKG_DEFAULT_OPTIONS= pf
.else
PKG_DEFAULT_OPTIONS= ipfilter
.endif
.include "../../mk/bsd.options.mk"
.if !empty(PKG_OPTIONS:Miptables)
CFLAGS+= -DFILTER_CMD="iptables"
.elif !empty(PKG_OPTIONS:Mpf)
CFLAGS+= -DFILTER_CMD="pf"
.elif !empty(PKG_OPTIONS:Mipfilter)
CFLAGS+= -DFILTER_CMD="ipfilter"
.else
PKG_FAIL_REASON+= "${PKG_OPTIONS_VAR} must contaion one of" \
"\"iptables\" or \"pf\" or \"ipfilter\"!"
.endif

View file

@ -1,4 +1,4 @@
$NetBSD: patch-af,v 1.2 2005/04/21 11:12:01 obache Exp $
$NetBSD: patch-af,v 1.3 2005/04/21 13:04:58 obache Exp $
--- pmlist.cpp.orig 2003-01-03 04:14:24.000000000 +0900
+++ pmlist.cpp
@ -15,17 +15,17 @@ $NetBSD: patch-af,v 1.2 2005/04/21 11:12:01 obache Exp $
{
char command[255];
+#ifdef __linux__
+#if FILTER_CMD==iptables
sprintf(command,"/usr/sbin/iptables -t nat -A PREROUTING -p %s -d %s --dport %d -j DNAT --to %s:%d", Proto, ExtIP, ExtPort, IntIP, IntPort);
system(command);
+#elif defined(__OpenBSD__)
+#elif FILTER_CMD==pf
+ snprintf(command, 255, "/sbin/pfctl -a upnpd:%s-%s-%d -f -", ExtIf, Proto, ExtPort);
+ FILE *ipf = popen(command, "w");
+ if (ipf == NULL) return 0;
+ snprintf(command, 255, "rdr pass on %s proto %s from any to %s port %d -> %s port %d\n", ExtIf, Proto, ExtIP, ExtPort, IntIP, IntPort);
+ fprintf(ipf, command);
+ pclose(ipf);
+#else
+#elif FILTER_CMD==ipfilter
+ FILE *ipnat = popen("/usr/sbin/ipnat -f -", "w");
+ if (ipnat == NULL) return 0;
+ snprintf(command, 255, "rdr %s %s/32 port %d -> %s port %d %s\n", ExtIf, ExtIP, ExtPort, IntIP, IntPort, Proto);