mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-25 14:46:04 +03:00
5ae3791a8e
Co-authored-by: kunson <kunson@kunsondeMacBook-Pro-3.local> Co-authored-by: 世界 <i@sekai.icu>
43 lines
809 B
Go
43 lines
809 B
Go
//go:build !linux
|
|
|
|
package wireguard
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"net/netip"
|
|
|
|
"golang.zx2c4.com/wireguard/tun/netstack"
|
|
)
|
|
|
|
var _ Tunnel = (*gvisorNet)(nil)
|
|
|
|
type gvisorNet struct {
|
|
tunnel
|
|
net *netstack.Net
|
|
}
|
|
|
|
func (g *gvisorNet) Close() error {
|
|
return g.tunnel.Close()
|
|
}
|
|
|
|
func (g *gvisorNet) DialContextTCPAddrPort(ctx context.Context, addr netip.AddrPort) (
|
|
net.Conn, error,
|
|
) {
|
|
return g.net.DialContextTCPAddrPort(ctx, addr)
|
|
}
|
|
|
|
func (g *gvisorNet) DialUDPAddrPort(laddr, raddr netip.AddrPort) (net.Conn, error) {
|
|
return g.net.DialUDPAddrPort(laddr, raddr)
|
|
}
|
|
|
|
func CreateTun(localAddresses []netip.Addr, mtu int) (Tunnel, error) {
|
|
out := &gvisorNet{}
|
|
tun, n, err := netstack.CreateNetTUN(localAddresses, nil, mtu)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
out.tun, out.net = tun, n
|
|
return out, nil
|
|
}
|