/
tungate.go
61 lines (47 loc) · 1.23 KB
/
tungate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net"
"net/http"
"os"
"github.com/costinm/tungate"
"github.com/costinm/tungate/gvisor"
"github.com/costinm/ugate"
"github.com/costinm/ugate/pkg/ugatesvc"
"github.com/costinm/ugate/pkg/auth"
)
// Similar with the sample micro-gate, but adding a TUN capture.
// Used to experiment with TUN instead of iptables capture.
func main() {
config := ugatesvc.NewConf(".")
auth := auth.NewAuth(config, "", "h.webinf.info")
cfg := &ugate.GateCfg{
BasePort: 12300,
}
data, err := ioutil.ReadFile("h2gate.json")
if err != nil {
json.Unmarshal(data, cfg)
}
// By default, pass through using net.Dialer
ug := ugatesvc.NewGate(&net.Dialer{}, auth, cfg)
//ugate.Reversed = true
fd, err := tungate.OpenTun("dmesh1")
if err != nil {
log.Fatal("Failed to open tun", err)
}
tun := gvisor.NewTUNFD(fd,ug, ug)
ug.TUNUDPWriter = tun
log.Println("TUN started ", tun)
// direct TCP connect to local iperf3 and fortio (or HTTP on default port)
ug.Add(&ugate.Listener{
Address: ":12311",
ForwardTo: "localhost:5201",
})
log.Println("Started debug on 12319, UID/GID", os.Getuid(), os.Getegid())
err = http.ListenAndServe(":12319", nil)
if err != nil {
log.Fatal(err)
}
}