netfilter/hook关于ICMP协议过滤的样例
来源:互联网 发布:大非农数据利空金银 编辑:程序博客网 时间:2024/05/18 18:01
#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/netfilter.h>#include <linux/skbuff.h>#include <linux/ip.h>#include <linux/netdevice.h>#include <linux/if_ether.h>#include <linux/if_packet.h>#include <net/tcp.h>#include <net/udp.h>#include <net/icmp.h>#include <linux/netfilter_ipv4.h>MODULE_LICENSE("GPL");MODULE_AUTHOR("ljk@xdja.com");MODULE_DESCRIPTION("netfilter hook");static unsigned int hook_icmp_func(unsigned int hooknum,struct sk_buff *skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *)){struct ethhdr *mac_header = (struct ethhdr *)skb_mac_header(skb); struct iphdr *ip_header = (struct iphdr *)skb_network_header(skb);if(!skb)return NF_ACCEPT;if(ip_header->protocol == IPPROTO_ICMP){printk(KERN_INFO "src_mac: %pM\n", mac_header->h_source); printk(KERN_INFO "dst_mac: %pM\n", mac_header->h_dest); printk(KERN_INFO "src_ip: %pI4\n", &ip_header->saddr); printk(KERN_INFO "dst_ip: %pI4\n", &ip_header->daddr); printk(KERN_INFO "the protocol ICMP(%d) is dropped...\n", IPPROTO_ICMP);return NF_DROP;}return NF_ACCEPT;}static struct nf_hook_ops nf_hook_icmp_ops = {.list = {NULL, NULL},.hook = hook_icmp_func,.owner = THIS_MODULE,.pf = PF_INET/*PF_INET6*/,.hooknum = NF_INET_LOCAL_OUT,.priority = NF_IP_PRI_FIRST};static int __init hook_icmp_init(void){return nf_register_hook(&nf_hook_icmp_ops);}static void __exit hook_icmp_exit(void){nf_unregister_hook(&nf_hook_icmp_ops);}module_init(hook_icmp_init);module_exit(hook_icmp_exit);
0 0
- netfilter/hook关于ICMP协议过滤的样例
- netfilter 过滤icmp包
- 关于netfilter钩子 hook值的问题
- Netfilter协议过滤功能
- 利用netfilter的hook来实现数据包的过滤(For Kernel2.4)
- netfilter hook
- netfilter hook
- ICMP协议的禁止
- Netfilter中5个HOOK 的理解
- linux netfilter IP层的HOOK点
- 文章标题 netfilter的hook函数
- ICMP协议的PING程序
- 14、ICMP协议的主要功能
- Netfilter 基本的数据报过滤技术
- Netfilter与FreeBSD的网络包过滤
- netfilter五个hook点
- netfilter hook 点详解
- linux netfilter hook point
- 提交用户名和密码到指定的服务器
- [LeedCode OJ]#19 Remove Nth Node From End of List
- Mms 短信设置里添加常用短信时出现错误的解决办法
- 06-查看dns
- 机房收费——“上下机”还原生活
- netfilter/hook关于ICMP协议过滤的样例
- ListView+RecyclerView
- Java面试题
- sublime 常用正则表达式
- Android基础学习之Activity
- 深入理解C++动态绑定和静态绑定
- PULL-SAX解析
- 内存管理单元 MMU
- Lua程序设计:第3章 表达式