geoip: read source IP from EDNS0 subnet if provided (#5183)

* geoip: read source IP from EDNS0 subnet if provided

This patch implements EDNS backend processing (similar in powerdns: https://doc.powerdns.com/authoritative/settings.html#setting-edns-subnet-processing). This feature comes very handy to test whether your geo config is working properly.

Signed-off-by: Balazs Nagy <julsevern@gmail.com>
This commit is contained in:
Balazs Nagy 2022-05-02 19:25:02 +02:00 committed by GitHub
parent 66f2ac7568
commit 4ae29a449c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 122 additions and 50 deletions

View file

@ -26,6 +26,7 @@ func setup(c *caddy.Controller) error {
func geoipParse(c *caddy.Controller) (*GeoIP, error) {
var dbPath string
var edns0 bool
for c.Next() {
if !c.NextArg() {
@ -39,13 +40,16 @@ func geoipParse(c *caddy.Controller) (*GeoIP, error) {
if len(c.RemainingArgs()) != 0 {
return nil, c.ArgErr()
}
// The plugin should not have any config block.
if c.NextBlock() {
return nil, c.Err("unexpected config block")
for c.NextBlock() {
if c.Val() != "edns-subnet" {
return nil, c.Errf("unknown property %q", c.Val())
}
edns0 = true
}
}
geoIP, err := newGeoIP(dbPath)
geoIP, err := newGeoIP(dbPath, edns0)
if err != nil {
return geoIP, c.Err(err.Error())
}