mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2025-10-06 17:26:58 +08:00
Feature: windows tun more params support
Supported params: - Name - MTU - ComponentID - Network
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/device"
|
||||
"github.com/xjasonlyu/tun2socks/device/tun"
|
||||
"github.com/xjasonlyu/tun2socks/proxy"
|
||||
)
|
||||
|
||||
@@ -22,14 +21,12 @@ func parseDevice(s string, mtu uint32) (device.Device, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
name := u.Host
|
||||
driver := u.Scheme
|
||||
|
||||
var d device.Device
|
||||
|
||||
driver := strings.ToLower(u.Scheme)
|
||||
switch driver {
|
||||
case "tun":
|
||||
d, err = tun.Open(tun.WithName(name), tun.WithMTU(mtu))
|
||||
d, err = openTUN(u, mtu)
|
||||
default:
|
||||
err = fmt.Errorf("unsupported driver: %s", driver)
|
||||
}
|
||||
|
15
engine/tun.go
Normal file
15
engine/tun.go
Normal file
@@ -0,0 +1,15 @@
|
||||
// +build !windows
|
||||
|
||||
package engine
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/device"
|
||||
"github.com/xjasonlyu/tun2socks/device/tun"
|
||||
)
|
||||
|
||||
func openTUN(u *url.URL, mtu uint32) (device.Device, error) {
|
||||
name := u.Host
|
||||
return tun.Open(tun.WithName(name), tun.WithMTU(mtu))
|
||||
}
|
33
engine/tun_windows.go
Normal file
33
engine/tun_windows.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"github.com/xjasonlyu/tun2socks/device"
|
||||
"github.com/xjasonlyu/tun2socks/device/tun"
|
||||
)
|
||||
|
||||
func openTUN(u *url.URL, mtu uint32) (device.Device, error) {
|
||||
/*
|
||||
e.g. tun://TUN0/?id=tap0901&network=10.10.10.10/24
|
||||
*/
|
||||
|
||||
name := u.Host
|
||||
|
||||
componentID := u.Query().Get("id")
|
||||
network := u.Query().Get("network")
|
||||
|
||||
if componentID == "" {
|
||||
componentID = "tap0901" /* default */
|
||||
}
|
||||
if network == "" {
|
||||
network = "10.10.10.10/24" /* default */
|
||||
}
|
||||
|
||||
return tun.Open(
|
||||
tun.WithName(name),
|
||||
tun.WithMTU(mtu),
|
||||
tun.WithComponentID(componentID),
|
||||
tun.WithNetwork(network),
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user