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.