tpws split-pos

This commit is contained in:
bolvan 2016-03-07 17:48:23 +03:00
parent 24dd590ece
commit eb9edbde6e
5 changed files with 59 additions and 38 deletions

View File

@ -49,3 +49,7 @@ ipban : added ipban ipset. place domains banned by ip to zapret-hosts-user-ipban
these IPs must be soxified for both http and https these IPs must be soxified for both http and https
ISP support : tiera support ISP support : tiera support
ISP support : added DNS filtering to ubuntu and debian scripts ISP support : added DNS filtering to ubuntu and debian scripts
v10
tpws : added split-pos option. split every message at specified position

View File

@ -1,13 +1,12 @@
CFLAGS=-Wall CC = gcc
CFLAGS = -s
LIBS = -lnetfilter_queue -lnfnetlink LIBS = -lnetfilter_queue -lnfnetlink
SRC_FILES = *.c
all: nfqws all: nfqws
nfqws: nfqws.o nfqws: $(SRC_FILES)
$(CC) $(CFLAGS) -o "$@" $< $(LIBS) $(CC) $(CFLAGS) -o $@ $^ $(LIBS)
nfqws.o: nfqws.c
$(CC) $(CFLAGS) -c $<
clean: clean:
rm -f *.o nfqws rm -f nfqws *.o

View File

@ -1,5 +1,4 @@
zapret v.9 zapret v.10
Для чего это надо Для чего это надо
----------------- -----------------
@ -111,6 +110,7 @@ tpws - это transparent proxy.
--daemon ; демонизировать прогу --daemon ; демонизировать прогу
--user=<username> ; менять uid процесса --user=<username> ; менять uid процесса
--split-http-req=method|host ; способ разделения http запросов на сегменты : около метода (GET,POST) или около заголовка Host --split-http-req=method|host ; способ разделения http запросов на сегменты : около метода (GET,POST) или около заголовка Host
--split-pos=<offset> ; делить все посылы на сегменты в указанной позиции. Если отсыл длинее 8Kb (размер буфера приема), то будет разделен каждый блок по 8Kb.
--hostcase ; замена "Host:" => "host:" --hostcase ; замена "Host:" => "host:"
--hostdot ; добавление точки после имени хоста : "Host: kinozal.tv." --hostdot ; добавление точки после имени хоста : "Host: kinozal.tv."
--methodspace ; добавить пробел после метода : "GET /" => "GET /" --methodspace ; добавить пробел после метода : "GET /" => "GET /"

View File

@ -1,5 +1,5 @@
CC = gcc CC = gcc
CFLAGS = CFLAGS = -s
LIBS = LIBS =
SRC_FILES = *.c SRC_FILES = *.c
@ -10,5 +10,3 @@ tpws: $(SRC_FILES)
clean: clean:
rm -f tpws *.o rm -f tpws *.o
.PHONY: clean

View File

@ -35,6 +35,7 @@ struct params_s
bool daemon; bool daemon;
bool hostcase,hostdot,methodspace; bool hostcase,hostdot,methodspace;
enum splithttpreq split_http_req; enum splithttpreq split_http_req;
int split_pos;
int maxconn; int maxconn;
}; };
@ -150,6 +151,13 @@ bool handle_epollin(tproxy_conn_t *conn,int *data_transferred){
} }
} }
} }
if (params.split_pos)
{
split_array = NULL;
split_pos = params.split_pos<bs ? params.split_pos : 0;
}
else
{
switch (params.split_http_req) switch (params.split_http_req)
{ {
case split_method: case split_method:
@ -175,6 +183,7 @@ bool handle_epollin(tproxy_conn_t *conn,int *data_transferred){
split_array = NULL; split_array = NULL;
split_pos=0; split_pos=0;
} }
}
if (split_array) if (split_array)
{ {
// we havent found split post yet. need to search. // we havent found split post yet. need to search.
@ -384,7 +393,7 @@ int8_t block_sigpipe(){
void exithelp() void exithelp()
{ {
printf(" --bind-addr=<ipv4_addr>|<ipv6_addr>\n --port=<port>\n --maxconn=<max_connections>\n --split-http-req=method|host\n --hostcase\t\t; change Host: => host:\n --hostdot\t\t; add \".\" after Host: name\n --methodspace\t\t; add extra space after method\n --daemon\t\t; daemonize\n --user=<username>\t; drop root privs\n"); printf(" --bind-addr=<ipv4_addr>|<ipv6_addr>\n --port=<port>\n --maxconn=<max_connections>\n --split-http-req=method|host\n --split-pos=<numeric_offset>\t split at specified pos. invalidates split-http-req.\n --hostcase\t\t; change Host: => host:\n --hostdot\t\t; add \".\" after Host: name\n --methodspace\t\t; add extra space after method\n --daemon\t\t; daemonize\n --user=<username>\t; drop root privs\n");
exit(1); exit(1);
} }
@ -407,7 +416,8 @@ void parse_params(int argc, char *argv[])
{"hostcase",no_argument,0,0},// optidx=7 {"hostcase",no_argument,0,0},// optidx=7
{"hostdot",no_argument,0,0},// optidx=8 {"hostdot",no_argument,0,0},// optidx=8
{"split-http-req",required_argument,0,0},// optidx=9 {"split-http-req",required_argument,0,0},// optidx=9
{"methodspace",no_argument,0,0},// optidx=10 {"split-pos",required_argument,0,0},// optidx=10
{"methodspace",no_argument,0,0},// optidx=11
{NULL,0,NULL,0} {NULL,0,NULL,0}
}; };
while ((v=getopt_long_only(argc,argv,"",long_options,&option_index))!=-1) while ((v=getopt_long_only(argc,argv,"",long_options,&option_index))!=-1)
@ -472,7 +482,17 @@ void parse_params(int argc, char *argv[])
exit(1); exit(1);
} }
break; break;
case 10: /* methodspace */ case 10: /* split-pos */
i = atoi(optarg);
if (i)
params.split_pos = i;
else
{
fprintf(stderr,"Invalid argument for split-pos\n");
exit(1);
}
break;
case 11: /* methodspace */
params.methodspace = true; params.methodspace = true;
break; break;
} }