Skip to content

Commit

Permalink
migrate tfw_sched_match to the new http_match API
Browse files Browse the repository at this point in the history
related to:
#5 - Load balancing
  • Loading branch information
vdmit11 committed Oct 8, 2014
1 parent d7f171c commit a062b86
Show file tree
Hide file tree
Showing 14 changed files with 906 additions and 1,207 deletions.
4 changes: 2 additions & 2 deletions tempesta.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
SSOCKET=sync_socket
TDB=tempesta_db
TFW=tempesta_fw
SCHED=dummy
SCHED=http
TFW_ROOT=`pwd`/$TFW
TFW_CACHE_SIZE=`expr 256 \* 1024`
TFW_CACHE_PATH=$TFW_ROOT/cache
Expand Down Expand Up @@ -45,7 +45,7 @@ start()
cache_path="$TFW_CACHE_PATH"
[ $? -ne 0 ] && error "cannot load tempesta module"

insmod $TFW_ROOT/sched/$SCHED/*.ko
insmod $TFW_ROOT/sched/tfw_sched_${SCHED}.ko
[ $? -ne 0 ] && error "cannot load scheduler module"

sysctl --load=tempesta.sysctl.conf
Expand Down
58 changes: 33 additions & 25 deletions tempesta_fw/http_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ match_uri_eq(const TfwHttpReq *req, const TfwMatchArg *arg)
* - Characters other than those in the "reserved" and "unsafe"
* sets (see RFC 2396) are equivalent to their ""%" HEX HEX" encoding.
*/
return tfw_str_eq_cstr_ci(&req->uri, arg->str.s, arg->str.len);
return tfw_str_eq_cstr_ci(&req->uri, arg->str, arg->len);
}

static bool
match_uri_prefix(const TfwHttpReq *req, const TfwMatchArg *arg)
{
return tfw_str_startswith_cstr_ci(&req->uri, arg->str.s, arg->str.len);
return tfw_str_startswith_cstr_ci(&req->uri, arg->str, arg->len);
}

static bool
Expand All @@ -54,7 +54,7 @@ match_host_eq(const TfwHttpReq *req, const TfwMatchArg *arg)
* URI or Host header (the header is used if URI is not absolute).
* - Empty port and default port (80) are equal when comparing URIs.
*/
return tfw_str_eq_cstr_ci(&req->host, arg->str.s, arg->str.len);
return tfw_str_eq_cstr_ci(&req->host, arg->str, arg->len);
}

static bool
Expand All @@ -67,7 +67,7 @@ match_headers(const TfwHttpReq *req, const TfwMatchArg *arg,

for (i = 0; i < tbl->size; ++i) {
hdr = &tbl->tbl[i].field;
if (cmp_fn(hdr, arg->str.s, arg->str.len))
if (cmp_fn(hdr, arg->str, arg->len))
return true;
}

Expand Down Expand Up @@ -144,6 +144,28 @@ tfw_http_match_req(const TfwHttpReq *req, const TfwHttpMatchList *mlst)
}
EXPORT_SYMBOL(tfw_http_match_req);

TfwHttpMatchRule *
tfw_http_match_rule_new(TfwHttpMatchList *mlst, size_t arg_len)
{
TfwHttpMatchRule *rule;
size_t size = TFW_HTTP_MATCH_RULE_SIZE(arg_len);

BUG_ON(!mlst || !mlst->pool);

rule = tfw_pool_alloc(mlst->pool, size);
if (!rule) {
TFW_ERR("Can't allocate a rule for match list: %p\n", mlst);
return NULL;
}

memset(rule, 0, size);
INIT_LIST_HEAD(&rule->list);
list_add_tail(&rule->list, &mlst->list);

return rule;
}
EXPORT_SYMBOL(tfw_http_match_rule_new);

