mirror of
				https://github.com/3proxy/3proxy.git
				synced 2025-11-04 15:52:39 +08:00 
			
		
		
		
	Add support to bind to interface (-Di / -Do) via SO_BINDTODEVICE
This commit is contained in:
		
							parent
							
								
									6010190940
								
							
						
					
					
						commit
						b17b36cbce
					
				@ -714,7 +714,9 @@ int doconnect(struct clientparam * param){
 | 
			
		||||
#endif
 | 
			
		||||
	}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef SO_BINDTODEVICE
 | 
			
		||||
	if(param->srv->obindtodevice) so._setsockopt(param->remsock, SOL_SOCKET, SO_BINDTODEVICE, param->srv->obindtodevice, strlen(param->srv->obindtodevice) + 1);
 | 
			
		||||
#endif
 | 
			
		||||
	if(SAISNULL(¶m->sinsl)){
 | 
			
		||||
#ifndef NOIPV6
 | 
			
		||||
		if(*SAFAMILY(¶m->sinsr) == AF_INET6) param->sinsl = param->srv->extsa6;
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
/*
 | 
			
		||||
   3APA3A simpliest proxy server
 | 
			
		||||
   (c) 2002-2016 by Vladimir Dubrovin <3proxy@3proxy.ru>
 | 
			
		||||
   (c) 2002-2017 by Vladimir Dubrovin <3proxy@3proxy.ru>
 | 
			
		||||
 | 
			
		||||
   please read License Agreement
 | 
			
		||||
 | 
			
		||||
@ -176,6 +176,10 @@ int MODULEMAINFUNC (int argc, char** argv){
 | 
			
		||||
	" -u never ask for username\n"
 | 
			
		||||
	" -u2 always ask for username\n"
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef SO_BINDTODEVICE
 | 
			
		||||
	" -Di(DEVICENAME) bind to incoming device, e.g. eth1\n"
 | 
			
		||||
	" -Do(DEVICENAME) bind to outgoing device, e.g. eth1\n"
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef WITHSLICE
 | 
			
		||||
	" -s Use slice() - faster proxing, but no filtering for data\n"
 | 
			
		||||
#endif
 | 
			
		||||
@ -302,6 +306,12 @@ int MODULEMAINFUNC (int argc, char** argv){
 | 
			
		||||
			if(!conf.demon)daemonize();
 | 
			
		||||
			conf.demon = 1;
 | 
			
		||||
			break;
 | 
			
		||||
#ifdef SO_BINDTODEVICE
 | 
			
		||||
		 case 'D':
 | 
			
		||||
			if(argv[i][2] == 'i') srv.ibindtodevice = mystrdup(argv[i] + 3);
 | 
			
		||||
			else if(argv[i][2] == 'o') srv.obindtodevice = mystrdup(argv[i] + 3);
 | 
			
		||||
			break;
 | 
			
		||||
#endif
 | 
			
		||||
		 case 'l':
 | 
			
		||||
			srv.logfunc = logstdout;
 | 
			
		||||
			if(srv.logtarget) myfree(srv.logtarget);
 | 
			
		||||
@ -565,6 +575,9 @@ int MODULEMAINFUNC (int argc, char** argv){
 | 
			
		||||
#ifdef SO_REUSEPORT
 | 
			
		||||
		opt = 1;
 | 
			
		||||
		so._setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (char *)&opt, sizeof(int));
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef SO_BINDTODEVICE
 | 
			
		||||
		if(srv.ibindtodevice) so._setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, srv.ibindtodevice, strlen(srv.ibindtodevice) + 1);
 | 
			
		||||
#endif
 | 
			
		||||
	}
 | 
			
		||||
	size = sizeof(srv.intsa);
 | 
			
		||||
@ -916,6 +929,10 @@ void srvfree(struct srvparam * srv){
 | 
			
		||||
 if(srv->logtarget) myfree(srv->logtarget);
 | 
			
		||||
 if(srv->logformat) myfree(srv->logformat);
 | 
			
		||||
 if(srv->nonprintable) myfree(srv->nonprintable);
 | 
			
		||||
#ifdef SO_BINDTODEVICE
 | 
			
		||||
 if(srv->ibindtodevice) myfree(srv->ibindtodevice);
 | 
			
		||||
 if(srv->obindtodevice) myfree(srv->obindtodevice);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -417,6 +417,10 @@ struct srvparam {
 | 
			
		||||
	struct pollfd fds;
 | 
			
		||||
	FILE *stdlog;
 | 
			
		||||
	unsigned char * target;
 | 
			
		||||
#ifdef SO_BINDTODEVICE
 | 
			
		||||
	char * ibindtodevice;
 | 
			
		||||
	char * obindtodevice;
 | 
			
		||||
#endif
 | 
			
		||||
	struct auth *authenticate;
 | 
			
		||||
	struct pollfd * srvfds;
 | 
			
		||||
	struct ace *acl;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user