mirror of
https://github.com/openziti/zrok.git
synced 2025-06-13 21:37:01 +02: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/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/songgao/water/waterutil"
|
"github.com/songgao/water/waterutil"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -88,10 +89,15 @@ func (b *Backend) readTun() {
|
|||||||
|
|
||||||
logrus.WithField("packet", pkt).Trace("read from tun device")
|
logrus.WithField("packet", pkt).Trace("read from tun device")
|
||||||
dest := pkt.destination()
|
dest := pkt.destination()
|
||||||
|
|
||||||
if clt, ok := b.clients.Get(dest); ok {
|
if clt, ok := b.clients.Get(dest); ok {
|
||||||
_, err := clt.conn.Write(pkt)
|
_, err := clt.conn.Write(pkt)
|
||||||
if err != nil {
|
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)
|
logrus.WithError(err).Errorf("failed to write packet to clt[%v]", dest)
|
||||||
_ = clt.conn.Close()
|
_ = clt.conn.Close()
|
||||||
b.clients.Remove(dest)
|
b.clients.Remove(dest)
|
||||||
@ -153,6 +159,13 @@ func (b *Backend) handle(conn net.Conn) {
|
|||||||
MTU: b.mtu,
|
MTU: b.mtu,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
b.cfg.RequestsChan <- &endpoints.Request{
|
||||||
|
Stamp: time.Now(),
|
||||||
|
RemoteAddr: ipv4.String(),
|
||||||
|
Method: "CONNECTED",
|
||||||
|
Path: cfg.ServerIP,
|
||||||
|
}
|
||||||
|
|
||||||
j, err := json.Marshal(&cfg)
|
j, err := json.Marshal(&cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("failed to write client VPN config")
|
logrus.WithError(err).Error("failed to write client VPN config")
|
||||||
@ -171,14 +184,22 @@ func (b *Backend) handle(conn net.Conn) {
|
|||||||
for {
|
for {
|
||||||
read, err := conn.Read(buf)
|
read, err := conn.Read(buf)
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
pkt := packet(buf[:read])
|
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)
|
_, err = b.tun.Write(pkt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("failed to write packet to tun")
|
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 {
|
func ipToDest(addr net.IP) dest {
|
||||||
return dest{
|
d := dest{}
|
||||||
addr: [4]byte{addr[0], addr[1], addr[2], addr[3]},
|
copy(d.addr[:], addr.To4())
|
||||||
}
|
return d
|
||||||
}
|
}
|
||||||
|
|
||||||
type packet []byte
|
type packet []byte
|
||||||
|
Loading…
x
Reference in New Issue
Block a user