]> git.ipfire.org Git - thirdparty/knot-resolver.git/commit
lib/cache/api: generalize ECS code to support longest prefix match
authorMarek Vavruša <mvavrusa@cloudflare.com>
Mon, 11 Jun 2018 00:12:00 +0000 (17:12 -0700)
committerMarek Vavruša <mvavrusa@cloudflare.com>
Fri, 7 Sep 2018 17:45:21 +0000 (10:45 -0700)
commit438e031713ea05a8319865e6f84725567d02b812
tree499a60b0a48b189be16fcc7b84b7e1e50c35c074
parent31ac73402a627b4b621a8c36bcc94c5b5f17f7bc
lib/cache/api: generalize ECS code to support longest prefix match

The current semantics is to try to look up an exact match, or
look into global scope. This commit changes that to longest prefix
match, so that wider cache scopes can be used to match against
multiple prefixes. In order to do this, the key scope format needs to
be changed from:

```
u8[] address
u8   scope_len
```

To:

```
u8[4 or 16] address
u8          scope_len
```

The fixed address length is necessary to be able to use lexicographic
lesser-or-equal scan supported by the database. For example, if the
search key is 192.168.0/24 (`\192\168\0\0\24'), any wider prefix
must be lexicographically smaller. The `\192\168\16` wouldn't be,
but the `\192\168\0\0\16` is, hence the key format change.

The fixed key size is also necessary to separate IPv4 scopes from
IPv6 scopes and vice versa. This is checked by comparing the
length of the found lesser-or-equal key - if the length is the same,
and key (without the scope part) is equal, the scope must be the same address
family.
daemon/lua/kres-gen.lua
daemon/lua/kres-gen.sh
daemon/lua/kres.lua
lib/cache/api.c
lib/cache/api.h
lib/cache/entry_pkt.c
lib/cache/impl.h
lib/cache/peek.c
lib/resolve.h