mirror of
				https://github.com/3proxy/3proxy.git
				synced 2025-11-04 07:42:39 +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
 | 
					TYPECOMMAND = cat
 | 
				
			||||||
COMPATLIBS =
 | 
					COMPATLIBS =
 | 
				
			||||||
MAKEFILE = Makefile.unix
 | 
					MAKEFILE = Makefile.unix
 | 
				
			||||||
PLUGINS = StringsPlugin TrafficPlugin PCREPlugin PamAuth
 | 
					PLUGINS = StringsPlugin TrafficPlugin PCREPlugin PamAuth TransparentPlugin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include Makefile.inc
 | 
					include Makefile.inc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -10,7 +10,7 @@
 | 
				
			|||||||
BUILDDIR =
 | 
					BUILDDIR =
 | 
				
			||||||
CC = gcc
 | 
					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 
 | 
					COUT = -o 
 | 
				
			||||||
LN = gcc
 | 
					LN = gcc
 | 
				
			||||||
DCFLAGS = -fpic
 | 
					DCFLAGS = -fpic
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,7 @@ REMOVECOMMAND = rm -f
 | 
				
			|||||||
TYPECOMMAND = cat
 | 
					TYPECOMMAND = cat
 | 
				
			||||||
COMPATLIBS =
 | 
					COMPATLIBS =
 | 
				
			||||||
MAKEFILE = Makefile.Solaris
 | 
					MAKEFILE = Makefile.Solaris
 | 
				
			||||||
PLUGINS = StringsPlugin TrafficPlugin PCREPlugin
 | 
					PLUGINS = StringsPlugin TrafficPlugin PCREPlugin TransparentPlugin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include Makefile.inc
 | 
					include Makefile.inc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -32,7 +32,7 @@ REMOVECOMMAND = rm -f
 | 
				
			|||||||
TYPECOMMAND = cat
 | 
					TYPECOMMAND = cat
 | 
				
			||||||
COMPATLIBS =
 | 
					COMPATLIBS =
 | 
				
			||||||
MAKEFILE = Makefile.unix
 | 
					MAKEFILE = Makefile.unix
 | 
				
			||||||
PLUGINS = StringsPlugin TrafficPlugin PCREPlugin PamAuth
 | 
					PLUGINS = StringsPlugin TrafficPlugin PCREPlugin PamAuth TransparentPlugin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include Makefile.inc
 | 
					include Makefile.inc
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -6,14 +6,18 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef WITH_NETFILTER
 | 
				
			||||||
#include <sys/utsname.h>
 | 
					#include <sys/utsname.h>
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
#include "../../structures.h"
 | 
					#include "../../structures.h"
 | 
				
			||||||
#include "../../proxy.h"
 | 
					#include "../../proxy.h"
 | 
				
			||||||
 | 
					#ifdef WITH_NETFILTER
 | 
				
			||||||
#include <sys/types.h>
 | 
					#include <sys/types.h>
 | 
				
			||||||
#include <sys/socket.h>
 | 
					#include <sys/socket.h>
 | 
				
			||||||
#include <limits.h>
 | 
					#include <limits.h>
 | 
				
			||||||
#include <linux/netfilter_ipv4.h>
 | 
					#include <linux/netfilter_ipv4.h>
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef  __cplusplus
 | 
					#ifdef  __cplusplus
 | 
				
			||||||
extern "C" {
 | 
					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){
 | 
					static FILTER_ACTION transparent_filter_client(void *fo, struct clientparam * param, void** fc){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef SO_ORIGINAL_DST
 | 
					 | 
				
			||||||
	struct sockaddr_in addr;
 | 
					 | 
				
			||||||
	socklen_t len;
 | 
						socklen_t len;
 | 
				
			||||||
	unsigned u;
 | 
						char addrbuf[60];
 | 
				
			||||||
	unsigned short p;
 | 
						int i=0;
 | 
				
			||||||
	char addrbuf[24];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		len = sizeof(addr);
 | 
						len = sizeof(param->req);
 | 
				
			||||||
		if(getsockopt(param->clisock, SOL_IP, SO_ORIGINAL_DST,(struct sockaddr *) &addr, &len) || !addr.sin_addr.s_addr){
 | 
					
 | 
				
			||||||
 | 
					#ifdef WITH_NETFILTER
 | 
				
			||||||
 | 
					#ifdef SO_ORIGINAL_DST
 | 
				
			||||||
 | 
						if(getsockopt(param->clisock, SOL_IP, SO_ORIGINAL_DST,(struct sockaddr *) ¶m->req, &len)){
 | 
				
			||||||
		return PASS;
 | 
							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);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        	pl->parsehostname(addrbuf, param, 0);
 | 
					 | 
				
			||||||
		return PASS;
 | 
					 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
#error No SO_ORIGINAL_DST defined
 | 
					#error No SO_ORIGINAL_DST defined
 | 
				
			||||||
       	param->srv->logfunc(param, (unsigned char *)"transparent_plugin: No SO_ORIGINAL_DST defined");
 | 
					       	param->srv->logfunc(param, (unsigned char *)"transparent_plugin: No SO_ORIGINAL_DST defined");
 | 
				
			||||||
	return REJECT;
 | 
						return REJECT;
 | 
				
			||||||
#endif
 | 
					#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;
 | 
						return PASS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user