Skip to content

Commit

Permalink
Faster wildcard elaboration
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Apr 9, 2020
1 parent e8957d7 commit 4593074
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions pkg/massdns/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,39 +127,37 @@ func (c *Client) filterWildcards(st *store.Store) error {
wildcardWg := sizedwaitgroup.New(c.config.WildcardsThreads)

for _, record := range st.IP {
wildcardWg.Add()

go func(record *store.IPMeta) {
defer wildcardWg.Done()

// We've stumbled upon a wildcard, just ignore it.
c.wildcardIPMutex.Lock()
if _, ok := c.wildcardIPMap[record.IP]; ok {
c.wildcardIPMutex.Unlock()
return
}
// We've stumbled upon a wildcard, just ignore it.
c.wildcardIPMutex.Lock()
if _, ok := c.wildcardIPMap[record.IP]; ok {
c.wildcardIPMutex.Unlock()

// If the same ip has been found more than 5 times, perform wildcard detection
// on it now, if an IP is found in the wildcard we add it to the wildcard map
// so that further runs don't require such filtering again.
if record.Counter >= 5 && !record.Validated {
for host := range record.Hostnames {
continue
}
c.wildcardIPMutex.Unlock()

// If the same ip has been found more than 5 times, perform wildcard detection
// on it now, if an IP is found in the wildcard we add it to the wildcard map
// so that further runs don't require such filtering again.
if record.Counter >= 5 && !record.Validated {
for host := range record.Hostnames {
wildcardWg.Add()
go func(host string) {
defer wildcardWg.Done()
wildcard, ips := c.wildcardResolver.LookupHost(host)
if wildcard {
c.wildcardIPMutex.Lock()
for ip := range ips {
c.wildcardIPMap[ip] = struct{}{}
}
c.wildcardIPMutex.Unlock()
continue
}
record.Validated = true
}
}(host)
record.Validated = true
}
}(record)
}

wildcardWg.Wait()
}
wildcardWg.Wait()

// drop all wildcard from the store
for wildcardIP := range c.wildcardIPMap {
Expand Down

0 comments on commit 4593074

Please sign in to comment.