implement udp nat and proxy

This commit is contained in:
octeep 2022-10-07 13:12:50 +01:00 committed by octeep
parent 20bf08e41a
commit 32ce704189
2 changed files with 77 additions and 14 deletions

View file

@ -3,7 +3,9 @@ package wireproxy
import (
"bytes"
"fmt"
"github.com/patrickmn/go-cache"
"net/netip"
"time"
"github.com/MakeNowJust/heredoc/v2"
"golang.zx2c4.com/wireguard/conn"
@ -73,8 +75,17 @@ func StartWireguard(conf *DeviceConfig) (*VirtualTun, error) {
return nil, err
}
natTable := cache.New(30*time.Second, time.Minute)
natTableRev := make(map[uint16]string)
natTable.OnEvicted(func(srcAddr string, i interface{}) {
entry := i.(*NatEntry)
_ = entry.conn.Close()
delete(natTableRev, entry.mappedPort)
})
return &VirtualTun{
tnet: tnet,
systemDNS: len(setting.dns) == 0,
tnet: tnet,
systemDNS: len(setting.dns) == 0,
mappedPortToNatEntry: natTableRev,
natEntryToMappedPort: natTable,
}, nil
}