-
Notifications
You must be signed in to change notification settings - Fork 584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] permissions: redesign address permissions regarding networks #2551
Comments
Here is an attempt to implement it on 2.4.11 branch. EDIT: |
To explain it quickly, each partition holds arrays of Subnet functions were removed, and hash functions were updated to use |
The same based on branch |
The patched OpenSIPS 2.4.11 has been tested for over a month on production systems, with no issues noted so far. |
@Nestorfish , thanks for your work and contribution here. Could you generate a PR against the master branch, so we can do a proper review ? |
@bogdan-iancu The branch is updated against master. I left documentation untouched. |
Hi, @Nestorfish! Regarding this FR and the PR in #2648, please note that #3560 is to be merged soon, which eliminates the "128" subnet limitation, while also boosting lookup performance by converting all internal data structures in permissions module to use trie data structures. Moreover, the whole extension is backwards-compatible: same MI output in Is this enough to fullfill your use case too? I notice you would prefer a longest-prefix-match, but what is the use-case? Because, after all, if you're trying to match source IP in group |
Is your feature request related to a problem? Please describe.
We will soon have to insert quite a lot of IPv4 network ranges in
address
, so I took a look at the way OpenSIPS handles this, and more generally address permissions.Here is what I found so far (the following applies to a partition):
Storage
Individual hosts (mask 32 or 128 depending on address family) are stored in a hash-map, IP address begin the key.
The maximum number of buckets is set during compilation (
PERM_HASH_SIZE
, default 128, used inperm_hash
macro as parameter tocore_hash
)There is no particular ordering for elements matching this key, they are inserted in front of a chained list as they are read from database.
Non-host network addresses are stored in a fixed-size array, whose size is set during compilation (the same
PERM_HASH_SIZE
, default 128).They are ordered by
group_id
.Match
OpenSIPS first looks into the hosts hash-map.
It checks if the given
group_id
(if any) exists in any value, and aborts if not.Then it iterates the chained list corresponding to the IP address.
If no matching entry is found above, it uses the networks array.
It first checks if there is any entry for the given
group_id
(if any), and aborts if not.Then it looks for a matching entry.
(By the way, it forgets meantime the index where the
group_id
was found in the array, it could have avoided restarting from first position by remembering it)Remarks
group_id
exists? If it is absent, it only produces a LM_DBG statement along with a different return code (which is not documented for now I guess)cache_collections
parameter of modulecachedb_local
which sets the number of bits). Not a must-have howeverDescribe the solution you'd like
Treat all entries the same way, namely:
No limitation for number of network entries
Match the smallest network first, being an host or not
Implementation
Proposal
Storage
ip
value after zeroing host bits.Match
Hash IP address
Set the initial index to the IP address family size (eg. 128 or 32)
Search for a matching entry in the hash-map present at this index, at the computed hash
If none found:
Break if index == 0
Decrement index
If the bit that passed from network part to host part of IP address == 1:
Go to 3.
permissions
moduleThe text was updated successfully, but these errors were encountered: