Linearize instead of kmalloc

This commit is contained in:
Vadim Vetrov 2024-09-02 00:11:58 +03:00
parent b20f15086e
commit 5870df44df
No known key found for this signature in database
GPG Key ID: E8A308689D7A73A5

View File

@ -56,7 +56,7 @@ struct config_t config = {
#ifdef DEBUG #ifdef DEBUG
.verbose = 2, .verbose = 2,
#else #else
.verbose = 0, .verbose = 1,
#endif #endif
.domains_str = defaul_snistr, .domains_str = defaul_snistr,
@ -76,26 +76,24 @@ MODULE_DESCRIPTION("Linux kernel module for youtube unblock");
static unsigned int ykb_nf_hook(void *priv, static unsigned int ykb_nf_hook(void *priv,
struct sk_buff *skb, struct sk_buff *skb,
const struct nf_hook_state *state) { const struct nf_hook_state *state) {
int ret;
if ((skb->mark & config.mark) == config.mark) if ((skb->mark & config.mark) == config.mark)
goto accept_no_free; goto accept;
if (skb->head == NULL) if (skb->head == NULL)
goto accept_no_free; goto accept;
uint32_t buflen = skb->len; if (skb->len > MAX_PACKET_SIZE)
if (buflen > MAX_PACKET_SIZE) goto accept;
goto accept_no_free;
NETBUF_ALLOC(buf, buflen); ret = skb_linearize(skb);
if (!NETBUF_CHECK(buf)) if (ret < 0) {
goto accept_no_free; lgerror("Cannot linearize", ret);
if (skb_copy_bits(skb, 0, buf, buflen) < 0) {
pr_err("Unable copy bits\n");
goto accept; goto accept;
} }
int vrd = process_packet(buf, buflen); int vrd = process_packet(skb->data, skb->len);
switch(vrd) { switch(vrd) {
case PKT_ACCEPT: case PKT_ACCEPT:
@ -105,11 +103,8 @@ static unsigned int ykb_nf_hook(void *priv,
} }
accept: accept:
NETBUF_FREE(buf);
accept_no_free:
return NF_ACCEPT; return NF_ACCEPT;
drop: drop:
NETBUF_FREE(buf);
kfree_skb(skb); kfree_skb(skb);
return NF_STOLEN; return NF_STOLEN;
} }