Skip to content

Commit

Permalink
fix(dns): should reject with nx instead of 0.0.0.0 (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
mzz2017 authored Jul 16, 2023
1 parent e5e0701 commit 00b39df
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 134 deletions.
15 changes: 9 additions & 6 deletions control/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,12 @@ func NewControlPlane(
}
return nil
},
NewCache: func(fqdn string, answers []dnsmessage.RR, deadline time.Time) (cache *DnsCache, err error) {
NewCache: func(fqdn string, answers []dnsmessage.RR, deadline time.Time, originalDeadline time.Time) (cache *DnsCache, err error) {
return &DnsCache{
DomainBitmap: plane.routingMatcher.domainMatcher.MatchDomainBitmap(fqdn),
Answer: answers,
Deadline: deadline,
DomainBitmap: plane.routingMatcher.domainMatcher.MatchDomainBitmap(fqdn),
Answer: answers,
Deadline: deadline,
OriginalDeadline: originalDeadline,
}, nil
},
BestDialerChooser: plane.chooseBestDnsDialer,
Expand All @@ -423,7 +424,9 @@ func NewControlPlane(
return nil, err
}
// Refresh domain routing cache with new routing.
if dnsCache != nil && len(dnsCache) > 0 {
// FIXME: We temperarily disable it because we want to make change of DNS section take effects immediately.
// TODO: Add change detection.
if false && len(dnsCache) > 0 {
for cacheKey, cache := range dnsCache {
// Also refresh out-dated routing because kernel map items have no expiration.
lastDot := strings.LastIndex(cacheKey, ".")
Expand Down Expand Up @@ -556,7 +559,7 @@ func (c *ControlPlane) ChooseDialTarget(outbound consts.OutboundIndex, dst netip
if !outbound.IsReserved() && domain != "" {
switch c.dialMode {
case consts.DialMode_Domain:
if cache := c.dnsController.LookupDnsRespCache(domain, common.AddrToDnsType(dst.Addr())); cache != nil {
if cache := c.dnsController.LookupDnsRespCache(c.dnsController.cacheKey(domain, common.AddrToDnsType(dst.Addr())), true); cache != nil {
// Has A/AAAA records. It is a real domain.
dialMode = consts.DialMode_Domain
} else {
Expand Down
7 changes: 4 additions & 3 deletions control/dns_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (
)

type DnsCache struct {
DomainBitmap []uint32
Answer []dnsmessage.RR
Deadline time.Time
DomainBitmap []uint32
Answer []dnsmessage.RR
Deadline time.Time
OriginalDeadline time.Time // This field is not impacted by `fixed_domain_ttl`.
}

func (c *DnsCache) FillInto(req *dnsmessage.Msg) {
Expand Down
Loading

0 comments on commit 00b39df

Please sign in to comment.