linux 2.6.32-504.23.4.el6.x86_64…
来源:互联网 发布:雷蛇键盘mac驱动 编辑:程序博客网 时间:2024/04/29 18:42
linux内核更新,sk_buff变了,博一个linux2.6.32-504.23.4.el6.x86_64下的netfilter钩子
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define NIPQUAD(addr) \
((unsigned char *)&addr)[0], \
((unsigned char *)&addr)[1], \
((unsigned char *)&addr)[2], \
((unsigned char *)&addr)[3]
MODULE_LICENSE("GPL");
MODULE_AUTHOR("FrankXiong");
static struct nf_hook_ops nfho;
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 *)) {
struct sk_buff *sb;
struct iphdr *iph;
// struct ethdhr *eth;
struct udphdr *udp;
__be32 sip,dip;
sb = skb;
iph = ip_hdr(sb);
udp = (struct udphdr*)&sb->transport_header;
sip = iph->saddr;
dip = iph->daddr;
printk("src= %d.%d.%d.%d\n",NIPQUAD(sip));
printk("dst= %d.%d.%d.%d\n",NIPQUAD(dip));
// ti qu IP tou
if(skb->pkt_type == PACKET_BROADCAST) {
return NF_ACCEPT;
}
if(skb->protocol == htons(ETH_P_IP)){
switch (iph->protocol) {
case IPPROTO_TCP: {
printk("TCP packet\n");
break;
}
case IPPROTO_ICMP: {
printk("ICMP packet\n");
break;
}
case IPPROTO_UDP: {
printk("UDP packet\n");
if (ntohs(udp->dest) == 520) {
printk("RIP packet\n");
}
break;
}
case IPPROTO_IP: {
printk("IP packet\n");
break;
}
default:
printk("other packet\n");
}
}
printk("===========\n");
return NF_ACCEPT;
}
static int kexec_test_init(void) {
printk("hook start ...\n");
nfho.hook = hook_func;
nfho.owner = NULL;
nfho.pf = PF_INET;
nfho.hooknum = NF_INET_PRE_ROUTING;
nfho.priority = NF_IP_PRI_FIRST;
nf_register_hook(&nfho); /// 注册一个钩子函数
return 0;
}
static void kexec_test_exit(void) {
printk("hook init...\n");
nf_unregister_hook(&nfho);
}
module_init(kexec_test_init);
module_exit(kexec_test_exit);
Makefile:
obj-m := netfilter_hook.o
KERNELBUILD := /lib/modules/`uname -r`/build
default:
make -C $(KERNELBUILD) M=$(shell pwd) modules
clean:
rm -rf *.o .*.cmd *.ko *.mod.c .tmp_versions Module.symvers*.ko.unsigned modules.order
阅读全文
0 0
- linux 2.6.32-504.23.4.el6.x86_64…
- linux centos6.5 2.6.32-431.el6.x86_64 php5.5.9 apache2.4.7 mysql5 最新快速编译安装
- linux centos6.5 2.6.32-431.el6.x86_64 php5.5.9 apache2.4.7 mysql5 最新快速编译安装
- You are running linux kernel version 2.6.32-431.el6.x86_64, which might be unstable running docker.
- CentOS 6.6 x86_64升级内核到最新版2.6.32-642.3.1.el6.x86_64
- centos防火墙添加端口8080 版本2.6.32-279.el6.x86_64
- make: *** /lib/modules/2.6.32-573.7.1.el6.x86_64/build/: No such file or directory. Stop.
- make: *** /lib/modules/2.6.32-573.el6.x86_64/build: 没有那个文件或目录。 停止。
- make: *** /lib/modules/2.6.32-573.el6.x86_64/build: 没有那个文件或目录。 停止。
- /lib/modules/2.6.32-431.el6.x86_64/build/: No such file or directory
- CentOS6.9中/boot下initramfs-2.6.32-696.el6.x86_64.img的删除和恢复
- 阿里云CentOS 64位解决kernel-2.6.32-220.13.1.el6.x86_64 has missing requires错误
- 【Tiny4412】 编译dnw源码报错 /lib/modules/2.6.32-431.el6.x86_64/build/: No such file or directory
- CentOS之——make: *** /lib/modules/2.6.32-431.el6.x86_64/build/: No such file or directory. Stop.
- Linux安装aapt问题之libstdc++-4.4.7-16.el6.i686 != libstdc++-4.4.7-11.el6.x86_64
- linux 下安装mysql-5.7.16-1.el6.x86_64.rpm-bundle
- linux 下安装mysql-5.7.16-1.el6.x86_64.rpm-bundle
- python-libs-2.6.6-66.el6_8.x86_64 is a duplicate with python-libs-2.6.6-64.el6.x86_64
- 数据结构----双向队列
- 数据结构----FIFO队列
- multiDex导致NoClassDefFoundError错误
- 2015年04月02日
- F
- linux 2.6.32-504.23.4.el6.x86_64…
- webpack-config.js 内容讲解
- QT5和libpcap混合编程
- Git部署项目流程与常用命令
- px->sp;dp->px等
- 使用jquery触发a标签跳转
- MFC上CSerialPort类解决线程内异步…
- 八数码
- VC++ 回调函数+线程回调