Add flags for kernel module

This commit is contained in:
Vadim Vetrov 2024-09-07 09:13:50 +03:00
parent f96ac2252b
commit b3668f07ba
No known key found for this signature in database
GPG Key ID: E8A308689D7A73A5
5 changed files with 150 additions and 53 deletions

2
Kbuild
View File

@ -1,3 +1,3 @@
obj-m := kyoutubeUnblock.o obj-m := kyoutubeUnblock.o
kyoutubeUnblock-objs := kytunblock.o mangle.o quic.o utils.o kmod_utils.o kyoutubeUnblock-objs := kytunblock.o mangle.o quic.o utils.o kmod_utils.o kargs.o
ccflags-y := -std=gnu11 -DKERNEL_SPACE -Wno-error -Wno-declaration-after-statement ccflags-y := -std=gnu11 -DKERNEL_SPACE -Wno-error -Wno-declaration-after-statement

View File

@ -111,6 +111,8 @@ extern struct config_t config;
#define MAX_PACKET_SIZE 8192 #define MAX_PACKET_SIZE 8192
static const char defaul_snistr[] = "googlevideo.com,ggpht.com,ytimg.com,youtube.com,play.google.com,youtu.be,googleapis.com,googleusercontent.com,gstatic.com,l.google.com"; #define DEFAULT_SNISTR "googlevideo.com,ggpht.com,ytimg.com,youtube.com,play.google.com,youtu.be,googleapis.com,googleusercontent.com,gstatic.com,l.google.com"
static const char defaul_snistr[] = DEFAULT_SNISTR;
#endif /* YTB_CONFIG_H */ #endif /* YTB_CONFIG_H */

146
kargs.c Normal file
View File

@ -0,0 +1,146 @@
#include "config.h"
#include "raw_replacements.h"
#include "types.h"
#include <linux/moduleparam.h>
#define STR_MAXLEN 1024
struct config_t config = {
.frag_sni_reverse = 1,
.frag_sni_faked = 0,
.fragmentation_strategy = FRAGMENTATION_STRATEGY,
.faking_strategy = FAKING_STRATEGY,
.faking_ttl = FAKE_TTL,
.fake_sni = 1,
.fake_sni_seq_len = 1,
.frag_middle_sni = 1,
.frag_sni_pos = 1,
.use_ipv6 = 1,
.fakeseq_offset = 10000,
.mark = DEFAULT_RAWSOCKET_MARK,
.synfake = 0,
.synfake_len = 0,
.sni_detection = SNI_DETECTION_PARSE,
#ifdef SEG2_DELAY
.seg2_delay = SEG2_DELAY,
#else
.seg2_delay = 0,
#endif
#ifdef USE_GSO
.use_gso = 1,
#else
.use_gso = false,
#endif
#ifdef DEBUG
.verbose = 2,
#else
.verbose = 1,
#endif
.domains_str = defaul_snistr,
.domains_strlen = sizeof(defaul_snistr),
.queue_start_num = DEFAULT_QUEUE_NUM,
.fake_sni_pkt = fake_sni_old,
.fake_sni_pkt_sz = sizeof(fake_sni_old) - 1, // - 1 for null-terminator
};
static int unumeric_set(const char *val, const struct kernel_param *kp) {
int n = 0, ret;
ret = kstrtoint(val, 10, &n);
if (ret != 0 || n < 0)
return -EINVAL;
return param_set_int(val, kp);
}
static int boolean_set(const char *val, const struct kernel_param *kp) {
int n = 0, ret;
ret = kstrtoint(val, 10, &n);
if (ret != 0 || (n != 0 && n != 1))
return -EINVAL;
return param_set_int(val, kp);
}
static const struct kernel_param_ops unumeric_parameter_ops = {
.set = unumeric_set,
.get = param_get_int
};
static const struct kernel_param_ops boolean_parameter_ops = {
.set = boolean_set,
.get = param_get_int
};
module_param_cb(fake_sni, &boolean_parameter_ops, &config.fake_sni, 0664);
module_param_cb(fake_sni_seq_len, &unumeric_parameter_ops, &config.fake_sni_seq_len, 0664);
module_param_cb(faking_ttl, &unumeric_parameter_ops, &config.faking_ttl, 0664);
module_param_cb(fake_seq_offset, &unumeric_parameter_ops, &config.fakeseq_offset, 0664);
module_param_cb(frag_sni_reverse, &unumeric_parameter_ops, &config.frag_sni_reverse, 0664);
module_param_cb(frag_sni_faked, &boolean_parameter_ops, &config.frag_sni_faked, 0664);
module_param_cb(frag_middle_sni, &boolean_parameter_ops, &config.frag_middle_sni, 0664);
module_param_cb(frag_sni_pos, &unumeric_parameter_ops, &config.frag_sni_pos, 0664);
module_param_cb(fk_winsize, &unumeric_parameter_ops, &config.fk_winsize, 0664);
module_param_cb(synfake, &boolean_parameter_ops, &config.synfake, 0664);
module_param_cb(synfake_len, &unumeric_parameter_ops, &config.synfake_len, 0664);
module_param_cb(packet_mark, &unumeric_parameter_ops, &config.mark, 0664);
static int sni_domains_set(const char *val, const struct kernel_param *kp) {
size_t len;
int ret;
len = strnlen(val, STR_MAXLEN + 1);
if (len == STR_MAXLEN + 1) {
pr_err("%s: string parameter too long\n", kp->name);
return -ENOSPC;
}
ret = param_set_charp(val, kp);
if (ret < 0) {
config.domains_strlen = 0;
} else {
config.domains_strlen = len;
if (len == 3 && !strcmp(config.domains_str, "all")) {
config.all_domains = 1;
}
}
return ret;
}
static const struct kernel_param_ops sni_domains_ops = {
.set = sni_domains_set,
.get = param_get_charp,
};
module_param_cb(sni_domains, &sni_domains_ops, &config.domains_str, 0664);
static int exclude_domains_set(const char *val, const struct kernel_param *kp) {
size_t len;
int ret;
len = strnlen(val, STR_MAXLEN + 1);
if (len == STR_MAXLEN + 1) {
pr_err("%s: string parameter too long\n", kp->name);
return -ENOSPC;
}
ret = param_set_charp(val, kp);
if (ret < 0) {
config.domains_strlen = 0;
} else {
config.domains_strlen = len;
}
return ret;
}

View File

@ -16,62 +16,15 @@
#include "mangle.h" #include "mangle.h"
#include "config.h" #include "config.h"
#include "raw_replacements.h"
#include "utils.h" #include "utils.h"
#include "logging.h" #include "logging.h"
#include "kmod_utils.h" #include "kmod_utils.h"
struct config_t config = {
.threads = THREADS_NUM,
.frag_sni_reverse = 1,
.frag_sni_faked = 0,
.fragmentation_strategy = FRAGMENTATION_STRATEGY,
.faking_strategy = FAKING_STRATEGY,
.faking_ttl = FAKE_TTL,
.fake_sni = 1,
.fake_sni_seq_len = 1,
.frag_middle_sni = 1,
.frag_sni_pos = 1,
.use_ipv6 = 1,
.fakeseq_offset = 10000,
.mark = DEFAULT_RAWSOCKET_MARK,
.synfake = 0,
.synfake_len = 0,
.sni_detection = SNI_DETECTION_PARSE,
#ifdef SEG2_DELAY
.seg2_delay = SEG2_DELAY,
#else
.seg2_delay = 0,
#endif
#ifdef USE_GSO
.use_gso = 1,
#else
.use_gso = false,
#endif
#ifdef DEBUG
.verbose = 2,
#else
.verbose = 1,
#endif
.domains_str = defaul_snistr,
.domains_strlen = sizeof(defaul_snistr),
.queue_start_num = DEFAULT_QUEUE_NUM,
.fake_sni_pkt = fake_sni_old,
.fake_sni_pkt_sz = sizeof(fake_sni_old) - 1, // - 1 for null-terminator
};
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
MODULE_VERSION("0.3.2"); MODULE_VERSION("0.3.2");
MODULE_AUTHOR("Vadim Vetrov <vetrovvd@gmail.com>"); MODULE_AUTHOR("Vadim Vetrov <vetrovvd@gmail.com>");
MODULE_DESCRIPTION("Linux kernel module for youtube unblock"); 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) {

View File

@ -42,8 +42,6 @@ void ip4_set_checksum(struct iphdr *iph)
} }
void tcp6_set_checksum(struct tcphdr *tcph, struct ip6_hdr *iph) { void tcp6_set_checksum(struct tcphdr *tcph, struct ip6_hdr *iph) {
uint16_t old_check = ntohs(tcph->check);
#ifdef KERNEL_SPACE #ifdef KERNEL_SPACE
tcph->check = 0; tcph->check = 0;
tcph->check = csum_ipv6_magic(&iph->saddr, &iph->daddr, tcph->check = csum_ipv6_magic(&iph->saddr, &iph->daddr,
@ -252,7 +250,6 @@ int udp4_payload_split(uint8_t *pkt, uint32_t buflen,
struct iphdr *hdr; struct iphdr *hdr;
uint32_t hdr_len; uint32_t hdr_len;
struct udphdr *uhdr; struct udphdr *uhdr;
uint32_t uhdr_len;
uint8_t *ip_ph; uint8_t *ip_ph;
uint32_t ip_phlen; uint32_t ip_phlen;
@ -291,7 +288,6 @@ int udp6_payload_split(uint8_t *pkt, uint32_t buflen,
struct ip6_hdr *hdr; struct ip6_hdr *hdr;
uint32_t hdr_len; uint32_t hdr_len;
struct udphdr *uhdr; struct udphdr *uhdr;
uint32_t uhdr_len;
uint8_t *ip_ph; uint8_t *ip_ph;
uint32_t ip_phlen; uint32_t ip_phlen;