Skip to content

Commit

Permalink
tun: delete tun + windows related tun code
Browse files Browse the repository at this point in the history
  • Loading branch information
markpash committed Jan 27, 2025
1 parent ac12900 commit 424e50b
Show file tree
Hide file tree
Showing 12 changed files with 10 additions and 568 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/go-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,6 @@ jobs:
go-version: '1.22'
check-latest: true

- name: Cache wintun
id: cache
uses: actions/cache@v4
if: matrix.goos == 'windows'
env:
cache-name: cache-wintun
with:
path: ~/wintun-0.14.1.zip
key: wintun-0.14.1.zip

- name: Download wintun
if: matrix.goos == 'windows' && steps.cache.outputs.cache-hit != 'true'
run: |
curl -LO https://www.wintun.net/builds/wintun-0.14.1.zip --output-dir ~/
ls -lah ~/
- name: Validate wintun
if: matrix.goos == 'windows'
run: |
pushd ~/
echo "07c256185d6ee3652e09fa55c0b673e2624b565e02c4b9091c79ca7d2f24ef51 wintun-0.14.1.zip" | sha256sum --check --status
unzip ~/wintun-0.14.1.zip -d ~/wintun
popd
- name: Build warp-plus
run: |
go build -v -o warp-plus_${{ env.ASSET_NAME }}/ -trimpath -ldflags "-s -w -buildid= -X main.version=${{ github.ref }}" ./cmd/warp-plus
Expand All @@ -117,17 +93,6 @@ jobs:
cp ${GITHUB_WORKSPACE}/README.md ./warp-plus_${{ env.ASSET_NAME }}/README.md
cp ${GITHUB_WORKSPACE}/LICENSE ./warp-plus_${{ env.ASSET_NAME }}/LICENSE
- name: Redistribute wintun.dll
if: matrix.goos == 'windows'
run: |
if [ "$GOARCH" = "amd64" ]; then
mv ~/wintun/wintun/bin/amd64/wintun.dll ./warp-plus_${{ env.ASSET_NAME }}/
elif [ "$GOARCH" = "arm64" ]; then
mv ~/wintun/wintun/bin/arm64/wintun.dll ./warp-plus_${{ env.ASSET_NAME }}/
elif [ "$GOARCH" = "386" ]; then
mv ~/wintun/wintun/bin/x86/wintun.dll ./warp-plus_${{ env.ASSET_NAME }}/
fi
- name: Create ZIP archive
shell: bash
run: |
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
/warp-scan.exe
.idea
stuff/
wintun.dll
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ FLAGS
--scan enable warp scanning
--rtt DURATION scanner rtt limit (default: 1s)
--cache-dir STRING directory to store generated profiles
--tun-experimental enable tun interface (experimental)
--fwmark UINT set linux firewall mark for tun mode (default: 4981)
--reserved STRING override wireguard reserved value (format: '1,2,3')
--wgconf STRING path to a normal wireguard config
Expand Down
83 changes: 6 additions & 77 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type WarpOptions struct {
Gool bool
Scan *wiresocks.ScanOptions
CacheDir string
Tun bool
FwMark uint32
WireguardConfig string
Reserved string
Expand All @@ -56,10 +55,6 @@ func RunWarp(ctx context.Context, l *slog.Logger, opts WarpOptions) error {
return errors.New("must provide country for psiphon")
}

if opts.Psiphon != nil && opts.Tun {
return errors.New("can't use psiphon and tun at the same time")
}

// Decide Working Scenario
endpoints := []string{opts.Endpoint, opts.Endpoint}

Expand Down Expand Up @@ -135,43 +130,18 @@ func runWireguard(ctx context.Context, l *slog.Logger, opts WarpOptions) error {
conf.Peers[i] = peer
}

if opts.Tun {
// Establish wireguard tunnel on tun interface
var werr error
var tunDev tun.Device
for _, t := range []string{"t1", "t2"} {
// Create a new tun interface
tunDev, werr = newNormalTun([]netip.Addr{opts.DnsAddr})
if werr != nil {
continue
}

werr = establishWireguard(l, conf, tunDev, true, opts.FwMark, t)
if werr != nil {
continue
}
break
}
if werr != nil {
return werr
}

l.Info("serving tun", "interface", "warp0")
return nil
}

// Establish wireguard on userspace stack
var werr error
var tnet *netstack.Net
var tunDev tun.Device
for _, t := range []string{"t1", "t2"} {
// Create userspace tun network stack
tunDev, tnet, werr = netstack.CreateNetTUN(conf.Interface.Addresses, conf.Interface.DNS, conf.Interface.MTU)
if err != nil {
if werr != nil {
continue
}

werr = establishWireguard(l, conf, tunDev, false, opts.FwMark, t)
werr = establishWireguard(l, conf, tunDev, opts.FwMark, t)
if werr != nil {
continue
}
Expand Down Expand Up @@ -230,31 +200,6 @@ func runWarp(ctx context.Context, l *slog.Logger, opts WarpOptions, endpoint str
conf.Peers[i] = peer
}

if opts.Tun {
// Establish wireguard tunnel on tun interface
var werr error
var tunDev tun.Device
for _, t := range []string{"t1", "t2"} {
// Create a new tun interface
tunDev, werr = newNormalTun([]netip.Addr{opts.DnsAddr})
if werr != nil {
continue
}

// Create userspace tun network stack
werr = establishWireguard(l, &conf, tunDev, true, opts.FwMark, t)
if werr != nil {
continue
}
break
}
if werr != nil {
return werr
}
l.Info("serving tun", "interface", "warp0")
return nil
}

// Establish wireguard on userspace stack
var werr error
var tnet *netstack.Net
Expand All @@ -265,7 +210,7 @@ func runWarp(ctx context.Context, l *slog.Logger, opts WarpOptions, endpoint str
continue
}

werr = establishWireguard(l, &conf, tunDev, false, opts.FwMark, t)
werr = establishWireguard(l, &conf, tunDev, opts.FwMark, t)
if werr != nil {
continue
}
Expand Down Expand Up @@ -334,7 +279,7 @@ func runWarpInWarp(ctx context.Context, l *slog.Logger, opts WarpOptions, endpoi
continue
}

werr = establishWireguard(l.With("gool", "outer"), &conf, tunDev, opts.Tun, opts.FwMark, t)
werr = establishWireguard(l.With("gool", "outer"), &conf, tunDev, opts.FwMark, t)
if werr != nil {
continue
}
Expand Down Expand Up @@ -386,30 +331,14 @@ func runWarpInWarp(ctx context.Context, l *slog.Logger, opts WarpOptions, endpoi
conf.Peers[i] = peer
}

if opts.Tun {
// Create a new tun interface
tunDev, err := newNormalTun([]netip.Addr{opts.DnsAddr})
if err != nil {
return err
}

// Establish wireguard tunnel on tun interface but don't bind
// wireguard sockets to default interface and don't apply fwmark.
if err := establishWireguard(l.With("gool", "inner"), &conf, tunDev, false, opts.FwMark, "t0"); err != nil {
return err
}
l.Info("serving tun", "interface", "warp0")
return nil
}

// Create userspace tun network stack
tunDev, tnet2, err := netstack.CreateNetTUN(conf.Interface.Addresses, conf.Interface.DNS, conf.Interface.MTU)
if err != nil {
return err
}

// Establish wireguard on userspace stack
if err := establishWireguard(l.With("gool", "inner"), &conf, tunDev, false, opts.FwMark, "t0"); err != nil {
if err := establishWireguard(l.With("gool", "inner"), &conf, tunDev, opts.FwMark, "t0"); err != nil {
return err
}

Expand Down Expand Up @@ -470,7 +399,7 @@ func runWarpWithPsiphon(ctx context.Context, l *slog.Logger, opts WarpOptions, e
continue
}

werr = establishWireguard(l, &conf, tunDev, false, opts.FwMark, t)
werr = establishWireguard(l, &conf, tunDev, opts.FwMark, t)
if werr != nil {
continue
}
Expand Down
22 changes: 0 additions & 22 deletions app/tun_others.go

This file was deleted.

Loading

0 comments on commit 424e50b

Please sign in to comment.