tungo: additional metadata options
This commit is contained in:
@@ -19,6 +19,7 @@ const (
|
||||
|
||||
type metadata struct {
|
||||
config *tun_util.Config
|
||||
guid string
|
||||
}
|
||||
|
||||
func (l *tunListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -102,5 +103,7 @@ func (l *tunListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
|
||||
l.md.config = config
|
||||
|
||||
l.md.guid = mdutil.GetString(md, "guid", "tun.guid")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ import (
|
||||
"net"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
"golang.zx2c4.com/wireguard/tun"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -14,15 +17,40 @@ const (
|
||||
writeOffset = 0
|
||||
)
|
||||
|
||||
func init() {
|
||||
tun.WintunTunnelType = "GOST"
|
||||
}
|
||||
|
||||
func (l *tunListener) createTun() (ifce io.ReadWriteCloser, name string, ip net.IP, err error) {
|
||||
if l.md.config.Name == "" {
|
||||
l.md.config.Name = defaultTunName
|
||||
}
|
||||
|
||||
if l.md.guid != "" {
|
||||
var guid windows.GUID
|
||||
guid, err = windows.GUIDFromString(l.md.guid)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
tun.WintunStaticRequestedGUID = &guid
|
||||
}
|
||||
|
||||
ifce, name, err = l.createTunDevice()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if l.md.config.MTU > 0 {
|
||||
cmd := fmt.Sprintf("netsh interface ip set subinterface %s mtu=%d", name, l.md.config.MTU)
|
||||
l.log.Debug(cmd)
|
||||
|
||||
args := strings.Split(cmd, " ")
|
||||
if er := exec.Command(args[0], args[1:]...).Run(); er != nil {
|
||||
err = fmt.Errorf("%s: %v", cmd, er)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if len(l.md.config.Net) > 0 {
|
||||
ipNet := l.md.config.Net[0]
|
||||
cmd := fmt.Sprintf("netsh interface ip set address name=%s "+
|
||||
|
||||
@@ -12,12 +12,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
defaultMTU = 1420
|
||||
defaultName = "tungo"
|
||||
defaultMTU = 1420
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
config *tun_util.Config
|
||||
guid string
|
||||
}
|
||||
|
||||
func (l *tunListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
@@ -29,9 +29,6 @@ func (l *tunListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
if config.MTU <= 0 {
|
||||
config.MTU = defaultMTU
|
||||
}
|
||||
if config.Name == "" {
|
||||
config.Name = defaultName
|
||||
}
|
||||
if gw := mdutil.GetString(md, "gw", "tun.gw"); gw != "" {
|
||||
config.Gateway = net.ParseIP(gw)
|
||||
}
|
||||
@@ -93,5 +90,7 @@ func (l *tunListener) parseMetadata(md mdata.Metadata) (err error) {
|
||||
|
||||
l.md.config = config
|
||||
|
||||
l.md.guid = mdutil.GetString(md, "guid", "tun.guid")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -11,11 +11,15 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
readOffset = 0
|
||||
writeOffset = 16
|
||||
defaultTunName = "tungo"
|
||||
readOffset = 0
|
||||
writeOffset = 16
|
||||
)
|
||||
|
||||
func (l *tunListener) createTun() (dev io.ReadWriteCloser, name string, ip net.IP, err error) {
|
||||
if l.md.config.Name == "" {
|
||||
l.md.config.Name = defaultTunName
|
||||
}
|
||||
dev, name, err = l.createTunDevice()
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
defaultTunName = "tun0"
|
||||
defaultTunName = "tungo"
|
||||
readOffset = 4
|
||||
writeOffset = 4
|
||||
)
|
||||
|
||||
@@ -6,23 +6,51 @@ import (
|
||||
"net"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
"golang.zx2c4.com/wireguard/tun"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultTunName = "wintun"
|
||||
defaultTunName = "tungo"
|
||||
readOffset = 0
|
||||
writeOffset = 0
|
||||
)
|
||||
|
||||
func init() {
|
||||
tun.WintunTunnelType = "GOST"
|
||||
}
|
||||
|
||||
func (l *tunListener) createTun() (ifce io.ReadWriteCloser, name string, ip net.IP, err error) {
|
||||
if l.md.config.Name == "" {
|
||||
l.md.config.Name = defaultTunName
|
||||
}
|
||||
|
||||
if l.md.guid != "" {
|
||||
var guid windows.GUID
|
||||
guid, err = windows.GUIDFromString(l.md.guid)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
tun.WintunStaticRequestedGUID = &guid
|
||||
}
|
||||
|
||||
ifce, name, err = l.createTunDevice()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if l.md.config.MTU > 0 {
|
||||
cmd := fmt.Sprintf("netsh interface ip set subinterface %s mtu=%d", name, l.md.config.MTU)
|
||||
l.log.Debug(cmd)
|
||||
|
||||
args := strings.Split(cmd, " ")
|
||||
if er := exec.Command(args[0], args[1:]...).Run(); er != nil {
|
||||
err = fmt.Errorf("%s: %v", cmd, er)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if len(l.md.config.Net) > 0 {
|
||||
ipNet := l.md.config.Net[0]
|
||||
cmd := fmt.Sprintf("netsh interface ip set address name=%s "+
|
||||
|
||||
Reference in New Issue
Block a user