当前位置: 首页 > 图文教程 > 操作系统 > Unix/Linux > Linux下的网络HOOK实现以及使用方法

Unix/Linux
linux root 密码忘了怎么办?
Debian LINUX 基础知识介绍
在Linux操作系统下修改IP、DNS和路由配置
Linux网络管理员指南(下载)
Linux环境进程间通信:管道及有名管道
Linux操作系统中的七件超厉害的武器
linux下vi编辑器命令大全
Linux服务器安全小技巧
Linux和UNIX病毒需特别重视
配置安全的SCO UNIX网络系统
IIS的安全性全解析
UNIX防止非法用户注册的技术
linux 远程桌面连接
Vsftpd+tcp_wrappers控制主机和用户访问
挂载(mount)命令使用技巧
linux 如何结束进程
cpio 解压参数
gzip和gunzip 解压参数
compress与uncompress参数使用
bzip2 bunzip2 bzcat参数使用

Unix/Linux 中的 Linux下的网络HOOK实现以及使用方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-01   浏览: 52 ::
收藏到网摘: n/a

最近疯狂的研究Linux的种种功能,也颇有心得,这里讲述一下Linux下的Net的Hook,使用net的Hook可以实现很多很多非常底层的功能,比如过滤报文,做防火墙,做代理等等。

Now,Let's Go!

使用的是Linux 2.6.19.1的内核代码。

首先是 在./Source/net/netfilter/core.c文件中的函数 nf_register_hook:

static DEFINE_SPINLOCK(nf_hook_lock);

int nf_register_hook(struct nf_hook_ops *reg)

{

struct list_head *i;

spin_lock_bh(&nf_hook_lock);

list_for_each(i, &nf_hooks[reg->pf][reg->hooknum]) {

if (reg->priority < ((struct nf_hook_ops *)i)->priority)

break;

}

list_add_rcu(®->list, i->prev);

spin_unlock_bh(&nf_hook_lock);

synchronize_net();

return 0;

}

EXPORT_SYMBOL(nf_register_hook);

void nf_unregister_hook(struct nf_hook_ops *reg)

{

spin_lock_bh(&nf_hook_lock);

list_del_rcu(®->list);

spin_unlock_bh(&nf_hook_lock);

synchronize_net();

}

EXPORT_SYMBOL(nf_unregister_hook);

int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n)

{

unsigned int i;

int err = 0;

for (i = 0; i < n; i++) {

err = nf_register_hook(®[i]);

if (err)

goto err;

}

return err;

err:

if (i > 0)

nf_unregister_hooks(reg, i);

return err;

}

EXPORT_SYMBOL(nf_register_hooks);

void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n)

{

unsigned int i;

for (i = 0; i < n; i++)

nf_unregister_hook(®[i]);

}

EXPORT_SYMBOL(nf_unregister_hooks);

 

[1] [2] 下一页