mirror of
https://github.com/3proxy/3proxy.git
synced 2026-11-22 23:59:41 +08:00
Allow to set internal / external namespace on linux
This commit is contained in:
1 parent
b87e998e4d
commit
51a82613a6
21 files changed
+623
-205
No files matched your search
+7
-10
@@ -22,9 +22,6 @@ base64$(OBJSUFFICS): base64.c
|
||||
ftp$(OBJSUFFICS): ftp.c proxy.h structures.h
|
||||
$(CC) $(CFLAGS) ftp.c
|
||||
|
||||
#$(COMPATLIBS):
|
||||
# $(CC) $(CFLAGS) strncasecmp.c
|
||||
|
||||
sockgetchar$(OBJSUFFICS): sockgetchar.c proxy.h structures.h
|
||||
$(CC) $(CFLAGS) sockgetchar.c
|
||||
|
||||
@@ -131,7 +128,7 @@ redirect$(OBJSUFFICS): redirect.c proxy.h structures.h
|
||||
hash$(OBJSUFFICS): hash.c proxy.h structures.h
|
||||
$(CC) $(COUT)hash$(OBJSUFFICS) $(CFLAGS) hash.c
|
||||
|
||||
hashtables$(OBJSUFFICS): hashtables.c proxy.h structures.h
|
||||
hashtables$(OBJSUFFICS): hashtables.c proxy.h structures.h blake2_compat.h
|
||||
$(CC) $(COUT)hashtables$(OBJSUFFICS) $(CFLAGS) hashtables.c
|
||||
|
||||
resolve$(OBJSUFFICS): resolve.c proxy.h structures.h
|
||||
@@ -149,13 +146,13 @@ log$(OBJSUFFICS): log.c proxy.h structures.h
|
||||
datatypes$(OBJSUFFICS): datatypes.c proxy.h structures.h
|
||||
$(CC) $(COUT)datatypes$(OBJSUFFICS) $(CFLAGS) datatypes.c
|
||||
|
||||
3proxy_crypt$(OBJSUFFICS): 3proxy_crypt.c
|
||||
3proxy_crypt$(OBJSUFFICS): 3proxy_crypt.c blake2_compat.h
|
||||
$(CC) $(COUT)3proxy_crypt$(OBJSUFFICS) $(CFLAGS) 3proxy_crypt.c
|
||||
|
||||
3proxy_cryptmain$(OBJSUFFICS): 3proxy_crypt.c
|
||||
3proxy_cryptmain$(OBJSUFFICS): 3proxy_crypt.c blake2_compat.h
|
||||
$(CC) $(COUT)3proxy_cryptmain$(OBJSUFFICS) $(CFLAGS) $(DEFINEOPTION)WITHMAIN 3proxy_crypt.c
|
||||
|
||||
blake2$(OBJSUFFICS): libs/blake2.h libs/blake2-impl.h libs/blake2b-ref.c
|
||||
blake2$(OBJSUFFICS): libs/blake2b-ref.c
|
||||
$(CC) $(COUT)blake2$(OBJSUFFICS) $(CFLAGS) libs/blake2b-ref.c
|
||||
|
||||
$(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS): blake2$(OBJSUFFICS) 3proxy_cryptmain$(OBJSUFFICS) base64$(OBJSUFFICS)
|
||||
@@ -164,13 +161,13 @@ $(BUILDDIR)$(CRYPT_PREFIX)crypt$(EXESUFFICS): blake2$(OBJSUFFICS) 3proxy_cryptma
|
||||
stringtable$(OBJSUFFICS): stringtable.c
|
||||
$(CC) $(COUT)stringtable$(OBJSUFFICS) $(CFLAGS) stringtable.c
|
||||
|
||||
ssllib$(OBJSUFFICS): ssllib.c
|
||||
ssllib$(OBJSUFFICS): ssllib.c structures.h proxy.h ssl.h
|
||||
$(CC) $(COUT)ssllib$(OBJSUFFICS) $(CFLAGS) ssllib.c
|
||||
|
||||
ssl$(OBJSUFFICS): ssl.c
|
||||
ssl$(OBJSUFFICS): ssl.c structures.h proxy.h ssl.h
|
||||
$(CC) $(COUT)ssl$(OBJSUFFICS) $(CFLAGS) ssl.c
|
||||
|
||||
pcre$(OBJSUFFICS): pcre.c
|
||||
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) 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) blake2$(OBJSUFFICS) 3proxy_crypt$(OBJSUFFICS) base64$(OBJSUFFICS) ftp$(OBJSUFFICS) stringtable$(OBJSUFFICS) srvwebadmin$(OBJSUFFICS) srvdnspr$(OBJSUFFICS) plugins$(OBJSUFFICS) $(SSL_OBJS) $(PCRE_OBJS) $(COMPATLIBS) $(VERSIONDEP)
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
|
||||
#include "proxy.h"
|
||||
#ifdef __linux__
|
||||
#include <sched.h>
|
||||
#endif
|
||||
|
||||
#define param ((struct clientparam *) p)
|
||||
#ifdef _WIN32
|
||||
@@ -209,6 +212,10 @@ static void freesrvstrings(struct srvparam *srv, unsigned char *cbc_string, unsi
|
||||
if(srv->ibindtodevice) myfree(srv->ibindtodevice);
|
||||
if(srv->obindtodevice) myfree(srv->obindtodevice);
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
if(srv->inetns) myfree(srv->inetns);
|
||||
if(srv->onetns) myfree(srv->onetns);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef MODULEMAINFUNC
|
||||
@@ -256,6 +263,9 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
FILE *fp = NULL;
|
||||
struct linger lg;
|
||||
int nlog = 5000;
|
||||
#ifdef __linux__
|
||||
int saved_nsfd = -1;
|
||||
#endif
|
||||
char loghelp[] =
|
||||
#ifdef STDMAIN
|
||||
#ifndef _WIN32
|
||||
@@ -438,6 +448,12 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
else if(argv[i][3] == 'i') getip46(46, (unsigned char *)argv[i]+3, (struct sockaddr *)&srv.intNat);
|
||||
else getip46(46, (unsigned char *)argv[i]+2, (struct sockaddr *)&srv.extNat);
|
||||
break;
|
||||
#ifdef __linux__
|
||||
case 'n':
|
||||
if(argv[i][2] == 'i') { if(srv.inetns) myfree(srv.inetns); srv.inetns = mystrdup(argv[i] + 3); }
|
||||
else if(argv[i][2] == 'e') { if(srv.onetns) myfree(srv.onetns); srv.onetns = mystrdup(argv[i] + 3); }
|
||||
break;
|
||||
#endif
|
||||
case 'p':
|
||||
*SAPORT(&srv.intsa) = htons(atoi(argv[i]+2));
|
||||
break;
|
||||
@@ -655,6 +671,33 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
|
||||
|
||||
|
||||
#ifdef __linux__
|
||||
if(srv.inetns) {
|
||||
saved_nsfd = open("/proc/self/ns/net", O_RDONLY);
|
||||
if(saved_nsfd == -1) {
|
||||
dolog(&defparam, (unsigned char *)"failed to open /proc/self/ns/net");
|
||||
freesrvstrings(&srv, cbc_string, cbl_string);
|
||||
return -13;
|
||||
}
|
||||
{
|
||||
int nsfd = open(srv.inetns, O_RDONLY);
|
||||
if(nsfd == -1) {
|
||||
dolog(&defparam, (unsigned char *)"failed to open inetns");
|
||||
close(saved_nsfd);
|
||||
freesrvstrings(&srv, cbc_string, cbl_string);
|
||||
return -13;
|
||||
}
|
||||
if(setns(nsfd, CLONE_NEWNET)) {
|
||||
dolog(&defparam, (unsigned char *)"failed to setns inetns");
|
||||
close(nsfd);
|
||||
close(saved_nsfd);
|
||||
freesrvstrings(&srv, cbc_string, cbl_string);
|
||||
return -13;
|
||||
}
|
||||
close(nsfd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!iscbc) {
|
||||
if(srv.srvsock == INVALID_SOCKET){
|
||||
if(!isudp){
|
||||
@@ -750,6 +793,33 @@ int MODULEMAINFUNC (int argc, char** argv){
|
||||
dolog(&defparam, buf);
|
||||
}
|
||||
}
|
||||
#ifdef __linux__
|
||||
if(saved_nsfd != -1) {
|
||||
if(setns(saved_nsfd, CLONE_NEWNET)) {
|
||||
dolog(&defparam, (unsigned char *)"failed to restore netns");
|
||||
close(saved_nsfd);
|
||||
freesrvstrings(&srv, cbc_string, cbl_string);
|
||||
return -14;
|
||||
}
|
||||
close(saved_nsfd);
|
||||
saved_nsfd = -1;
|
||||
}
|
||||
if(srv.onetns) {
|
||||
int nsfd = open(srv.onetns, O_RDONLY);
|
||||
if(nsfd == -1) {
|
||||
dolog(&defparam, (unsigned char *)"failed to open onetns");
|
||||
freesrvstrings(&srv, cbc_string, cbl_string);
|
||||
return -14;
|
||||
}
|
||||
if(setns(nsfd, CLONE_NEWNET)) {
|
||||
dolog(&defparam, (unsigned char *)"failed to setns onetns");
|
||||
close(nsfd);
|
||||
freesrvstrings(&srv, cbc_string, cbl_string);
|
||||
return -14;
|
||||
}
|
||||
close(nsfd);
|
||||
}
|
||||
#endif
|
||||
if(iscbl){
|
||||
parsehost(srv.family, cbl_string, (struct sockaddr *)&cbsa);
|
||||
if((srv.cbsock=srv.so._socket(srv.so.state, SASOCK(&cbsa), SOCK_STREAM, IPPROTO_TCP))==INVALID_SOCKET) {
|
||||
@@ -1165,6 +1235,10 @@ void srvfree(struct srvparam * srv){
|
||||
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF
|
||||
if(srv->ibindtodevice) myfree(srv->ibindtodevice);
|
||||
if(srv->obindtodevice) myfree(srv->obindtodevice);
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
if(srv->inetns) myfree(srv->inetns);
|
||||
if(srv->onetns) myfree(srv->onetns);
|
||||
#endif
|
||||
if(srv->so.freefunc) srv->so.freefunc(srv->so.state);
|
||||
}
|
||||
|
||||
@@ -557,6 +557,10 @@ struct srvparam {
|
||||
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF
|
||||
char * ibindtodevice;
|
||||
char * obindtodevice;
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
char * inetns;
|
||||
char * onetns;
|
||||
#endif
|
||||
struct auth *authenticate;
|
||||
struct pollfd * srvfds;
|
||||
|
||||
Reference in new issue
Block a user