gpt4 book ai didi

sockets - 连接到哪个物理接口(interface) tun/tap 设备

转载 作者:行者123 更新时间:2023-12-04 05:48:19 25 4
gpt4 key购买 nike

我在理解 tun/tap 设备的实际工作方式时遇到了一点问题,这是来自 wiki 的内容

  1. How does Virtual network device actually work ? Virtual network device can be viewed as a simple Point-to-Point or Ethernet device, which instead of receiving packets from a physical media, receives them from user space program and instead of sending packets via physical media sends them to the user space program.

Let's say that you configured IPX on the tap0, then whenever the kernel sends an IPX packet to tap0, it is passed to the application (VTun for example). The application encrypts, compresses and sends it to the other side over TCP or UDP. The application on the other side decompresses and decrypts the data received and writes the packet to the TAP device, the kernel handles the packet like it came from real physical device.

好的应用程序加密、压缩并通过 TCP 或 UDP 将其发送到另一端。

如果您有 3 个物理连接,每个都路由到互联网,tun/tap 设备将使用哪个物理设备路由到互联网?

我很困惑,因为没有人真正谈论 tun/tap 接口(interface)和实际物理接口(interface)之间的真正关系是什么

提前准备好

最佳答案

没有内在联系。

重要的是要了解 TUN/TAP 或任何其他设备都不会进行路由。 Internet 协议(protocol) (IP) 路由由 IP 堆栈处理,它无法真正区分 TAP 接口(interface)和真正的以太网接口(interface)。 IP 堆栈从 TUN/TAP 接口(interface)接收的数据包由同一台机器上的程序生成,当 IP 堆栈将数据包路由出 TUN 或 TAP 接口(interface)时,它们仅由打开接口(interface)的软件接收。将它们视为连接到软件而不是真正的以太网网络的以太网端口。

你似乎很好地理解了你引用的例子。 Vtun(软件)同时打开 tap0 接口(interface)和套接字,然后像任何其他 IP 流量一样进行路由。 Vtun 获取它在 tap0 上接收到的数据包,并通过加密和压缩将它们封装起来,然后将它们推出套接字。该套接字另一端的另一个 Vtun 实例(可能在不同的机器上运行)从套接字中解封装数据包并将它们推出其 TAP 接口(interface)以供其内核的网络层处理。

但是套接字根本不是 TAP 的一部分,它如何路由取决于 IP 堆栈。如果 Vtun 的两个实例在同一个系统上运行,则套接字将不需要路由出物理接口(interface)。在这样的用例中,可以完全删除套接字(以及加密和压缩)。您可以让一个程序在两个 TAP 接口(interface)之间笨拙地复制数据。 TUN/TAP 规范中没有任何内容需要套接字或物理接口(interface);示例套接字是偶然的,是 Vtun 程序的性质引入的功能。

因此,您关于到互联网的三个物理连接的问题与 TUN/TAP 无关,而是关于一般 IP 路由。那里的答案在很大程度上取决于您的具体配置。

关于sockets - 连接到哪个物理接口(interface) tun/tap 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21546895/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com