如何使用 tun/tap 接口拆分数据包、建立隧道然后重新组装。 (类似于MLPPP)

发布于 2024-11-07 16:27:38 字数 1375 浏览 0 评论 0原文

我正在寻找创建一个客户端/服务器应用程序,我可以用它来将网络数据包切成两半,通过单独的 udp 连接隧道传输数据包的每一半(因为每个 udp 连接将通过不同的 wifi 链接),然后重新组装在另一端拆分数据包。除了拆分数据包之外,每个半数据包还必须具有 ID 和序列号,以便可以正确地重新组装它们。

基本上我正在尝试做类似的事情 MLPPP

我希望使用 python 和 TUN/TAP 网络驱动程序来做到这一点。 我发现了以下 python 代码示例和模块,我认为它们可能对这个项目有帮助。

Python tun/tap

Python 原始数据包操作

我的问题是可以使用 python 完成必要的数据包修改吗?解决这个问题的可能方法是什么?我可以使用上面的模块来做到这一点还是有更好的解决方案?我正在寻找一些可以引导我走向正确方向的输入,因为我不是一个经验丰富的程序员。欢迎任何代码示例或其他链接。

I am looking to create a client/server application that I can use to slit network packets in half, tunnel each half of the packet over a separate udp connection (because each udp connection will be going over a different wifi link) and then reassemble the split packets on the other end. In addition to splitting the packets each half packet will also have to have an ID and sequence number so that they can be reassembled properly.

Basically I am trying to do something similar to MLPPP

I am looking to do this using python and the TUN/TAP network driver.
I have found the following python code samples and modules that I think might be helpful for this project.

Python tun/tap

Python raw packet manipulation

My question is can the necessary packet modification be done using python and what would be a possible way to approach this? Can I use the modules above to do this or is there a better solution? I am looking for some input that will steer me in the right direction as I am not an experienced programmer. Any code samples or additional links are welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

但可醉心 2024-11-14 16:27:38

我们在生产中正在做类似的事情,而且效果很好。不过,我们不会拆分单独的数据包。我们为每个连接设置分数权重(无限制)并将数据包发送出去。我们有一些代码来处理每行的不同延迟。在另一端,我们缓冲它们并重新排序。性能非常好 - 我们的网站拥有 5 条以上的 ADSL 线路,并且速度良好,下载速度为 40+ Mbps。

拆分数据包(例如 1500/2 = 750)会引入不必要的开销...让数据包尽可能大。

我们为 UDP 数据包开发了自己的协议(标头格式)。我们已经对 tun/tap 进行了高达 200 Mbps 的环回测试,因此内核与用户空间的交互肯定运行良好。以前我们使用 NFQUEUE 但存在可靠性问题。

以上所有内容都是用 Python 编写的。

We are doing something like this in production and it works quite well. We don't split individual packets though. We set fractional weights for each connection (unlimited) and send the packets out. We have some code in place to deal with different latencies on each line. On the other end we buffer them and reorder. Performance is pretty good - we have sites with 5+ ADSL lines and get good speeds, 40+ Mbps on the download.

Splitting packets (eg 1500/2 = 750) would introduce unnecessary overhead... keep your packets as big as possible.

We have developed our own protocol (header format) for the UDP packets. We have done loopback testing on the tun/tap up to 200 Mbps, so definitely the kernel to user space interaction works well. Previously we used NFQUEUE but that had reliability issues.

All of the above was written in Python.

萌︼了一个春 2024-11-14 16:27:38

在我看来这完全有可能。

您发现的 tun/tap 模块看起来可以完成这项工作。扭曲将是高性能和伤脑筋的成本全力以赴。

至于拆分数据包,您不需要以任何方式解释数据,只需将其视为二进制数据块,将其拆分为两部分并添加标头 - 我不会为此使用任何第三方模块,只是普通的 python 字符串处理。

或者,如果您想要一种易于使用的数据包封装格式,您可以使用 netstrings

我不认为它会像火箭一样发展,但我相信你会从中学到很多东西!

It looks perfectly possible to me.

The tun/tap modules you've discovered look like they would do the job. Twisted will be high performance and the cost of hurting your head working it all out.

As for splitting the packets, you don't need to interpret the data in any way, just treat it as a blob of binary data, split it in two and add a header - I wouldn't use any 3rd party modules for that, just normal python string handling.

Or you could use netstrings if you want an easy to use packet encapsulation format.

I don't suppose it would go like a rocket, but I'm sure you would learn lots doing it!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文