TfwHttpMatchList *
tfw_http_match_list_alloc(void)
{
Expand All @@ -164,29 +186,15 @@ EXPORT_SYMBOL(tfw_http_match_list_alloc);
void
tfw_http_match_list_free(TfwHttpMatchList *mlst)
{
BUG_ON(!mlst || !mlst->pool);
tfw_pool_free(mlst->pool);
if (mlst)
tfw_pool_free(mlst->pool);
}
EXPORT_SYMBOL(tfw_http_match_list_free);

TfwHttpMatchRule *
tfw_http_match_rule_new(TfwHttpMatchList *mlst, size_t extra_len)
void
tfw_http_match_list_rcu_free(struct rcu_head *r)
{
TfwHttpMatchRule *rule;
size_t size = sizeof(*rule) + extra_len;

BUG_ON(!mlst || !mlst->pool);

rule = tfw_pool_alloc(mlst->pool, size);
if (!rule) {
TFW_ERR("Can't allocate a rule for match list: %p\n", mlst);
return NULL;
}

memset(rule, 0, size);
INIT_LIST_HEAD(&rule->list);
list_add_tail(&rule->list, &mlst->list);

return rule;
TfwHttpMatchList *l = container_of(r, TfwHttpMatchList, rcu);
tfw_pool_free(l->pool);
}
EXPORT_SYMBOL(tfw_http_match_rule_new);
EXPORT_SYMBOL(tfw_http_match_list_rcu_free);
33 changes: 20 additions & 13 deletions tempesta_fw/http_match.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define __TFW_HTTP_MATCH_H__

#include <linux/list.h>
#include <linux/rcupdate.h>

#include "pool.h"
#include "http.h"
Expand All @@ -42,34 +43,40 @@ typedef enum {
} tfw_http_match_op_t;

typedef struct {
short len;
const char *s;
} TfwMatchArgStr;

typedef union {
unsigned char method;
TfwAddr addr;
TfwMatchArgStr str;
short len; /* Actual amount of memory allocated for the union below. */
union {
unsigned char method;
TfwAddr addr;
char str[0];
};
} TfwMatchArg;

typedef struct {
struct list_head list;
tfw_http_match_fld_t field;
tfw_http_match_op_t op;
TfwMatchArg arg;
char extra[0]; /* May be consumed for variable-length @arg. */
} TfwHttpMatchRule;

#define TFW_HTTP_MATCH_RULE_SIZE(arg_len) \
(offsetof(TfwHttpMatchRule, arg.str) + arg_len)

#define TFW_HTTP_MATCH_CONT_SIZE(container_struct_name, arg_len) \
(sizeof(container_struct_name) - sizeof(TfwHttpMatchRule) \
+ TFW_HTTP_MATCH_RULE_SIZE(arg_len))

typedef struct {
struct list_head list;
TfwPool *pool;
struct rcu_head rcu;
} TfwHttpMatchList;


TfwHttpMatchList *tfw_http_match_list_alloc(void);
void tfw_http_match_list_free(TfwHttpMatchList *);
TfwHttpMatchRule *tfw_http_match_rule_new(TfwHttpMatchList *, size_t extra_len);
TfwHttpMatchRule * tfw_http_match_req(const TfwHttpReq *, const TfwHttpMatchList *);
void tfw_http_match_list_rcu_free(struct rcu_head *);
TfwHttpMatchRule *tfw_http_match_req(const TfwHttpReq *, const TfwHttpMatchList *);
TfwHttpMatchRule *tfw_http_match_rule_new(TfwHttpMatchList *, size_t arg_len);

#define tfw_http_match_req_entry(req, mlst, container, member) \
({ \
Expand All @@ -80,9 +87,9 @@ TfwHttpMatchRule * tfw_http_match_req(const TfwHttpReq *, const TfwHttpMatchList
_c; \
})

#define tfw_http_match_entry_new(mlst, container, member, extra_len) \
#define tfw_http_match_entry_new(mlst, container, member, arg_len) \
({ \
size_t _s = sizeof(container) + (extra_len); \
size_t _s = TFW_HTTP_MATCH_CONT_SIZE(container, arg_len); \
container *_c = tfw_pool_alloc((mlst)->pool, _s); \
if (!_c) { \
TFW_ERR("Can't allocate memory from pool\n"); \
Expand Down
5 changes: 4 additions & 1 deletion tempesta_fw/sched/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
# this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.

obj-m = dummy/ rr/ match/
EXTRA_CFLAGS = -I$(src)/../ -I$(src)/../../tempesta_db -I$(src)/../../sync_socket

EXTRA_CFLAGS += -Og -g3 -DDEBUG

obj-m = tfw_sched_dummy.o tfw_sched_rr.o tfw_sched_http.o
21 changes: 0 additions & 21 deletions tempesta_fw/sched/dummy/Makefile

This file was deleted.

22 changes: 0 additions & 22 deletions tempesta_fw/sched/match/Makefile

This file was deleted.

Loading

0 comments on commit a062b86

Please sign in to comment.