简体   繁体   English

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

[英]How to use tun/tap interface to split packets, tunnel and then reassemble. (similar to MLPPP)

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

Basically I am trying to do something similar to MLPPP 基本上我正在尝试做类似于MLPPP的事情

I am looking to do this using python and the TUN/TAP network driver. 我希望使用python和TUN / TAP网络驱动程序来做到这一点。 I have found the following python code samples and modules that I think might be helpful for this project. 我发现以下python代码示例和模块,我认为可能对此项目有所帮助。

Python tun/tap Python tun / tap

Python raw packet manipulation Python原始数据包操作

My question is can the necessary packet modification be done using python and what would be a possible way to approach this? 我的问题是可以使用python完成必要的数据包修改,这可能是什么方法来解决这个问题? 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. 欢迎使用任何代码示例或其他链接。

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. 性能非常好 - 我们的网站拥有5条以上的ADSL线路,并且下载速度可达40+ Mbps。

Splitting packets (eg 1500/2 = 750) would introduce unnecessary overhead... keep your packets as big as possible. 拆分数据包(例如1500/2 = 750)会引入不必要的开销......保持数据包尽可能大。

We have developed our own protocol (header format) for the UDP packets. 我们为UDP数据包开发了自己的协议(报头格式)。 We have done loopback testing on the tun/tap up to 200 Mbps, so definitely the kernel to user space interaction works well. 我们已经对高达200 Mbps的tun / tap进行了环回测试,因此用户空间交互的内核肯定运行良好。 Previously we used NFQUEUE but that had reliability issues. 以前我们使用NFQUEUE但有可靠性问题。

All of the above was written in Python. 以上所有都是用Python编写的。

It looks perfectly possible to me. 它对我来说非常可能。

The tun/tap modules you've discovered look like they would do the job. 你发现的tun / tap模块看起来就像他们会做的那样。 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. 至于拆分数据包,您不需要以任何方式解释数据,只需将其视为二进制数据blob,将其拆分为两个并添加标题 - 我不会使用任何第三方模块,只是普通的python字符串处理。

Or you could use netstrings if you want an easy to use packet encapsulation format. 或者,如果您想要一种易于使用的数据包封装格式,则可以使用netstrings

I don't suppose it would go like a rocket, but I'm sure you would learn lots doing it! 我不认为它会像火箭一样,但我相信你会学到很多东西!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM