mirror of
https://github.com/3proxy/3proxy.git
synced 2025-02-23 02:25:40 +08:00
Simplify transparent + add support for BSD PF/IPF
This commit is contained in:
parent
105522b24e
commit
b99fa7aaa4
@ -31,7 +31,7 @@ REMOVECOMMAND = rm -f
|
||||
TYPECOMMAND = cat
|
||||
COMPATLIBS =
|
||||
MAKEFILE = Makefile.unix
|
||||
PLUGINS = StringsPlugin TrafficPlugin PCREPlugin PamAuth
|
||||
PLUGINS = StringsPlugin TrafficPlugin PCREPlugin PamAuth TransparentPlugin
|
||||
|
||||
include Makefile.inc
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
BUILDDIR =
|
||||
CC = gcc
|
||||
|
||||
CFLAGS = -g -O2 -c -pthread -DWITHSPLICE -DGETHOSTBYNAME_R -D_THREAD_SAFE -D_REENTRANT -DNOODBC -DWITH_STD_MALLOC -DFD_SETSIZE=4096 -DWITH_POLL
|
||||
CFLAGS = -g -O2 -c -pthread -DWITHSPLICE -DGETHOSTBYNAME_R -D_THREAD_SAFE -D_REENTRANT -DNOODBC -DWITH_STD_MALLOC -DFD_SETSIZE=4096 -DWITH_POLL -DWITH_NETFILTER
|
||||
COUT = -o
|
||||
LN = gcc
|
||||
DCFLAGS = -fpic
|
||||
|
@ -28,7 +28,7 @@ REMOVECOMMAND = rm -f
|
||||
TYPECOMMAND = cat
|
||||
COMPATLIBS =
|
||||
MAKEFILE = Makefile.Solaris
|
||||
PLUGINS = StringsPlugin TrafficPlugin PCREPlugin
|
||||
PLUGINS = StringsPlugin TrafficPlugin PCREPlugin TransparentPlugin
|
||||
|
||||
include Makefile.inc
|
||||
|
||||
|
@ -32,7 +32,7 @@ REMOVECOMMAND = rm -f
|
||||
TYPECOMMAND = cat
|
||||
COMPATLIBS =
|
||||
MAKEFILE = Makefile.unix
|
||||
PLUGINS = StringsPlugin TrafficPlugin PCREPlugin PamAuth
|
||||
PLUGINS = StringsPlugin TrafficPlugin PCREPlugin PamAuth TransparentPlugin
|
||||
|
||||
include Makefile.inc
|
||||
|
||||
|
@ -6,14 +6,18 @@
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#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" {
|
||||
@ -38,35 +42,37 @@ static void* transparent_filter_open(void * idata, struct srvparam * param){
|
||||
|
||||
static FILTER_ACTION transparent_filter_client(void *fo, struct clientparam * param, void** fc){
|
||||
|
||||
#ifdef SO_ORIGINAL_DST
|
||||
struct sockaddr_in addr;
|
||||
socklen_t len;
|
||||
unsigned u;
|
||||
unsigned short p;
|
||||
char addrbuf[24];
|
||||
char addrbuf[60];
|
||||
int i=0;
|
||||
|
||||
len = sizeof(addr);
|
||||
if(getsockopt(param->clisock, SOL_IP, SO_ORIGINAL_DST,(struct sockaddr *) &addr, &len) || !addr.sin_addr.s_addr){
|
||||
return PASS;
|
||||
}
|
||||
u = ntohl(addr.sin_addr.s_addr);
|
||||
p = ntohs(addr.sin_port);
|
||||
sprintf(addrbuf, "%u.%u.%u.%u:%hu",
|
||||
((u&0xFF000000)>>24),
|
||||
((u&0x00FF0000)>>16),
|
||||
((u&0x0000FF00)>>8),
|
||||
((u&0x000000FF)),
|
||||
p);
|
||||
len = sizeof(param->req);
|
||||
|
||||
pl->parsehostname(addrbuf, param, 0);
|
||||
#ifdef WITH_NETFILTER
|
||||
#ifdef SO_ORIGINAL_DST
|
||||
if(getsockopt(param->clisock, SOL_IP, SO_ORIGINAL_DST,(struct sockaddr *) ¶m->req, &len)){
|
||||
return PASS;
|
||||
}
|
||||
#else
|
||||
#error No SO_ORIGINAL_DST defined
|
||||
param->srv->logfunc(param, (unsigned char *)"transparent_plugin: No SO_ORIGINAL_DST defined");
|
||||
return REJECT;
|
||||
param->srv->logfunc(param, (unsigned char *)"transparent_plugin: No SO_ORIGINAL_DST defined");
|
||||
return REJECT;
|
||||
#endif
|
||||
|
||||
|
||||
#else
|
||||
if(!memcmp(¶m->req, ¶m->sincl,sizeof(param->req))){
|
||||
param->req = param->sincl;
|
||||
param->sincl = param->srv->intsa;
|
||||
}
|
||||
#endif
|
||||
addrbuf[i++] = '[';
|
||||
i += pl->myinet_ntop(*SAFAMILY(¶m->req), SAADDR(¶m->req), (char *)addrbuf + i, sizeof(addrbuf));
|
||||
sprintf((char *)addrbuf+i, "]:%hu", ntohs(*SAPORT(¶m->req)));
|
||||
#ifdef mystrdup
|
||||
#undef mystrdup
|
||||
#undef myfree
|
||||
#endif
|
||||
if(param->hostname) pl->myfree(param->hostname);
|
||||
param->hostname = pl->mystrdup(addrbuf);
|
||||
return PASS;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user