@@ -19,9 +19,9 @@ const (
19
19
)
20
20
21
21
var (
22
- ErrInvalidIPVersion = errors .New ("invalid IP version specified, must be 4 or 6" )
23
- ErrLoopDetected = errors .New ("loop detected in SPF resolution" )
24
- ErrExceededMaxDepth = errors .New ("maximum SPF include depth exceeded" )
22
+ ErrInvalidIPVersion = errors .New ("spf2ip: invalid IP version specified, must be 4 or 6" )
23
+ ErrLoopDetected = errors .New ("spf2ip: loop detected in SPF resolution" )
24
+ ErrExceededMaxDepth = errors .New ("spf2ip: maximum SPF include depth exceeded" )
25
25
)
26
26
27
27
type SPF2IPResolver struct {
@@ -108,7 +108,7 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
108
108
r .debugLogPrintf ("Debug: Failed to get SPF record for %s: %v" , domain , err )
109
109
r .resolvedIPsCache [domain ] = nil
110
110
111
- return nil , fmt .Errorf ("failed to get SPF record for %s: %w" , domain , err )
111
+ return nil , fmt .Errorf ("spf2ip: failed to get SPF record for %s: %w" , domain , err )
112
112
}
113
113
114
114
if spfString == "" {
@@ -142,14 +142,14 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
142
142
case "ip4" :
143
143
if r .ipVersion == ipv4 {
144
144
if err := r .addIPOrCIDRToSet (value , currentDomainIPs ); err != nil {
145
- return nil , fmt .Errorf ("failed to add IP/CIDR for ip4 mechanism in %s: %w" , domain , err )
145
+ return nil , fmt .Errorf ("spf2ip: failed to add IP/CIDR for ip4 mechanism in %s: %w" , domain , err )
146
146
}
147
147
}
148
148
149
149
case "ip6" :
150
150
if r .ipVersion == ipv6 {
151
151
if err := r .addIPOrCIDRToSet (value , currentDomainIPs ); err != nil {
152
- return nil , fmt .Errorf ("failed to add IP/CIDR for ip6 mechanism in %s: %w" , domain , err )
152
+ return nil , fmt .Errorf ("spf2ip: failed to add IP/CIDR for ip6 mechanism in %s: %w" , domain , err )
153
153
}
154
154
}
155
155
@@ -168,7 +168,7 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
168
168
169
169
for _ , ip := range ips {
170
170
if err := r .addIPOrCIDRToSet (ip .String ()+ maskSuffix , currentDomainIPs ); err != nil {
171
- return nil , fmt .Errorf ("failed to add IP/CIDR for A mechanism in %s: %w" , domain , err )
171
+ return nil , fmt .Errorf ("spf2ip: failed to add IP/CIDR for A mechanism in %s: %w" , domain , err )
172
172
}
173
173
}
174
174
@@ -182,7 +182,7 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
182
182
continue
183
183
}
184
184
185
- return nil , fmt .Errorf ("MX lookup failed for %s (directive in %s): %w" , targetHost , domain , err )
185
+ return nil , fmt .Errorf ("spf2ip: MX lookup failed for %s (directive in %s): %w" , targetHost , domain , err )
186
186
}
187
187
188
188
for _ , mx := range mxs {
@@ -201,7 +201,7 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
201
201
202
202
for _ , ip := range ips {
203
203
if err := r .addIPOrCIDRToSet (ip .String ()+ maskSuffix , currentDomainIPs ); err != nil {
204
- return nil , fmt .Errorf ("failed to add IP/CIDR for MX mechanism in %s: %w" , domain , err )
204
+ return nil , fmt .Errorf ("spf2ip: failed to add IP/CIDR for MX mechanism in %s: %w" , domain , err )
205
205
}
206
206
}
207
207
}
@@ -211,12 +211,12 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
211
211
r .debugLogPrintf ("Debug: 'include' modifier without domain in %s" , domain )
212
212
r .resolvedIPsCache [domain ] = nil
213
213
214
- return nil , fmt .Errorf ("include without domain in %s" , domain )
214
+ return nil , fmt .Errorf ("spf2ip: include without domain in %s" , domain )
215
215
}
216
216
217
217
includedIPs , includeErr := r .processDomain (ctx , value , depth + 1 )
218
218
if includeErr != nil {
219
- return nil , fmt .Errorf ("include failed for %s (directive in %s): %w" , value , domain , includeErr )
219
+ return nil , fmt .Errorf ("spf2ip: include failed for %s (directive in %s): %w" , value , domain , includeErr )
220
220
}
221
221
222
222
for ip := range includedIPs {
@@ -228,7 +228,7 @@ func (r *SPF2IPResolver) processDomain(ctx context.Context, domain string, depth
228
228
r .debugLogPrintf ("Debug: 'redirect' modifier without domain in %s" , domain )
229
229
r .resolvedIPsCache [domain ] = nil
230
230
231
- return nil , fmt .Errorf ("redirect without domain in %s" , domain )
231
+ return nil , fmt .Errorf ("spf2ip: redirect without domain in %s" , domain )
232
232
}
233
233
234
234
r .debugLogPrintf ("Debug: Redirecting from %s to %s. Discarding IPs found so far for %s." , domain , value , domain )
@@ -290,8 +290,8 @@ func parseSPFMechanismTargetAndMask(defaultDomain, mechanismValue string) (targe
290
290
}
291
291
292
292
var (
293
- errIgnorableDNSErr = errors .New ("ignorable DNS error" )
294
- errDNSErr = errors .New ("DNS error" )
293
+ errIgnorableDNSErr = errors .New ("spf2ip: ignorable DNS error" )
294
+ errDNSErr = errors .New ("spf2ip: DNS error" )
295
295
)
296
296
297
297
func (r * SPF2IPResolver ) getSPFRecord (ctx context.Context , domain string ) (string , error ) {
@@ -329,7 +329,7 @@ func (r *SPF2IPResolver) addIPOrCIDRToSet(value string, targetSet map[string]str
329
329
return nil
330
330
}
331
331
332
- return fmt .Errorf ("CIDR '%s' is not of the required IP version (v%d)" , value , r .ipVersion )
332
+ return fmt .Errorf ("spf2ip: CIDR '%s' is not of the required IP version (v%d)" , value , r .ipVersion )
333
333
}
334
334
335
335
// Try plain IP
@@ -347,10 +347,10 @@ func (r *SPF2IPResolver) addIPOrCIDRToSet(value string, targetSet map[string]str
347
347
return nil
348
348
}
349
349
350
- return fmt .Errorf ("IP address '%s' is not of the required IP version (v%d)" , value , r .ipVersion )
350
+ return fmt .Errorf ("spf2ip: IP address '%s' is not of the required IP version (v%d)" , value , r .ipVersion )
351
351
}
352
352
353
- return fmt .Errorf ("value '%s' is not a valid IP address or CIDR block" , value )
353
+ return fmt .Errorf ("spf2ip: value '%s' is not a valid IP address or CIDR block" , value )
354
354
}
355
355
356
356
// debugLogPrintf logs debug messages if debug logging is enabled.
0 commit comments