mirror of
https://github.com/Waujito/youtubeUnblock.git
synced 2026-02-01 23:20:33 +03:00
Add youtubeUnblock statistics
The statistis will be printed on exit in userspace version. In kernel space version, use `cat /proc/kyoutubeUnblock`. The feature was proposed by @IceCat74 in #220
This commit is contained in:
@@ -435,6 +435,12 @@ cat /sys/module/kyoutubeUnblock/parameters/parameters
|
|||||||
|
|
||||||
and check all the parameters configured.
|
and check all the parameters configured.
|
||||||
|
|
||||||
|
You can check up the statistics of youtubeUnblock with
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo cat /proc/kyoutubeUnblock
|
||||||
|
```
|
||||||
|
|
||||||
### Building kernel module
|
### Building kernel module
|
||||||
|
|
||||||
#### Building on host system
|
#### Building on host system
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include "getopt.h"
|
#include "getopt.h"
|
||||||
#include "raw_replacements.h"
|
#include "raw_replacements.h"
|
||||||
|
|
||||||
|
struct statistics_data global_stats;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logging definitions
|
* Logging definitions
|
||||||
|
|||||||
@@ -339,4 +339,13 @@ struct packet_data {
|
|||||||
struct ytb_conntrack yct;
|
struct ytb_conntrack yct;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct statistics_data {
|
||||||
|
unsigned long all_packet_counter;
|
||||||
|
unsigned long packet_counter;
|
||||||
|
unsigned long target_counter;
|
||||||
|
unsigned long sent_counter;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct statistics_data global_stats;
|
||||||
|
|
||||||
#endif /* YTB_CONFIG_H */
|
#endif /* YTB_CONFIG_H */
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include <linux/net.h>
|
#include <linux/net.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/version.h>
|
#include <linux/version.h>
|
||||||
|
#include <linux/proc_fs.h>
|
||||||
|
|
||||||
#include <linux/netfilter.h>
|
#include <linux/netfilter.h>
|
||||||
#include <linux/netfilter_ipv4.h>
|
#include <linux/netfilter_ipv4.h>
|
||||||
@@ -329,6 +330,8 @@ erret_lc:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
++global_stats.sent_counter;
|
||||||
|
|
||||||
int ipvx = netproto_version(pkt, pktlen);
|
int ipvx = netproto_version(pkt, pktlen);
|
||||||
|
|
||||||
if (ipvx == IP4VERSION) {
|
if (ipvx == IP4VERSION) {
|
||||||
@@ -483,6 +486,8 @@ static NF_CALLBACK(ykb_nf_hook, skb) {
|
|||||||
struct config_t *config = cur_config;
|
struct config_t *config = cur_config;
|
||||||
kref_get(&config->refcount);
|
kref_get(&config->refcount);
|
||||||
|
|
||||||
|
++global_stats.all_packet_counter;
|
||||||
|
|
||||||
if ((skb->mark & config->mark) == config->mark) {
|
if ((skb->mark & config->mark) == config->mark) {
|
||||||
goto send_verdict;
|
goto send_verdict;
|
||||||
}
|
}
|
||||||
@@ -523,12 +528,14 @@ static NF_CALLBACK(ykb_nf_hook, skb) {
|
|||||||
pd.payload_len = skb->len;
|
pd.payload_len = skb->len;
|
||||||
|
|
||||||
int vrd = process_packet(config, &pd);
|
int vrd = process_packet(config, &pd);
|
||||||
|
++global_stats.packet_counter;
|
||||||
|
|
||||||
switch(vrd) {
|
switch(vrd) {
|
||||||
case PKT_ACCEPT:
|
case PKT_ACCEPT:
|
||||||
nf_verdict = NF_ACCEPT;
|
nf_verdict = NF_ACCEPT;
|
||||||
break;
|
break;
|
||||||
case PKT_DROP:
|
case PKT_DROP:
|
||||||
|
++global_stats.target_counter;
|
||||||
nf_verdict = NF_STOLEN;
|
nf_verdict = NF_STOLEN;
|
||||||
kfree_skb(skb);
|
kfree_skb(skb);
|
||||||
break;
|
break;
|
||||||
@@ -580,6 +587,22 @@ static struct pernet_operations ykb_pernet_ops = {
|
|||||||
};
|
};
|
||||||
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0) */
|
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0) */
|
||||||
|
|
||||||
|
#ifdef CONFIG_PROC_FS
|
||||||
|
|
||||||
|
static int stats_show(struct seq_file *s, void *v) {
|
||||||
|
seq_printf(s, "youtubeUnblock stats: \n"
|
||||||
|
"\tCatched: %ld packets\n"
|
||||||
|
"\tProcessed: %ld packets\n"
|
||||||
|
"\tTargetted: %ld packets\n"
|
||||||
|
"\tSent over socket %ld packets\n",
|
||||||
|
global_stats.all_packet_counter, global_stats.packet_counter,
|
||||||
|
global_stats.target_counter, global_stats.sent_counter);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
static int __init ykb_init(void) {
|
static int __init ykb_init(void) {
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@@ -615,6 +638,13 @@ static int __init ykb_init(void) {
|
|||||||
}
|
}
|
||||||
#endif /* NO_IPV6 */
|
#endif /* NO_IPV6 */
|
||||||
|
|
||||||
|
#ifdef CONFIG_PROC_FS
|
||||||
|
if (!proc_create_single_data("kyoutubeUnblock", 0440, NULL,
|
||||||
|
stats_show, NULL)) {
|
||||||
|
lgwarning("kyoutubeUnblock procfs entry creation failed");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
|
||||||
ret = register_pernet_subsys(&ykb_pernet_ops);
|
ret = register_pernet_subsys(&ykb_pernet_ops);
|
||||||
#else
|
#else
|
||||||
@@ -651,6 +681,10 @@ static void __exit ykb_destroy(void) {
|
|||||||
close_raw6_socket();
|
close_raw6_socket();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_PROC_FS
|
||||||
|
remove_proc_entry("kyoutubeUnblock", NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
close_raw_socket();
|
close_raw_socket();
|
||||||
kref_put(&cur_config->refcount, config_release);
|
kref_put(&cur_config->refcount, config_release);
|
||||||
lginfo("youtubeUnblock kernel module destroyed.\n");
|
lginfo("youtubeUnblock kernel module destroyed.\n");
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
#include <linux/netfilter.h>
|
#include <linux/netfilter.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "mangle.h"
|
#include "mangle.h"
|
||||||
@@ -546,6 +547,7 @@ erret_lc:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
++global_stats.sent_counter;
|
||||||
int ipvx = netproto_version(pkt, pktlen);
|
int ipvx = netproto_version(pkt, pktlen);
|
||||||
|
|
||||||
if (ipvx == IP4VERSION) {
|
if (ipvx == IP4VERSION) {
|
||||||
@@ -640,6 +642,8 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data) {
|
|||||||
uint16_t l3num;
|
uint16_t l3num;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
|
||||||
|
++global_stats.all_packet_counter;
|
||||||
|
|
||||||
if (nfq_nlmsg_parse(nlh, attr) < 0) {
|
if (nfq_nlmsg_parse(nlh, attr) < 0) {
|
||||||
lgerror(-errno, "Attr parse");
|
lgerror(-errno, "Attr parse");
|
||||||
return MNL_CB_ERROR;
|
return MNL_CB_ERROR;
|
||||||
@@ -694,8 +698,11 @@ ct_out:
|
|||||||
|
|
||||||
ret = process_packet(cur_config, &packet);
|
ret = process_packet(cur_config, &packet);
|
||||||
|
|
||||||
|
++global_stats.packet_counter;
|
||||||
|
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case PKT_DROP:
|
case PKT_DROP:
|
||||||
|
++global_stats.target_counter;
|
||||||
nfq_nlmsg_verdict_put(verdnlh, id, NF_DROP);
|
nfq_nlmsg_verdict_put(verdnlh, id, NF_DROP);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -875,6 +882,16 @@ struct instance_config_t instance_config = {
|
|||||||
.send_delayed_packet = delay_packet_send,
|
.send_delayed_packet = delay_packet_send,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void sigint_handler(int s) {
|
||||||
|
lginfo("youtubeUnblock stats: catched %ld packets, "
|
||||||
|
"processed %ld packets, "
|
||||||
|
"targetted %ld packets, sent over socket %ld packets",
|
||||||
|
global_stats.all_packet_counter, global_stats.packet_counter,
|
||||||
|
global_stats.target_counter, global_stats.sent_counter);
|
||||||
|
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int ret;
|
int ret;
|
||||||
struct config_t config;
|
struct config_t config;
|
||||||
@@ -893,6 +910,8 @@ int main(int argc, char *argv[]) {
|
|||||||
parse_global_lgconf(&config);
|
parse_global_lgconf(&config);
|
||||||
cur_config = &config;
|
cur_config = &config;
|
||||||
|
|
||||||
|
signal(SIGINT, sigint_handler);
|
||||||
|
signal(SIGTERM, sigint_handler);
|
||||||
|
|
||||||
if (open_raw_socket() < 0) {
|
if (open_raw_socket() < 0) {
|
||||||
lgerror(-errno, "Unable to open raw socket");
|
lgerror(-errno, "Unable to open raw socket");
|
||||||
|
|||||||
Reference in New Issue
Block a user