huangya

ipsec 虚拟网卡模式

  •  
  •   huangya · Jan 17, 2024 · 1874 views
    This topic created in 873 days ago, the information mentioned may be changed or developed.

    最近在 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 replies    2024-01-18 18:57:53 +08:00
    fortitudeZDY
        1
    fortitudeZDY  
       Jan 17, 2024 via Android
    应该是 policy based 和 route based 两种吧,你这种应该后者,可以通过路由指到 ipsec 接口,但是这个 tun 接口感觉性能应该不怎么行
    huangya
        2
    huangya  
    OP
       Jan 17, 2024
    @fortitudeZDY 是由什么配置参数导致的吗
    mantouboji
        3
    mantouboji  
       Jan 17, 2024
    玩 wireguard 吧,ipsec 这种东西有点儿过时了。
    RecursiveG
        4
    RecursiveG  
       Jan 18, 2024
    L2TP/IPsec
    HawkinsSherpherd
        5
    HawkinsSherpherd  
       Jan 18, 2024
    传输模式和隧道模式的区别,但我不建议直接用 IPSec 隧道,它不支持组播,跑不了 OSPF 之类的协议。
    IPSec 配置好鬼麻烦,我建议要是设备都支持的话选择 Tinc 或 Wireguard ,配置简单。
    huangya
        6
    huangya  
    OP
       Jan 18, 2024   ❤️ 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
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3840 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 10:22 · PVG 18:22 · LAX 03:22 · JFK 06:22
    ♥ Do have faith in what you're doing.