mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
Transparent moved to main code (TransparentPlugin removed), BSD pf support added
(cherry picked from commit 88b3225bdf)
This commit is contained in:
1 parent
69c6ddc8c4
commit
da66016c7f
19 files changed
+972
-191
No files matched your search
@@ -13,6 +13,9 @@ void ssl_install(void);
|
||||
#ifdef WITH_PCRE
|
||||
void pcre_install(void);
|
||||
#endif
|
||||
#ifdef WITH_TRANSPARENT
|
||||
void transparent_install(void);
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
#include <sys/resource.h>
|
||||
#ifndef NOPLUGINS
|
||||
@@ -529,6 +532,9 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
|
||||
#ifdef WITH_PCRE
|
||||
pcre_install();
|
||||
#endif
|
||||
#ifdef WITH_TRANSPARENT
|
||||
transparent_install();
|
||||
#endif
|
||||
|
||||
freeconf(&conf);
|
||||
initcommands();
|
||||
|
||||
+5
-2
@@ -116,6 +116,9 @@ srvsocks$(OBJSUFFICS): socks.c proxy.h structures.h
|
||||
srvwebadmin$(OBJSUFFICS): webadmin.c proxy.h structures.h
|
||||
$(CC) $(COUT)srvwebadmin$(OBJSUFFICS) $(CFLAGS) webadmin.c
|
||||
|
||||
transparent$(OBJSUFFICS): transparent.c proxy.h structures.h
|
||||
$(CC) $(COUT)transparent$(OBJSUFFICS) $(CFLAGS) transparent.c
|
||||
|
||||
srvhttpsrv$(OBJSUFFICS): httpsrv.c proxy.h structures.h
|
||||
$(CC) $(COUT)srvhttpsrv$(OBJSUFFICS) $(CFLAGS) httpsrv.c
|
||||
|
||||
@@ -191,6 +194,6 @@ ssl$(OBJSUFFICS): ssl.c structures.h proxy.h ssl.h
|
||||
pcre$(OBJSUFFICS): pcre.c structures.h
|
||||
$(CC) $(COUT)pcre$(OBJSUFFICS) $(CFLAGS) $(DEFINEOPTION)WITH_PCRE pcre.c
|
||||
|
||||
$(BUILDDIR)3proxy$(EXESUFFICS): 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvimapp$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) log$(OBJSUFFICS) datatypes$(OBJSUFFICS) md4$(OBJSUFFICS) md5$(OBJSUFFICS) blake2$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) $(HTTPSRV_OBJS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(SSL_OBJS) $(PCRE_OBJS) $(COMPATLIBS) $(VERSIONDEP)
|
||||
$(LN) $(LNOUT)$(BUILDDIR)3proxy$(EXESUFFICS) $(LDFLAGS) $(VERFILE) 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) datatypes$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvimapp$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) md4$(OBJSUFFICS) md5$(OBJSUFFICS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) $(HTTPSRV_OBJS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(SSL_OBJS) $(PCRE_OBJS) $(COMPATLIBS) $(LIBS) $(PCRE_LIBS)
|
||||
$(BUILDDIR)3proxy$(EXESUFFICS): 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvimapp$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) log$(OBJSUFFICS) datatypes$(OBJSUFFICS) md4$(OBJSUFFICS) md5$(OBJSUFFICS) blake2$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) $(HTTPSRV_OBJS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(SSL_OBJS) $(PCRE_OBJS) $(TRANSPARENT_OBJS) $(COMPATLIBS) $(VERSIONDEP)
|
||||
$(LN) $(LNOUT)$(BUILDDIR)3proxy$(EXESUFFICS) $(LDFLAGS) $(VERFILE) 3proxy$(OBJSUFFICS) mainfunc$(OBJSUFFICS) auth$(OBJSUFFICS) acl$(OBJSUFFICS) limiter$(OBJSUFFICS) redirect$(OBJSUFFICS) authradius$(OBJSUFFICS) hash$(OBJSUFFICS) hashtables$(OBJSUFFICS) resolve$(OBJSUFFICS) sql$(OBJSUFFICS) conf$(OBJSUFFICS) datatypes$(OBJSUFFICS) srvauto$(OBJSUFFICS) srvproxy$(OBJSUFFICS) srvpop3p$(OBJSUFFICS) srvimapp$(OBJSUFFICS) srvsmtpp$(OBJSUFFICS) srvftppr$(OBJSUFFICS) srvsocks$(OBJSUFFICS) srvtcppm$(OBJSUFFICS) srvtlspr$(OBJSUFFICS) srvudppm$(OBJSUFFICS) sockmap$(OBJSUFFICS) udpsockmap$(OBJSUFFICS) sockgetchar$(OBJSUFFICS) common$(OBJSUFFICS) log$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) md4$(OBJSUFFICS) md5$(OBJSUFFICS) blake2$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) $(HTTPSRV_OBJS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) mdhash$(OBJSUFFICS) $(SSL_OBJS) $(PCRE_OBJS) $(TRANSPARENT_OBJS) $(COMPATLIBS) $(LIBS) $(PCRE_LIBS)
|
||||
|
||||
+14
@@ -18,6 +18,9 @@ void ssl_install(void);
|
||||
#ifdef WITH_PCRE
|
||||
void pcre_install(void);
|
||||
#endif
|
||||
#ifdef WITH_TRANSPARENT
|
||||
void transparent_install(void);
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
#include <sys/resource.h>
|
||||
#include <pwd.h>
|
||||
@@ -1793,6 +1796,10 @@ int h_server_verify(int argc, unsigned char **argv);
|
||||
int h_no_server_verify(int argc, unsigned char **argv);
|
||||
int h_client_mode(int argc, unsigned char **argv);
|
||||
#endif
|
||||
#ifdef WITH_TRANSPARENT
|
||||
int h_transparent(int argc, unsigned char **argv);
|
||||
int h_notransparent(int argc, unsigned char **argv);
|
||||
#endif
|
||||
#ifdef WITH_PCRE
|
||||
int h_pcre(int argc, unsigned char **argv);
|
||||
int h_pcre_rewrite(int argc, unsigned char **argv);
|
||||
@@ -1922,6 +1929,10 @@ struct commands commandhandlers[]={
|
||||
{NULL, "ssl_client_mode", h_client_mode, 1, 2},
|
||||
{NULL, "ssl_certcache", h_certcache, 2, 2},
|
||||
#endif
|
||||
#ifdef WITH_TRANSPARENT
|
||||
{NULL, "transparent", h_transparent, 1, 2},
|
||||
{NULL, "notransparent", h_notransparent, 1, 1},
|
||||
#endif
|
||||
#ifdef WITH_PCRE
|
||||
{NULL, "pcre", h_pcre, 4, 0},
|
||||
{NULL, "pcre_rewrite", h_pcre_rewrite, 5, 0},
|
||||
@@ -2212,6 +2223,9 @@ int reload (void){
|
||||
#endif
|
||||
#ifdef WITH_PCRE
|
||||
pcre_install();
|
||||
#endif
|
||||
#ifdef WITH_TRANSPARENT
|
||||
transparent_install();
|
||||
#endif
|
||||
conf.paused++;
|
||||
freeconf(&conf);
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
# TransparentPlugin
|
||||
# Works on Linux (with netfilter), BSD and macOS (without netfilter support)
|
||||
|
||||
add_3proxy_plugin(TransparentPlugin
|
||||
SOURCES transparent_plugin.c
|
||||
)
|
||||
@@ -1 +0,0 @@
|
||||
include Makefile.var
|
||||
@@ -1,10 +0,0 @@
|
||||
all: $(BUILDDIR)TransparentPlugin$(DLSUFFICS)
|
||||
|
||||
|
||||
|
||||
transparent_plugin$(OBJSUFFICS): transparent_plugin.c
|
||||
$(CC) $(CFLAGS) $(DCFLAGS) transparent_plugin.c
|
||||
|
||||
|
||||
$(BUILDDIR)TransparentPlugin$(DLSUFFICS): transparent_plugin$(OBJSUFFICS)
|
||||
$(LN) $(LNOUT)../../$(BUILDDIR)TransparentPlugin$(DLSUFFICS) $(LDFLAGS) $(DLFLAGS) transparent_plugin$(OBJSUFFICS)
|
||||
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
3APA3A simplest proxy server
|
||||
(c) 2002-2026 by Vladimir Dubrovin <vlad@3proxy.org>
|
||||
|
||||
please read License Agreement
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifdef WITH_NETFILTER
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
#include "../../structures.h"
|
||||
#include "../../proxy.h"
|
||||
#ifdef WITH_NETFILTER
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <limits.h>
|
||||
#include <linux/netfilter_ipv4.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
static struct pluginlink * pl;
|
||||
|
||||
static int transparent_loaded = 0;
|
||||
|
||||
static void* transparent_filter_open(void * idata, struct srvparam * param){
|
||||
return idata;
|
||||
}
|
||||
|
||||
static FILTER_ACTION transparent_filter_client(void *fo, struct clientparam * param, void** fc){
|
||||
|
||||
char addrbuf[64];
|
||||
|
||||
#ifdef WITH_NETFILTER
|
||||
socklen_t len;
|
||||
|
||||
len = sizeof(param->req);
|
||||
#ifdef SO_ORIGINAL_DST
|
||||
|
||||
if(getsockopt(param->clisock,
|
||||
#ifndef NOIPV6
|
||||
#ifdef SOL_IPV6
|
||||
*SAFAMILY(¶m->sincr) == AF_INET6?SOL_IPV6:
|
||||
#endif
|
||||
#endif
|
||||
SOL_IP, SO_ORIGINAL_DST,(struct sockaddr *) ¶m->req, &len) || !memcmp((char *)SAADDR(¶m->req), "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", SAADDRLEN(¶m->req))){
|
||||
return PASS;
|
||||
}
|
||||
#else
|
||||
#error No SO_ORIGINAL_DST defined
|
||||
param->srv->logfunc(param, (unsigned char *)"transparent_plugin: No SO_ORIGINAL_DST defined");
|
||||
return REJECT;
|
||||
#endif
|
||||
#else
|
||||
if(*SAFAMILY(¶m->sincl) == AF_INET || *SAFAMILY(¶m->sincl) == AF_INET6){
|
||||
param->req = param->sincl;
|
||||
param->sincl = param->srv->intsa;
|
||||
}
|
||||
#endif
|
||||
pl->myinet_ntop(*SAFAMILY(¶m->req), SAADDR(¶m->req), (char *)addrbuf, sizeof(addrbuf));
|
||||
if(param->hostname) pl->freefunc(param->hostname);
|
||||
param->hostname = (unsigned char *)pl->strdupfunc(addrbuf);
|
||||
param->sinsr = param->req;
|
||||
return PASS;
|
||||
}
|
||||
|
||||
|
||||
static void transparent_filter_clear(void *fo){
|
||||
}
|
||||
|
||||
static void transparent_filter_close(void *fo){
|
||||
}
|
||||
|
||||
static struct filter transparent_filter = {
|
||||
NULL,
|
||||
"Transparent filter",
|
||||
"Transparent filter",
|
||||
transparent_filter_open,
|
||||
transparent_filter_client,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
transparent_filter_clear,
|
||||
transparent_filter_close
|
||||
};
|
||||
|
||||
static int h_transparent(int argc, unsigned char **argv){
|
||||
transparent_filter.filter_open = transparent_filter_open;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int h_notransparent(int argc, unsigned char **argv){
|
||||
transparent_filter.filter_open = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct commands transparent_commandhandlers[] = {
|
||||
{transparent_commandhandlers+1, "transparent", h_transparent, 1, 1},
|
||||
{NULL, "notransparent", h_notransparent, 1, 1}
|
||||
};
|
||||
|
||||
|
||||
#ifdef WATCOM
|
||||
#pragma aux transparent_plugin "*" parm caller [ ] value struct float struct routine [eax] modify [eax ecx edx]
|
||||
#undef PLUGINCALL
|
||||
#define PLUGINCALL
|
||||
#endif
|
||||
|
||||
|
||||
PLUGINAPI int PLUGINCALL transparent_plugin (struct pluginlink * pluginlink,
|
||||
int argc, char** argv){
|
||||
pl = pluginlink;
|
||||
if(!transparent_loaded){
|
||||
transparent_loaded = 1;
|
||||
transparent_filter.next = pl->conf->filters;
|
||||
pl->conf->filters = &transparent_filter;
|
||||
transparent_commandhandlers[1].next = pl->commandhandlers->next;
|
||||
pl->commandhandlers->next = transparent_commandhandlers;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,240 @@
|
||||
/*
|
||||
3APA3A simplest proxy server
|
||||
(c) 2002-2026 by Vladimir Dubrovin <vlad@3proxy.org>
|
||||
|
||||
please read License Agreement
|
||||
|
||||
*/
|
||||
|
||||
#include "structures.h"
|
||||
#include "proxy.h"
|
||||
|
||||
#ifdef WITH_TRANSPARENT
|
||||
|
||||
#ifdef WITH_NETFILTER
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <limits.h>
|
||||
#include <linux/netfilter_ipv4.h>
|
||||
#endif
|
||||
|
||||
#ifdef WITH_PF
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <net/if.h>
|
||||
#include <net/pfvar.h>
|
||||
#endif
|
||||
|
||||
/* Where the address the client was trying to reach is read from.
|
||||
|
||||
AUTO uses what the platform offers, which is the only thing an
|
||||
installation usually needs. The rest name one mechanism, for a machine
|
||||
that has more than one and redirects with a particular one.
|
||||
*/
|
||||
#define TRANSPARENT_AUTO 0
|
||||
#define TRANSPARENT_NETFILTER 1
|
||||
#define TRANSPARENT_PF 2
|
||||
#define TRANSPARENT_SOCKET 3
|
||||
|
||||
static struct pluginlink * pl;
|
||||
|
||||
static int transparent_loaded = 0;
|
||||
static int transparent_mode = TRANSPARENT_AUTO;
|
||||
|
||||
#ifdef WITH_PF
|
||||
static int pf_device = -1;
|
||||
|
||||
/* Ask the packet filter what the connection was addressed to before it was
|
||||
redirected. pf keeps that in its state table rather than on the socket,
|
||||
so it has to be looked up with the addresses of both ends.
|
||||
*/
|
||||
static int transparent_pf(struct clientparam *param)
|
||||
{
|
||||
struct pfioc_natlook nl;
|
||||
|
||||
if(pf_device < 0){
|
||||
pf_device = open("/dev/pf", O_RDONLY);
|
||||
if(pf_device < 0) return 1;
|
||||
}
|
||||
memset(&nl, 0, sizeof(nl));
|
||||
nl.proto = IPPROTO_TCP;
|
||||
nl.direction = PF_OUT;
|
||||
#ifndef NOIPV6
|
||||
if(*SAFAMILY(¶m->sincr) == AF_INET6){
|
||||
nl.af = AF_INET6;
|
||||
memcpy(&nl.saddr.v6, SAADDR(¶m->sincr), 16);
|
||||
memcpy(&nl.daddr.v6, SAADDR(¶m->sincl), 16);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nl.af = AF_INET;
|
||||
memcpy(&nl.saddr.v4, SAADDR(¶m->sincr), 4);
|
||||
memcpy(&nl.daddr.v4, SAADDR(¶m->sincl), 4);
|
||||
}
|
||||
nl.sport = *SAPORT(¶m->sincr);
|
||||
nl.dport = *SAPORT(¶m->sincl);
|
||||
|
||||
if(ioctl(pf_device, DIOCNATLOOK, &nl)) return 1;
|
||||
|
||||
memset(¶m->req, 0, sizeof(param->req));
|
||||
*SAFAMILY(¶m->req) = nl.af;
|
||||
#ifndef NOIPV6
|
||||
if(nl.af == AF_INET6) memcpy(SAADDR(¶m->req), &nl.rdaddr.v6, 16);
|
||||
else
|
||||
#endif
|
||||
memcpy(SAADDR(¶m->req), &nl.rdaddr.v4, 4);
|
||||
*SAPORT(¶m->req) = nl.rdport;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_NETFILTER
|
||||
/* Linux keeps the original address for the connection it redirected. */
|
||||
static int transparent_netfilter(struct clientparam *param)
|
||||
{
|
||||
socklen_t len = sizeof(param->req);
|
||||
|
||||
#ifdef SO_ORIGINAL_DST
|
||||
if(getsockopt(param->clisock,
|
||||
#ifndef NOIPV6
|
||||
#ifdef SOL_IPV6
|
||||
*SAFAMILY(¶m->sincr) == AF_INET6?SOL_IPV6:
|
||||
#endif
|
||||
#endif
|
||||
SOL_IP, SO_ORIGINAL_DST, (struct sockaddr *) ¶m->req, &len)
|
||||
|| !memcmp((char *)SAADDR(¶m->req), "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", SAADDRLEN(¶m->req))){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
#error No SO_ORIGINAL_DST defined
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Some redirections leave the original address on the socket itself, so the
|
||||
local address of the accepted connection is what the client asked for.
|
||||
|
||||
A connection which was not redirected at all arrives at the address the
|
||||
service listens on, and taking that as the destination would send the
|
||||
service to itself. Refuse instead of making the connection.
|
||||
*/
|
||||
static int transparent_socket(struct clientparam *param)
|
||||
{
|
||||
if(*SAFAMILY(¶m->sincl) != AF_INET && *SAFAMILY(¶m->sincl) != AF_INET6)
|
||||
return 1;
|
||||
if(*SAPORT(¶m->sincl) == *SAPORT(¶m->srv->intsa)
|
||||
&& (SAISNULL(¶m->srv->intsa)
|
||||
|| !memcmp(SAADDR(¶m->sincl), SAADDR(¶m->srv->intsa), SAADDRLEN(¶m->sincl))))
|
||||
return 2;
|
||||
param->req = param->sincl;
|
||||
param->sincl = param->srv->intsa;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void* transparent_filter_open(void * idata, struct srvparam * param){
|
||||
return idata;
|
||||
}
|
||||
|
||||
static FILTER_ACTION transparent_filter_client(void *fo, struct clientparam * param, void** fc){
|
||||
|
||||
char addrbuf[64];
|
||||
int res = 1;
|
||||
|
||||
#ifdef WITH_NETFILTER
|
||||
if(transparent_mode == TRANSPARENT_AUTO || transparent_mode == TRANSPARENT_NETFILTER)
|
||||
res = transparent_netfilter(param);
|
||||
#endif
|
||||
#ifdef WITH_PF
|
||||
if(res && (transparent_mode == TRANSPARENT_AUTO || transparent_mode == TRANSPARENT_PF))
|
||||
res = transparent_pf(param);
|
||||
#endif
|
||||
if(res && (transparent_mode == TRANSPARENT_AUTO || transparent_mode == TRANSPARENT_SOCKET)){
|
||||
res = transparent_socket(param);
|
||||
if(res == 2){
|
||||
param->srv->logfunc(param, (unsigned char *)"transparent: connection was not redirected");
|
||||
return REJECT;
|
||||
}
|
||||
}
|
||||
/* Nothing knows where this was going: leave the request alone, so the
|
||||
service decides as it would without the command. */
|
||||
if(res) return PASS;
|
||||
|
||||
pl->myinet_ntop(*SAFAMILY(¶m->req), SAADDR(¶m->req), (char *)addrbuf, sizeof(addrbuf));
|
||||
if(param->hostname) pl->freefunc(param->hostname);
|
||||
param->hostname = (unsigned char *)pl->strdupfunc(addrbuf);
|
||||
param->sinsr = param->req;
|
||||
return PASS;
|
||||
}
|
||||
|
||||
|
||||
static void transparent_filter_clear(void *fo){
|
||||
}
|
||||
|
||||
static void transparent_filter_close(void *fo){
|
||||
}
|
||||
|
||||
static struct filter transparent_filter = {
|
||||
NULL,
|
||||
"Transparent filter",
|
||||
"Transparent filter",
|
||||
transparent_filter_open,
|
||||
transparent_filter_client,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
transparent_filter_clear,
|
||||
transparent_filter_close
|
||||
};
|
||||
|
||||
int h_transparent(int argc, unsigned char **argv){
|
||||
transparent_mode = TRANSPARENT_AUTO;
|
||||
if(argc > 1){
|
||||
if(!strcmp((char *)argv[1], "auto")) transparent_mode = TRANSPARENT_AUTO;
|
||||
else if(!strcmp((char *)argv[1], "netfilter")){
|
||||
#ifndef WITH_NETFILTER
|
||||
fprintf(stderr, "transparent: netfilter is not available in this build\n");
|
||||
return 1;
|
||||
#else
|
||||
transparent_mode = TRANSPARENT_NETFILTER;
|
||||
#endif
|
||||
}
|
||||
else if(!strcmp((char *)argv[1], "pf")){
|
||||
#ifndef WITH_PF
|
||||
fprintf(stderr, "transparent: pf is not available in this build\n");
|
||||
return 1;
|
||||
#else
|
||||
transparent_mode = TRANSPARENT_PF;
|
||||
#endif
|
||||
}
|
||||
else if(!strcmp((char *)argv[1], "socket")) transparent_mode = TRANSPARENT_SOCKET;
|
||||
else {
|
||||
fprintf(stderr, "transparent: unknown mode %s, expected auto, netfilter, pf or socket\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
transparent_filter.filter_open = transparent_filter_open;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int h_notransparent(int argc, unsigned char **argv){
|
||||
transparent_filter.filter_open = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void transparent_install(void){
|
||||
pl = &pluginlink;
|
||||
/* A reload runs this again: the filter is a single static entry, so it
|
||||
is only linked in once, and the commands decide whether it acts. */
|
||||
if(!transparent_loaded){
|
||||
transparent_loaded = 1;
|
||||
transparent_filter.next = pl->conf->filters;
|
||||
pl->conf->filters = &transparent_filter;
|
||||
}
|
||||
transparent_filter.filter_open = NULL;
|
||||
transparent_mode = TRANSPARENT_AUTO;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user