From 9c8da8f11fe989a47f9b5866d2c727078942a42a Mon Sep 17 00:00:00 2001 From: z3APA3A <3APA3A@3proxy.ru> Date: Thu, 19 Nov 2020 02:30:19 +0300 Subject: [PATCH] better dat filters handling --- src/proxy.c | 23 +++++++++++++++++++---- src/sockmap.c | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/proxy.c b/src/proxy.c index 720aa58..cccef29 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -483,17 +483,28 @@ for(;;){ RETURN(0); } if(action != PASS) RETURN(517); - if(param->ndatfilterscli > 0 && contentlength64 > 0){ + param->nolongdatfilter = 0; + + + if (conf.filtermaxsize && contentlength64 > (uint64_t)conf.filtermaxsize) { + param->nolongdatfilter = 1; + } + else if(param->ndatfilterscli > 0 && contentlength64 > 0){ uint64_t newlen64; newlen64 = sockfillbuffcli(param, (unsigned long)contentlength64, CONNECTION_S); if(newlen64 == contentlength64) { + action = handlepredatflt(param); + if(action == HANDLED){ + RETURN(0); + } + if(action != PASS) RETURN(19); action = handledatfltcli(param, ¶m->clibuf, (int *)¶m->clibufsize, 0, (int *)¶m->cliinbuf); if(action == HANDLED){ RETURN(0); } if(action != PASS) RETURN(517); contentlength64 = param->cliinbuf; - param->ndatfilterscli = 0; + param->nolongdatfilter = 1; } sprintf((char*)buf+strlen((char *)buf), "Content-Length: %"PRIu64"\r\n", contentlength64); } @@ -828,7 +839,6 @@ for(;;){ sleeptime = param->bandlimfunc(param, 0, (int)strlen((char *)buf)); } if(contentlength64 > 0){ - param->nolongdatfilter = 0; param->waitclient64 = contentlength64; res = mapsocket(param, conf.timeouts[CONNECTION_S]); param->waitclient64 = 0; @@ -931,10 +941,15 @@ for(;;){ if (conf.filtermaxsize && contentlength64 > (uint64_t)conf.filtermaxsize) { param->nolongdatfilter = 1; } - else if(param->unsafefilter && param->ndatfilterssrv > 0 && contentlength64 > 0 && param->operation != HTTP_HEAD && res != 204 && res != 304){ + else if(param->ndatfilterssrv > 0 && contentlength64 > 0 && param->operation != HTTP_HEAD && res != 204 && res != 304){ uint64_t newlen; newlen = (uint64_t)sockfillbuffsrv(param, (unsigned long) contentlength64, CONNECTION_S); if(newlen == contentlength64) { + action = handlepredatflt(param); + if(action == HANDLED){ + RETURN(0); + } + if(action != PASS) RETURN(19); action = handledatfltsrv(param, ¶m->srvbuf, (int *)¶m->srvbufsize, 0, (int *)¶m->srvinbuf); param->nolongdatfilter = 1; if(action == HANDLED){ diff --git a/src/sockmap.c b/src/sockmap.c index 239f042..bdc2f54 100644 --- a/src/sockmap.c +++ b/src/sockmap.c @@ -67,7 +67,7 @@ int sockmap(struct clientparam * param, int timeo, int usesplice){ int pipesrv[2] = {-1,-1}; int pipecli[2] = {-1,-1}; - if(param->operation == UDPASSOC) usesplice = 0; + if(param->operation == UDPASSOC || (!param->nolongdatfilter && (param->ndatfilterscli > 0 || param->ndatfilterssrv))) usesplice = 0; if(usesplice){ TOCLIENTPIPE = FROMCLIENTPIPE = TOSERVERPIPE = FROMSERVERPIPE = 1; TOCLIENTBUF = TOSERVERBUF = 0;