第一:我本身電腦是ubuntu18,gcc是7.4,內核版本是4.1,我第一次看net filter的時候也是參照網上的例子,結果make的時候始終過不去。大體意思就是nf_register_hook在新版的內核裏面換掉了,新版內核函數變成了 nf_register_net_hook(&init_net, reg);因此的加上這樣一句linux
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) nf_register_net_hook(&init_net, reg) #else nf_register_hook(reg) #endif
第二:我服務器上是centos,gcc4.3,可是make的時候直接說沒有include/linux這個目錄,這個仍是比較簡單的,直接下載一個對應版本的源文件放在/usr/src/include下面便可。因此直接 yum install kernel-devel.ubuntu
第三,自從kernel4.13開始 hook函數的原型就是centos
int sample_nf_hookfn(void *priv, struct sk_buff *skb, const struct nf_hook_state *state);
而不是網上例子裏面的 服務器
static unsigned int sample( unsigned int hooknum, struct sk_buff * skb, const struct net_device *in, const struct net_device *out, int (*okfn) (struct sk_buff *))
,對於新的內核,須要編寫新的函數實現方式函數