Skip to content

Commit 4593074

Browse files
committed
Faster wildcard elaboration
1 parent e8957d7 commit 4593074

1 file changed

Lines changed: 20 additions & 22 deletions

File tree

pkg/massdns/process.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,39 +127,37 @@ func (c *Client) filterWildcards(st *store.Store) error {
127127
wildcardWg := sizedwaitgroup.New(c.config.WildcardsThreads)
128128

129129
for _, record := range st.IP {
130-
wildcardWg.Add()
131-
132-
go func(record *store.IPMeta) {
133-
defer wildcardWg.Done()
134-
135-
// We've stumbled upon a wildcard, just ignore it.
136-
c.wildcardIPMutex.Lock()
137-
if _, ok := c.wildcardIPMap[record.IP]; ok {
138-
c.wildcardIPMutex.Unlock()
139-
return
140-
}
130+
// We've stumbled upon a wildcard, just ignore it.
131+
c.wildcardIPMutex.Lock()
132+
if _, ok := c.wildcardIPMap[record.IP]; ok {
141133
c.wildcardIPMutex.Unlock()
142-
143-
// If the same ip has been found more than 5 times, perform wildcard detection
144-
// on it now, if an IP is found in the wildcard we add it to the wildcard map
145-
// so that further runs don't require such filtering again.
146-
if record.Counter >= 5 && !record.Validated {
147-
for host := range record.Hostnames {
134+
continue
135+
}
136+
c.wildcardIPMutex.Unlock()
137+
138+
// If the same ip has been found more than 5 times, perform wildcard detection
139+
// on it now, if an IP is found in the wildcard we add it to the wildcard map
140+
// so that further runs don't require such filtering again.
141+
if record.Counter >= 5 && !record.Validated {
142+
for host := range record.Hostnames {
143+
wildcardWg.Add()
144+
go func(host string) {
145+
defer wildcardWg.Done()
148146
wildcard, ips := c.wildcardResolver.LookupHost(host)
149147
if wildcard {
150148
c.wildcardIPMutex.Lock()
151149
for ip := range ips {
152150
c.wildcardIPMap[ip] = struct{}{}
153151
}
154152
c.wildcardIPMutex.Unlock()
155-
continue
156153
}
157-
record.Validated = true
158-
}
154+
}(host)
155+
record.Validated = true
159156
}
160-
}(record)
157+
}
158+
159+
wildcardWg.Wait()
161160
}
162-
wildcardWg.Wait()
163161

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

0 commit comments

Comments
 (0)