Skip to content

Commit

Permalink
Update kmod logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Waujito committed Nov 29, 2024
1 parent 62551a9 commit 09c504a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
58 changes: 34 additions & 24 deletions kytunblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static int open_raw_socket(void) {
ret = sock_create(AF_INET, SOCK_RAW, IPPROTO_RAW, &rawsocket);

if (ret < 0) {
pr_alert("Unable to create raw socket\n");
lgerror(ret, "Unable to create raw socket\n");
goto err;
}

Expand Down Expand Up @@ -100,7 +100,7 @@ static int open_raw6_socket(void) {
ret = sock_create(AF_INET6, SOCK_RAW, IPPROTO_RAW, &raw6socket);

if (ret < 0) {
pr_alert("Unable to create raw socket\n");
lgerror(ret, "Unable to create raw socket\n");
goto err;
}

Expand Down Expand Up @@ -219,7 +219,7 @@ static int send_raw_socket(const uint8_t *pkt, uint32_t pktlen) {
}

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);
}

Expand Down Expand Up @@ -350,41 +350,51 @@ static int __init ykb_init(void) {
ret = open_raw_socket();
if (ret < 0) goto err;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0)
struct net *n;

for_each_net(n) {
ret = nf_register_net_hook(n, &ykb_nf_reg);
if (ret < 0) {
lgerror(ret, "register net_hook");
}
}
#else
ret = nf_register_hook(&ykb_nf_reg);
if (ret < 0) {
lgerror(ret, "register net_hook");
}
#endif


if (config.use_ipv6) {
ret = open_raw6_socket();
if (ret < 0) goto close_rawsocket;
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, "bad rat");
if (ret < 0) {
lgerror(ret, "register net6_hook");
}
}
#else
nf_register_hook(&ykb6_nf_reg);
ret = nf_register_hook(&ykb6_nf_reg);
if (ret < 0) {
lgerror(ret, "register net6_hook");
}
#endif
}


#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0)
struct net *n;

for_each_net(n) {
ret = nf_register_net_hook(n, &ykb_nf_reg);
if (ret < 0)
lgerror(ret, "bad rat");
}
#else
nf_register_hook(&ykb_nf_reg);
#endif

pr_info("youtubeUnblock kernel module started.\n");
ipv6_fallback:
lginfo("youtubeUnblock kernel module started.\n");
return 0;

close_rawsocket:
close_raw_socket();
err:
return ret;
}
Expand All @@ -410,7 +420,7 @@ static void __exit ykb_destroy(void) {
#endif

close_raw_socket();
pr_info("youtubeUnblock kernel module destroyed.\n");
lginfo("youtubeUnblock kernel module destroyed.\n");
}

module_init(ykb_init);
Expand Down
7 changes: 6 additions & 1 deletion logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
#define printf pr_info
#define perror pr_err


#define log_message(level, msg, ...) \
(printf(msg, ##__VA_ARGS__))
(printk(level msg, ##__VA_ARGS__))

#define lgerror(ret, msg, ...) __extension__ ({ \
pr_err(msg ": %d\n", ##__VA_ARGS__, ret); \
})

#define LOG_ERR KERN_ERR
#define LOG_INFO KERN_INFO
#define LOG_WARN KERN_WARNING
#else
#include <stdio.h> // IWYU pragma: export
#include <errno.h>
Expand Down

0 comments on commit 09c504a

Please sign in to comment.