mirror of
https://github.com/daeuniverse/dae.git
synced 2025-01-22 02:07:50 +07:00
optimize: avoid conflict with potential local dns server (#422)
This commit is contained in:
parent
41d5de1056
commit
b0f6205cc9
@ -38,7 +38,9 @@ func (a *Anyfrom) afterWrite(err error) {
|
||||
a.RefreshTtl()
|
||||
}
|
||||
func (a *Anyfrom) RefreshTtl() {
|
||||
a.deadlineTimer.Reset(a.ttl)
|
||||
if a.deadlineTimer != nil {
|
||||
a.deadlineTimer.Reset(a.ttl)
|
||||
}
|
||||
}
|
||||
func (a *Anyfrom) SupportGso(size int) bool {
|
||||
if size > math.MaxUint16 {
|
||||
@ -202,16 +204,19 @@ func (p *AnyfromPool) GetOrCreate(lAddr string, ttl time.Duration) (conn *Anyfro
|
||||
gotGSOError: false,
|
||||
gso: isGSOSupported(uConn),
|
||||
}
|
||||
af.deadlineTimer = time.AfterFunc(ttl, func() {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
_af := p.pool[lAddr]
|
||||
if _af == af {
|
||||
delete(p.pool, lAddr)
|
||||
af.Close()
|
||||
}
|
||||
})
|
||||
p.pool[lAddr] = af
|
||||
|
||||
if ttl > 0 {
|
||||
af.deadlineTimer = time.AfterFunc(ttl, func() {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
_af := p.pool[lAddr]
|
||||
if _af == af {
|
||||
delete(p.pool, lAddr)
|
||||
af.Close()
|
||||
}
|
||||
})
|
||||
p.pool[lAddr] = af
|
||||
}
|
||||
return af, true, nil
|
||||
} else {
|
||||
af.RefreshTtl()
|
||||
|
@ -89,7 +89,12 @@ func sendPkt(data []byte, from netip.AddrPort, realTo, to netip.AddrPort, lConn
|
||||
return sendPktWithHdrWithFlag(data, from, lConn, to, lanWanFlag)
|
||||
}
|
||||
|
||||
uConn, _, err := DefaultAnyfromPool.GetOrCreate(from.String(), AnyfromTimeout)
|
||||
transparentTimeout := AnyfromTimeout
|
||||
if from.Port() == 53 {
|
||||
// Add port 53 (udp) to whitelist to avoid conflicts with the potential local dns server.
|
||||
transparentTimeout = 0
|
||||
}
|
||||
uConn, _, err := DefaultAnyfromPool.GetOrCreate(from.String(), transparentTimeout)
|
||||
if err != nil && errors.Is(err, syscall.EADDRINUSE) {
|
||||
logrus.WithField("from", from).
|
||||
WithField("to", to).
|
||||
|
Loading…
Reference in New Issue
Block a user