-
Notifications
You must be signed in to change notification settings - Fork 25
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
Pytrap improved UnirecIPAddr and added UnirecIPList #226
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This version uses hard/deep copy of the user value, which leads to issues during deallocation. Thus, this version leaks memory when the UnirecIPList object is deleted.
The example of usage is shown in the test/ipblacklist_unittest.py: ``` >>> import pytrap >>> iplist = pytrap.UnirecIPList({ ... pytrap.UnirecIPAddrRange("192.168.1.0/24"): "ip4", ... pytrap.UnirecIPAddrRange("2001::1/48"): "ipv6", ... pytrap.UnirecIPAddrRange(pytrap.UnirecIPAddr("10.0.0.1"), ... pytrap.UnirecIPAddr("10.0.0.1")): "host" }) >>> >>> pytrap.UnirecIPAddr("192.168.1.255") in iplist True >>> print(iplist.find(pytrap.UnirecIPAddr("1.0.0.1"))) None >>> print(iplist.find(pytrap.UnirecIPAddr("10.0.0.1"))) host ```
The example usage is as follows: ``` >>> import pytrap >>> import ipaddress >>> a = ipaddress.ip_address("1.0.1.1") >>> i = pytrap.UnirecIPAddr.from_ipaddress(a) >>> print(a) 1.0.1.1 >>> print(i) 1.0.1.1 >>> ```
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #226 +/- ##
===========================================
+ Coverage 70.00% 85.00% +15.00%
===========================================
Files 2 2
Lines 10 20 +10
Branches 2 2
===========================================
+ Hits 7 17 +10
Misses 2 2
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
The example usage is as follows: ``` >>> import pytrap >>> import ipaddress >>> ip = pytrap.UnirecIPAddr("1.0.1.1") >>> out = ip.to_ipaddress() >>> print(out) 1.0.1.1 >>> ip = pytrap.UnirecIPAddr("2001::3:1002") >>> out = ip.to_ipaddress() >>> print(out) 2001::3:1002 >>> ip = pytrap.UnirecIPAddrRange("2.0.1.1/8") >>> out = ip.to_ipaddress() >>> print(out) 2.0.0.0/8 >>> ip = pytrap.UnirecIPAddrRange("2001::3:1002/48") >>> out = ip.to_ipaddress() >>> print(out) 2001::/48 ```
Thanks to tests by Richard, we discovered segfault when ipps_ctx is not initialized properly and _dealloc() is called. Co-authored-by: @rplny
ip_prefix_search and UnirecIPAddrRange computed netmasks badly for /0 mask This commit contains bugfixes and improved checks. For UnirecIPAddrRange(IP, IP), netmask is computed now! For non-cidr ranges it might be an issue to use netmask; however, it seems ip_prefix_search requires CIDR subnets for IP ranges. Co-authored-by: @rplny
* add UnirecIPList to store <IP range>-<value> pairs and look up IP addresses * add UnirecIPAddr.from_ipaddress() to load IP from python ipaddress * add UnirecIPAddr.to_ipaddress() to convert IP to python ipaddress * add UnirecIPAddrRange.to_ipaddress() to convert IP range to python ipaddress * fixed IP range / ip_prefix_search handling /0 netmask
cejkato2
force-pushed
the
pytrap_uriplist
branch
from
July 29, 2024 08:25
d143e85
to
47a45e7
Compare
SiskaPavel
approved these changes
Jul 29, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.