Skip to content

Commit

Permalink
Merge pull request #1000 from tempesta-tech/ao-166
Browse files Browse the repository at this point in the history
Fix #166: transition to standard skb linkage inside TempstaFW.
  • Loading branch information
aleksostapenko committed Apr 14, 2018
2 parents 881466a + a83be28 commit 6de9198
Show file tree
Hide file tree
Showing 20 changed files with 391 additions and 569 deletions.
538 changes: 189 additions & 349 deletions linux-4.9.35.patch → linux-4.14.32.patch

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tempesta_db/core/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ tempesta_map_file(struct file *file, unsigned long len, int node)
oldfs = get_fs();
set_fs(get_ds());

addr = vfs_read(file, (char *)ma->start, len, &off);
addr = kernel_read(file, (char *)ma->start, len, &off);
if (addr != len) {
TDB_ERR("Cannot read %lu bytes to addr %p, ret = %ld\n",
len, (void *)ma->start, addr);
Expand Down Expand Up @@ -242,7 +242,7 @@ tempesta_unmap_file(struct file *file, unsigned long addr, unsigned long len,
oldfs = get_fs();
set_fs(get_ds());

r = vfs_write(file, (void *)ma->start, len, &off);
r = kernel_write(file, (void *)ma->start, len, &off);
if (r != len) {
TDB_WARN("Cannot sync mapping %lx of size %lu pages\n",
ma->start, ma->pages);
Expand Down
3 changes: 2 additions & 1 deletion tempesta_db/core/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ tdb_if_check_tblname(const TdbMsg *m)
}

static int
tdb_if_proc_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
tdb_if_proc_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
struct netlink_ext_ack *extack)
{
TdbMsg *m;

Expand Down
4 changes: 2 additions & 2 deletions tempesta_fw/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1451,15 +1451,15 @@ tfw_cache_build_resp_body(TDB *db, TfwHttpResp *resp, TdbVRec *trec,
if (it->frag >= MAX_SKB_FRAGS - 1) {
if (!(it->skb = ss_skb_alloc()))
return -ENOMEM;
ss_skb_queue_tail(&resp->msg.skb_list, it->skb);
ss_skb_queue_tail(&resp->msg.skb_head, it->skb);
it->frag = 0;
}

while (1) {
if (it->frag == MAX_SKB_FRAGS) {
if (!(it->skb = ss_skb_alloc()))
return -ENOMEM;
ss_skb_queue_tail(&resp->msg.skb_list, it->skb);
ss_skb_queue_tail(&resp->msg.skb_head, it->skb);
it->frag = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions tempesta_fw/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1612,8 +1612,8 @@ tfw_cfg_read_file(const char *path, size_t *file_size)
do {
TFW_DBG3("read by offset: %d\n", (int)offset);
read_size = min((size_t)(buf_size - offset), PAGE_SIZE);
bytes_read = vfs_read(fp, out_buf + offset, read_size, \
&offset);
bytes_read = kernel_read(fp, out_buf + offset, read_size,
&offset);
if (bytes_read < 0) {
TFW_ERR_NL("can't read file: %s (err: %zu)\n", path,
bytes_read);
Expand Down
2 changes: 1 addition & 1 deletion tempesta_fw/classifier/frang.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ frang_http_req_process(FrangAcc *ra, TfwConn *conn, const TfwFsmData *data)
int r = TFW_PASS;
TfwHttpReq *req = (TfwHttpReq *)data->req;
struct sk_buff *skb = data->skb;
struct sk_buff *head_skb = ss_skb_peek(&req->msg.skb_list);
struct sk_buff *head_skb = req->msg.skb_head;
__FRANG_FSM_INIT();

BUG_ON(!ra);
Expand Down
21 changes: 19 additions & 2 deletions tempesta_fw/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,23 @@ static struct nf_hook_ops tfw_nf_ops[] __read_mostly = {
},
};

static int
tfw_nf_register(struct net *net)
{
return nf_register_net_hooks(net, tfw_nf_ops, ARRAY_SIZE(tfw_nf_ops));
}

static void
tfw_nf_unregister(struct net *net)
{
nf_unregister_net_hooks(net, tfw_nf_ops, ARRAY_SIZE(tfw_nf_ops));
}

static struct pernet_operations tfw_net_ops = {
.init = tfw_nf_register,
.exit = tfw_nf_unregister,
};

static int
tfw_filter_start(void)
{
Expand All @@ -283,7 +300,7 @@ tfw_filter_start(void)
if (!ip_filter_db)
return -EINVAL;

if ((r = nf_register_hooks(tfw_nf_ops, ARRAY_SIZE(tfw_nf_ops)))) {
if ((r = register_pernet_subsys(&tfw_net_ops))) {
TFW_ERR_NL("can't register netfilter hooks\n");
tdb_close(ip_filter_db);
return r;
Expand All @@ -298,7 +315,7 @@ tfw_filter_stop(void)
if (tfw_runstate_is_reconfig())
return;
if (ip_filter_db) {
nf_unregister_hooks(tfw_nf_ops, ARRAY_SIZE(tfw_nf_ops));
unregister_pernet_subsys(&tfw_net_ops);
tdb_close(ip_filter_db);
}
}
Expand Down
10 changes: 5 additions & 5 deletions tempesta_fw/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,7 @@ tfw_http_conn_drop(TfwConn *conn)
static int
tfw_http_conn_send(TfwConn *conn, TfwMsg *msg)
{
return ss_send(conn->sk, &msg->skb_list, msg->ss_flags);
return ss_send(conn->sk, &msg->skb_head, msg->ss_flags);
}

/**
Expand Down Expand Up @@ -1897,7 +1897,7 @@ tfw_http_msg_create_sibling(TfwHttpMsg *hm, struct sk_buff **skb,
tfw_http_conn_msg_free(shm);
return NULL;
}
ss_skb_queue_tail(&shm->msg.skb_list, nskb);
ss_skb_queue_tail(&shm->msg.skb_head, nskb);
*skb = nskb;

return shm;
Expand Down Expand Up @@ -2037,7 +2037,7 @@ tfw_http_add_x_forwarded_for(TfwHttpMsg *hm)
int r;
char *p, *buf = *this_cpu_ptr(&g_buf);

p = ss_skb_fmt_src_addr(hm->msg.skb_list.first, buf);
p = ss_skb_fmt_src_addr(hm->msg.skb_head, buf);

r = tfw_http_msg_hdr_xfrm(hm, "X-Forwarded-For",
sizeof("X-Forwarded-For") - 1, buf, p - buf,
Expand Down Expand Up @@ -3052,7 +3052,7 @@ tfw_http_resp_terminate(TfwHttpMsg *hm)
* sent to the client. The full skb->len is used as the
* offset to mark this case in the post-processing phase.
*/
data.skb = ss_skb_peek_tail(&hm->msg.skb_list);
data.skb = ss_skb_peek_tail(&hm->msg.skb_head);
BUG_ON(!data.skb);
data.off = data.skb->len;
data.req = NULL;
Expand Down Expand Up @@ -3285,7 +3285,7 @@ tfw_http_msg_process(void *conn, const TfwFsmData *data)
}

TFW_DBG2("Add skb %p to message %p\n", data->skb, c->msg);
ss_skb_queue_tail(&c->msg->skb_list, data->skb);
ss_skb_queue_tail(&c->msg->skb_head, data->skb);

return (TFW_CONN_TYPE(c) & Conn_Clnt)
? tfw_http_req_process(c, data)
Expand Down
27 changes: 13 additions & 14 deletions tempesta_fw/http_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ tfw_http_msg_hdr_open(TfwHttpMsg *hm, unsigned char *hdr_start)
BUG_ON(!TFW_STR_EMPTY(hdr));

hdr->ptr = hdr_start;
hdr->skb = ss_skb_peek_tail(&hm->msg.skb_list);
hdr->skb = ss_skb_peek_tail(&hm->msg.skb_head);

BUG_ON(!hdr->skb);

Expand Down Expand Up @@ -482,8 +482,8 @@ __hdr_add(TfwHttpMsg *hm, const TfwStr *hdr, unsigned int hid)
TfwStr it = {};
TfwStr *h = TFW_STR_CHUNK(&hm->crlf, 0);

r = ss_skb_get_room(&hm->msg.skb_list, hm->crlf.skb,
h->ptr, tfw_str_total_len(hdr), &it);
r = ss_skb_get_room(hm->msg.skb_head, hm->crlf.skb, h->ptr,
tfw_str_total_len(hdr), &it);
if (r)
return r;

Expand Down Expand Up @@ -519,8 +519,7 @@ __hdr_expand(TfwHttpMsg *hm, TfwStr *orig_hdr, const TfwStr *hdr, bool append)
BUG_ON(!append && (hdr->len < orig_hdr->len));

h = TFW_STR_LAST(orig_hdr);
r = ss_skb_get_room(&hm->msg.skb_list,
h->skb, (char *)h->ptr + h->len,
r = ss_skb_get_room(hm->msg.skb_head, h->skb, (char *)h->ptr + h->len,
append ? hdr->len : hdr->len - orig_hdr->len, &it);
if (r)
return r;
Expand All @@ -545,8 +544,8 @@ __hdr_del(TfwHttpMsg *hm, unsigned int hid)

/* Delete the underlying data. */
TFW_STR_FOR_EACH_DUP(dup, hdr, end) {
if (ss_skb_cutoff_data(&hm->msg.skb_list,
dup, 0, tfw_str_eolen(dup)))
if (ss_skb_cutoff_data(hm->msg.skb_head, dup, 0,
tfw_str_eolen(dup)))
return TFW_BLOCK;
};

Expand Down Expand Up @@ -588,7 +587,7 @@ __hdr_sub(TfwHttpMsg *hm, const TfwStr *hdr, unsigned int hid)
* adjustment is needed.
*/
if (dst->len != hdr->len
&& ss_skb_cutoff_data(&hm->msg.skb_list, dst, hdr->len, 0))
&& ss_skb_cutoff_data(hm->msg.skb_head, dst, hdr->len, 0))
return TFW_BLOCK;
if (tfw_strcpy(dst, hdr))
return TFW_BLOCK;
Expand All @@ -602,8 +601,8 @@ __hdr_sub(TfwHttpMsg *hm, const TfwStr *hdr, unsigned int hid)
cleanup:
TFW_STR_FOR_EACH_DUP(tmp, orig_hdr, end) {
if (tmp != dst
&& ss_skb_cutoff_data(&hm->msg.skb_list,
tmp, 0, tfw_str_eolen(tmp)))
&& ss_skb_cutoff_data(hm->msg.skb_head, tmp, 0,
tfw_str_eolen(tmp)))
return TFW_BLOCK;
}

Expand Down Expand Up @@ -771,7 +770,7 @@ __msg_alloc_skb_data(TfwHttpMsg *hm, size_t len)
skb = ss_skb_alloc_pages(min(len, SS_SKB_MAX_DATA_LEN));
if (!skb)
return -ENOMEM;
ss_skb_queue_tail(&hm->msg.skb_list, skb);
ss_skb_queue_tail(&hm->msg.skb_head, skb);
}

return 0;
Expand Down Expand Up @@ -803,7 +802,7 @@ tfw_http_msg_setup(TfwHttpMsg *hm, TfwMsgIter *it, size_t data_len)
if ((ret = __msg_alloc_skb_data(hm, data_len)))
return ret;

it->skb = ss_skb_peek(&hm->msg.skb_list);
it->skb = hm->msg.skb_head;
it->frag = 0;

BUG_ON(!it->skb);
Expand Down Expand Up @@ -949,7 +948,7 @@ tfw_http_msg_free(TfwHttpMsg *m)
return;

tfw_http_msg_unpair(m);
ss_skb_queue_purge(&m->msg.skb_list);
ss_skb_queue_purge(&m->msg.skb_head);

if (m->destructor)
m->destructor(m);
Expand Down Expand Up @@ -1000,7 +999,7 @@ __tfw_http_msg_alloc(int type, bool full)
tfw_http_init_parser_resp((TfwHttpResp *)hm);
}

ss_skb_queue_head_init(&hm->msg.skb_list);
hm->msg.skb_head = NULL;

if (type & Conn_Clnt) {
INIT_LIST_HEAD(&hm->msg.seq_list);
Expand Down
4 changes: 2 additions & 2 deletions tempesta_fw/http_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ __tfw_http_msg_set_str_data(TfwStr *str, void *data, struct sk_buff *skb)
}
#define tfw_http_msg_set_str_data(hm, str, data) \
__tfw_http_msg_set_str_data(str, data, \
ss_skb_peek_tail(&hm->msg.skb_list))
ss_skb_peek_tail(&hm->msg.skb_head))

void __http_msg_hdr_val(TfwStr *hdr, unsigned id, TfwStr *val, bool client);

Expand Down Expand Up @@ -103,7 +103,7 @@ int __tfw_http_msg_add_str_data(TfwHttpMsg *hm, TfwStr *str, void *data,
size_t len, struct sk_buff *skb);
#define tfw_http_msg_add_str_data(hm, str, data, len) \
__tfw_http_msg_add_str_data(hm, str, data, len, \
ss_skb_peek_tail(&hm->msg.skb_list))
ss_skb_peek_tail(&hm->msg.skb_head))

unsigned int tfw_http_msg_hdr_lookup(TfwHttpMsg *hm, const TfwStr *hdr);
int tfw_http_msg_hdr_add(TfwHttpMsg *hm, const TfwStr *hdr);
Expand Down
2 changes: 1 addition & 1 deletion tempesta_fw/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ static struct ctl_table tfw_sysctl_tbl[] = {
.mode = 0644,
.proc_handler = tfw_ctlfn_state_io,
},
{ 0 }
{}
};

#define DO_INIT(mod) \
Expand Down
4 changes: 2 additions & 2 deletions tempesta_fw/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

/**
* @seq_list - member in the ordered queue of messages;
* @skb_list - list of sk_buff that belong to the message;
* @ss_flags - message processing flags;
* @skb_head - head of the list of sk_buff that belong to the message;
* @len - total message length;
*
* TODO: Currently seq_list is used only in requests. Responses are not
Expand All @@ -43,8 +43,8 @@
*/
typedef struct {
struct list_head seq_list;
struct sk_buff *skb_head;
int ss_flags;
SsSkbList skb_list;
size_t len;
} TfwMsg;

Expand Down
Loading

0 comments on commit 6de9198

Please sign in to comment.