4,469
社区成员
发帖
与我相关
我的任务
分享#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>
static unsigned int icmp_srv(unsigned int hook,
struct sk_buff **pskb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *)
)
{
//printk(KERN_INFO"hook_icmp::icmp_srv()\n");
struct iphdr *iph = (*pskb)->nh.iph;
if(iph->protocol == IPPROTO_ICMP)
{
printk(KERN_INFO"hook_icmp::icmp_srv: receive ICMP packet\n");
printk(KERN_INFO"src: ");
}
return NF_ACCEPT;
}
static struct nf_hook_ops icmpsrv_ops =
{
.hook = icmp_srv,
.pf = PF_INET,
.hooknum = NF_IP_PRE_ROUTING,
.priority = NF_IP_PRI_FILTER -1,
};
static int __init init_hook_icmp(void)
{
return nf_register_hook(&icmpsrv_ops);
}
static void __exit fini_hook_icmp(void)
{
nf_unregister_hook(&icmpsrv_ops);
}
MODULE_LICENSE("GPL");
module_init(init_hook_icmp);
module_exit(fini_hook_icmp);