mirror of
https://github.com/openziti/zrok.git
synced 2024-11-25 09:33:43 +01:00
show client connect/disconnect events
This commit is contained in:
parent
b7f046abf5
commit
bbeb435dfa
@ -13,6 +13,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/songgao/water/waterutil"
|
||||
"io"
|
||||
"net"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@ -88,10 +89,15 @@ func (b *Backend) readTun() {
|
||||
|
||||
logrus.WithField("packet", pkt).Trace("read from tun device")
|
||||
dest := pkt.destination()
|
||||
|
||||
if clt, ok := b.clients.Get(dest); ok {
|
||||
_, err := clt.conn.Write(pkt)
|
||||
if err != nil {
|
||||
b.cfg.RequestsChan <- &endpoints.Request{
|
||||
Stamp: time.Now(),
|
||||
RemoteAddr: dest.String(),
|
||||
Method: "DISCONNECTED",
|
||||
}
|
||||
|
||||
logrus.WithError(err).Errorf("failed to write packet to clt[%v]", dest)
|
||||
_ = clt.conn.Close()
|
||||
b.clients.Remove(dest)
|
||||
@ -153,6 +159,13 @@ func (b *Backend) handle(conn net.Conn) {
|
||||
MTU: b.mtu,
|
||||
}
|
||||
|
||||
b.cfg.RequestsChan <- &endpoints.Request{
|
||||
Stamp: time.Now(),
|
||||
RemoteAddr: ipv4.String(),
|
||||
Method: "CONNECTED",
|
||||
Path: cfg.ServerIP,
|
||||
}
|
||||
|
||||
j, err := json.Marshal(&cfg)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("failed to write client VPN config")
|
||||
@ -171,14 +184,22 @@ func (b *Backend) handle(conn net.Conn) {
|
||||
for {
|
||||
read, err := conn.Read(buf)
|
||||
if err != nil {
|
||||
logrus.Error("read error", err)
|
||||
if err != io.EOF {
|
||||
logrus.WithError(err).Error("read error")
|
||||
}
|
||||
b.cfg.RequestsChan <- &endpoints.Request{
|
||||
Stamp: time.Now(),
|
||||
RemoteAddr: ipv4.String(),
|
||||
Method: "DISCONNECTED",
|
||||
}
|
||||
return
|
||||
}
|
||||
pkt := packet(buf[:read])
|
||||
logrus.WithField("packet", pkt).Info("read from ziti")
|
||||
logrus.WithField("packet", pkt).Trace("read from ziti")
|
||||
_, err = b.tun.Write(pkt)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("failed to write packet to tun")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,9 +31,9 @@ func (d dest) toInt32() uint32 {
|
||||
}
|
||||
|
||||
func ipToDest(addr net.IP) dest {
|
||||
return dest{
|
||||
addr: [4]byte{addr[0], addr[1], addr[2], addr[3]},
|
||||
}
|
||||
d := dest{}
|
||||
copy(d.addr[:], addr.To4())
|
||||
return d
|
||||
}
|
||||
|
||||
type packet []byte
|
||||
|
Loading…
Reference in New Issue
Block a user