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

Unix/Linux
Fedora Core 3 使用 YUM 安裝 Mono
Linux网络安全之经验谈2
解决在编译过程中需要链接静态库的问题
LINUX网络安全文献
RHEL AS3U3 "vsftpd dead but subsys locked" problem
系统入侵
Linux上如何阻止系统攻击者
中软Linux邮件系统解决方案
Linux安装要点
XteamLinux系统简介
Linux操作系统分析
红旗RS-Linux安全系统简介
linux系统上的网络应用
Linux下的3个windows仿真器评测(下)
Linux的7件武器(下)
在KDE的菜单&桌面上为某应用程序创建自定义图标的快捷方式?
最基本RedHat7.3汉化步骤
RedHatLinux网络服务器构架实务(三)
RedHatLinux网络服务器构架实务(二)
RedHatLinux网络服务器构架实务(一)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-01   浏览: 183 ::
收藏到网摘: 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] 下一页