Skip to content

Commit

Permalink
tun: set dns on windows
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Pashmfouroush <[email protected]>
  • Loading branch information
markpash committed May 20, 2024
1 parent 6179fff commit 3690da7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func runWarp(ctx context.Context, l *slog.Logger, opts WarpOptions, endpoint str

if opts.Tun {
// Create a new tun interface
tunDev, err := newNormalTun()
tunDev, err := newNormalTun([]netip.Addr{opts.DnsAddr})
if err != nil {
return err
}
Expand Down Expand Up @@ -224,7 +224,7 @@ func runWarpInWarp(ctx context.Context, l *slog.Logger, opts WarpOptions, endpoi

if opts.Tun {
// Create a new tun interface
tunDev, err := newNormalTun()
tunDev, err := newNormalTun([]netip.Addr{opts.DnsAddr})
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions app/tun_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
package app

import (
"net/netip"

"github.com/bepass-org/warp-plus/wireguard/device"
wgtun "github.com/bepass-org/warp-plus/wireguard/tun"
)

func newNormalTun() (wgtun.Device, error) {
func newNormalTun(_ []netip.Addr) (wgtun.Device, error) {
tunDev, err := wgtun.CreateTUN("warp0", 1280)
if err != nil {
return nil, err
}
return tunDev, nil

}

func bindToIface(_ *device.Device) error {
Expand Down
7 changes: 6 additions & 1 deletion app/tun_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const wintunGUID = "c33d325f-20cd-44e5-998c-19b0c15b4df1"
const family4 = winipcfg.AddressFamily(windows.AF_INET)
const family6 = winipcfg.AddressFamily(windows.AF_INET6)

func newNormalTun() (wgtun.Device, error) {
func newNormalTun(dns []netip.Addr) (wgtun.Device, error) {
guid, _ := windows.GUIDFromString(wintunGUID)
tunDev, err := wgtun.CreateTUNWithRequestedGUID("warp0", &guid, 1280)
if err != nil {
Expand Down Expand Up @@ -96,6 +96,11 @@ tryAgain6:
return nil, fmt.Errorf("unable to set metric and MTU: %w", err)
}

err = luid.SetDNS(family4, dns, nil)
if err != nil {
return nil, fmt.Errorf("unable to set DNS: %w", err)
}

return tunDev, nil

}
Expand Down

0 comments on commit 3690da7

Please sign in to comment.