mirror of
https://github.com/whyvl/wireproxy.git
synced 2025-04-29 19:01:42 +02:00
implement udp nat and proxy
This commit is contained in:
parent
20bf08e41a
commit
32ce704189
2 changed files with 77 additions and 14 deletions
15
wireguard.go
15
wireguard.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue