From 77a030721d8e77c044bab28a030266b8f03c8336 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 21 Sep 2015 17:48:05 +0300 Subject: [PATCH 01/11] test frang 06 --- tempesta_fw/t/unit/test_frang.c | 616 ++++++++++++++++++++++++++++++++ 1 file changed, 616 insertions(+) create mode 100644 tempesta_fw/t/unit/test_frang.c diff --git a/tempesta_fw/t/unit/test_frang.c b/tempesta_fw/t/unit/test_frang.c new file mode 100644 index 0000000000..84906a9571 --- /dev/null +++ b/tempesta_fw/t/unit/test_frang.c @@ -0,0 +1,616 @@ +/** + * Tempesta FW + * + * Copyright (C) 2012-2014 NatSys Lab. (info@natsys-lab.com). + * Copyright (C) 2015 Tempesta Technologies, Inc. + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with + * his program; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "test.h" +#include "sched_helper.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include "/usr/include/arpa/inet.h" +#include +//#include +#include +//#include +#include "../../tempesta_fw.h" +#include "../../lib.h" +#include "../../log.h" +#include "../../msg.h" +#include "../../http.h" +#include "cfg.h" +#include "../../gfsm.h" +#include "../../client.h" +#include "../../connection.h" +//#ifdef module_init +//#undef module_init +//#endif + +//#ifndef _INCLUDE_FRANG_CODE +//#define _INCLUDE_FRANG_CODE +//#include +//#include "../../classifier/frang.c" +//#endif +//#undef module_init +#include "test.h" +#include "kallsyms_helper.h" + +#include +#include +#include +#include + +#include "../../addr.h" +#include "../../classifier.h" +#include "../../client.h" +#include "../../connection.h" +#include "../../gfsm.h" +#include "../../http_msg.h" +#include "../../log.h" +#include "../../lib.h" +#include "../../tempesta_fw.h" + +#include "addr.h" +#include "helpers.h" +#define TFW_GFSM_FRANG_STATE(s) ((TFW_FSM_FRANG << \ +TFW_GFSM_FSM_SHIFT) | (s)) +enum { + /* Run the FSM for each HTTP request chunk. */ + TFW_FRANG_FSM_INIT = TFW_GFSM_FRANG_STATE(0), + /* Run the FSM for fully read HTTP request. */ + TFW_FRANG_FSM_MSG = TFW_GFSM_FRANG_STATE(1), + TFW_FRANG_FSM_DONE = TFW_GFSM_FRANG_STATE(TFW_GFSM_STATE_LAST) +}; + +enum { + /* TODO Enter FSM with this state for each HTTP request chunk. */ + __Frang_Chunk_0, + + Frang_Req_0 = __Frang_Chunk_0, + + Frang_Req_Hdr_Start, + Frang_Req_Hdr_Method, + Frang_Req_Hdr_UriLen, + Frang_Req_Hdr_FieldDup, + Frang_Req_Hdr_FieldLenRaw, + Frang_Req_Hdr_FieldLenSpecial, + Frang_Req_Hdr_Crlf, + Frang_Req_Hdr_Host, + Frang_Req_Hdr_ContentType, + + Frang_Req_Hdr_NoState, + + /* TODO Enter FSM with this state when HTTP request if fully read. */ + __Frang_Msg_0, + + Frang_Req_Body_Start = __Frang_Msg_0, + Frang_Req_Body_Timeout, + Frang_Req_Body_ChunkCnt, + Frang_Req_Body_Len, + + Frang_Req_Body_NoState, + + __Frang_LastState, + + Frang_Req_NothingToDo = __Frang_LastState, +}; + + + + +//#include "classifier.h" +typedef struct { + struct hlist_head list; + spinlock_t lock; +} FrangHashBucket; +#define FRANG_HASH_BITS 17 + + FrangHashBucket *frang_hash/*[1 << FRANG_HASH_BITS]*/; +#define FRANG_FREQ 8 +typedef struct { + unsigned long ts; + unsigned int conn_new; + unsigned int req; +} FrangRates; + +typedef struct frang_account_t { + struct hlist_node hentry; + struct in6_addr addr; /* client address */ + unsigned long last_ts; /* last access time */ + unsigned int conn_curr; /* current connections number */ + FrangRates history[FRANG_FREQ]; +} FrangAcc; +//extern void frang_get_ipv6addr(struct sock *sk,struct in6_addr *addr); +//extern void *get_sym_ptr(const char* name); +// void (*frang_get_ipv6addr_ptr)(struct sock *sk,struct in6_addr *addr); +#define FRANG_HASH_BITS 17 +static void +get_ipv6addr(struct sock *sk, struct in6_addr *addr) +{ + struct inet_sock *isk = (struct inet_sock *)sk; +TFW_DBG("frang_getipv6:%s;%lu\n","isk from sk:",(unsigned long)isk); +#if IS_ENABLED(CONFIG_IPV6) + if (isk->pinet6) + memcpy(addr, &isk->pinet6->saddr, sizeof(*addr)); + else +#endif + ipv6_addr_set_v4mapped(isk->inet_saddr, addr); +} + + + +FrangAcc* get_frang_acc(struct sock *sk){ +struct in6_addr addr; +FrangHashBucket *hb; +struct hlist_node *tmp; +FrangAcc *ra; +unsigned int key; +struct inet_sock *insk; +//frang_get_ipv6addr_ptr = get_sym_ptr("frang_get_ipv6addr"); +insk = (struct inet_sock *)sk; + + +get_ipv6addr(sk,&addr); +TFW_DBG("frang_conn_get_acc:after addr %d",addr.s6_addr32[1]); + +key = addr.s6_addr32[0] ^ addr.s6_addr32[1] ^ addr.s6_addr32[2] \ +^ addr.s6_addr32[3]; + +TFW_DBG("frang_conn_get_acc:%s;%d\n","key",key); +frang_hash = (FrangHashBucket*)get_sym_ptr("frang_hash"); +hb = &frang_hash[hash_min(key,FRANG_HASH_BITS)]; +hlist_for_each_entry_safe(ra,tmp,&hb->list,hentry){ +TFW_DBG("frang_conn_get_acc:%s;%d\n","in_list",ra->addr.s6_addr32[1]); + +if(ipv6_addr_equal(&addr,&ra->addr)) +break; +} +return ra; +} + +const int (*frang_conn_new_ptr)(struct sock*); + struct sock mockSock; + struct inet_sock *isk; + int res; + + TfwCfgMod frang_cfg_mod; + + + #define FRANG_FREQ 8 + const char* inet_addr = "192.168.168.245.1"; +unsigned short i = 0; +typedef struct { + char *str; + size_t len; /* The pre-computed strlen(@str). */ +} FrangCtVal; +typedef struct { + /* Limits (zero means unlimited). */ + unsigned int req_rate; + unsigned int req_burst; + unsigned int conn_rate; + unsigned int conn_burst; + unsigned int conn_max; + + /* + * Limits on time it takes to receive + * a full header or a body chunk. + */ + unsigned long clnt_hdr_timeout; + unsigned long clnt_body_timeout; + + /* Limits for HTTP request contents: uri, headers, body, etc. */ + unsigned int http_uri_len; + unsigned int http_field_len; + unsigned int http_body_len; + unsigned int http_hchunk_cnt; + unsigned int http_bchunk_cnt; + bool http_ct_required; + bool http_host_required; + /* The bitmask of allowed HTTP Method values. */ + unsigned long http_methods_mask; + /* The list of allowed Content-Type values. */ + FrangCtVal *http_ct_vals; +} FrangCfg; +FrangCfg *frang_cfg; + struct inet_sock *isk; +static int (*frang_conn_limit_ptr)(FrangAcc *ra, struct sock *sk); +//extern int frang_account_do(struct sock *sk, int *func(FrangAcc *ra,struct sock *sk)); +extern TfwConnection* tfw_cli_conn_alloc(void); +static int (*frang_http_req_handler_ptr)(void *obj, + struct sk_buff *skb , + unsigned int off); + +int req_handler(TfwHttpReq *req) +{ +TfwConnection *conn; + +//conn = (TfwConnection*)req->msg->conn; +//tfw_cli_conn_alloc_ptr = get_sym_ptr("tfw_cli_conn_alloc"); +//if(!tfw_cli_conn_alloc_ptr){ +// TFW_DBG("req_handler: alloc is null\n"); + //} + +conn = (TfwConnection*)tfw_cli_conn_alloc(); +conn->msg = &req->msg; +if(!conn){ + TFW_DBG("req_handler: conn is null\n"); + +} + +//tfw_http_conn_msg_alloc(conn); + +//conn->msg = req->msg; + +frang_http_req_handler_ptr = get_sym_ptr("frang_http_req_handler"); +/*TFW_DBG("req_handler:%s;%lu\n","hand_ptr:",(unsigned long)frang_http_req_handler_ptr);*/ +if(! frang_http_req_handler_ptr){ +TFW_DBG("frang_req_handleris null str:%d\n",392); +} +//if(&mockReq->msg == NULL || &mockReq->msg.skb_list == NULL){ +//TFW_DBG("frang_req_handleris null param:%d\n",404); +//} +return frang_http_req_handler_ptr((void*)conn,req->msg.skb_list.first,25); +} + +TEST(frang, max_conn){ +FrangAcc *ra; +unsigned long ts; +//unsigned long ts; +frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); +frang_cfg->conn_max =5; +isk = (struct inet_sock*)(&mockSock); + isk->inet_saddr = htonl(in_aton("127.0.0.1")); + frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); + res = frang_conn_new_ptr(&mockSock); +TFW_DBG("frang_conn_max:%s;%d\n","before ra",isk->inet_saddr); +ra = get_frang_acc(&mockSock); +TFW_DBG("frang_conn_max:%s;%d\n","after ra",ra->conn_curr); + +/*while(i<5){ + ndelay(1000); + isk = (struct inet_sock*)(&mockSock); +// isk->inet_saddr = in_aton(inet_addr); + frang_conn_limit(ra,&mockSock); + i++; + };*/ + isk = (struct inet_sock*)(&mockSock); +// isk->inet_saddr = in_aton(inet_addr); + ra->conn_curr = 5; + frang_conn_limit_ptr = get_sym_ptr("frang_conn_limit"); + res = frang_conn_limit_ptr(ra,&mockSock); + EXPECT_EQ(TFW_BLOCK, res); +ts = jiffies * FRANG_FREQ / HZ; +i = ts % FRANG_FREQ; + frang_cfg->conn_max = 0; + frang_cfg->conn_rate = 5; + ra->history[i].conn_new =5; + res = frang_conn_limit_ptr(ra, &mockSock); + EXPECT_EQ(TFW_BLOCK,res); + frang_cfg->conn_max =0; + frang_cfg->conn_rate = 0; + frang_cfg->conn_burst = 5; + ra->history[i].conn_new = 5; + res = frang_conn_limit_ptr(ra,&mockSock); + EXPECT_EQ(TFW_BLOCK,res); + + + + } +//static int (*frang_http_uri_ptr)(const TfwHttpReq *req); +//extern int frang_http_uri_len(const TfwHttpReq *req); + +TEST(frang,uri){ +TfwHttpReq *mockReq; +TfwStr uri; +mockReq = test_req_alloc(26); +tfw_http_parse_req(mockReq,"GET /index.html HTTP /1.1",25); +// const char* conf_max_uri = "http_uri_len=10";frang_cfg = get_sym_ptr("frang_cfg"); +//TFW_DBG("uri_len:%s;%lu\n","start conf:",(unsigned long)frang_cfg); + if(!frang_cfg){ + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + } + + frang_cfg->http_uri_len = 5; +// LIST_HEAD(frang_cfg_mod); +// tfw_cfg_start_mods(conf_max_uri, &frang_cfg_mod); + +uri.len = 17; +uri.ptr = (void*)"/home/index.html"; +mockReq->uri_path = uri; +//frang_http_uri_ptr = get_sym_ptr("frang_http_uri_len"); +//TFW_DBG("uri_len funk ptr:%lu\n",(unsigned long)frang_http_uri_ptr); +res = req_handler(mockReq); +//res = frang_http_uri_len(mockReq); +EXPECT_EQ(TFW_BLOCK,res); +} +//static int (*frang_http_methods_ptr)(const TfwHttpReq *req); + +//static int (*frang_http_ct_check_ptr)(const TfwHttpReq *req); +TEST(frang,ct_check){ +TfwHttpReq * mockReq; +FrangCtVal ctval[1]; + + mockReq = test_req_alloc(22); + tfw_http_parse_req(mockReq,"POST /foo HTTP/1.1\r\n",20); + TFW_DBG("ct_check:%s;%lu\n","after parse req req:",(unsigned long)mockReq); + if(!frang_cfg){ + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + } +//TFW_DBG("ct_check:%s;%lu\n","after conf conf:",(unsigned long)frang_cfg); +ctval[0].len = 17; +ctval[0].str ="application/html"; + frang_cfg->http_ct_required = true; + res = req_handler(mockReq); +EXPECT_EQ(TFW_BLOCK,res); + +// frang_cfg->http_ct_vals = ctval; +// frang_cfg->http_ct_vals[0].len = 17; +//W_DBG("ct_check:%s;%d\n","after conf ct_vals:",358); + mockReq->frang_st = 9; + res = req_handler(mockReq); +EXPECT_EQ(TFW_BLOCK,res); +} + +//frang_http_ct_check_ptr = get_sym_ptr("frang_http_ct_check"); +//res = frang_http_ct_check_ptr(mockReq); +//EXPECT_EQ(TFW_BLO/CK,res); +//test_req_free(mockReq); +//mockReq = test_req_alloc(92); +//TFW_DBG("ct_check:%s\n","after parse"); +//frang_cfg->http_ct_vals[0].len =17; +//res = frang_http_ct_check_ptr(mockReq); +//EXPECT_EQ(TFW_BLOCK,res); +//} +//extern int frang_http_methods(const TfwHttpReq *req); +TEST(frang,req_method){ +TfwHttpReq *mockReq; + +mockReq = test_req_alloc(17); +tfw_http_parse_req(mockReq,"PUT /index.html",16); +TFW_DBG("frang_req_method:%d",mockReq->method); + if(!frang_cfg){ + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + } + +frang_cfg->http_methods_mask = 2; +//frang_http_methods_ptr = get_sym_ptr("frang_http_methods"); +res =req_handler(mockReq);//frang_http_methods_ptr(mockReq); + EXPECT_EQ(TFW_BLOCK,res); +} +//static int (*frang_http_field_len_raw_ptr)(const TfwHttpReq *req); +TEST(frang,field_len){ +TfwHttpReq *mockReq; +mockReq = test_req_alloc(20); +tfw_http_parse_req(mockReq,"GET /foo HTTP/1.1\r\n",19); + + if(!frang_cfg){ + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + } + frang_cfg->http_field_len =3; +//frang_http_field_len_raw_ptr = get_sym_ptr("frang_http_field_len_raw"); +res = req_handler(mockReq);//frang_http_field_len_raw_ptr(mockReq); +EXPECT_EQ(TFW_BLOCK,res); +} +//static int (*frang_http_host_check_ptr)(TfwHttpReq* req); +TEST(frang,host){ +TfwHttpReq *mockReq; + +mockReq = test_req_alloc(7); +tfw_http_parse_req(mockReq,"GET /foo HTTP/1.1\r\n",19); + +//tfw_http_parse_req(&mockReq,"GET /\n",6); + if(!frang_cfg){ + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + } + frang_cfg->http_host_required = true; +//frang_http_host_check_ptr = get_sym_ptr("frang_http_host_check"); +res = req_handler(mockReq);//frang_http_host_check_ptr(mockReq); +EXPECT_EQ(TFW_BLOCK,res); +} +static int (*frang_req_limit_ptr)(FrangAcc *ra, struct sock *sk); +// static int (*frang_http_req_handler_ptr)(void *obj, +// struct sk_buff *skb , +// unsigned int off); +TEST(frang, req_count){ + TfwConnection mockConn; +unsigned long ts; +//TfwHttpReq *mockReq; + FrangAcc *ra; + frang_cfg->conn_max =0; + frang_cfg->conn_burst = 0; + frang_cfg->conn_rate = 0; + frang_cfg->req_rate = 5; + //frang_cfg.req_rate = 0; + mockConn.sk = &mockSock; +// mockReq = test_req_alloc(15); +// tfw_http_parse_req(&mockReq,"GET / HTTP /1.1",15); +// mockConn.msg = (TfwMsg*)&mockReq; +// res = frang_http_req_handler(&mockConn, "GET / HTTP /1.1",15); + ra = (FrangAcc*)get_frang_acc(&mockSock); +// TFW_DBG("frang conn:%d",ra->conn_curr); +// i = 0; +//while(i<5){ +//ndelay(1000); +// frang_req_limit(ra,&mockSock); +// i++; +//} +ts = jiffies * FRANG_FREQ / HZ; +i = ts % FRANG_FREQ; +ra->history[i].req = 5; +TFW_DBG("frang_req_i:%d;%d",i,ra->history[i].req); +frang_req_limit_ptr = get_sym_ptr("frang_req_limit"); +res = frang_req_limit_ptr(ra,&mockSock); +EXPECT_EQ(TFW_BLOCK,res); +frang_cfg->req_burst = 5; +ra->history[i].req = 5; +res = frang_req_limit_ptr(ra,&mockSock); +EXPECT_EQ(TFW_BLOCK,res); + +} +//TFW_DBG("frang_req_method:%d",mockReq->method); +//extern TfwMsg *tfw_http_conn_msg_alloc(TfwConnection *conn); + static int (*frang_http_req_handler_ptr)(void *obj, + struct sk_buff *skb , + unsigned int off); +/*int req_handler(TfwHttpReq *req) +{ +TfwConnection *conn; + +//conn = (TfwConnection*)req->msg->conn; +//tfw_cli_conn_alloc_ptr = get_sym_ptr("tfw_cli_conn_alloc"); +//if(!tfw_cli_conn_alloc_ptr){ +// TFW_DBG("req_handler: alloc is null\n"); + //} + +conn = (TfwConnection*)tfw_cli_conn_alloc(); +conn->msg = &req->msg; +if(!conn){ + TFW_DBG("req_handler: conn is null\n"); + +} + +//tfw_http_conn_msg_alloc(conn); + +//conn->msg = req->msg; + +frang_http_req_handler_ptr = get_sym_ptr("frang_http_req_handler"); +TFW_DBG("req_handler:%s;%lu\n","hand_ptr:",(unsigned long)frang_http_req_handler_ptr); +if(! frang_http_req_handler_ptr){ +TFW_DBG("frang_req_handleris null str:%d\n",392); +} +//if(&mockReq->msg == NULL || &mockReq->msg.skb_list == NULL){ +//TFW_DBG("frang_req_handleris null param:%d\n",404); +//} +return frang_http_req_handler_ptr((void*)conn,req->msg.skb_list.first,25); +}*/ + +TEST(frang,body_len) +{ +TfwHttpReq *mockReq; +TfwStr body; +TfwStr crlf; +mockReq = test_req_alloc(22); +TFW_DBG("body_len:%s;%lu\n","after req_alloc:",(unsigned long)mockReq); + +tfw_http_parse_req(mockReq,"POST /foo HTTP/1.1\r\n",20); +TFW_DBG("body_len:%s;%lu\n","after parse:",(unsigned long)mockReq); + +body.ptr = "GET http://natsys-lab.com/foo"; +body.len = 29; +crlf.len = 2; +crlf.ptr = "\r\n"; +TFW_DBG("body_len:%s;%lu\n","after body params:",(unsigned long)mockReq->body.len); + +//mockReq->body = body; +mockReq->crlf = crlf; + +mockReq->body.len = 29; + if(!frang_cfg){ + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + } + +TFW_DBG("body_len:%s;%lu\n","before set params:",(unsigned long)frang_cfg); + +frang_cfg->http_body_len = 3; +mockReq->frang_st = 0; +TFW_DBG("body_len:%s;%lu\n","before handler:",(unsigned long)mockReq); + +res = req_handler(mockReq); +EXPECT_EQ(TFW_BLOCK,res); +} +TEST(frang,body_timeout) +{ +TfwHttpReq *mockReq; +mockReq = test_req_alloc(62); +tfw_http_parse_req(mockReq,"POST http://natsys-lab.com/foo HTTP/1.1\r\n \ +Content-Length:29\r\n",61); + if(!frang_cfg){ + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + } + +frang_cfg->clnt_body_timeout = 1; +mockReq->frang_st = 12; +mockReq->tm_bchunk = jiffies - 100; +res = req_handler(mockReq); +EXPECT_EQ(TFW_BLOCK,res); +} +TEST(frang,hdr_timeout) +{ +TfwHttpReq *mockReq; +mockReq = test_req_alloc(62); +tfw_http_parse_req(mockReq,"POST http://natsys-lab.com/foo HTTP/1.1\r\n \ +Content-Length:29\r\n",61); + + + if(!frang_cfg){ + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + } + +frang_cfg->clnt_body_timeout = 0; +frang_cfg->clnt_hdr_timeout = 1; +mockReq->frang_st = 12; +mockReq->tm_header = jiffies - 100; +res = req_handler(mockReq); +EXPECT_EQ(TFW_BLOCK,res); +} +TEST(frang,chunk_cnt) +{ +TfwHttpReq *mockReq; +mockReq = test_req_alloc(62); +tfw_http_parse_req(mockReq,"POST http://natsys-lab.com/foo HTTP/1.1\r\n \ +Content-Length:29\r\n",61); + + + if(!frang_cfg){ + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + } +frang_cfg->http_hchunk_cnt = 1; +mockReq->chunk_cnt = 3; +mockReq->frang_st = 2; +res = req_handler(mockReq); +EXPECT_EQ(TFW_BLOCK,res); +frang_cfg->http_hchunk_cnt = 0; +frang_cfg->http_bchunk_cnt = 1; +mockReq->chunk_cnt =3; +res = req_handler(mockReq); +EXPECT_EQ(TFW_BLOCK,res); +} + +TEST_SUITE(frang){ + TEST_RUN(frang,uri); + TEST_RUN(frang,body_len); + TEST_RUN(frang,ct_check); + TEST_RUN(frang,field_len); + TEST_RUN(frang,host); + TEST_RUN(frang,req_method); + TEST_RUN(frang,max_conn); + TEST_RUN(frang,chunk_cnt); + TEST_RUN(frang,req_count); + TEST_RUN(frang,body_timeout); + TEST_RUN(frang,hdr_timeout); + + } From 12be7fef4bad27eafdb4f8acd7549c11a66c535d Mon Sep 17 00:00:00 2001 From: root Date: Fri, 25 Sep 2015 17:10:17 +0300 Subject: [PATCH 02/11] test frang 07 --- tempesta_fw/t/unit/test_frang.c | 162 +++++++++++++++++++++++++------- 1 file changed, 126 insertions(+), 36 deletions(-) diff --git a/tempesta_fw/t/unit/test_frang.c b/tempesta_fw/t/unit/test_frang.c index 84906a9571..42d7ef493e 100644 --- a/tempesta_fw/t/unit/test_frang.c +++ b/tempesta_fw/t/unit/test_frang.c @@ -66,6 +66,7 @@ #include "../../addr.h" #include "../../classifier.h" +#include "../../sync_socket.h" #include "../../client.h" #include "../../connection.h" #include "../../gfsm.h" @@ -201,7 +202,7 @@ const int (*frang_conn_new_ptr)(struct sock*); #define FRANG_FREQ 8 - const char* inet_addr = "192.168.168.245.1"; + const char* inet_addr = "192.168.168.245.128"; unsigned short i = 0; typedef struct { char *str; @@ -237,17 +238,19 @@ typedef struct { } FrangCfg; FrangCfg *frang_cfg; struct inet_sock *isk; -static int (*frang_conn_limit_ptr)(FrangAcc *ra, struct sock *sk); +//static int (*frang_conn_limit_ptr)(FrangAcc *ra, struct sock *sk); //extern int frang_account_do(struct sock *sk, int *func(FrangAcc *ra,struct sock *sk)); extern TfwConnection* tfw_cli_conn_alloc(void); static int (*frang_http_req_handler_ptr)(void *obj, struct sk_buff *skb , unsigned int off); +//static FrangAcc* (*frang_get_clnt_ra_ptr)(struct sock *sk); + int req_handler(TfwHttpReq *req) { TfwConnection *conn; - +//FrangAcc *ra; //conn = (TfwConnection*)req->msg->conn; //tfw_cli_conn_alloc_ptr = get_sym_ptr("tfw_cli_conn_alloc"); //if(!tfw_cli_conn_alloc_ptr){ @@ -260,35 +263,72 @@ if(!conn){ TFW_DBG("req_handler: conn is null\n"); } +conn->sk = &mockSock; +isk = (struct inet_sock*)(&mockSock); + isk->inet_saddr = htonl(in_aton(inet_addr)); +// frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); +//ra = get_frang_acc(&mockSock); +if(!conn->sk->sk_security){ +frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); +res = frang_conn_new_ptr(conn->sk); +} +//conn->sk->sk_security = ra; +/* if(!conn->sk->sk_security){ +frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); +res = frang_conn_new_ptr(conn->sk); + }*/ + +//TFW_DBG("req_handler:%s;%lu\n","after ra:",(unsigned long)ra); //tfw_http_conn_msg_alloc(conn); //conn->msg = req->msg; frang_http_req_handler_ptr = get_sym_ptr("frang_http_req_handler"); -/*TFW_DBG("req_handler:%s;%lu\n","hand_ptr:",(unsigned long)frang_http_req_handler_ptr);*/ +TFW_DBG("req_handler:%s;%lu\n","hand_ptr:",(unsigned long)frang_http_req_handler_ptr); if(! frang_http_req_handler_ptr){ TFW_DBG("frang_req_handleris null str:%d\n",392); } //if(&mockReq->msg == NULL || &mockReq->msg.skb_list == NULL){ //TFW_DBG("frang_req_handleris null param:%d\n",404); //} +TFW_DBG("req_handler:%s\n","before real call hand"); return frang_http_req_handler_ptr((void*)conn,req->msg.skb_list.first,25); } - TEST(frang, max_conn){ +TfwHttpReq *mockReq; FrangAcc *ra; unsigned long ts; //unsigned long ts; -frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); +mockReq = test_req_alloc(17); +tfw_http_parse_req(mockReq,"GET / HTTP/1.1\r\n",16); + if(!frang_cfg){ + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + } frang_cfg->conn_max =5; isk = (struct inet_sock*)(&mockSock); - isk->inet_saddr = htonl(in_aton("127.0.0.1")); + isk->inet_saddr = htonl(in_aton(inet_addr)); + TFW_DBG("max_conn:%s\n","after set iaddr,before funk addr"); + frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); + if(!frang_conn_new_ptr){ + TFW_DBG("max_conn:%s\n","conn_new ptr is null"); + } res = frang_conn_new_ptr(&mockSock); -TFW_DBG("frang_conn_max:%s;%d\n","before ra",isk->inet_saddr); -ra = get_frang_acc(&mockSock); -TFW_DBG("frang_conn_max:%s;%d\n","after ra",ra->conn_curr); + ra = mockSock.sk_security; +//TFW_DBG("frang_conn_max:%s;%d\n","after conn_new res:",res); +// TFW_DBG("max_conn:%s;%lu\n","ra from conn_new:",(unsigned long)ra); + +//frang_get_clnt_ra_ptr = get_sym_ptr("frang_get_clnt_ra"); +// if(!frang_get_clnt_ra_ptr){ +// TFW_DBG("max_conn:%s\n","get_clnt_ptr is null"); + +// } + +//ra = get_frang_acc(&mockSock);//frang_get_clnt_ra_ptr(&mockSock); +//TFW_DBG("frang_conn_max:%s;%lu\n","after ra:",(unsigned long)ra); + +//TFW_DBG("frang_conn_max:%s;%d\n","after ra",ra->conn_curr); /*while(i<5){ ndelay(1000); @@ -298,32 +338,36 @@ TFW_DBG("frang_conn_max:%s;%d\n","after ra",ra->conn_curr); i++; };*/ isk = (struct inet_sock*)(&mockSock); -// isk->inet_saddr = in_aton(inet_addr); + isk->inet_saddr = in_aton(inet_addr); ra->conn_curr = 5; - frang_conn_limit_ptr = get_sym_ptr("frang_conn_limit"); - res = frang_conn_limit_ptr(ra,&mockSock); +// frang_conn_limit_ptr = get_sym_ptr("frang_conn_limit"); +// if(!frang_conn_limit_ptr){ +// TFW_DBG("max_conn:%s\n","conn_limit ptr is null"); +// } + mockSock.sk_security = ra; + res = req_handler(mockReq);//frang_conn_new_ptr(&mockSock); EXPECT_EQ(TFW_BLOCK, res); ts = jiffies * FRANG_FREQ / HZ; i = ts % FRANG_FREQ; frang_cfg->conn_max = 0; frang_cfg->conn_rate = 5; ra->history[i].conn_new =5; - res = frang_conn_limit_ptr(ra, &mockSock); +mockSock.sk_security = ra; + res = req_handler(mockReq); EXPECT_EQ(TFW_BLOCK,res); frang_cfg->conn_max =0; frang_cfg->conn_rate = 0; frang_cfg->conn_burst = 5; ra->history[i].conn_new = 5; - res = frang_conn_limit_ptr(ra,&mockSock); - EXPECT_EQ(TFW_BLOCK,res); - - - + mockSock.sk_security = ra; + res = req_handler(mockReq); +EXPECT_EQ(TFW_BLOCK,res); } //static int (*frang_http_uri_ptr)(const TfwHttpReq *req); //extern int frang_http_uri_len(const TfwHttpReq *req); -TEST(frang,uri){ +TEST(frang,uri) +{ TfwHttpReq *mockReq; TfwStr uri; mockReq = test_req_alloc(26); @@ -340,9 +384,16 @@ tfw_http_parse_req(mockReq,"GET /index.html HTTP /1.1",25); uri.len = 17; uri.ptr = (void*)"/home/index.html"; +uri.flags = TFW_STR_COMPLETE; mockReq->uri_path = uri; +TFW_DBG("uri:%s\n","after set uri to req"); //frang_http_uri_ptr = get_sym_ptr("frang_http_uri_len"); //TFW_DBG("uri_len funk ptr:%lu\n",(unsigned long)frang_http_uri_ptr); +mockReq->frang_st = 3; +// if(!mockReq->sk_security){ +// frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); +// res = frang_conn_new_ptr(&mockReq); +// } res = req_handler(mockReq); //res = frang_http_uri_len(mockReq); EXPECT_EQ(TFW_BLOCK,res); @@ -438,19 +489,38 @@ static int (*frang_req_limit_ptr)(FrangAcc *ra, struct sock *sk); TEST(frang, req_count){ TfwConnection mockConn; unsigned long ts; -//TfwHttpReq *mockReq; +TfwHttpReq *mockReq; FrangAcc *ra; - frang_cfg->conn_max =0; +mockReq = test_req_alloc(17); +tfw_http_parse_req(mockReq,"GET / HTTP/1.1\r\n",16); + if(!frang_cfg){ + frang_cfg = get_sym_ptr("frang_cfg"); + } + frang_req_limit_ptr = get_sym_ptr("frang_req_limit"); + if(!frang_req_limit_ptr){ + TFW_DBG("req_count:%s;\n","req_limit ptr is null"); + } +frang_cfg->conn_max =0; frang_cfg->conn_burst = 0; frang_cfg->conn_rate = 0; frang_cfg->req_rate = 5; //frang_cfg.req_rate = 0; +// TFW_DBG("req_count:%s;%lu\n","set conn sk:",(unsigned long)&mockSock); +isk = (struct inet_sock*)(&mockSock); + isk->inet_saddr = htonl(in_aton(inet_addr)); + mockConn.sk = &mockSock; // mockReq = test_req_alloc(15); // tfw_http_parse_req(&mockReq,"GET / HTTP /1.1",15); // mockConn.msg = (TfwMsg*)&mockReq; // res = frang_http_req_handler(&mockConn, "GET / HTTP /1.1",15); - ra = (FrangAcc*)get_frang_acc(&mockSock); +// ra = (FrangAcc*)get_frang_acc(&mockSock); + + frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); + TFW_DBG("req_count507:%s;%lu\n","get conn_new:",(unsigned long)frang_conn_new_ptr); + res = frang_conn_new_ptr(&mockSock); + ra = mockConn.sk->sk_security; + // TFW_DBG("frang conn:%d",ra->conn_curr); // i = 0; //while(i<5){ @@ -462,20 +532,36 @@ ts = jiffies * FRANG_FREQ / HZ; i = ts % FRANG_FREQ; ra->history[i].req = 5; TFW_DBG("frang_req_i:%d;%d",i,ra->history[i].req); -frang_req_limit_ptr = get_sym_ptr("frang_req_limit"); -res = frang_req_limit_ptr(ra,&mockSock); + if(!frang_conn_new_ptr){ + TFW_DBG("frang_req_count507:%s\n","conn_new ptr is null"); + } +//= frang_req_limit_ptr(ra,&mockSock); +mockSock.sk_security = ra; +mockReq->frang_st = 0; +res = req_handler(mockReq); +TFW_DBG("frang_req_count:%s;%d\n","req_rate:",res); + +//frang_req_limit_ptr = get_sym_ptr("frang_req_limit"); EXPECT_EQ(TFW_BLOCK,res); -frang_cfg->req_burst = 5; -ra->history[i].req = 5; -res = frang_req_limit_ptr(ra,&mockSock); + frang_cfg->req_rate = 5; + frang_cfg->req_burst = 5; + ra->history[i].req = 5; +/* if(!frang_conn_new_ptr){ + TFW_DBG("frang_req_count 517:%s\n","conn_new ptr is null"); +}*/ +mockSock.sk_security = ra; +mockReq->frang_st = 0; + +res = req_handler(mockReq); +TFW_DBG("frang_req_count:%s;%d\n","req_burst:",res); EXPECT_EQ(TFW_BLOCK,res); } //TFW_DBG("frang_req_method:%d",mockReq->method); //extern TfwMsg *tfw_http_conn_msg_alloc(TfwConnection *conn); - static int (*frang_http_req_handler_ptr)(void *obj, - struct sk_buff *skb , - unsigned int off); + static int (*frang_http_req_handler_ptr)(void *obj, \ +struct sk_buff *skb , \ +unsigned int off); /*int req_handler(TfwHttpReq *req) { TfwConnection *conn; @@ -572,9 +658,10 @@ Content-Length:29\r\n",61); frang_cfg->clnt_body_timeout = 0; frang_cfg->clnt_hdr_timeout = 1; -mockReq->frang_st = 12; +mockReq->frang_st = 0; mockReq->tm_header = jiffies - 100; res = req_handler(mockReq); +TFW_DBG("hdr_timeout:%s;%d\n","res:",res); EXPECT_EQ(TFW_BLOCK,res); } TEST(frang,chunk_cnt) @@ -590,27 +677,30 @@ Content-Length:29\r\n",61); } frang_cfg->http_hchunk_cnt = 1; mockReq->chunk_cnt = 3; -mockReq->frang_st = 2; +mockReq->frang_st = 0; res = req_handler(mockReq); +TFW_DBG("hdr_timeout:%s;%d\n","frang_st:",mockReq->frang_st); EXPECT_EQ(TFW_BLOCK,res); frang_cfg->http_hchunk_cnt = 0; frang_cfg->http_bchunk_cnt = 1; mockReq->chunk_cnt =3; res = req_handler(mockReq); +TFW_DBG("hdr_timeout:%s;%d\n","res:",res); + EXPECT_EQ(TFW_BLOCK,res); } TEST_SUITE(frang){ + TEST_RUN(frang,req_count); + TEST_RUN(frang,max_conn); TEST_RUN(frang,uri); TEST_RUN(frang,body_len); TEST_RUN(frang,ct_check); TEST_RUN(frang,field_len); TEST_RUN(frang,host); TEST_RUN(frang,req_method); - TEST_RUN(frang,max_conn); TEST_RUN(frang,chunk_cnt); - TEST_RUN(frang,req_count); - TEST_RUN(frang,body_timeout); + TEST_RUN(frang,body_timeout); TEST_RUN(frang,hdr_timeout); } From 244c7b3764796505564eb3b60bb8294f170d7236 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 30 Sep 2015 18:56:08 +0300 Subject: [PATCH 03/11] test fang 08 --- tempesta_fw/t/unit/Makefile | 3 +- tempesta_fw/t/unit/test.c | 3 + tempesta_fw/t/unit/test_frang.c | 270 +++++++++++++++----------------- 3 files changed, 131 insertions(+), 145 deletions(-) diff --git a/tempesta_fw/t/unit/Makefile b/tempesta_fw/t/unit/Makefile index 3d83850c05..c6444ebc82 100644 --- a/tempesta_fw/t/unit/Makefile +++ b/tempesta_fw/t/unit/Makefile @@ -44,4 +44,5 @@ tfw_test-objs = \ test_sched_hash.o \ test_sched_http.o \ test_http_sticky.o \ - kallsyms_helper.o + kallsyms_helper.o \ + test_frang.o diff --git a/tempesta_fw/t/unit/test.c b/tempesta_fw/t/unit/test.c index e0c0320a4e..92e2b5ac9f 100644 --- a/tempesta_fw/t/unit/test.c +++ b/tempesta_fw/t/unit/test.c @@ -92,6 +92,7 @@ TEST_SUITE(cfg); TEST_SUITE(sched_rr); TEST_SUITE(sched_hash); TEST_SUITE(sched_http); +TEST_SUITE(frang); int test_run_all(void) @@ -108,6 +109,8 @@ test_run_all(void) TEST_SUITE_RUN(sched_rr); TEST_SUITE_RUN(sched_hash); TEST_SUITE_RUN(sched_http); + TEST_SUITE_RUN(frang); + return test_fail_counter; } diff --git a/tempesta_fw/t/unit/test_frang.c b/tempesta_fw/t/unit/test_frang.c index 42d7ef493e..68a04e8d3f 100644 --- a/tempesta_fw/t/unit/test_frang.c +++ b/tempesta_fw/t/unit/test_frang.c @@ -245,6 +245,24 @@ static int (*frang_http_req_handler_ptr)(void *obj, struct sk_buff *skb , unsigned int off); //static FrangAcc* (*frang_get_clnt_ra_ptr)(struct sock *sk); +static struct kmem_cache *tfw_test_conn_cache; + +TfwConnection * test_conn_alloc(void) + { +TfwConnection *conn; + +if(!tfw_test_conn_cache){ + tfw_test_conn_cache = kmem_cache_create("tfw_test_conn_cache", \ + sizeof(TfwConnection), \ + 0,0,NULL); +} + conn = kmem_cache_alloc(tfw_test_conn_cache, GFP_ATOMIC); + if (!conn) + return NULL; + + tfw_connection_init(conn); + return conn; + } int req_handler(TfwHttpReq *req) @@ -257,11 +275,10 @@ TfwConnection *conn; // TFW_DBG("req_handler: alloc is null\n"); //} -conn = (TfwConnection*)tfw_cli_conn_alloc(); + conn = test_conn_alloc(); conn->msg = &req->msg; if(!conn){ TFW_DBG("req_handler: conn is null\n"); - } conn->sk = &mockSock; isk = (struct inet_sock*)(&mockSock); @@ -285,30 +302,29 @@ res = frang_conn_new_ptr(conn->sk); //conn->msg = req->msg; frang_http_req_handler_ptr = get_sym_ptr("frang_http_req_handler"); -TFW_DBG("req_handler:%s;%lu\n","hand_ptr:",(unsigned long)frang_http_req_handler_ptr); +//TFW_DBG("req_handler:%s;%lu\n","hand_ptr:",(unsigned long)frang_http_req_handler_ptr); if(! frang_http_req_handler_ptr){ TFW_DBG("frang_req_handleris null str:%d\n",392); } //if(&mockReq->msg == NULL || &mockReq->msg.skb_list == NULL){ //TFW_DBG("frang_req_handleris null param:%d\n",404); //} -TFW_DBG("req_handler:%s\n","before real call hand"); +//TFW_DBG("req_handler:%s\n","before real call hand"); return frang_http_req_handler_ptr((void*)conn,req->msg.skb_list.first,25); } TEST(frang, max_conn){ -TfwHttpReq *mockReq; -FrangAcc *ra; -unsigned long ts; -//unsigned long ts; -mockReq = test_req_alloc(17); -tfw_http_parse_req(mockReq,"GET / HTTP/1.1\r\n",16); + TfwHttpReq *mockReq; + FrangAcc *ra; + unsigned long ts; + mockReq = test_req_alloc(17); + tfw_http_parse_req(mockReq,"GET / HTTP/1.1\r\n",16); if(!frang_cfg){ frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } -frang_cfg->conn_max =5; -isk = (struct inet_sock*)(&mockSock); + frang_cfg->conn_max =5; + isk = (struct inet_sock*)(&mockSock); isk->inet_saddr = htonl(in_aton(inet_addr)); - TFW_DBG("max_conn:%s\n","after set iaddr,before funk addr"); +// TFW_DBG("max_conn:%s\n","after set iaddr,before funk addr"); frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); if(!frang_conn_new_ptr){ @@ -330,13 +346,6 @@ isk = (struct inet_sock*)(&mockSock); //TFW_DBG("frang_conn_max:%s;%d\n","after ra",ra->conn_curr); -/*while(i<5){ - ndelay(1000); - isk = (struct inet_sock*)(&mockSock); -// isk->inet_saddr = in_aton(inet_addr); - frang_conn_limit(ra,&mockSock); - i++; - };*/ isk = (struct inet_sock*)(&mockSock); isk->inet_saddr = in_aton(inet_addr); ra->conn_curr = 5; @@ -347,13 +356,14 @@ isk = (struct inet_sock*)(&mockSock); mockSock.sk_security = ra; res = req_handler(mockReq);//frang_conn_new_ptr(&mockSock); EXPECT_EQ(TFW_BLOCK, res); -ts = jiffies * FRANG_FREQ / HZ; -i = ts % FRANG_FREQ; + ts = jiffies * FRANG_FREQ / HZ; + i = ts % FRANG_FREQ; frang_cfg->conn_max = 0; frang_cfg->conn_rate = 5; ra->history[i].conn_new =5; -mockSock.sk_security = ra; + mockSock.sk_security = ra; res = req_handler(mockReq); + //conn_rate EXPECT_EQ(TFW_BLOCK,res); frang_cfg->conn_max =0; frang_cfg->conn_rate = 0; @@ -361,17 +371,18 @@ mockSock.sk_security = ra; ra->history[i].conn_new = 5; mockSock.sk_security = ra; res = req_handler(mockReq); -EXPECT_EQ(TFW_BLOCK,res); + //conn_max + EXPECT_EQ(TFW_BLOCK,res); } //static int (*frang_http_uri_ptr)(const TfwHttpReq *req); //extern int frang_http_uri_len(const TfwHttpReq *req); TEST(frang,uri) { -TfwHttpReq *mockReq; -TfwStr uri; -mockReq = test_req_alloc(26); -tfw_http_parse_req(mockReq,"GET /index.html HTTP /1.1",25); + TfwHttpReq *mockReq; + TfwStr uri; + mockReq = test_req_alloc(26); + tfw_http_parse_req(mockReq,"GET /index.html HTTP /1.1",25); // const char* conf_max_uri = "http_uri_len=10";frang_cfg = get_sym_ptr("frang_cfg"); //TFW_DBG("uri_len:%s;%lu\n","start conf:",(unsigned long)frang_cfg); if(!frang_cfg){ @@ -382,11 +393,11 @@ tfw_http_parse_req(mockReq,"GET /index.html HTTP /1.1",25); // LIST_HEAD(frang_cfg_mod); // tfw_cfg_start_mods(conf_max_uri, &frang_cfg_mod); -uri.len = 17; -uri.ptr = (void*)"/home/index.html"; -uri.flags = TFW_STR_COMPLETE; -mockReq->uri_path = uri; -TFW_DBG("uri:%s\n","after set uri to req"); + uri.len = 17; + uri.ptr = (void*)"/home/index.html"; + uri.flags = TFW_STR_COMPLETE; + mockReq->uri_path = uri; +//TFW_DBG("uri:%s\n","after set uri to req"); //frang_http_uri_ptr = get_sym_ptr("frang_http_uri_len"); //TFW_DBG("uri_len funk ptr:%lu\n",(unsigned long)frang_http_uri_ptr); mockReq->frang_st = 3; @@ -402,8 +413,8 @@ EXPECT_EQ(TFW_BLOCK,res); //static int (*frang_http_ct_check_ptr)(const TfwHttpReq *req); TEST(frang,ct_check){ -TfwHttpReq * mockReq; -FrangCtVal ctval[1]; + TfwHttpReq * mockReq; + FrangCtVal ctval[1]; mockReq = test_req_alloc(22); tfw_http_parse_req(mockReq,"POST /foo HTTP/1.1\r\n",20); @@ -412,8 +423,8 @@ FrangCtVal ctval[1]; frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } //TFW_DBG("ct_check:%s;%lu\n","after conf conf:",(unsigned long)frang_cfg); -ctval[0].len = 17; -ctval[0].str ="application/html"; + ctval[0].len = 17; + ctval[0].str ="application/html"; frang_cfg->http_ct_required = true; res = req_handler(mockReq); EXPECT_EQ(TFW_BLOCK,res); @@ -438,40 +449,38 @@ EXPECT_EQ(TFW_BLOCK,res); //} //extern int frang_http_methods(const TfwHttpReq *req); TEST(frang,req_method){ -TfwHttpReq *mockReq; - -mockReq = test_req_alloc(17); -tfw_http_parse_req(mockReq,"PUT /index.html",16); -TFW_DBG("frang_req_method:%d",mockReq->method); + TfwHttpReq *mockReq; + mockReq = test_req_alloc(17); + tfw_http_parse_req(mockReq,"PUT /index.html",16); +//TFW_DBG("frang_req_method:%d",mockReq->method); if(!frang_cfg){ frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } -frang_cfg->http_methods_mask = 2; + frang_cfg->http_methods_mask = 2; //frang_http_methods_ptr = get_sym_ptr("frang_http_methods"); -res =req_handler(mockReq);//frang_http_methods_ptr(mockReq); + res =req_handler(mockReq);//frang_http_methods_ptr(mockReq); EXPECT_EQ(TFW_BLOCK,res); } //static int (*frang_http_field_len_raw_ptr)(const TfwHttpReq *req); TEST(frang,field_len){ -TfwHttpReq *mockReq; -mockReq = test_req_alloc(20); -tfw_http_parse_req(mockReq,"GET /foo HTTP/1.1\r\n",19); + TfwHttpReq *mockReq; + mockReq = test_req_alloc(20); + tfw_http_parse_req(mockReq,"GET /foo HTTP/1.1\r\n",19); if(!frang_cfg){ frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } frang_cfg->http_field_len =3; //frang_http_field_len_raw_ptr = get_sym_ptr("frang_http_field_len_raw"); -res = req_handler(mockReq);//frang_http_field_len_raw_ptr(mockReq); -EXPECT_EQ(TFW_BLOCK,res); + res = req_handler(mockReq);//frang_http_field_len_raw_ptr(mockReq); + EXPECT_EQ(TFW_BLOCK,res); } //static int (*frang_http_host_check_ptr)(TfwHttpReq* req); TEST(frang,host){ -TfwHttpReq *mockReq; - -mockReq = test_req_alloc(7); -tfw_http_parse_req(mockReq,"GET /foo HTTP/1.1\r\n",19); + TfwHttpReq *mockReq; + mockReq = test_req_alloc(7); + tfw_http_parse_req(mockReq,"GET /foo HTTP/1.1\r\n",19); //tfw_http_parse_req(&mockReq,"GET /\n",6); if(!frang_cfg){ @@ -479,8 +488,8 @@ tfw_http_parse_req(mockReq,"GET /foo HTTP/1.1\r\n",19); } frang_cfg->http_host_required = true; //frang_http_host_check_ptr = get_sym_ptr("frang_http_host_check"); -res = req_handler(mockReq);//frang_http_host_check_ptr(mockReq); -EXPECT_EQ(TFW_BLOCK,res); + res = req_handler(mockReq);//frang_http_host_check_ptr(mockReq); + EXPECT_EQ(TFW_BLOCK,res); } static int (*frang_req_limit_ptr)(FrangAcc *ra, struct sock *sk); // static int (*frang_http_req_handler_ptr)(void *obj, @@ -488,11 +497,11 @@ static int (*frang_req_limit_ptr)(FrangAcc *ra, struct sock *sk); // unsigned int off); TEST(frang, req_count){ TfwConnection mockConn; -unsigned long ts; -TfwHttpReq *mockReq; + unsigned long ts; + TfwHttpReq *mockReq; FrangAcc *ra; -mockReq = test_req_alloc(17); -tfw_http_parse_req(mockReq,"GET / HTTP/1.1\r\n",16); + mockReq = test_req_alloc(17); + tfw_http_parse_req(mockReq,"GET / HTTP/1.1\r\n",16); if(!frang_cfg){ frang_cfg = get_sym_ptr("frang_cfg"); } @@ -500,7 +509,7 @@ tfw_http_parse_req(mockReq,"GET / HTTP/1.1\r\n",16); if(!frang_req_limit_ptr){ TFW_DBG("req_count:%s;\n","req_limit ptr is null"); } -frang_cfg->conn_max =0; + frang_cfg->conn_max =0; frang_cfg->conn_burst = 0; frang_cfg->conn_rate = 0; frang_cfg->req_rate = 5; @@ -509,7 +518,7 @@ frang_cfg->conn_max =0; isk = (struct inet_sock*)(&mockSock); isk->inet_saddr = htonl(in_aton(inet_addr)); - mockConn.sk = &mockSock; + mockConn.sk = &mockSock; // mockReq = test_req_alloc(15); // tfw_http_parse_req(&mockReq,"GET / HTTP /1.1",15); // mockConn.msg = (TfwMsg*)&mockReq; @@ -553,144 +562,118 @@ mockSock.sk_security = ra; mockReq->frang_st = 0; res = req_handler(mockReq); -TFW_DBG("frang_req_count:%s;%d\n","req_burst:",res); +//TFW_DBG("frang_req_count:%s;%d\n","req_burst:",res); EXPECT_EQ(TFW_BLOCK,res); - } //TFW_DBG("frang_req_method:%d",mockReq->method); //extern TfwMsg *tfw_http_conn_msg_alloc(TfwConnection *conn); - static int (*frang_http_req_handler_ptr)(void *obj, \ -struct sk_buff *skb , \ -unsigned int off); -/*int req_handler(TfwHttpReq *req) -{ -TfwConnection *conn; - -//conn = (TfwConnection*)req->msg->conn; -//tfw_cli_conn_alloc_ptr = get_sym_ptr("tfw_cli_conn_alloc"); -//if(!tfw_cli_conn_alloc_ptr){ -// TFW_DBG("req_handler: alloc is null\n"); - //} - -conn = (TfwConnection*)tfw_cli_conn_alloc(); -conn->msg = &req->msg; -if(!conn){ - TFW_DBG("req_handler: conn is null\n"); - -} //tfw_http_conn_msg_alloc(conn); //conn->msg = req->msg; -frang_http_req_handler_ptr = get_sym_ptr("frang_http_req_handler"); -TFW_DBG("req_handler:%s;%lu\n","hand_ptr:",(unsigned long)frang_http_req_handler_ptr); -if(! frang_http_req_handler_ptr){ -TFW_DBG("frang_req_handleris null str:%d\n",392); -} +//frang_http_req_handler_ptr = get_sym_ptr("frang_http_req_handler"); +//TFW_DBG("req_handler:%s;%lu\n","hand_ptr:",(unsigned long)frang_http_req_handler_ptr); +//(! frang_http_req_handler_ptr){ +//TFW_DBG("frang_req_handleris null str:%d\n",392); +//} //if(&mockReq->msg == NULL || &mockReq->msg.skb_list == NULL){ //TFW_DBG("frang_req_handleris null param:%d\n",404); //} -return frang_http_req_handler_ptr((void*)conn,req->msg.skb_list.first,25); -}*/ TEST(frang,body_len) { -TfwHttpReq *mockReq; -TfwStr body; -TfwStr crlf; -mockReq = test_req_alloc(22); -TFW_DBG("body_len:%s;%lu\n","after req_alloc:",(unsigned long)mockReq); + TfwHttpReq *mockReq; + TfwStr body; + TfwStr crlf; + mockReq = test_req_alloc(22); +//TFW_DBG("body_len:%s;%lu\n","after req_alloc:",(unsigned long)mockReq); -tfw_http_parse_req(mockReq,"POST /foo HTTP/1.1\r\n",20); -TFW_DBG("body_len:%s;%lu\n","after parse:",(unsigned long)mockReq); + tfw_http_parse_req(mockReq,"POST /foo HTTP/1.1\r\n",20); +//TFW_DBG("body_len:%s;%lu\n","after parse:",(unsigned long)mockReq); -body.ptr = "GET http://natsys-lab.com/foo"; -body.len = 29; + body.ptr = "GET http://natsys-lab.com/foo"; + body.len = 29; crlf.len = 2; -crlf.ptr = "\r\n"; -TFW_DBG("body_len:%s;%lu\n","after body params:",(unsigned long)mockReq->body.len); + crlf.ptr = "\r\n"; +//TFW_DBG("body_len:%s;%lu\n","after body params:",(unsigned long)mockReq->body.len); //mockReq->body = body; -mockReq->crlf = crlf; + mockReq->crlf = crlf; -mockReq->body.len = 29; + mockReq->body.len = 29; if(!frang_cfg){ frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } -TFW_DBG("body_len:%s;%lu\n","before set params:",(unsigned long)frang_cfg); +//TFW_DBG("body_len:%s;%lu\n","before set params:",(unsigned long)frang_cfg); -frang_cfg->http_body_len = 3; -mockReq->frang_st = 0; -TFW_DBG("body_len:%s;%lu\n","before handler:",(unsigned long)mockReq); + frang_cfg->http_body_len = 3; + mockReq->frang_st = 0; +//TFW_DBG("body_len:%s;%lu\n","before handler:",(unsigned long)mockReq); res = req_handler(mockReq); EXPECT_EQ(TFW_BLOCK,res); } TEST(frang,body_timeout) { -TfwHttpReq *mockReq; -mockReq = test_req_alloc(62); + TfwHttpReq *mockReq; + mockReq = test_req_alloc(62); tfw_http_parse_req(mockReq,"POST http://natsys-lab.com/foo HTTP/1.1\r\n \ Content-Length:29\r\n",61); if(!frang_cfg){ frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } -frang_cfg->clnt_body_timeout = 1; -mockReq->frang_st = 12; -mockReq->tm_bchunk = jiffies - 100; -res = req_handler(mockReq); -EXPECT_EQ(TFW_BLOCK,res); + frang_cfg->clnt_body_timeout = 1; + mockReq->frang_st = 12; + mockReq->tm_bchunk = jiffies - 100; + res = req_handler(mockReq); + EXPECT_EQ(TFW_BLOCK,res); } TEST(frang,hdr_timeout) { -TfwHttpReq *mockReq; -mockReq = test_req_alloc(62); + TfwHttpReq *mockReq; + mockReq = test_req_alloc(62); tfw_http_parse_req(mockReq,"POST http://natsys-lab.com/foo HTTP/1.1\r\n \ Content-Length:29\r\n",61); - - if(!frang_cfg){ frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } -frang_cfg->clnt_body_timeout = 0; -frang_cfg->clnt_hdr_timeout = 1; -mockReq->frang_st = 0; -mockReq->tm_header = jiffies - 100; -res = req_handler(mockReq); -TFW_DBG("hdr_timeout:%s;%d\n","res:",res); -EXPECT_EQ(TFW_BLOCK,res); + frang_cfg->clnt_body_timeout = 0; + frang_cfg->clnt_hdr_timeout = 1; + mockReq->frang_st = 0; + mockReq->tm_header = jiffies - 100; + res = req_handler(mockReq); +//TFW_DBG("hdr_timeout:%s;%d\n","res:",res); + EXPECT_EQ(TFW_BLOCK,res); } TEST(frang,chunk_cnt) { -TfwHttpReq *mockReq; -mockReq = test_req_alloc(62); + TfwHttpReq *mockReq; + mockReq = test_req_alloc(62); tfw_http_parse_req(mockReq,"POST http://natsys-lab.com/foo HTTP/1.1\r\n \ Content-Length:29\r\n",61); - - if(!frang_cfg){ frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } -frang_cfg->http_hchunk_cnt = 1; -mockReq->chunk_cnt = 3; -mockReq->frang_st = 0; -res = req_handler(mockReq); -TFW_DBG("hdr_timeout:%s;%d\n","frang_st:",mockReq->frang_st); -EXPECT_EQ(TFW_BLOCK,res); -frang_cfg->http_hchunk_cnt = 0; -frang_cfg->http_bchunk_cnt = 1; -mockReq->chunk_cnt =3; -res = req_handler(mockReq); -TFW_DBG("hdr_timeout:%s;%d\n","res:",res); - + frang_cfg->http_hchunk_cnt = 1; + mockReq->chunk_cnt = 3; + mockReq->frang_st = 0; + res = req_handler(mockReq); +//TFW_DBG("hdr_timeout:%s;%d\n","frang_st:",mockReq->frang_st); EXPECT_EQ(TFW_BLOCK,res); + frang_cfg->http_hchunk_cnt = 0; + frang_cfg->http_bchunk_cnt = 1; + mockReq->chunk_cnt =3; + res = req_handler(mockReq); +//TFW_DBG("hdr_timeout:%s;%d\n","res:",res); + EXPECT_EQ(TFW_BLOCK,res); } -TEST_SUITE(frang){ +TEST_SUITE(frang) +{ TEST_RUN(frang,req_count); TEST_RUN(frang,max_conn); TEST_RUN(frang,uri); @@ -700,7 +683,6 @@ TEST_SUITE(frang){ TEST_RUN(frang,host); TEST_RUN(frang,req_method); TEST_RUN(frang,chunk_cnt); - TEST_RUN(frang,body_timeout); + TEST_RUN(frang,body_timeout); TEST_RUN(frang,hdr_timeout); - - } +} From 59305a7513e72f0ccffeab7dd800c18e9744c987 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 6 Oct 2015 17:48:53 +0300 Subject: [PATCH 04/11] sched_helper --- tempesta_fw/t/unit/sched_helper.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tempesta_fw/t/unit/sched_helper.c b/tempesta_fw/t/unit/sched_helper.c index c1c6232939..5e4740a45a 100644 --- a/tempesta_fw/t/unit/sched_helper.c +++ b/tempesta_fw/t/unit/sched_helper.c @@ -95,20 +95,30 @@ test_create_srv(const char *in_addr, TfwSrvGroup *sg) return srv; } - +void (*tfw_connection_link_peer_ptr)(TfwConnection *conn,TfwPeer *peer); TfwSrvConnection * test_create_conn(TfwPeer *peer) { + static struct sock __test_sock = { .sk_state = TCP_ESTABLISHED, }; TfwSrvConnection *srv_conn; + + if(!tfw_connection_link_peer_ptr){ + tfw_connection_link_peer_ptr = + get_sym_ptr("tfw_connection_link_peer"); + } + + if(!tfw_connection_link_peer_ptr) + TFW_DBG("sched_help: link_peer_ptr null\n"); + BUG_ON(tfw_srv_conn_alloc_ptr == NULL); srv_conn = tfw_srv_conn_alloc_ptr(); BUG_ON(!srv_conn); - tfw_connection_link_peer(&srv_conn->conn, peer); + tfw_connection_link_peer_ptr(&srv_conn->conn, peer); srv_conn->conn.sk = &__test_sock; return srv_conn; From 36d85256dafd6bec3eeab13ab6fa5a0471d65cac Mon Sep 17 00:00:00 2001 From: root Date: Tue, 6 Oct 2015 18:47:17 +0300 Subject: [PATCH 05/11] edit 09 --- tempesta_fw/t/unit/test_frang.c | 290 +++----------------------------- 1 file changed, 25 insertions(+), 265 deletions(-) diff --git a/tempesta_fw/t/unit/test_frang.c b/tempesta_fw/t/unit/test_frang.c index 68a04e8d3f..4af91ffdd1 100644 --- a/tempesta_fw/t/unit/test_frang.c +++ b/tempesta_fw/t/unit/test_frang.c @@ -32,11 +32,8 @@ #include #include #include -//#include "/usr/include/arpa/inet.h" #include -//#include #include -//#include #include "../../tempesta_fw.h" #include "../../lib.h" #include "../../log.h" @@ -46,16 +43,6 @@ #include "../../gfsm.h" #include "../../client.h" #include "../../connection.h" -//#ifdef module_init -//#undef module_init -//#endif - -//#ifndef _INCLUDE_FRANG_CODE -//#define _INCLUDE_FRANG_CODE -//#include -//#include "../../classifier/frang.c" -//#endif -//#undef module_init #include "test.h" #include "kallsyms_helper.h" @@ -77,60 +64,9 @@ #include "addr.h" #include "helpers.h" -#define TFW_GFSM_FRANG_STATE(s) ((TFW_FSM_FRANG << \ -TFW_GFSM_FSM_SHIFT) | (s)) -enum { - /* Run the FSM for each HTTP request chunk. */ - TFW_FRANG_FSM_INIT = TFW_GFSM_FRANG_STATE(0), - /* Run the FSM for fully read HTTP request. */ - TFW_FRANG_FSM_MSG = TFW_GFSM_FRANG_STATE(1), - TFW_FRANG_FSM_DONE = TFW_GFSM_FRANG_STATE(TFW_GFSM_STATE_LAST) -}; -enum { - /* TODO Enter FSM with this state for each HTTP request chunk. */ - __Frang_Chunk_0, - - Frang_Req_0 = __Frang_Chunk_0, - - Frang_Req_Hdr_Start, - Frang_Req_Hdr_Method, - Frang_Req_Hdr_UriLen, - Frang_Req_Hdr_FieldDup, - Frang_Req_Hdr_FieldLenRaw, - Frang_Req_Hdr_FieldLenSpecial, - Frang_Req_Hdr_Crlf, - Frang_Req_Hdr_Host, - Frang_Req_Hdr_ContentType, - - Frang_Req_Hdr_NoState, - - /* TODO Enter FSM with this state when HTTP request if fully read. */ - __Frang_Msg_0, - - Frang_Req_Body_Start = __Frang_Msg_0, - Frang_Req_Body_Timeout, - Frang_Req_Body_ChunkCnt, - Frang_Req_Body_Len, - - Frang_Req_Body_NoState, - - __Frang_LastState, - - Frang_Req_NothingToDo = __Frang_LastState, -}; - - - - -//#include "classifier.h" -typedef struct { - struct hlist_head list; - spinlock_t lock; -} FrangHashBucket; #define FRANG_HASH_BITS 17 - FrangHashBucket *frang_hash/*[1 << FRANG_HASH_BITS]*/; #define FRANG_FREQ 8 typedef struct { unsigned long ts; @@ -145,64 +81,13 @@ typedef struct frang_account_t { unsigned int conn_curr; /* current connections number */ FrangRates history[FRANG_FREQ]; } FrangAcc; -//extern void frang_get_ipv6addr(struct sock *sk,struct in6_addr *addr); -//extern void *get_sym_ptr(const char* name); -// void (*frang_get_ipv6addr_ptr)(struct sock *sk,struct in6_addr *addr); -#define FRANG_HASH_BITS 17 -static void -get_ipv6addr(struct sock *sk, struct in6_addr *addr) -{ - struct inet_sock *isk = (struct inet_sock *)sk; -TFW_DBG("frang_getipv6:%s;%lu\n","isk from sk:",(unsigned long)isk); -#if IS_ENABLED(CONFIG_IPV6) - if (isk->pinet6) - memcpy(addr, &isk->pinet6->saddr, sizeof(*addr)); - else -#endif - ipv6_addr_set_v4mapped(isk->inet_saddr, addr); -} - - - -FrangAcc* get_frang_acc(struct sock *sk){ -struct in6_addr addr; -FrangHashBucket *hb; -struct hlist_node *tmp; -FrangAcc *ra; -unsigned int key; -struct inet_sock *insk; -//frang_get_ipv6addr_ptr = get_sym_ptr("frang_get_ipv6addr"); -insk = (struct inet_sock *)sk; - - -get_ipv6addr(sk,&addr); -TFW_DBG("frang_conn_get_acc:after addr %d",addr.s6_addr32[1]); - -key = addr.s6_addr32[0] ^ addr.s6_addr32[1] ^ addr.s6_addr32[2] \ -^ addr.s6_addr32[3]; - -TFW_DBG("frang_conn_get_acc:%s;%d\n","key",key); -frang_hash = (FrangHashBucket*)get_sym_ptr("frang_hash"); -hb = &frang_hash[hash_min(key,FRANG_HASH_BITS)]; -hlist_for_each_entry_safe(ra,tmp,&hb->list,hentry){ -TFW_DBG("frang_conn_get_acc:%s;%d\n","in_list",ra->addr.s6_addr32[1]); - -if(ipv6_addr_equal(&addr,&ra->addr)) -break; -} -return ra; -} const int (*frang_conn_new_ptr)(struct sock*); struct sock mockSock; struct inet_sock *isk; int res; - - TfwCfgMod frang_cfg_mod; - - #define FRANG_FREQ 8 - const char* inet_addr = "192.168.168.245.128"; +const char* inet_addr = "192.168.168.245.128"; unsigned short i = 0; typedef struct { char *str; @@ -238,17 +123,13 @@ typedef struct { } FrangCfg; FrangCfg *frang_cfg; struct inet_sock *isk; -//static int (*frang_conn_limit_ptr)(FrangAcc *ra, struct sock *sk); -//extern int frang_account_do(struct sock *sk, int *func(FrangAcc *ra,struct sock *sk)); -extern TfwConnection* tfw_cli_conn_alloc(void); static int (*frang_http_req_handler_ptr)(void *obj, struct sk_buff *skb , unsigned int off); -//static FrangAcc* (*frang_get_clnt_ra_ptr)(struct sock *sk); static struct kmem_cache *tfw_test_conn_cache; TfwConnection * test_conn_alloc(void) - { +{ TfwConnection *conn; if(!tfw_test_conn_cache){ @@ -262,18 +143,12 @@ if(!tfw_test_conn_cache){ tfw_connection_init(conn); return conn; - } +} int req_handler(TfwHttpReq *req) { TfwConnection *conn; -//FrangAcc *ra; -//conn = (TfwConnection*)req->msg->conn; -//tfw_cli_conn_alloc_ptr = get_sym_ptr("tfw_cli_conn_alloc"); -//if(!tfw_cli_conn_alloc_ptr){ -// TFW_DBG("req_handler: alloc is null\n"); - //} conn = test_conn_alloc(); conn->msg = &req->msg; @@ -283,36 +158,21 @@ if(!conn){ conn->sk = &mockSock; isk = (struct inet_sock*)(&mockSock); isk->inet_saddr = htonl(in_aton(inet_addr)); -// frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); -//ra = get_frang_acc(&mockSock); if(!conn->sk->sk_security){ frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); res = frang_conn_new_ptr(conn->sk); } -//conn->sk->sk_security = ra; -/* if(!conn->sk->sk_security){ -frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); -res = frang_conn_new_ptr(conn->sk); - }*/ - -//TFW_DBG("req_handler:%s;%lu\n","after ra:",(unsigned long)ra); -//tfw_http_conn_msg_alloc(conn); -//conn->msg = req->msg; frang_http_req_handler_ptr = get_sym_ptr("frang_http_req_handler"); -//TFW_DBG("req_handler:%s;%lu\n","hand_ptr:",(unsigned long)frang_http_req_handler_ptr); -if(! frang_http_req_handler_ptr){ +if(!frang_http_req_handler_ptr){ TFW_DBG("frang_req_handleris null str:%d\n",392); } -//if(&mockReq->msg == NULL || &mockReq->msg.skb_list == NULL){ -//TFW_DBG("frang_req_handleris null param:%d\n",404); -//} -//TFW_DBG("req_handler:%s\n","before real call hand"); return frang_http_req_handler_ptr((void*)conn,req->msg.skb_list.first,25); } -TEST(frang, max_conn){ +TEST(frang, max_conn) +{ TfwHttpReq *mockReq; FrangAcc *ra; unsigned long ts; @@ -324,37 +184,21 @@ TEST(frang, max_conn){ frang_cfg->conn_max =5; isk = (struct inet_sock*)(&mockSock); isk->inet_saddr = htonl(in_aton(inet_addr)); -// TFW_DBG("max_conn:%s\n","after set iaddr,before funk addr"); frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); if(!frang_conn_new_ptr){ - TFW_DBG("max_conn:%s\n","conn_new ptr is null"); + TFW_DBG("max_conn:%s\n","conn_new ptr is null"); } res = frang_conn_new_ptr(&mockSock); ra = mockSock.sk_security; -//TFW_DBG("frang_conn_max:%s;%d\n","after conn_new res:",res); -// TFW_DBG("max_conn:%s;%lu\n","ra from conn_new:",(unsigned long)ra); -//frang_get_clnt_ra_ptr = get_sym_ptr("frang_get_clnt_ra"); -// if(!frang_get_clnt_ra_ptr){ -// TFW_DBG("max_conn:%s\n","get_clnt_ptr is null"); -// } - -//ra = get_frang_acc(&mockSock);//frang_get_clnt_ra_ptr(&mockSock); -//TFW_DBG("frang_conn_max:%s;%lu\n","after ra:",(unsigned long)ra); - -//TFW_DBG("frang_conn_max:%s;%d\n","after ra",ra->conn_curr); isk = (struct inet_sock*)(&mockSock); isk->inet_saddr = in_aton(inet_addr); ra->conn_curr = 5; -// frang_conn_limit_ptr = get_sym_ptr("frang_conn_limit"); -// if(!frang_conn_limit_ptr){ -// TFW_DBG("max_conn:%s\n","conn_limit ptr is null"); -// } mockSock.sk_security = ra; - res = req_handler(mockReq);//frang_conn_new_ptr(&mockSock); + res = req_handler(mockReq); EXPECT_EQ(TFW_BLOCK, res); ts = jiffies * FRANG_FREQ / HZ; i = ts % FRANG_FREQ; @@ -363,7 +207,7 @@ TEST(frang, max_conn){ ra->history[i].conn_new =5; mockSock.sk_security = ra; res = req_handler(mockReq); - //conn_rate + /*conn_rate*/ EXPECT_EQ(TFW_BLOCK,res); frang_cfg->conn_max =0; frang_cfg->conn_rate = 0; @@ -371,11 +215,9 @@ TEST(frang, max_conn){ ra->history[i].conn_new = 5; mockSock.sk_security = ra; res = req_handler(mockReq); - //conn_max + /*conn_max*/ EXPECT_EQ(TFW_BLOCK,res); } -//static int (*frang_http_uri_ptr)(const TfwHttpReq *req); -//extern int frang_http_uri_len(const TfwHttpReq *req); TEST(frang,uri) { @@ -383,35 +225,20 @@ TEST(frang,uri) TfwStr uri; mockReq = test_req_alloc(26); tfw_http_parse_req(mockReq,"GET /index.html HTTP /1.1",25); -// const char* conf_max_uri = "http_uri_len=10";frang_cfg = get_sym_ptr("frang_cfg"); -//TFW_DBG("uri_len:%s;%lu\n","start conf:",(unsigned long)frang_cfg); if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } frang_cfg->http_uri_len = 5; -// LIST_HEAD(frang_cfg_mod); -// tfw_cfg_start_mods(conf_max_uri, &frang_cfg_mod); uri.len = 17; uri.ptr = (void*)"/home/index.html"; uri.flags = TFW_STR_COMPLETE; mockReq->uri_path = uri; -//TFW_DBG("uri:%s\n","after set uri to req"); -//frang_http_uri_ptr = get_sym_ptr("frang_http_uri_len"); -//TFW_DBG("uri_len funk ptr:%lu\n",(unsigned long)frang_http_uri_ptr); mockReq->frang_st = 3; -// if(!mockReq->sk_security){ -// frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); -// res = frang_conn_new_ptr(&mockReq); -// } res = req_handler(mockReq); -//res = frang_http_uri_len(mockReq); EXPECT_EQ(TFW_BLOCK,res); } -//static int (*frang_http_methods_ptr)(const TfwHttpReq *req); - -//static int (*frang_http_ct_check_ptr)(const TfwHttpReq *req); TEST(frang,ct_check){ TfwHttpReq * mockReq; FrangCtVal ctval[1]; @@ -422,80 +249,56 @@ TEST(frang,ct_check){ if(!frang_cfg){ frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } -//TFW_DBG("ct_check:%s;%lu\n","after conf conf:",(unsigned long)frang_cfg); ctval[0].len = 17; ctval[0].str ="application/html"; frang_cfg->http_ct_required = true; res = req_handler(mockReq); EXPECT_EQ(TFW_BLOCK,res); -// frang_cfg->http_ct_vals = ctval; -// frang_cfg->http_ct_vals[0].len = 17; -//W_DBG("ct_check:%s;%d\n","after conf ct_vals:",358); mockReq->frang_st = 9; res = req_handler(mockReq); EXPECT_EQ(TFW_BLOCK,res); } -//frang_http_ct_check_ptr = get_sym_ptr("frang_http_ct_check"); -//res = frang_http_ct_check_ptr(mockReq); -//EXPECT_EQ(TFW_BLO/CK,res); -//test_req_free(mockReq); -//mockReq = test_req_alloc(92); -//TFW_DBG("ct_check:%s\n","after parse"); -//frang_cfg->http_ct_vals[0].len =17; -//res = frang_http_ct_check_ptr(mockReq); -//EXPECT_EQ(TFW_BLOCK,res); -//} -//extern int frang_http_methods(const TfwHttpReq *req); TEST(frang,req_method){ TfwHttpReq *mockReq; mockReq = test_req_alloc(17); tfw_http_parse_req(mockReq,"PUT /index.html",16); -//TFW_DBG("frang_req_method:%d",mockReq->method); if(!frang_cfg){ frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } frang_cfg->http_methods_mask = 2; -//frang_http_methods_ptr = get_sym_ptr("frang_http_methods"); - res =req_handler(mockReq);//frang_http_methods_ptr(mockReq); + res =req_handler(mockReq); EXPECT_EQ(TFW_BLOCK,res); } -//static int (*frang_http_field_len_raw_ptr)(const TfwHttpReq *req); TEST(frang,field_len){ TfwHttpReq *mockReq; mockReq = test_req_alloc(20); tfw_http_parse_req(mockReq,"GET /foo HTTP/1.1\r\n",19); if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } frang_cfg->http_field_len =3; -//frang_http_field_len_raw_ptr = get_sym_ptr("frang_http_field_len_raw"); - res = req_handler(mockReq);//frang_http_field_len_raw_ptr(mockReq); + res = req_handler(mockReq); EXPECT_EQ(TFW_BLOCK,res); } -//static int (*frang_http_host_check_ptr)(TfwHttpReq* req); TEST(frang,host){ TfwHttpReq *mockReq; mockReq = test_req_alloc(7); tfw_http_parse_req(mockReq,"GET /foo HTTP/1.1\r\n",19); -//tfw_http_parse_req(&mockReq,"GET /\n",6); if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } frang_cfg->http_host_required = true; -//frang_http_host_check_ptr = get_sym_ptr("frang_http_host_check"); - res = req_handler(mockReq);//frang_http_host_check_ptr(mockReq); + res = req_handler(mockReq); EXPECT_EQ(TFW_BLOCK,res); } static int (*frang_req_limit_ptr)(FrangAcc *ra, struct sock *sk); -// static int (*frang_http_req_handler_ptr)(void *obj, -// struct sk_buff *skb , -// unsigned int off); -TEST(frang, req_count){ +TEST(frang, req_count) +{ TfwConnection mockConn; unsigned long ts; TfwHttpReq *mockReq; @@ -503,40 +306,26 @@ TEST(frang, req_count){ mockReq = test_req_alloc(17); tfw_http_parse_req(mockReq,"GET / HTTP/1.1\r\n",16); if(!frang_cfg){ - frang_cfg = get_sym_ptr("frang_cfg"); + frang_cfg = get_sym_ptr("frang_cfg"); } frang_req_limit_ptr = get_sym_ptr("frang_req_limit"); if(!frang_req_limit_ptr){ - TFW_DBG("req_count:%s;\n","req_limit ptr is null"); + TFW_DBG("req_count:%s;\n","req_limit ptr is null"); } frang_cfg->conn_max =0; frang_cfg->conn_burst = 0; frang_cfg->conn_rate = 0; frang_cfg->req_rate = 5; - //frang_cfg.req_rate = 0; -// TFW_DBG("req_count:%s;%lu\n","set conn sk:",(unsigned long)&mockSock); isk = (struct inet_sock*)(&mockSock); isk->inet_saddr = htonl(in_aton(inet_addr)); mockConn.sk = &mockSock; -// mockReq = test_req_alloc(15); -// tfw_http_parse_req(&mockReq,"GET / HTTP /1.1",15); -// mockConn.msg = (TfwMsg*)&mockReq; -// res = frang_http_req_handler(&mockConn, "GET / HTTP /1.1",15); -// ra = (FrangAcc*)get_frang_acc(&mockSock); frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); TFW_DBG("req_count507:%s;%lu\n","get conn_new:",(unsigned long)frang_conn_new_ptr); res = frang_conn_new_ptr(&mockSock); ra = mockConn.sk->sk_security; -// TFW_DBG("frang conn:%d",ra->conn_curr); -// i = 0; -//while(i<5){ -//ndelay(1000); -// frang_req_limit(ra,&mockSock); -// i++; -//} ts = jiffies * FRANG_FREQ / HZ; i = ts % FRANG_FREQ; ra->history[i].req = 5; @@ -544,73 +333,47 @@ TFW_DBG("frang_req_i:%d;%d",i,ra->history[i].req); if(!frang_conn_new_ptr){ TFW_DBG("frang_req_count507:%s\n","conn_new ptr is null"); } -//= frang_req_limit_ptr(ra,&mockSock); mockSock.sk_security = ra; mockReq->frang_st = 0; res = req_handler(mockReq); TFW_DBG("frang_req_count:%s;%d\n","req_rate:",res); -//frang_req_limit_ptr = get_sym_ptr("frang_req_limit"); EXPECT_EQ(TFW_BLOCK,res); frang_cfg->req_rate = 5; frang_cfg->req_burst = 5; ra->history[i].req = 5; -/* if(!frang_conn_new_ptr){ TFW_DBG("frang_req_count 517:%s\n","conn_new ptr is null"); -}*/ + mockSock.sk_security = ra; mockReq->frang_st = 0; res = req_handler(mockReq); -//TFW_DBG("frang_req_count:%s;%d\n","req_burst:",res); EXPECT_EQ(TFW_BLOCK,res); } -//TFW_DBG("frang_req_method:%d",mockReq->method); -//extern TfwMsg *tfw_http_conn_msg_alloc(TfwConnection *conn); - -//tfw_http_conn_msg_alloc(conn); - -//conn->msg = req->msg; - -//frang_http_req_handler_ptr = get_sym_ptr("frang_http_req_handler"); -//TFW_DBG("req_handler:%s;%lu\n","hand_ptr:",(unsigned long)frang_http_req_handler_ptr); -//(! frang_http_req_handler_ptr){ -//TFW_DBG("frang_req_handleris null str:%d\n",392); -//} -//if(&mockReq->msg == NULL || &mockReq->msg.skb_list == NULL){ -//TFW_DBG("frang_req_handleris null param:%d\n",404); -//} - TEST(frang,body_len) { TfwHttpReq *mockReq; TfwStr body; TfwStr crlf; mockReq = test_req_alloc(22); -//TFW_DBG("body_len:%s;%lu\n","after req_alloc:",(unsigned long)mockReq); tfw_http_parse_req(mockReq,"POST /foo HTTP/1.1\r\n",20); -//TFW_DBG("body_len:%s;%lu\n","after parse:",(unsigned long)mockReq); body.ptr = "GET http://natsys-lab.com/foo"; body.len = 29; crlf.len = 2; crlf.ptr = "\r\n"; -//TFW_DBG("body_len:%s;%lu\n","after body params:",(unsigned long)mockReq->body.len); -//mockReq->body = body; mockReq->crlf = crlf; mockReq->body.len = 29; if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } -//TFW_DBG("body_len:%s;%lu\n","before set params:",(unsigned long)frang_cfg); frang_cfg->http_body_len = 3; mockReq->frang_st = 0; -//TFW_DBG("body_len:%s;%lu\n","before handler:",(unsigned long)mockReq); res = req_handler(mockReq); EXPECT_EQ(TFW_BLOCK,res); @@ -622,7 +385,7 @@ TEST(frang,body_timeout) tfw_http_parse_req(mockReq,"POST http://natsys-lab.com/foo HTTP/1.1\r\n \ Content-Length:29\r\n",61); if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } frang_cfg->clnt_body_timeout = 1; @@ -638,7 +401,7 @@ TEST(frang,hdr_timeout) tfw_http_parse_req(mockReq,"POST http://natsys-lab.com/foo HTTP/1.1\r\n \ Content-Length:29\r\n",61); if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + rang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } frang_cfg->clnt_body_timeout = 0; @@ -646,7 +409,6 @@ Content-Length:29\r\n",61); mockReq->frang_st = 0; mockReq->tm_header = jiffies - 100; res = req_handler(mockReq); -//TFW_DBG("hdr_timeout:%s;%d\n","res:",res); EXPECT_EQ(TFW_BLOCK,res); } TEST(frang,chunk_cnt) @@ -656,19 +418,17 @@ TEST(frang,chunk_cnt) tfw_http_parse_req(mockReq,"POST http://natsys-lab.com/foo HTTP/1.1\r\n \ Content-Length:29\r\n",61); if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); + frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); } frang_cfg->http_hchunk_cnt = 1; mockReq->chunk_cnt = 3; mockReq->frang_st = 0; res = req_handler(mockReq); -//TFW_DBG("hdr_timeout:%s;%d\n","frang_st:",mockReq->frang_st); EXPECT_EQ(TFW_BLOCK,res); frang_cfg->http_hchunk_cnt = 0; frang_cfg->http_bchunk_cnt = 1; mockReq->chunk_cnt =3; res = req_handler(mockReq); -//TFW_DBG("hdr_timeout:%s;%d\n","res:",res); EXPECT_EQ(TFW_BLOCK,res); } From bd62aa1a5200eb80634f7e0cb22baa3a409db2c9 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 8 Oct 2015 11:46:33 +0300 Subject: [PATCH 06/11] edit14 --- tempesta_fw/t/unit/sched_helper.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tempesta_fw/t/unit/sched_helper.c b/tempesta_fw/t/unit/sched_helper.c index 5e4740a45a..c18fcb9ff0 100644 --- a/tempesta_fw/t/unit/sched_helper.c +++ b/tempesta_fw/t/unit/sched_helper.c @@ -95,10 +95,10 @@ test_create_srv(const char *in_addr, TfwSrvGroup *sg) return srv; } -void (*tfw_connection_link_peer_ptr)(TfwConnection *conn,TfwPeer *peer); TfwSrvConnection * test_create_conn(TfwPeer *peer) { + void (*tfw_connection_link_peer)(TfwConnection *conn,TfwPeer *peer); static struct sock __test_sock = { .sk_state = TCP_ESTABLISHED, @@ -106,19 +106,17 @@ test_create_conn(TfwPeer *peer) TfwSrvConnection *srv_conn; - if(!tfw_connection_link_peer_ptr){ - tfw_connection_link_peer_ptr = - get_sym_ptr("tfw_connection_link_peer"); - } + tfw_connection_link_peer = get_sym_ptr("tfw_connection_link_peer"); + - if(!tfw_connection_link_peer_ptr) - TFW_DBG("sched_help: link_peer_ptr null\n"); + if(!tfw_connection_link_peer) + TFW_DBG("sched_help: link_peer ptr null\n"); BUG_ON(tfw_srv_conn_alloc_ptr == NULL); srv_conn = tfw_srv_conn_alloc_ptr(); BUG_ON(!srv_conn); - tfw_connection_link_peer_ptr(&srv_conn->conn, peer); + tfw_connection_link_peer(&srv_conn->conn, peer); srv_conn->conn.sk = &__test_sock; return srv_conn; From 1cdbbcef7e49b09a12b946196ec4c6996dc47aa3 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 9 Oct 2015 11:43:24 +0300 Subject: [PATCH 07/11] editf1 --- tempesta_fw/t/unit/test_frang.c | 658 +++++++++++++++++--------------- 1 file changed, 346 insertions(+), 312 deletions(-) diff --git a/tempesta_fw/t/unit/test_frang.c b/tempesta_fw/t/unit/test_frang.c index 4af91ffdd1..4be7c13004 100644 --- a/tempesta_fw/t/unit/test_frang.c +++ b/tempesta_fw/t/unit/test_frang.c @@ -68,381 +68,415 @@ #define FRANG_HASH_BITS 17 #define FRANG_FREQ 8 -typedef struct { - unsigned long ts; - unsigned int conn_new; - unsigned int req; +typedef struct +{ + unsigned long ts; + unsigned int conn_new; + unsigned int req; } FrangRates; -typedef struct frang_account_t { - struct hlist_node hentry; - struct in6_addr addr; /* client address */ - unsigned long last_ts; /* last access time */ - unsigned int conn_curr; /* current connections number */ - FrangRates history[FRANG_FREQ]; +typedef struct frang_account_t +{ + struct hlist_node hentry; + struct in6_addr addr; /* client address */ + unsigned long last_ts; /* last access time */ + unsigned int conn_curr; /* current connections number */ + FrangRates history[FRANG_FREQ]; } FrangAcc; -const int (*frang_conn_new_ptr)(struct sock*); - struct sock mockSock; - struct inet_sock *isk; - int res; - -const char* inet_addr = "192.168.168.245.128"; +const int (*frang_conn_new) (struct sock *); +struct sock mockSock; +struct inet_sock *isk; +int res; + +const char *inet_addr = "192.168.168.245.128"; unsigned short i = 0; -typedef struct { - char *str; - size_t len; /* The pre-computed strlen(@str). */ +typedef struct +{ + char *str; + size_t len; /* The pre-computed strlen(@str). */ } FrangCtVal; -typedef struct { - /* Limits (zero means unlimited). */ - unsigned int req_rate; - unsigned int req_burst; - unsigned int conn_rate; - unsigned int conn_burst; - unsigned int conn_max; - - /* - * Limits on time it takes to receive - * a full header or a body chunk. - */ - unsigned long clnt_hdr_timeout; - unsigned long clnt_body_timeout; - - /* Limits for HTTP request contents: uri, headers, body, etc. */ - unsigned int http_uri_len; - unsigned int http_field_len; - unsigned int http_body_len; - unsigned int http_hchunk_cnt; - unsigned int http_bchunk_cnt; - bool http_ct_required; - bool http_host_required; - /* The bitmask of allowed HTTP Method values. */ - unsigned long http_methods_mask; - /* The list of allowed Content-Type values. */ - FrangCtVal *http_ct_vals; +typedef struct +{ + /* Limits (zero means unlimited). */ + unsigned int req_rate; + unsigned int req_burst; + unsigned int conn_rate; + unsigned int conn_burst; + unsigned int conn_max; + + /* + * Limits on time it takes to receive + * a full header or a body chunk. + */ + unsigned long clnt_hdr_timeout; + unsigned long clnt_body_timeout; + + /* Limits for HTTP request contents: uri, headers, body, etc. */ + unsigned int http_uri_len; + unsigned int http_field_len; + unsigned int http_body_len; + unsigned int http_hchunk_cnt; + unsigned int http_bchunk_cnt; + bool http_ct_required; + bool http_host_required; + /* The bitmask of allowed HTTP Method values. */ + unsigned long http_methods_mask; + /* The list of allowed Content-Type values. */ + FrangCtVal *http_ct_vals; } FrangCfg; FrangCfg *frang_cfg; - struct inet_sock *isk; -static int (*frang_http_req_handler_ptr)(void *obj, - struct sk_buff *skb , - unsigned int off); +struct inet_sock *isk; +static int (*frang_http_req_handler) (void *obj, + struct sk_buff * skb, unsigned int off); static struct kmem_cache *tfw_test_conn_cache; -TfwConnection * test_conn_alloc(void) +TfwConnection * +test_conn_alloc (void) { -TfwConnection *conn; - -if(!tfw_test_conn_cache){ - tfw_test_conn_cache = kmem_cache_create("tfw_test_conn_cache", \ - sizeof(TfwConnection), \ - 0,0,NULL); -} - conn = kmem_cache_alloc(tfw_test_conn_cache, GFP_ATOMIC); - if (!conn) - return NULL; - - tfw_connection_init(conn); + TfwConnection *conn; + + if (!tfw_test_conn_cache) + { + tfw_test_conn_cache = + kmem_cache_create ("tfw_test_conn_cache", + sizeof (TfwConnection), 0,0, NULL); + } + conn = kmem_cache_alloc (tfw_test_conn_cache, GFP_ATOMIC); + if (!conn) + return NULL; + + tfw_connection_init (conn); return conn; -} +} -int req_handler(TfwHttpReq *req) +int +req_handler (TfwHttpReq * req) { -TfwConnection *conn; + TfwConnection *conn; - conn = test_conn_alloc(); -conn->msg = &req->msg; -if(!conn){ - TFW_DBG("req_handler: conn is null\n"); -} -conn->sk = &mockSock; -isk = (struct inet_sock*)(&mockSock); - isk->inet_saddr = htonl(in_aton(inet_addr)); -if(!conn->sk->sk_security){ -frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); -res = frang_conn_new_ptr(conn->sk); + conn = test_conn_alloc (); + conn->msg = &req->msg; + if (!conn) + { + TFW_DBG ("req_handler: conn is null\n"); + } + conn->sk = &mockSock; + isk = (struct inet_sock *) (&mockSock); + isk->inet_saddr = htonl (in_aton (inet_addr)); + if (!conn->sk->sk_security) + { + frang_conn_new = get_sym_ptr ("frang_conn_new"); + res = frang_conn_new (conn->sk); + } + + + + frang_http_req_handler = get_sym_ptr ("frang_http_req_handler"); + if (!frang_http_req_handler_ptr) + { + FW_DBG ("frang_req_handleris null str:%d\n", 392); + } + return frang_http_req_handler ((void *) conn, + req->msg.skb_list.first, 25); } - - -frang_http_req_handler_ptr = get_sym_ptr("frang_http_req_handler"); -if(!frang_http_req_handler_ptr){ -TFW_DBG("frang_req_handleris null str:%d\n",392); -} -return frang_http_req_handler_ptr((void*)conn,req->msg.skb_list.first,25); -} TEST(frang, max_conn) { - TfwHttpReq *mockReq; + TfwHttpReq *mockReq; FrangAcc *ra; unsigned long ts; - mockReq = test_req_alloc(17); - tfw_http_parse_req(mockReq,"GET / HTTP/1.1\r\n",16); - if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); - } - frang_cfg->conn_max =5; - isk = (struct inet_sock*)(&mockSock); - isk->inet_saddr = htonl(in_aton(inet_addr)); - - frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); - if(!frang_conn_new_ptr){ - TFW_DBG("max_conn:%s\n","conn_new ptr is null"); + mockReq = test_req_alloc (17); + tfw_http_parse_req(mockReq, "GET / HTTP/1.1\r\n", 16); + if (!frang_cfg) + { + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); } - res = frang_conn_new_ptr(&mockSock); + frang_cfg->conn_max = 5; + isk = (struct inet_sock *) (&mockSock); + isk->inet_saddr = htonl (in_aton (inet_addr)); + + frang_conn_new = get_sym_ptr ("frang_conn_new"); + if (!frang_conn_new) + { + TFW_DBG ("max_conn:%s\n", "conn_new ptr is null"); + } + res = frang_conn_new (&mockSock); ra = mockSock.sk_security; - isk = (struct inet_sock*)(&mockSock); - isk->inet_saddr = in_aton(inet_addr); + isk = (struct inet_sock *) (&mockSock); + isk->inet_saddr = in_aton (inet_addr); ra->conn_curr = 5; mockSock.sk_security = ra; - res = req_handler(mockReq); - EXPECT_EQ(TFW_BLOCK, res); + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); ts = jiffies * FRANG_FREQ / HZ; i = ts % FRANG_FREQ; frang_cfg->conn_max = 0; frang_cfg->conn_rate = 5; - ra->history[i].conn_new =5; + ra->history[i].conn_new = 5; mockSock.sk_security = ra; - res = req_handler(mockReq); - /*conn_rate*/ - EXPECT_EQ(TFW_BLOCK,res); - frang_cfg->conn_max =0; + res = req_handler (mockReq); + /*conn_rate */ + EXPECT_EQ (TFW_BLOCK, res); + frang_cfg->conn_max = 0; frang_cfg->conn_rate = 0; - frang_cfg->conn_burst = 5; +frang_cfg->conn_burst = 5; ra->history[i].conn_new = 5; - mockSock.sk_security = ra; - res = req_handler(mockReq); - /*conn_max*/ - EXPECT_EQ(TFW_BLOCK,res); - } + mockSock.sk_security = ra; + res = req_handler (mockReq); + /*conn_max */ + EXPECT_EQ (TFW_BLOCK, res); +} -TEST(frang,uri) +TEST (frang, uri) { - TfwHttpReq *mockReq; - TfwStr uri; - mockReq = test_req_alloc(26); - tfw_http_parse_req(mockReq,"GET /index.html HTTP /1.1",25); - if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); - } - - frang_cfg->http_uri_len = 5; - - uri.len = 17; - uri.ptr = (void*)"/home/index.html"; - uri.flags = TFW_STR_COMPLETE; - mockReq->uri_path = uri; -mockReq->frang_st = 3; -res = req_handler(mockReq); -EXPECT_EQ(TFW_BLOCK,res); -} -TEST(frang,ct_check){ - TfwHttpReq * mockReq; - FrangCtVal ctval[1]; - - mockReq = test_req_alloc(22); - tfw_http_parse_req(mockReq,"POST /foo HTTP/1.1\r\n",20); - TFW_DBG("ct_check:%s;%lu\n","after parse req req:",(unsigned long)mockReq); - if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); - } - ctval[0].len = 17; - ctval[0].str ="application/html"; - frang_cfg->http_ct_required = true; - res = req_handler(mockReq); -EXPECT_EQ(TFW_BLOCK,res); - - mockReq->frang_st = 9; - res = req_handler(mockReq); -EXPECT_EQ(TFW_BLOCK,res); + TfwHttpReq *mockReq; + TfwStr uri; + mockReq = test_req_alloc (26); + tfw_http_parse_req (mockReq, "GET /index.html HTTP /1.1", 25); + if (!frang_cfg) + { + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } + + frang_cfg->http_uri_len = 5; + + uri.len = 17; + uri.ptr = (void *) "/home/index.html"; + uri.flags = TFW_STR_COMPLETE; + mockReq->uri_path = uri; + mockReq->frang_st = 3; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } -TEST(frang,req_method){ - TfwHttpReq *mockReq; - mockReq = test_req_alloc(17); - tfw_http_parse_req(mockReq,"PUT /index.html",16); - if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); - } +TEST (frang, ct_check) +{ + TfwHttpReq *mockReq; + FrangCtVal ctval[1]; + + mockReq = test_req_alloc (22); + tfw_http_parse_req (mockReq, "POST /foo HTTP/1.1\r\n", 20); + TFW_DBG ("ct_check:%s;%lu\n", "after parse req req:", + (unsigned long) mockReq); + if (!frang_cfg) + { + rang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } + ctval[0].len = 17; + ctval[0].str = "application/html"; + frang_cfg->http_ct_required = true; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); + + mockReq->frang_st = 9; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); +} - frang_cfg->http_methods_mask = 2; - res =req_handler(mockReq); - EXPECT_EQ(TFW_BLOCK,res); +TEST (frang, req_method) +{ + TfwHttpReq *mockReq; + mockReq = test_req_alloc (17); + tfw_http_parse_req (mockReq, "PUT /index.html", 16); + if (!frang_cfg) + { + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } + + frang_cfg->http_methods_mask = 2; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } -TEST(frang,field_len){ - TfwHttpReq *mockReq; - mockReq = test_req_alloc(20); - tfw_http_parse_req(mockReq,"GET /foo HTTP/1.1\r\n",19); - if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); - } - frang_cfg->http_field_len =3; - res = req_handler(mockReq); - EXPECT_EQ(TFW_BLOCK,res); +TEST (frang, field_len) +{ + TfwHttpReq *mockReq; + mockReq = test_req_alloc (20); + tfw_http_parse_req (mockReq, "GET /foo HTTP/1.1\r\n", 19); + + if (!frang_cfg) + { + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } + frang_cfg->http_field_len = 3; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } -TEST(frang,host){ - TfwHttpReq *mockReq; - mockReq = test_req_alloc(7); - tfw_http_parse_req(mockReq,"GET /foo HTTP/1.1\r\n",19); - if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); - } - frang_cfg->http_host_required = true; - res = req_handler(mockReq); - EXPECT_EQ(TFW_BLOCK,res); +TEST (frang, host) +{ + TfwHttpReq *mockReq; + mockReq = test_req_alloc (7); + tfw_http_parse_req (mockReq, "GET /foo HTTP/1.1\r\n", 19); + + if (!frang_cfg) + { + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } + frang_cfg->http_host_required = true; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } -static int (*frang_req_limit_ptr)(FrangAcc *ra, struct sock *sk); -TEST(frang, req_count) + +static int (*frang_req_limit_ptr) (FrangAcc * ra, struct sock * sk); +TEST (frang, req_count) { - TfwConnection mockConn; - unsigned long ts; - TfwHttpReq *mockReq; - FrangAcc *ra; - mockReq = test_req_alloc(17); - tfw_http_parse_req(mockReq,"GET / HTTP/1.1\r\n",16); - if(!frang_cfg){ - frang_cfg = get_sym_ptr("frang_cfg"); - } - frang_req_limit_ptr = get_sym_ptr("frang_req_limit"); - if(!frang_req_limit_ptr){ - TFW_DBG("req_count:%s;\n","req_limit ptr is null"); - } - frang_cfg->conn_max =0; - frang_cfg->conn_burst = 0; - frang_cfg->conn_rate = 0; - frang_cfg->req_rate = 5; -isk = (struct inet_sock*)(&mockSock); - isk->inet_saddr = htonl(in_aton(inet_addr)); - - mockConn.sk = &mockSock; - - frang_conn_new_ptr = get_sym_ptr("frang_conn_new"); - TFW_DBG("req_count507:%s;%lu\n","get conn_new:",(unsigned long)frang_conn_new_ptr); - res = frang_conn_new_ptr(&mockSock); - ra = mockConn.sk->sk_security; - -ts = jiffies * FRANG_FREQ / HZ; -i = ts % FRANG_FREQ; -ra->history[i].req = 5; -TFW_DBG("frang_req_i:%d;%d",i,ra->history[i].req); - if(!frang_conn_new_ptr){ - TFW_DBG("frang_req_count507:%s\n","conn_new ptr is null"); - } -mockSock.sk_security = ra; -mockReq->frang_st = 0; -res = req_handler(mockReq); -TFW_DBG("frang_req_count:%s;%d\n","req_rate:",res); - -EXPECT_EQ(TFW_BLOCK,res); - frang_cfg->req_rate = 5; - frang_cfg->req_burst = 5; - ra->history[i].req = 5; - TFW_DBG("frang_req_count 517:%s\n","conn_new ptr is null"); - -mockSock.sk_security = ra; -mockReq->frang_st = 0; - -res = req_handler(mockReq); -EXPECT_EQ(TFW_BLOCK,res); + TfwConnection mockConn; + unsigned long ts; + TfwHttpReq *mockReq; + FrangAcc *ra; + mockReq = test_req_alloc (17); + tfw_http_parse_req (mockReq, "GET / HTTP/1.1\r\n", 16); + if (!frang_cfg) + { + frang_cfg = get_sym_ptr ("frang_cfg"); + } + frang_req_limit_ptr = get_sym_ptr ("frang_req_limit"); + if (!frang_req_limit_ptr) + { + TFW_DBG ("req_count:%s;\n", "req_limit ptr is null"); + } + frang_cfg->conn_max = 0; + frang_cfg->conn_burst = 0; + frang_cfg->conn_rate = 0; + frang_cfg->req_rate = 5; + isk = (struct inet_sock *) (&mockSock); + isk->inet_saddr = htonl (in_aton (inet_addr)); + + mockConn.sk = &mockSock; + + frang_conn_new = get_sym_ptr ("frang_conn_new"); + res = frang_conn_new (&mockSock); + ra = mockConn.sk->sk_security; + + ts = jiffies * FRANG_FREQ / HZ; + i = ts % FRANG_FREQ; + ra->history[i].req = 5; + if (!frang_conn_new) + { + TFW_DBG ("frang_req_count507:%s\n", "conn_new ptr is null"); + } + mockSock.sk_security = ra; + mockReq->frang_st = 0; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); + frang_cfg->req_rate = 5; + frang_cfg->req_burst = 5; + ra->history[i].req = 5; + TFW_DBG ("frang_req_count 517:%s\n", "conn_new ptr is null"); + + mockSock.sk_security = ra; + mockReq->frang_st = 0; + + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } -TEST(frang,body_len) + +TEST (frang, body_len) { - TfwHttpReq *mockReq; - TfwStr body; - TfwStr crlf; - mockReq = test_req_alloc(22); + TfwHttpReq *mockReq; + TfwStr body; + TfwStr crlf; + mockReq = test_req_alloc (22); - tfw_http_parse_req(mockReq,"POST /foo HTTP/1.1\r\n",20); + tfw_http_parse_req (mockReq, "POST /foo HTTP/1.1\r\n", 20); - body.ptr = "GET http://natsys-lab.com/foo"; - body.len = 29; -crlf.len = 2; - crlf.ptr = "\r\n"; + body.ptr = "GET http://natsys-lab.com/foo"; + body.len = 29; + crlf.len = 2; + crlf.ptr = "\r\n"; - mockReq->crlf = crlf; + mockReq->crlf = crlf; - mockReq->body.len = 29; - if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); - } + mockReq->body.len = 29; + if (!frang_cfg) + { + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } - frang_cfg->http_body_len = 3; - mockReq->frang_st = 0; + frang_cfg->http_body_len = 3; + mockReq->frang_st = 0; -res = req_handler(mockReq); -EXPECT_EQ(TFW_BLOCK,res); + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } -TEST(frang,body_timeout) -{ - TfwHttpReq *mockReq; - mockReq = test_req_alloc(62); -tfw_http_parse_req(mockReq,"POST http://natsys-lab.com/foo HTTP/1.1\r\n \ -Content-Length:29\r\n",61); - if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); - } - frang_cfg->clnt_body_timeout = 1; - mockReq->frang_st = 12; - mockReq->tm_bchunk = jiffies - 100; - res = req_handler(mockReq); - EXPECT_EQ(TFW_BLOCK,res); -} -TEST(frang,hdr_timeout) +TEST (frang, body_timeout) { - TfwHttpReq *mockReq; - mockReq = test_req_alloc(62); -tfw_http_parse_req(mockReq,"POST http://natsys-lab.com/foo HTTP/1.1\r\n \ -Content-Length:29\r\n",61); - if(!frang_cfg){ - rang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); - } + TfwHttpReq *mockReq; + mockReq = test_req_alloc (62); + tfw_http_parse_req (mockReq, "POST http://natsys-lab.com/foo HTTP/1.1\r\n \ +Content-Length:29\r\n", 61); + if (!frang_cfg) + { + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } + + frang_cfg->clnt_body_timeout = 1; + mockReq->frang_st = 12; + mockReq->tm_bchunk = jiffies - 100; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); +} - frang_cfg->clnt_body_timeout = 0; - frang_cfg->clnt_hdr_timeout = 1; - mockReq->frang_st = 0; - mockReq->tm_header = jiffies - 100; - res = req_handler(mockReq); - EXPECT_EQ(TFW_BLOCK,res); +TEST (frang, hdr_timeout) +{ + TfwHttpReq *mockReq; + mockReq = test_req_alloc (62); + tfw_http_parse_req (mockReq, "POST http://natsys-lab.com/foo HTTP/1.1\r\n \ +Content-Length:29\r\n", 61); + if (!frang_cfg) + { + rang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } + + frang_cfg->clnt_body_timeout = 0; + frang_cfg->clnt_hdr_timeout = 1; + mockReq->frang_st = 0; + mockReq->tm_header = jiffies - 100; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } -TEST(frang,chunk_cnt) + +TEST (frang, chunk_cnt) { - TfwHttpReq *mockReq; - mockReq = test_req_alloc(62); -tfw_http_parse_req(mockReq,"POST http://natsys-lab.com/foo HTTP/1.1\r\n \ -Content-Length:29\r\n",61); - if(!frang_cfg){ - frang_cfg = (FrangCfg*)get_sym_ptr("frang_cfg"); - } - frang_cfg->http_hchunk_cnt = 1; - mockReq->chunk_cnt = 3; - mockReq->frang_st = 0; - res = req_handler(mockReq); -EXPECT_EQ(TFW_BLOCK,res); - frang_cfg->http_hchunk_cnt = 0; - frang_cfg->http_bchunk_cnt = 1; - mockReq->chunk_cnt =3; - res = req_handler(mockReq); - EXPECT_EQ(TFW_BLOCK,res); + TfwHttpReq *mockReq; + mockReq = test_req_alloc (62); + tfw_http_parse_req (mockReq, "POST http://natsys-lab.com/foo HTTP/1.1\r\n \ +Content-Length:29\r\n", 61); + if (!frang_cfg) + { + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } + frang_cfg->http_hchunk_cnt = 1; + mockReq->chunk_cnt = 3; + mockReq->frang_st = 0; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); + frang_cfg->http_hchunk_cnt = 0; + frang_cfg->http_bchunk_cnt = 1; + mockReq->chunk_cnt = 3; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } -TEST_SUITE(frang) +TEST_SUITE (frang) { - TEST_RUN(frang,req_count); - TEST_RUN(frang,max_conn); - TEST_RUN(frang,uri); - TEST_RUN(frang,body_len); - TEST_RUN(frang,ct_check); - TEST_RUN(frang,field_len); - TEST_RUN(frang,host); - TEST_RUN(frang,req_method); - TEST_RUN(frang,chunk_cnt); - TEST_RUN(frang,body_timeout); - TEST_RUN(frang,hdr_timeout); + TEST_RUN (frang, req_count); + TEST_RUN (frang, max_conn); + TEST_RUN (frang, uri); + TEST_RUN (frang, body_len); + TEST_RUN (frang, ct_check); + TEST_RUN (frang, field_len); + TEST_RUN (frang, host); + TEST_RUN (frang, req_method); + TEST_RUN (frang, chunk_cnt); + TEST_RUN (frang, body_timeout); + TEST_RUN (frang, hdr_timeout); } From eab5a9c6c2c40c2354bed7dc3c13f71545010f24 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 9 Oct 2015 12:14:40 +0300 Subject: [PATCH 08/11] editf2 --- tempesta_fw/t/unit/test_frang.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tempesta_fw/t/unit/test_frang.c b/tempesta_fw/t/unit/test_frang.c index 4be7c13004..1cafad99a2 100644 --- a/tempesta_fw/t/unit/test_frang.c +++ b/tempesta_fw/t/unit/test_frang.c @@ -234,24 +234,24 @@ frang_cfg->conn_burst = 5; TEST (frang, uri) { - TfwHttpReq *mockReq; - TfwStr uri; - mockReq = test_req_alloc (26); - tfw_http_parse_req (mockReq, "GET /index.html HTTP /1.1", 25); - if (!frang_cfg) - { - frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); - } + TfwHttpReq *mockReq; + TfwStr uri; + mockReq = test_req_alloc (26); + tfw_http_parse_req(mockReq, "GET /index.html HTTP /1.1", 25); + if (!frang_cfg) + { + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } - frang_cfg->http_uri_len = 5; + frang_cfg->http_uri_len = 5; - uri.len = 17; - uri.ptr = (void *) "/home/index.html"; - uri.flags = TFW_STR_COMPLETE; - mockReq->uri_path = uri; - mockReq->frang_st = 3; - res = req_handler (mockReq); - EXPECT_EQ (TFW_BLOCK, res); + uri.len = 17; + uri.ptr = (void *) "/home/index.html"; + uri.flags = TFW_STR_COMPLETE; + mockReq->uri_path = uri; + mockReq->frang_st = 3; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } TEST (frang, ct_check) From 81762b019c8ba4c4ea072a94b5409b073fe16b08 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 9 Oct 2015 14:55:28 +0300 Subject: [PATCH 09/11] editf3 --- tempesta_fw/t/unit/sched_helper.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tempesta_fw/t/unit/sched_helper.c b/tempesta_fw/t/unit/sched_helper.c index c18fcb9ff0..dcee3ba5f4 100644 --- a/tempesta_fw/t/unit/sched_helper.c +++ b/tempesta_fw/t/unit/sched_helper.c @@ -99,23 +99,17 @@ TfwSrvConnection * test_create_conn(TfwPeer *peer) { void (*tfw_connection_link_peer)(TfwConnection *conn,TfwPeer *peer); - static struct sock __test_sock = { .sk_state = TCP_ESTABLISHED, }; TfwSrvConnection *srv_conn; - tfw_connection_link_peer = get_sym_ptr("tfw_connection_link_peer"); - - - if(!tfw_connection_link_peer) - TFW_DBG("sched_help: link_peer ptr null\n"); BUG_ON(tfw_srv_conn_alloc_ptr == NULL); srv_conn = tfw_srv_conn_alloc_ptr(); BUG_ON(!srv_conn); - + BUG_ON(tfw_connection_link_peer == NULL); tfw_connection_link_peer(&srv_conn->conn, peer); srv_conn->conn.sk = &__test_sock; From a0b9d9734bf504946f1624a284572bf750de6c95 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 9 Oct 2015 16:07:50 +0300 Subject: [PATCH 10/11] editf4 --- tempesta_fw/t/unit/test_frang.c | 118 ++++++++++++++------------------ 1 file changed, 52 insertions(+), 66 deletions(-) diff --git a/tempesta_fw/t/unit/test_frang.c b/tempesta_fw/t/unit/test_frang.c index 1cafad99a2..a4cb382fe8 100644 --- a/tempesta_fw/t/unit/test_frang.c +++ b/tempesta_fw/t/unit/test_frang.c @@ -174,11 +174,10 @@ req_handler (TfwHttpReq * req) frang_http_req_handler = get_sym_ptr ("frang_http_req_handler"); - if (!frang_http_req_handler_ptr) - { - FW_DBG ("frang_req_handleris null str:%d\n", 392); + if (!frang_http_req_handler){ + TFW_DBG("frang_req_handleris null str:%d\n", 392); } - return frang_http_req_handler ((void *) conn, + return frang_http_req_handler((void *) conn, req->msg.skb_list.first, 25); } @@ -256,74 +255,68 @@ TEST (frang, uri) TEST (frang, ct_check) { - TfwHttpReq *mockReq; - FrangCtVal ctval[1]; - - mockReq = test_req_alloc (22); - tfw_http_parse_req (mockReq, "POST /foo HTTP/1.1\r\n", 20); - TFW_DBG ("ct_check:%s;%lu\n", "after parse req req:", - (unsigned long) mockReq); - if (!frang_cfg) - { - rang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); - } - ctval[0].len = 17; - ctval[0].str = "application/html"; - frang_cfg->http_ct_required = true; - res = req_handler (mockReq); - EXPECT_EQ (TFW_BLOCK, res); + TfwHttpReq *mockReq; + FrangCtVal ctval[1]; + mockReq = test_req_alloc (22); + tfw_http_parse_req (mockReq, "POST /foo HTTP/1.1\r\n", 20); + if (!frang_cfg){ + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } + ctval[0].len = 17; + ctval[0].str = "application/html"; + frang_cfg->http_ct_required = true; + res = req_handler (mockReq); + /*ct_vals*/ + EXPECT_EQ (TFW_BLOCK, res); mockReq->frang_st = 9; - res = req_handler (mockReq); - EXPECT_EQ (TFW_BLOCK, res); + res = req_handler (mockReq); + /*ct_required*/ + EXPECT_EQ (TFW_BLOCK, res); } TEST (frang, req_method) { - TfwHttpReq *mockReq; - mockReq = test_req_alloc (17); - tfw_http_parse_req (mockReq, "PUT /index.html", 16); - if (!frang_cfg) - { - frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); - } + TfwHttpReq *mockReq; + mockReq = test_req_alloc (17); + tfw_http_parse_req (mockReq, "PUT /index.html", 16); + if (!frang_cfg){ + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } - frang_cfg->http_methods_mask = 2; - res = req_handler (mockReq); - EXPECT_EQ (TFW_BLOCK, res); + frang_cfg->http_methods_mask = 2; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } TEST (frang, field_len) { - TfwHttpReq *mockReq; - mockReq = test_req_alloc (20); - tfw_http_parse_req (mockReq, "GET /foo HTTP/1.1\r\n", 19); + TfwHttpReq *mockReq; + mockReq = test_req_alloc (20); + tfw_http_parse_req(mockReq, "GET /foo HTTP/1.1\r\n", 19); - if (!frang_cfg) - { - frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); - } - frang_cfg->http_field_len = 3; - res = req_handler (mockReq); - EXPECT_EQ (TFW_BLOCK, res); + if (!frang_cfg){ + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } + frang_cfg->http_field_len = 3; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } TEST (frang, host) { - TfwHttpReq *mockReq; - mockReq = test_req_alloc (7); - tfw_http_parse_req (mockReq, "GET /foo HTTP/1.1\r\n", 19); + TfwHttpReq *mockReq; + mockReq = test_req_alloc (7); + tfw_http_parse_req(mockReq, "GET /foo HTTP/1.1\r\n", 19); - if (!frang_cfg) - { - frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); - } - frang_cfg->http_host_required = true; - res = req_handler (mockReq); - EXPECT_EQ (TFW_BLOCK, res); + if (!frang_cfg){ + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } + frang_cfg->http_host_required = true; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } -static int (*frang_req_limit_ptr) (FrangAcc * ra, struct sock * sk); TEST (frang, req_count) { TfwConnection mockConn; @@ -332,15 +325,9 @@ TEST (frang, req_count) FrangAcc *ra; mockReq = test_req_alloc (17); tfw_http_parse_req (mockReq, "GET / HTTP/1.1\r\n", 16); - if (!frang_cfg) - { - frang_cfg = get_sym_ptr ("frang_cfg"); - } - frang_req_limit_ptr = get_sym_ptr ("frang_req_limit"); - if (!frang_req_limit_ptr) - { - TFW_DBG ("req_count:%s;\n", "req_limit ptr is null"); - } + if (!frang_cfg){ + frang_cfg = get_sym_ptr ("frang_cfg"); + } frang_cfg->conn_max = 0; frang_cfg->conn_burst = 0; frang_cfg->conn_rate = 0; @@ -431,10 +418,9 @@ TEST (frang, hdr_timeout) mockReq = test_req_alloc (62); tfw_http_parse_req (mockReq, "POST http://natsys-lab.com/foo HTTP/1.1\r\n \ Content-Length:29\r\n", 61); - if (!frang_cfg) - { - rang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); - } + if (!frang_cfg){ + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } frang_cfg->clnt_body_timeout = 0; frang_cfg->clnt_hdr_timeout = 1; From d6ad761e16de577cf9e9e515e8fc0512ca977d9e Mon Sep 17 00:00:00 2001 From: root Date: Fri, 9 Oct 2015 16:54:01 +0300 Subject: [PATCH 11/11] editf5 --- tempesta_fw/t/unit/test_frang.c | 219 +++++++++++++++----------------- 1 file changed, 99 insertions(+), 120 deletions(-) diff --git a/tempesta_fw/t/unit/test_frang.c b/tempesta_fw/t/unit/test_frang.c index a4cb382fe8..d9ca94d8b8 100644 --- a/tempesta_fw/t/unit/test_frang.c +++ b/tempesta_fw/t/unit/test_frang.c @@ -257,7 +257,6 @@ TEST (frang, ct_check) { TfwHttpReq *mockReq; FrangCtVal ctval[1]; - mockReq = test_req_alloc (22); tfw_http_parse_req (mockReq, "POST /foo HTTP/1.1\r\n", 20); if (!frang_cfg){ @@ -269,7 +268,7 @@ TEST (frang, ct_check) res = req_handler (mockReq); /*ct_vals*/ EXPECT_EQ (TFW_BLOCK, res); - mockReq->frang_st = 9; + mockReq->frang_st = 9; res = req_handler (mockReq); /*ct_required*/ EXPECT_EQ (TFW_BLOCK, res); @@ -319,150 +318,130 @@ TEST (frang, host) TEST (frang, req_count) { - TfwConnection mockConn; - unsigned long ts; - TfwHttpReq *mockReq; - FrangAcc *ra; - mockReq = test_req_alloc (17); - tfw_http_parse_req (mockReq, "GET / HTTP/1.1\r\n", 16); + TfwConnection mockConn; + unsigned long ts; + TfwHttpReq *mockReq; + FrangAcc *ra; + mockReq = test_req_alloc (17); + tfw_http_parse_req (mockReq, "GET / HTTP/1.1\r\n", 16); if (!frang_cfg){ - frang_cfg = get_sym_ptr ("frang_cfg"); + frang_cfg = get_sym_ptr ("frang_cfg"); } - frang_cfg->conn_max = 0; - frang_cfg->conn_burst = 0; - frang_cfg->conn_rate = 0; - frang_cfg->req_rate = 5; - isk = (struct inet_sock *) (&mockSock); - isk->inet_saddr = htonl (in_aton (inet_addr)); - - mockConn.sk = &mockSock; - - frang_conn_new = get_sym_ptr ("frang_conn_new"); - res = frang_conn_new (&mockSock); - ra = mockConn.sk->sk_security; - - ts = jiffies * FRANG_FREQ / HZ; - i = ts % FRANG_FREQ; - ra->history[i].req = 5; - if (!frang_conn_new) - { - TFW_DBG ("frang_req_count507:%s\n", "conn_new ptr is null"); - } - mockSock.sk_security = ra; - mockReq->frang_st = 0; - res = req_handler (mockReq); - EXPECT_EQ (TFW_BLOCK, res); - frang_cfg->req_rate = 5; - frang_cfg->req_burst = 5; - ra->history[i].req = 5; - TFW_DBG ("frang_req_count 517:%s\n", "conn_new ptr is null"); - - mockSock.sk_security = ra; - mockReq->frang_st = 0; - - res = req_handler (mockReq); - EXPECT_EQ (TFW_BLOCK, res); + frang_cfg->conn_max = 0; + frang_cfg->conn_burst = 0; + frang_cfg->conn_rate = 0; + frang_cfg->req_rate = 5; + isk = (struct inet_sock *) (&mockSock); + isk->inet_saddr = htonl (in_aton (inet_addr)); + mockConn.sk = &mockSock; + frang_conn_new = get_sym_ptr ("frang_conn_new"); + res = frang_conn_new (&mockSock); + ra = mockConn.sk->sk_security; + ts = jiffies * FRANG_FREQ / HZ; + i = ts % FRANG_FREQ; + ra->history[i].req = 5; + mockSock.sk_security = ra; + mockReq->frang_st = 0; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); + frang_cfg->req_rate = 5; + frang_cfg->req_burst = 5; + ra->history[i].req = 5; + mockSock.sk_security = ra; + mockReq->frang_st = 0; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } TEST (frang, body_len) { - TfwHttpReq *mockReq; - TfwStr body; - TfwStr crlf; - mockReq = test_req_alloc (22); - - tfw_http_parse_req (mockReq, "POST /foo HTTP/1.1\r\n", 20); - - body.ptr = "GET http://natsys-lab.com/foo"; - body.len = 29; - crlf.len = 2; - crlf.ptr = "\r\n"; - - mockReq->crlf = crlf; - - mockReq->body.len = 29; - if (!frang_cfg) - { - frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); - } - - - frang_cfg->http_body_len = 3; - mockReq->frang_st = 0; - - res = req_handler (mockReq); - EXPECT_EQ (TFW_BLOCK, res); + TfwHttpReq *mockReq; + TfwStr body; + TfwStr crlf; + mockReq = test_req_alloc (22); + tfw_http_parse_req (mockReq, "POST /foo HTTP/1.1\r\n", 20); + body.ptr = "GET http://natsys-lab.com/foo"; + body.len = 29; + crlf.len = 2; + crlf.ptr = "\r\n"; + mockReq->crlf = crlf; + mockReq->body.len = 29; + if (!frang_cfg){ + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } + frang_cfg->http_body_len = 3; + mockReq->frang_st = 0; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } TEST (frang, body_timeout) { - TfwHttpReq *mockReq; - mockReq = test_req_alloc (62); - tfw_http_parse_req (mockReq, "POST http://natsys-lab.com/foo HTTP/1.1\r\n \ + TfwHttpReq *mockReq; + mockReq = test_req_alloc (62); + tfw_http_parse_req(mockReq, "POST http://natsys-lab.com/foo HTTP/1.1\r\n \ Content-Length:29\r\n", 61); - if (!frang_cfg) - { - frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); - } + if (!frang_cfg){ + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } - frang_cfg->clnt_body_timeout = 1; - mockReq->frang_st = 12; - mockReq->tm_bchunk = jiffies - 100; - res = req_handler (mockReq); - EXPECT_EQ (TFW_BLOCK, res); + frang_cfg->clnt_body_timeout = 1; + mockReq->frang_st = 12; + mockReq->tm_bchunk = jiffies - 100; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } TEST (frang, hdr_timeout) { - TfwHttpReq *mockReq; - mockReq = test_req_alloc (62); - tfw_http_parse_req (mockReq, "POST http://natsys-lab.com/foo HTTP/1.1\r\n \ -Content-Length:29\r\n", 61); + TfwHttpReq *mockReq; + mockReq = test_req_alloc (62); + tfw_http_parse_req (mockReq, "POST http://natsys-lab.com/foo HTTP/1.1\r\n \ + Content-Length:29\r\n", 61); if (!frang_cfg){ frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); } - frang_cfg->clnt_body_timeout = 0; - frang_cfg->clnt_hdr_timeout = 1; - mockReq->frang_st = 0; - mockReq->tm_header = jiffies - 100; - res = req_handler (mockReq); - EXPECT_EQ (TFW_BLOCK, res); + frang_cfg->clnt_body_timeout = 0; + frang_cfg->clnt_hdr_timeout = 1; + mockReq->frang_st = 0; + mockReq->tm_header = jiffies - 100; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } TEST (frang, chunk_cnt) { - TfwHttpReq *mockReq; - mockReq = test_req_alloc (62); - tfw_http_parse_req (mockReq, "POST http://natsys-lab.com/foo HTTP/1.1\r\n \ -Content-Length:29\r\n", 61); - if (!frang_cfg) - { - frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); - } - frang_cfg->http_hchunk_cnt = 1; - mockReq->chunk_cnt = 3; - mockReq->frang_st = 0; - res = req_handler (mockReq); - EXPECT_EQ (TFW_BLOCK, res); - frang_cfg->http_hchunk_cnt = 0; - frang_cfg->http_bchunk_cnt = 1; - mockReq->chunk_cnt = 3; - res = req_handler (mockReq); - EXPECT_EQ (TFW_BLOCK, res); + TfwHttpReq *mockReq; + mockReq = test_req_alloc (62); + tfw_http_parse_req (mockReq, "POST http://natsys-lab.com/foo HTTP/1. 1\r\n \ + Content-Length:29\r\n", 61); + if (!frang_cfg){ + frang_cfg = (FrangCfg *) get_sym_ptr ("frang_cfg"); + } + frang_cfg->http_hchunk_cnt = 1; + mockReq->chunk_cnt = 3; + mockReq->frang_st = 0; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); + frang_cfg->http_hchunk_cnt = 0; + frang_cfg->http_bchunk_cnt = 1; + mockReq->chunk_cnt = 3; + res = req_handler (mockReq); + EXPECT_EQ (TFW_BLOCK, res); } TEST_SUITE (frang) { - TEST_RUN (frang, req_count); - TEST_RUN (frang, max_conn); - TEST_RUN (frang, uri); - TEST_RUN (frang, body_len); - TEST_RUN (frang, ct_check); - TEST_RUN (frang, field_len); - TEST_RUN (frang, host); - TEST_RUN (frang, req_method); - TEST_RUN (frang, chunk_cnt); - TEST_RUN (frang, body_timeout); - TEST_RUN (frang, hdr_timeout); + TEST_RUN (frang, req_count); + TEST_RUN (frang, max_conn); + TEST_RUN (frang, uri); + TEST_RUN (frang, body_len); + TEST_RUN (frang, ct_check); + TEST_RUN (frang, field_len); + TEST_RUN (frang, host); + TEST_RUN (frang, req_method); + TEST_RUN (frang, chunk_cnt); + TEST_RUN (frang, body_timeout); + TEST_RUN (frang, hdr_timeout); }