0x04 嵌入式---Ubuntu新版本Netfilter神坑

Ubuntu新版本的神坑一:

  • 以往的版本是使用 nf_register_hook(reg)
  • 而新版本是 nf_register_net_hook(&init_net, reg)
  • 注销函数也改成了 nf_unregister_net_hook(&init_net, reg)

Ubuntu新版本的神坑二:

  • 以往的版本是使用
static unsigned int xxxx(
unsigned int hooknum,
struct sk_buff * skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn) (struct sk_buff *))
  • 新版本是使用
unsigned int xxxxx(void *priv, struct sk_buff *skb, 
const struct nf_hook_state *state) 

Ubuntu新版本的神坑三:

  • 貌似也不用module_init(xxx);module_exit(xxx); 反正本人直接报错

本人亲测可以用Ubuntu(16.04 18.04)

#include <linux/kernel.h>  
#include <linux/module.h>  
#include <linux/netfilter.h>  
#include <linux/netfilter_ipv4.h>  
  
static struct nf_hook_ops nfho;

unsigned int hook_func(void *priv, struct sk_buff *skb, const struct nf_hook_state *state)  
{  
  printk(KERN_INFO "packet dropped\n");
  return NF_DROP;
}  

int init_module()  
{  
  nfho.hook = hook_func;
  nfho.hooknum = NF_INET_PRE_ROUTING;
  nfho.pf = PF_INET;
  nfho.priority = NF_IP_PRI_FIRST;
  nf_register_net_hook(&init_net, &nfho);
  return 0;
}  

void cleanup_module()
{  
  nf_unregister_net_hook(&init_net,&nfho);
}


  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值