From 310519037b98fb2a088611bfcbf78484defa1c7d Mon Sep 17 00:00:00 2001 From: harry ge Date: Wed, 3 Jun 2020 01:07:41 +0800 Subject: [PATCH] Make hello-packet works in kernel version >= 4.13 --- hello-packet.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hello-packet.c b/hello-packet.c index 2af0e02..b576564 100644 --- a/hello-packet.c +++ b/hello-packet.c @@ -3,6 +3,7 @@ #include // included for __init and __exit macros #include #include +#include //#undef __KERNEL__ #include @@ -31,7 +32,11 @@ static int init_filter_if(void) nfho.pf = PF_INET; nfho.priority = NF_IP_PRI_FIRST; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) + nf_register_net_hook(&init_net, &nfho); +#else nf_register_hook(&nfho); +#endif return 0; } @@ -45,7 +50,12 @@ static int __init hello_init(void) static void __exit hello_cleanup(void) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) + nf_unregister_net_hook(&init_net, &nfho); +#else nf_unregister_hook(&nfho); +#endif + printk(KERN_INFO "Cleaning up module.\n"); }