V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
huangya
V2EX  ›  宽带症候群

ipsec 虚拟网卡模式

  •  
  •   huangya · 101 天前 · 913 次点击
    这是一个创建于 101 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在 openwrt 上安装了某 ipsec 插件[1].发现此 ipsec 的实现方式是基于 linux tun 虚拟接口的。

    root@OpenWrt:~# ip tuntap

    ipsec0: tun

    root@OpenWrt:~# ifconfig ipsec0

    ipsec0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00

          inet addr:192.168.6.1  P-t-P:192.168.6.1  Mask:255.255.255.0
          inet6 addr: fe80::953b:92c0:5f2c:582/64 Scope:Link
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1400  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500
          RX bytes:0 (0.0 B)  TX bytes:304 (304.0 B)
          
    

    这个与我以前认知的不太一样。我以前的认知是 ipsec 基于物理网卡的。这种虚拟接口的 ipsec 实现方式有什么学名吗?是不是主要用于没有公网 ip 的场景?虚拟接口的方式是不是性能会下降很多?我看包是基于 udp 的。假设物理网卡收到了一个加密的包,是不是收到的包先要从物理网卡传到用户进程,然后在用户进程进行解密,然后再往虚拟接口送?如果是这样,有点像 openvpn 了。

    [1]https://github.com/Lienol/openwrt-package/tree/main/luci-app-ipsec-server

    6 条回复    2024-01-18 18:57:53 +08:00
    fortitudeZDY
        1
    fortitudeZDY  
       101 天前 via Android
    应该是 policy based 和 route based 两种吧,你这种应该后者,可以通过路由指到 ipsec 接口,但是这个 tun 接口感觉性能应该不怎么行
    huangya
        2
    huangya  
    OP
       101 天前
    @fortitudeZDY 是由什么配置参数导致的吗
    mantouboji
        3
    mantouboji  
       101 天前
    玩 wireguard 吧,ipsec 这种东西有点儿过时了。
    RecursiveG
        4
    RecursiveG  
       100 天前
    L2TP/IPsec
    HawkinsSherpherd
        5
    HawkinsSherpherd  
       100 天前
    传输模式和隧道模式的区别,但我不建议直接用 IPSec 隧道,它不支持组播,跑不了 OSPF 之类的协议。
    IPSec 配置好鬼麻烦,我建议要是设备都支持的话选择 Tinc 或 Wireguard ,配置简单。
    huangya
        6
    huangya  
    OP
       100 天前   ❤️ 1
    @fortitudeZDY 搞清楚了,我现在用的确实是属于 router based 的一种。参考[1]. 并且确实是用户态实现的。

    Based on our own userland IPsec implementation and the kernel-libipsec plugin it is possible to create route-based VPNs with TUN devices. Similar to VTI devices or XFRM interfaces the negotiated IPsec policies have to match the traffic routed via TUN device. In particular because packets have to be copied between kernel and userland it is not as efficient as the solutions above (also read the notes on kernel-libipsec).

    [1]https://docs.strongswan.org/docs/5.9/features/routeBasedVpn.html
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   972 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 22:51 · PVG 06:51 · LAX 15:51 · JFK 18:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.