| 1 |
package ecs |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
|
| 6 |
"codeberg.org/miekg/dns" |
| 7 |
"codeberg.org/miekg/dns/cmd/atomdns/internal/dnsctx" |
| 8 |
) |
| 9 |
|
| 10 |
type Ecs struct{} |
| 11 |
|
| 12 |
func (e *Ecs) HandlerFunc(next dns.HandlerFunc) dns.HandlerFunc { |
| 13 |
return dns.HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) { |
| 14 |
for _, o := range r.Pseudo { |
| 15 |
if ecs, ok := o.(*dns.SUBNET); ok { |
| 16 |
ctx = dnsctx.WithValue(ctx, dnsctx.Key(e, "addr"), ecs.Address) |
| 17 |
break |
| 18 |
} |
| 19 |
} |
| 20 |
next.ServeDNS(ctx, w, r) |
| 21 |
}) |
| 22 |
} |