Skip to content

Add Wireguard Outbound#3624

Merged
xiaokangwang merged 6 commits intov2fly:masterfrom
xiaokangwang:dev-v2ray-wireguard-outbound
Feb 20, 2026
Merged

Add Wireguard Outbound#3624
xiaokangwang merged 6 commits intov2fly:masterfrom
xiaokangwang:dev-v2ray-wireguard-outbound

Conversation

@xiaokangwang
Copy link
Copy Markdown
Contributor

(Machine Generated)
This pull request introduces a new gVisor-based packet switch stack implementation and related utilities, refactors device and stack initialization, and improves UDP handler logic. The main changes are the addition of a gVisor stack adapter for packet switching, a new interconnect cable device for network-layer packet bridging, and several updates to device and handler interfaces for better abstraction and compatibility.

gVisor stack integration and packet switch improvements:

  • Added a new gvisorstack package, including:
    • adapter.go: Implements NetworkLayerDeviceToGvisorLinkEndpointAdaptor to bridge V2Ray's packet switch devices with gVisor's stack.LinkEndpoint interface. This enables seamless integration between V2Ray's internal packet switching and the gVisor network stack.
    • stack.go: Implements WrappedStack for creating and managing a gVisor stack, including NIC setup, address/routing configuration, and stack closure logic.
    • dialer.go: Adds TCP and UDP dial/listen methods on the gVisor stack, supporting both IPv4 and IPv6.
    • config.proto: Introduces a proto config for the new stack, supporting MTU, user level, IPs, routes, and socket settings.

Network-layer device interconnect:

  • Added interconnect package with networkLayer_cable.go:
    • Implements a NetworkLayerCable device to bridge two network-layer devices for bidirectional packet transfer, supporting dynamic attachment and detachment. [1] [2]

Device and stack interface refactoring:

  • Refactored device and stack initialization:
    • Removed unnecessary imports and the common.Closable interface from the Device interface in device.go.
    • Updated TUN stack creation to use NextNICID() instead of a deprecated or less appropriate method.
    • Adjusted imports for rawfile in gvisor_linux.go for clarity and correctness.
    • Changed the Close method signature for GvisorTUN to match the interface and avoid returning an error.

UDP handler improvements:

  • Improved UDP handler logic:
    • Updated the UDP forwarder callback to return a boolean for success/failure, aligning with gVisor's expectations. [1] [2]
    • Updated the construction of gonet.NewUDPConn to use the latest API.

Packet buffer interface updates:

  • Updated method signatures in packetaddradaptar.go to use *stack.PacketBuffer instead of stack.PacketBufferPtr, aligning with upstream gVisor changes.

These changes collectively modernize the V2Ray core's packet switching and device abstraction, enabling advanced use cases with gVisor and improving modularity and maintainability.

@xiaokangwang xiaokangwang force-pushed the dev-v2ray-wireguard-outbound branch from 9d4d4a6 to 6a9cbe2 Compare February 19, 2026 20:06
@xiaokangwang
Copy link
Copy Markdown
Contributor Author

Config Example:

{
  "log": {
    "error": {
      "level": "Debug",
      "type": "Console"
    },
    "access": {
      "type": "None"
    }
  },
  "inbounds": [
    {
      "protocol": "socks",
      "settings": {
        "udpEnabled": true,
        "address": "127.0.0.1",
        "packetEncoding": "Packet"
      },
      "port": 11802,
      "listen": "127.0.0.1"
    }
  ],
  "outbounds": [
    {
      "tag": "wg-outbound",
      "protocol": "wireguard",
      "settings": {
        "wg_device": {
          "private_key": "****",
          "listen_port": 51820,
          "mtu": 1420,
          "peers": [
            {
              "public_key": "****",
              "preshared_key": "****",
              "allowed_ips": [
                "0.0.0.0/0"
              ],
              "endpoint": "****",
              "persistent_keepalive_interval": 25
            }
          ]
        },
        "stack": {
          "mtu": 1420,
          "ips": [
            {
              "ip_addr": "****",
              "prefix": 32
            }
          ],
          "routes": [
            {
              "ip_addr": "0.0.0.0",
              "prefix": 0
            }
          ],
          "enable_promiscuous_mode": false,
          "enable_spoofing": false
        },
        "listen_on_system_network": true,
        "domain_strategy": "USE_IP4"
      }
    },
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {}
    }
  ],
  "dns": {
    "name_server": [
      {
        "address": {
          "address": "1.1.1.1",
          "port": 53
        }
      }
    ]
  }
}

@xiaokangwang xiaokangwang force-pushed the dev-v2ray-wireguard-outbound branch from 75990b2 to 8680c51 Compare February 19, 2026 23:41
@xiaokangwang xiaokangwang force-pushed the dev-v2ray-wireguard-outbound branch from 2862b42 to 6b1c373 Compare February 20, 2026 00:07
@xiaokangwang xiaokangwang force-pushed the dev-v2ray-wireguard-outbound branch from 102f44d to 3f51469 Compare February 20, 2026 11:12
@xiaokangwang
Copy link
Copy Markdown
Contributor Author

DualStack example:

{
  "log": {
    "error": {
      "level": "Debug",
      "type": "Console"
    },
    "access": {
      "type": "None"
    }
  },
  "inbounds": [
    {
      "protocol": "socks",
      "settings": {
        "udpEnabled": true,
        "address": "127.0.0.1",
        "packetEncoding": "Packet"
      },
      "port": 11802,
      "listen": "127.0.0.1"
    }
  ],
  "outbounds": [
    {
      "tag": "wg-outbound",
      "protocol": "wireguard",
      "settings": {
        "wg_device": {
          "private_key": "*****",
          "listen_port": 51821,
          "mtu": 1420,
          "peers": [
            {
              "public_key": "*****",
              "preshared_key": "",
              "allowed_ips": [
                "0.0.0.0/0",
                "::/0"
              ],
              "endpoint": "*****",
              "persistent_keepalive_interval": 25
            }
          ]
        },
        "stack": {
          "mtu": 1420,
          "ips": [
            {
              "ip_addr": "*****",
              "prefix": 32
            },
            {
              "ip_addr": "*****",
              "prefix": 128
            }
          ],
          "routes": [
            {
              "ip_addr": "0.0.0.0",
              "prefix": 0
            },
            {
              "ip_addr": "::",
              "prefix": 0
            }
          ],
          "enable_promiscuous_mode": false,
          "enable_spoofing": false
        },
        "listen_on_system_network": true,
        "domain_strategy": "USE_IP"
      }
    },
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {}
    }
  ],
  "dns": {
    "name_server": [
      {
        "address": {
          "address": "1.1.1.1",
          "port": 53
        }
      }
    ]
  }
}

@xiaokangwang xiaokangwang merged commit 2143d62 into v2fly:master Feb 20, 2026
37 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant