mirror of
https://github.com/daeuniverse/dae.git
synced 2025-02-02 04:14:31 +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()
|
a.RefreshTtl()
|
||||||
}
|
}
|
||||||
func (a *Anyfrom) 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 {
|
func (a *Anyfrom) SupportGso(size int) bool {
|
||||||
if size > math.MaxUint16 {
|
if size > math.MaxUint16 {
|
||||||
@ -202,16 +204,19 @@ func (p *AnyfromPool) GetOrCreate(lAddr string, ttl time.Duration) (conn *Anyfro
|
|||||||
gotGSOError: false,
|
gotGSOError: false,
|
||||||
gso: isGSOSupported(uConn),
|
gso: isGSOSupported(uConn),
|
||||||
}
|
}
|
||||||
af.deadlineTimer = time.AfterFunc(ttl, func() {
|
|
||||||
p.mu.Lock()
|
if ttl > 0 {
|
||||||
defer p.mu.Unlock()
|
af.deadlineTimer = time.AfterFunc(ttl, func() {
|
||||||
_af := p.pool[lAddr]
|
p.mu.Lock()
|
||||||
if _af == af {
|
defer p.mu.Unlock()
|
||||||
delete(p.pool, lAddr)
|
_af := p.pool[lAddr]
|
||||||
af.Close()
|
if _af == af {
|
||||||
}
|
delete(p.pool, lAddr)
|
||||||
})
|
af.Close()
|
||||||
p.pool[lAddr] = af
|
}
|
||||||
|
})
|
||||||
|
p.pool[lAddr] = af
|
||||||
|
}
|
||||||
return af, true, nil
|
return af, true, nil
|
||||||
} else {
|
} else {
|
||||||
af.RefreshTtl()
|
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)
|
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) {
|
if err != nil && errors.Is(err, syscall.EADDRINUSE) {
|
||||||
logrus.WithField("from", from).
|
logrus.WithField("from", from).
|
||||||
WithField("to", to).
|
WithField("to", to).
|
||||||
|
Loading…
Reference in New Issue
Block a user