首页 > Web开发 > 详细

Linux驱动4_NETFILTER

时间:2014-01-21 09:28:51      阅读:393      评论:0      收藏:0      [点我收藏+]
#include <linux/module.h>  
#include <linux/kernel.h>  
#include <linux/init.h>  
#include <linux/types.h>  
#include <linux/netdevice.h>  
#include <linux/skbuff.h>  
#include <linux/netfilter_ipv4.h>  
#include <linux/inet.h>  
#include <linux/in.h>  
#include <linux/ip.h>
//  hook函数
static unsigned int hook_func(unsigned int hooknum, struct sk_buff * skb, const struct net_device *in, 
    const struct net_device *out, int (*okfn) (struct sk_buff *))  
{
  unsigned int ret = NF_ACCEPT;
  if(!skb)
  {
    printk(KERN_ALERT "hook_func null skb.\n");
    goto err_null_skb;
  }
  printk(KERN_ALERT "hook_func get a skb.\n");
  return ret;
err_null_skb:
  return ret;
}  

struct nf_hook_ops hook_ops = {  
  .list =  {NULL,NULL},
  .hook = hook_func,
  //hook的协议族
  .pf = PF_INET,
  //接收到的包,路由之前的hook点  
  .hooknum = NF_INET_PRE_ROUTING,  
  .priority = NF_IP_PRI_FILTER
 };  
  
static int __init hook_init(void) 
{
  nf_register_hook(&hook_ops);  
  return 0;  
}  
  
static void __exit hook_exit(void) 
{  
  nf_unregister_hook(&hook_ops); 
}  
 
 MODULE_LICENSE("GPL");  
 module_init(hook_init);  
 module_exit(hook_exit);  

Linux驱动4_NETFILTER

原文:http://blog.csdn.net/nerdx/article/details/18268107

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!