(t)ftp-proxy: use libpfctl

Reviewed by:	glebius
MFC after:	4 weeks
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D29641
This commit is contained in:
Kristof Provost 2021-03-29 14:03:39 +02:00
parent 0d71f9f36e
commit 95be9288f0
4 changed files with 23 additions and 9 deletions

View File

@ -28,6 +28,7 @@
#include <err.h>
#include <errno.h>
#include <libpfctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
@ -68,7 +69,8 @@ add_filter(u_int32_t id, u_int8_t dir, struct sockaddr *src,
return (-1);
pfr.rule.direction = dir;
if (ioctl(dev, DIOCADDRULE, &pfr) == -1)
if (pfctl_add_rule(dev, &pfr.rule, pfr.anchor, pfr.anchor_call,
pfr.ticket, pfr.pool_ticket))
return (-1);
return (0);
@ -97,12 +99,14 @@ add_nat(u_int32_t id, struct sockaddr *src, struct sockaddr *dst,
&satosin6(nat)->sin6_addr.s6_addr, 16);
memset(&pfp.addr.addr.v.a.mask.addr8, 255, 16);
}
if (ioctl(dev, DIOCADDADDR, &pfp) == -1)
if (pfctl_add_rule(dev, &pfr.rule, pfr.anchor, pfr.anchor_call,
pfr.ticket, pfr.pool_ticket))
return (-1);
pfr.rule.rpool.proxy_port[0] = nat_range_low;
pfr.rule.rpool.proxy_port[1] = nat_range_high;
if (ioctl(dev, DIOCADDRULE, &pfr) == -1)
if (pfctl_add_rule(dev, &pfr.rule, pfr.anchor, pfr.anchor_call,
pfr.ticket, pfr.pool_ticket))
return (-1);
return (0);
@ -130,11 +134,13 @@ add_rdr(u_int32_t id, struct sockaddr *src, struct sockaddr *dst,
&satosin6(rdr)->sin6_addr.s6_addr, 16);
memset(&pfp.addr.addr.v.a.mask.addr8, 255, 16);
}
if (ioctl(dev, DIOCADDADDR, &pfp) == -1)
if (pfctl_add_rule(dev, &pfr.rule, pfr.anchor, pfr.anchor_call,
pfr.ticket, pfr.pool_ticket))
return (-1);
pfr.rule.rpool.proxy_port[0] = rdr_port;
if (ioctl(dev, DIOCADDRULE, &pfr) == -1)
if (pfctl_add_rule(dev, &pfr.rule, pfr.anchor, pfr.anchor_call,
pfr.ticket, pfr.pool_ticket))
return (-1);
return (0);

View File

@ -32,6 +32,7 @@
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <libpfctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -72,7 +73,8 @@ add_filter(u_int32_t id, u_int8_t dir, struct sockaddr *src,
return (-1);
pfr.rule.direction = dir;
if (ioctl(dev, DIOCADDRULE, &pfr) == -1)
if (pfctl_add_rule(dev, &pfr.rule, pfr.anchor, pfr.anchor_call,
pfr.ticket, pfr.pool_ticket))
return (-1);
return (0);
@ -106,7 +108,8 @@ add_nat(u_int32_t id, struct sockaddr *src, struct sockaddr *dst,
pfr.rule.rpool.proxy_port[0] = nat_range_low;
pfr.rule.rpool.proxy_port[1] = nat_range_high;
if (ioctl(dev, DIOCADDRULE, &pfr) == -1)
if (pfctl_add_rule(dev, &pfr.rule, pfr.anchor, pfr.anchor_call,
pfr.ticket, pfr.pool_ticket))
return (-1);
return (0);
@ -138,7 +141,8 @@ add_rdr(u_int32_t id, struct sockaddr *src, struct sockaddr *dst,
return (-1);
pfr.rule.rpool.proxy_port[0] = rdr_port;
if (ioctl(dev, DIOCADDRULE, &pfr) == -1)
if (pfctl_add_rule(dev, &pfr.rule, pfr.anchor, pfr.anchor_call,
pfr.ticket, pfr.pool_ticket))
return (-1);
return (0);

View File

@ -6,6 +6,9 @@ PROG= tftp-proxy
SRCS= tftp-proxy.c filter.c
MAN= tftp-proxy.8
CFLAGS+= -I${SRCTOP}/lib/libpfctl -I${OBJTOP}/lib/libpfctl
LIBADD= pfctl
WARNS?= 3
.include <bsd.prog.mk>

View File

@ -8,8 +8,9 @@ MAN= ftp-proxy.8
SRCS= ftp-proxy.c filter.c
CFLAGS+=-I${SRCTOP}/contrib/pf/libevent
CFLAGS+= -I${SRCTOP}/lib/libpfctl -I${OBJTOP}/lib/libpfctl
LIBADD= event1
LIBADD= event1 pfctl
WARNS?= 3