免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: meijusan123
打印 上一主题 下一主题

linux netfilter hook中自己构造skbuff,发送全新数据包 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2009-11-07 08:31 |只看该作者
原帖由 godbach 于 2009-11-6 22:41 发表


同样是我的总结的那文章说的一种方式,封装数据包之后让它进行路由。


我试着使用ip_route_output_key(&rt, &fl) 这个接口函数去手动路由,再触发dev_queue_xmit(skb)去发送数据包,但,tcpdump没抓到此包,可能是没有路由成功,没有帮我添加好MAC头,所有,中途丢弃了!

版主,你的意思“封装数据包之后让它进行路由”是怎么实现的?能不能说详细些,让我了解下 谢谢啦

论坛徽章:
0
12 [报告]
发表于 2009-11-07 15:42 |只看该作者

回复 #10 meijusan123 的帖子

net_tx_action works in a similar way. It can be triggered with raise_softirq_irqoff(NET_TX_SOFTIRQ) by devices in two different contexts, to accomplish two main tasks:

By netif_wake_queue when transmission is enabled on a device. In this case, it makes sure that frames waiting to be sent are actually sent when all the needed conditions are met (for instance, when the device has enough memory).

By dev_kfree_skb_irq when a transmission has completed and the device driver signals with the former routine that the associated buffer can be released. In this case, it deallocates the sk_buff structures associated with successfully transmitted buffers.

The reason for the second task is as follows. We know that when code from the device driver runs in interrupt context, it needs to be as quick as possible. Releasing a buffer can take time, so it is deferred by asking the net_tx_action softirq to take care of it. Instead of using dev_kfree_skb, device drivers use dev_kfree_skb_irq. While the former deallocates the sk_buff (which actually consists of the buffer going back into a per-CPU cache), the latter simply adds the pointer to the buffer being released to the completion_queue list of the softnet_data structure associated with the CPU and lets net_tx_action do the real job later.

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
13 [报告]
发表于 2009-11-07 16:18 |只看该作者
版主,你的意思“封装数据包之后让它进行路由”是怎么实现的?能不能说详细些,让我了解下

我的意思就是封装之后,你要手动路由吧,这个可以参考ipt_REJECT.c中的send_reset函数操作的路由方式,然后让数据包接着走NF框架的处理流程啊。

论坛徽章:
0
14 [报告]
发表于 2009-11-09 14:18 |只看该作者
原帖由 godbach 于 2009-11-7 16:18 发表

我的意思就是封装之后,你要手动路由吧,这个可以参考ipt_REJECT.c中的send_reset函数操作的路由方式,然后让数据包接着走NF框架的处理流程啊。


谢谢,版主,问题解决了。

可以,手动封装数据包,再手动路由,继续使用它路由过的hh结构,取出已经帮你填好的mac部分,再把skb放到dev_queue_xmit(skb)上,ok。抓包,可以抓到了!

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
15 [报告]
发表于 2009-11-09 14:30 |只看该作者
可以,手动封装数据包,再手动路由,继续使用它路由过的hh结构,取出已经帮你填好的mac部分,


这个是在自己单独构造数据包的情况下吧,通过手动路由也是为了获取源和目的MAC,有了正确的MAC之后,就可以调用dev_queue_xmit了,你是这样实现的吧

论坛徽章:
12
2015年辞旧岁徽章
日期:2015-03-03 16:54:1515-16赛季CBA联赛之同曦
日期:2017-03-17 19:13:162016科比退役纪念章
日期:2016-11-07 08:28:12luobin
日期:2016-06-17 17:46:36wusuopu
日期:2016-06-17 17:43:4515-16赛季CBA联赛之福建
日期:2016-01-14 12:49:22程序设计版块每日发帖之星
日期:2015-12-13 06:20:00程序设计版块每日发帖之星
日期:2015-06-08 22:20:00程序设计版块每日发帖之星
日期:2015-06-08 22:20:002015年亚洲杯之科威特
日期:2015-03-24 14:21:272015年迎新春徽章
日期:2015-03-04 09:57:092016科比退役纪念章
日期:2018-04-10 16:20:18
16 [报告]
发表于 2009-11-10 10:21 |只看该作者
各位大牛,我想学习下底层的网络编码。指点一下呗。我该从哪里入手?

论坛徽章:
0
17 [报告]
发表于 2009-11-10 10:24 |只看该作者

回复 #16 VIP_fuck 的帖子

先看书!
ldd3,或一些内核开发相关,不然,一下子没理论知识,到处碰壁的。

论坛徽章:
12
2015年辞旧岁徽章
日期:2015-03-03 16:54:1515-16赛季CBA联赛之同曦
日期:2017-03-17 19:13:162016科比退役纪念章
日期:2016-11-07 08:28:12luobin
日期:2016-06-17 17:46:36wusuopu
日期:2016-06-17 17:43:4515-16赛季CBA联赛之福建
日期:2016-01-14 12:49:22程序设计版块每日发帖之星
日期:2015-12-13 06:20:00程序设计版块每日发帖之星
日期:2015-06-08 22:20:00程序设计版块每日发帖之星
日期:2015-06-08 22:20:002015年亚洲杯之科威特
日期:2015-03-24 14:21:272015年迎新春徽章
日期:2015-03-04 09:57:092016科比退役纪念章
日期:2018-04-10 16:20:18
18 [报告]
发表于 2009-11-10 10:29 |只看该作者

回复 #17 meijusan123 的帖子

谢谢大牛指点。
谢谢

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
19 [报告]
发表于 2009-11-10 10:31 |只看该作者
原帖由 VIP_fuck 于 2009-11-10 10:21 发表
各位大牛,我想学习下底层的网络编码。指点一下呗。我该从哪里入手?


你得先说一下你的基础

论坛徽章:
12
2015年辞旧岁徽章
日期:2015-03-03 16:54:1515-16赛季CBA联赛之同曦
日期:2017-03-17 19:13:162016科比退役纪念章
日期:2016-11-07 08:28:12luobin
日期:2016-06-17 17:46:36wusuopu
日期:2016-06-17 17:43:4515-16赛季CBA联赛之福建
日期:2016-01-14 12:49:22程序设计版块每日发帖之星
日期:2015-12-13 06:20:00程序设计版块每日发帖之星
日期:2015-06-08 22:20:00程序设计版块每日发帖之星
日期:2015-06-08 22:20:002015年亚洲杯之科威特
日期:2015-03-24 14:21:272015年迎新春徽章
日期:2015-03-04 09:57:092016科比退役纪念章
日期:2018-04-10 16:20:18
20 [报告]
发表于 2009-11-10 10:36 |只看该作者

回复 #19 godbach 的帖子

会一点socket,学习 unp1.书看过几遍,不过不精。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP