Skip to content
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
merged 11 commits into from
Jul 29, 2024
Merged

Conversation

cejkato2
Copy link
Contributor

No description provided.

cejkato2 added 3 commits July 25, 2024 22:56
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-commenter
Copy link

codecov-commenter commented Jul 25, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.00%. Comparing base (10f312c) to head (47a45e7).

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               
Flag Coverage Δ
tests 85.00% <ø> (+15.00%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

cejkato2 added 8 commits July 26, 2024 10:29
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 cejkato2 merged commit a8d19d1 into master Jul 29, 2024
2 checks passed
@cejkato2 cejkato2 deleted the pytrap_uriplist branch July 29, 2024 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants