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:
parent
66f2ac7568
commit
4ae29a449c
5 changed files with 122 additions and 50 deletions
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue