Update kmod logging

This commit is contained in:
Vadim Vetrov 2024-11-29 12:12:29 +03:00
parent 62551a9f82
commit 3a5dbff8ac
No known key found for this signature in database
GPG Key ID: E8A308689D7A73A5
2 changed files with 47 additions and 34 deletions

View File

@ -38,7 +38,7 @@ static int open_raw_socket(void) {
ret = sock_create(AF_INET, SOCK_RAW, IPPROTO_RAW, &rawsocket); ret = sock_create(AF_INET, SOCK_RAW, IPPROTO_RAW, &rawsocket);
if (ret < 0) { if (ret < 0) {
pr_alert("Unable to create raw socket\n"); lgerror(ret, "Unable to create raw socket\n");
goto err; goto err;
} }
@ -100,7 +100,7 @@ static int open_raw6_socket(void) {
ret = sock_create(AF_INET6, SOCK_RAW, IPPROTO_RAW, &raw6socket); ret = sock_create(AF_INET6, SOCK_RAW, IPPROTO_RAW, &raw6socket);
if (ret < 0) { if (ret < 0) {
pr_alert("Unable to create raw socket\n"); lgerror(ret, "Unable to create raw socket\n");
goto err; goto err;
} }
@ -219,7 +219,7 @@ erret_lc:
} }
static int delay_packet_send(const unsigned char *data, unsigned int data_len, unsigned int delay_ms) { static int delay_packet_send(const unsigned char *data, unsigned int data_len, unsigned int delay_ms) {
pr_info("delay_packet_send won't work on current youtubeUnblock version"); lginfo("delay_packet_send won't work on current youtubeUnblock version");
return send_raw_socket(data, data_len); return send_raw_socket(data, data_len);
} }
@ -350,41 +350,51 @@ static int __init ykb_init(void) {
ret = open_raw_socket(); ret = open_raw_socket();
if (ret < 0) goto err; if (ret < 0) goto err;
if (config.use_ipv6) {
ret = open_raw6_socket();
if (ret < 0) goto close_rawsocket;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0)
struct net *n;
for_each_net(n) {
ret = nf_register_net_hook(n, &ykb6_nf_reg);
if (ret < 0)
lgerror(ret, "bad rat");
}
#else
nf_register_hook(&ykb6_nf_reg);
#endif
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0)
struct net *n; struct net *n;
for_each_net(n) { for_each_net(n) {
ret = nf_register_net_hook(n, &ykb_nf_reg); ret = nf_register_net_hook(n, &ykb_nf_reg);
if (ret < 0) if (ret < 0) {
lgerror(ret, "bad rat"); lgerror(ret, "register net_hook");
}
} }
#else #else
nf_register_hook(&ykb_nf_reg); ret = nf_register_hook(&ykb_nf_reg);
if (ret < 0) {
lgerror(ret, "register net_hook");
}
#endif #endif
pr_info("youtubeUnblock kernel module started.\n");
if (config.use_ipv6) {
ret = open_raw6_socket();
if (ret < 0) {
config.use_ipv6 = 0;
lgwarning("ipv6 disabled!");
goto ipv6_fallback;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0)
struct net *n;
for_each_net(n) {
ret = nf_register_net_hook(n, &ykb6_nf_reg);
if (ret < 0) {
lgerror(ret, "register net6_hook");
}
}
#else
ret = nf_register_hook(&ykb6_nf_reg);
if (ret < 0) {
lgerror(ret, "register net6_hook");
}
#endif
}
ipv6_fallback:
lginfo("youtubeUnblock kernel module started.\n");
return 0; return 0;
close_rawsocket:
close_raw_socket();
err: err:
return ret; return ret;
} }
@ -410,7 +420,7 @@ static void __exit ykb_destroy(void) {
#endif #endif
close_raw_socket(); close_raw_socket();
pr_info("youtubeUnblock kernel module destroyed.\n"); lginfo("youtubeUnblock kernel module destroyed.\n");
} }
module_init(ykb_init); module_init(ykb_init);

View File

@ -3,7 +3,6 @@
#include "config.h" #include "config.h"
#define LOG_LEVEL (config.verbose) #define LOG_LEVEL (config.verbose)
#define USE_SYSLOG (config.syslog)
#ifdef KERNEL_SPACE #ifdef KERNEL_SPACE
#include <linux/kernel.h> #include <linux/kernel.h>
@ -11,12 +10,16 @@
#define printf pr_info #define printf pr_info
#define perror pr_err #define perror pr_err
#define log_message(level, msg, ...) \ #define LOG_ERR KERN_ERR
(printf(msg, ##__VA_ARGS__)) #define LOG_INFO KERN_INFO
#define LOG_WARN KERN_WARNING
#define log_message(level, msg, ...) \
(printk(level msg, ##__VA_ARGS__))
#define lgerror(ret, msg, ...) \
(log_message(LOG_ERR, msg ": %d\n", ##__VA_ARGS__, ret))
#define lgerror(ret, msg, ...) __extension__ ({ \
pr_err(msg ": %d\n", ##__VA_ARGS__, ret); \
})
#else #else
#include <stdio.h> // IWYU pragma: export #include <stdio.h> // IWYU pragma: export
#include <errno.h> #include <errno.h>