sing-box/transport/wireguard/device.go

45 lines
967 B
Go
Raw Normal View History

2022-09-05 16:15:09 +00:00
package wireguard
import (
2024-11-21 10:10:41 +00:00
"context"
"net/netip"
"time"
"github.com/sagernet/sing-tun"
"github.com/sagernet/sing/common/logger"
2022-09-05 16:15:09 +00:00
N "github.com/sagernet/sing/common/network"
2024-11-21 10:10:41 +00:00
"github.com/sagernet/wireguard-go/device"
wgTun "github.com/sagernet/wireguard-go/tun"
2022-09-05 16:15:09 +00:00
)
type Device interface {
2024-11-21 10:10:41 +00:00
wgTun.Device
2022-09-05 16:15:09 +00:00
N.Dialer
Start() error
2024-11-21 10:10:41 +00:00
SetDevice(device *device.Device)
}
type DeviceOptions struct {
Context context.Context
Logger logger.ContextLogger
System bool
Handler tun.Handler
UDPTimeout time.Duration
CreateDialer func(interfaceName string) N.Dialer
Name string
MTU uint32
GSO bool
Address []netip.Prefix
AllowedAddress []netip.Prefix
}
func NewDevice(options DeviceOptions) (Device, error) {
if !options.System {
return newStackDevice(options)
} else if options.Handler == nil {
return newSystemDevice(options)
} else {
return newSystemStackDevice(options)
}
2022-09-05 16:15:09 +00:00
}