Add support to bind to interface (-Di / -Do) via SO_BINDTODEVICE

This commit is contained in:
z3APA3A 2017-08-14 18:22:15 +03:00
parent 6010190940
commit b17b36cbce
3 changed files with 25 additions and 2 deletions

View File

@ -714,7 +714,9 @@ int doconnect(struct clientparam * param){
#endif #endif
} }
#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(&param->sinsl)){ if(SAISNULL(&param->sinsl)){
#ifndef NOIPV6 #ifndef NOIPV6
if(*SAFAMILY(&param->sinsr) == AF_INET6) param->sinsl = param->srv->extsa6; if(*SAFAMILY(&param->sinsr) == AF_INET6) param->sinsl = param->srv->extsa6;

View File

@ -1,6 +1,6 @@
/* /*
3APA3A simpliest proxy server 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 please read License Agreement
@ -176,6 +176,10 @@ int MODULEMAINFUNC (int argc, char** argv){
" -u never ask for username\n" " -u never ask for username\n"
" -u2 always ask for username\n" " -u2 always ask for username\n"
#endif #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 #ifdef WITHSLICE
" -s Use slice() - faster proxing, but no filtering for data\n" " -s Use slice() - faster proxing, but no filtering for data\n"
#endif #endif
@ -302,6 +306,12 @@ int MODULEMAINFUNC (int argc, char** argv){
if(!conf.demon)daemonize(); if(!conf.demon)daemonize();
conf.demon = 1; conf.demon = 1;
break; 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': case 'l':
srv.logfunc = logstdout; srv.logfunc = logstdout;
if(srv.logtarget) myfree(srv.logtarget); if(srv.logtarget) myfree(srv.logtarget);
@ -565,6 +575,9 @@ int MODULEMAINFUNC (int argc, char** argv){
#ifdef SO_REUSEPORT #ifdef SO_REUSEPORT
opt = 1; opt = 1;
so._setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (char *)&opt, sizeof(int)); 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 #endif
} }
size = sizeof(srv.intsa); size = sizeof(srv.intsa);
@ -916,6 +929,10 @@ void srvfree(struct srvparam * srv){
if(srv->logtarget) myfree(srv->logtarget); if(srv->logtarget) myfree(srv->logtarget);
if(srv->logformat) myfree(srv->logformat); if(srv->logformat) myfree(srv->logformat);
if(srv->nonprintable) myfree(srv->nonprintable); if(srv->nonprintable) myfree(srv->nonprintable);
#ifdef SO_BINDTODEVICE
if(srv->ibindtodevice) myfree(srv->ibindtodevice);
if(srv->obindtodevice) myfree(srv->obindtodevice);
#endif
} }

View File

@ -417,6 +417,10 @@ struct srvparam {
struct pollfd fds; struct pollfd fds;
FILE *stdlog; FILE *stdlog;
unsigned char * target; unsigned char * target;
#ifdef SO_BINDTODEVICE
char * ibindtodevice;
char * obindtodevice;
#endif
struct auth *authenticate; struct auth *authenticate;
struct pollfd * srvfds; struct pollfd * srvfds;
struct ace *acl; struct ace *acl;