Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
gost
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
gost
Commits
c3ca971f
Commit
c3ca971f
authored
Dec 27, 2019
by
ginuerzh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tun: add Windows support
parent
4a9731a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
17 deletions
+51
-17
tun_linux.go
tun_linux.go
+0
-2
tun_win.go
tun_win.go
+0
-15
tun_windows.go
tun_windows.go
+51
-0
No files found.
tun_linux.go
View file @
c3ca971f
// +build linux
package
gost
import
(
...
...
tun_win.go
deleted
100644 → 0
View file @
4a9731a5
// +build windows
package
gost
import
(
"errors"
"net"
)
//TODO: wintun for Windows: https://www.wintun.net/
// https://godoc.org/golang.zx2c4.com/wireguard/tun/wintun
func
createTun
(
cfg
TunConfig
)
(
conn
net
.
Conn
,
ipNet
*
net
.
IPNet
,
err
error
)
{
err
=
errors
.
New
(
"tun is not supported on Windows"
)
return
}
tun_windows.go
0 → 100644
View file @
c3ca971f
package
gost
import
(
"fmt"
"net"
"os/exec"
"github.com/go-log/log"
"github.com/songgao/water"
)
func
createTun
(
cfg
TunConfig
)
(
conn
net
.
Conn
,
ipNet
*
net
.
IPNet
,
err
error
)
{
ip
,
ipNet
,
err
:=
net
.
ParseCIDR
(
cfg
.
Addr
)
if
err
!=
nil
{
return
}
ifce
,
err
:=
water
.
New
(
water
.
Config
{
DeviceType
:
water
.
TUN
,
PlatformSpecificParams
:
water
.
PlatformSpecificParams
{
ComponentID
:
"tap0901"
,
InterfaceName
:
cfg
.
Name
,
Network
:
cfg
.
Addr
,
},
})
if
err
!=
nil
{
return
}
cmd
:=
fmt
.
Sprintf
(
"netsh interface ip set address name=%s "
+
"source=static addr=%s mask=%s gateway=none"
,
ifce
.
Name
(),
ip
.
String
(),
ipMask
(
ipNet
.
Mask
))
log
.
Log
(
"[tun]"
,
cmd
)
if
er
:=
exec
.
Command
(
"netsh"
,
"interface"
,
"ip"
,
"set"
,
"address"
,
"name="
+
ifce
.
Name
(),
"source=static"
,
"addr="
+
ip
.
String
(),
"mask="
+
ipMask
(
ipNet
.
Mask
),
"gateway=none"
)
.
Run
();
er
!=
nil
{
err
=
fmt
.
Errorf
(
"%s: %v"
,
cmd
,
er
)
return
}
conn
=
&
tunConn
{
ifce
:
ifce
,
addr
:
&
net
.
IPAddr
{
IP
:
ip
},
}
return
}
func
ipMask
(
mask
net
.
IPMask
)
string
{
return
fmt
.
Sprintf
(
"%d.%d.%d.%d"
,
mask
[
0
],
mask
[
1
],
mask
[
2
],
mask
[
3
])
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment