all: watch lease files if send client info enabled

So users who run ctrld in Linux can still see clients info, even though
it's not an router platform that ctrld supports.
This commit is contained in:
Cuong Manh Le authored and Cuong Manh Le committed 2023-08-09 23:54:23 +07:00
1 parent 472bb05e95
commit 9fe6af684f
8 files changed
+250 -223

No files matched your search

-3
View File
@@ -219,9 +219,6 @@ func initCLI() {
if err := router.Cleanup(svcConfig); err != nil {
mainLog.Error().Err(err).Msg("could not cleanup router")
}
if err := router.Stop(); err != nil {
mainLog.Error().Err(err).Msg("problem occurred while stopping router")
}
p.resetDNS()
})
}
+2 -3
View File
@@ -22,7 +22,6 @@ import (
"github.com/Control-D-Inc/ctrld"
"github.com/Control-D-Inc/ctrld/internal/dnscache"
ctrldnet "github.com/Control-D-Inc/ctrld/internal/net"
"github.com/Control-D-Inc/ctrld/internal/router"
)
const (
@@ -56,7 +55,7 @@ func (p *prog) serveDNS(listenerNum string) error {
q := m.Question[0]
domain := canonicalName(q.Name)
reqId := requestID()
remoteAddr := spoofRemoteAddr(w.RemoteAddr(), router.GetClientInfoByMac(macFromMsg(m)))
remoteAddr := spoofRemoteAddr(w.RemoteAddr(), p.mt.GetClientInfoByMac(macFromMsg(m)))
fmtSrcToDest := fmtRemoteToLocal(listenerNum, remoteAddr.String(), w.LocalAddr().String())
t := time.Now()
ctx := context.WithValue(context.Background(), ctrld.ReqIdCtxKey{}, reqId)
@@ -247,7 +246,7 @@ func (p *prog) proxy(ctx context.Context, upstreams []string, failoverRcodes []i
}
resolve := func(n int, upstreamConfig *ctrld.UpstreamConfig, msg *dns.Msg) *dns.Msg {
if upstreamConfig.UpstreamSendClientInfo() {
ci := router.GetClientInfoByMac(macFromMsg(msg))
ci := p.mt.GetClientInfoByMac(macFromMsg(msg))
if ci != nil {
ctrld.Log(ctx, mainLog.Debug(), "including client info with the request")
ctx = context.WithValue(ctx, ctrld.ClientInfoCtxKey{}, ci)
+12
View File
@@ -13,6 +13,7 @@ import (
"github.com/kardianos/service"
"github.com/Control-D-Inc/ctrld"
"github.com/Control-D-Inc/ctrld/internal/clientinfo"
"github.com/Control-D-Inc/ctrld/internal/dnscache"
"github.com/Control-D-Inc/ctrld/internal/router"
)
@@ -39,6 +40,7 @@ type prog struct {
cfg *ctrld.Config
cache dnscache.Cacher
sema semaphore
mt *clientinfo.MacTable
started chan struct{}
onStarted []func()
@@ -100,6 +102,16 @@ func (p *prog) run() {
go uc.Ping()
}
p.mt = clientinfo.NewMacTable()
if p.cfg.HasUpstreamSendClientInfo() {
mainLog.Debug().Msg("Sending client info enabled")
if err := p.mt.Init(); err == nil {
mainLog.Debug().Msg("Start watching client info changes")
go p.mt.WatchLeaseFiles()
} else {
mainLog.Warn().Err(err).Msg("could not record client info")
}
}
go p.watchLinkState()
for listenerNum := range p.cfg.Listener {