Unbreak: replace ipf with pf support; from dhartmei@

This commit is contained in:
naddy 2001-12-19 22:31:55 +00:00
parent c7c0c7f373
commit e01d1839bb
3 changed files with 98 additions and 5 deletions

View File

@ -1,13 +1,10 @@
# $OpenBSD: Makefile,v 1.12 2001/10/28 13:05:48 espie Exp $
BROKEN= "requires IPF"
# $OpenBSD: Makefile,v 1.13 2001/12/19 22:31:55 naddy Exp $
COMMENT= "transparent IRC proxy"
DISTNAME= tircproxy-0.4.5
CATEGORIES= net
NEED_VERSION= 1.435
MASTER_SITES= http://bre.klaki.net/programs/tircproxy/
HOMEPAGE= http://bre.klaki.net/programs/tircproxy/
@ -16,8 +13,9 @@ PERMIT_PACKAGE_FTP= Yes
PERMIT_DISTFILES_CDROM= Yes
PERMIT_DISTFILES_FTP= Yes
CONFIGURE_STYLE= gnu
MASTER_SITES= ${HOMEPAGE}
CONFIGURE_STYLE= gnu
INSTALL_TARGET= install-strip
WRKDIST= ${WRKDIR}/tircproxy-0.4

View File

@ -0,0 +1,80 @@
$OpenBSD: patch-tircproxy_c,v 1.1 2001/12/19 22:31:55 naddy Exp $
--- tircproxy.c.orig Thu May 4 22:53:30 2000
+++ tircproxy.c Wed Dec 19 23:23:56 2001
@@ -142,6 +142,13 @@ char *Version =
# endif
#endif
+#ifdef PF
+#include <sys/ioctl.h>
+#include <sys/fcntl.h>
+#include <net/if.h>
+#include <net/pfvar.h>
+#endif
+
#ifndef LINUX
# define LINUX 0
#endif
@@ -1070,6 +1077,11 @@ static void trans_proxy(int sock, struct
natlookup_t natlook;
int fd;
#endif
+#ifdef PF
+ struct sockaddr_in ext, gwy;
+ struct pfioc_natlook natlook;
+ int fd;
+#endif
/* Give this thing 10 minutes to get started (paranoia).
*/
@@ -1166,6 +1178,50 @@ static void trans_proxy(int sock, struct
to_addr.sin_family = AF_INET;
to_addr.sin_port = htons(ntohs(natlook.nl_realport));
to_addr.sin_addr.s_addr = get_ip_addr(inet_ntoa(natlook.nl_realip));
+# else
+# ifdef PF
+ to_len = sizeof(ext);
+ if (getpeername(sock, (struct sockaddr *)&ext, &to_len) == -1)
+ {
+ perror("getpeername");
+ exit(-1);
+ }
+
+ to_len = sizeof(gwy);
+ if (getsockname(sock, (struct sockaddr *)&gwy, &to_len) == -1)
+ {
+ perror("getsockname");
+ exit(-1);
+ }
+
+ if ((fd = open("/dev/pf", O_RDWR)) == -1) {
+ perror("open(\"/dev/pf\")");
+ exit(-1);
+ }
+
+ memset(&natlook, 0, sizeof(struct pfioc_natlook));
+ natlook.af = AF_INET;
+ natlook.proto = IPPROTO_TCP;
+ natlook.direction = PF_IN; /* s = ext, d = gwy, r = lan */
+ natlook.saddr.v4.s_addr = ext.sin_addr.s_addr;
+ natlook.sport = ext.sin_port;
+ natlook.daddr.v4.s_addr = gwy.sin_addr.s_addr;
+ natlook.dport = gwy.sin_port;
+
+ if (ioctl(fd, DIOCNATLOOK, &natlook) == -1)
+ {
+ perror("ioctl");
+ close(fd);
+ exit(-1);
+ }
+
+ close(fd);
+
+ memset(&to_addr, 0, sizeof(to_addr));
+ to_addr.sin_family = AF_INET;
+ to_addr.sin_port = natlook.rsport;
+ to_addr.sin_addr.s_addr = natlook.rsaddr.v4.s_addr;
+# endif /* PF */
# endif /* IFP */
#endif /* LINUX */
}

View File

@ -0,0 +1,15 @@
$OpenBSD: patch-tircproxy_h,v 1.1 2001/12/19 22:31:55 naddy Exp $
--- tircproxy.h.orig Thu May 4 19:23:18 2000
+++ tircproxy.h Wed Dec 19 23:23:56 2001
@@ -37,9 +37,9 @@
#define BROADCAST_FILE "/tmp/ircbroadcast"
#define IRC_MOTD_FILE "/etc/motd.irc"
-/* Enable this if you want to use the IPF code for tranparency.
+/* Enable this if you want to use the PF code for transparency.
*/
-#define IPF 1
+#define PF 1
/* Enable this if you want to use the Linux code for tranparency.
*/