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

PPL cidr function #706

Merged
merged 13 commits into from
Oct 30, 2024
Merged

PPL cidr function #706

merged 13 commits into from
Oct 30, 2024

Conversation

salyh
Copy link
Contributor

@salyh salyh commented Sep 26, 2024

Description

Implement cidr function to check wether an ip address is with a given cidr

Issues Resolved

#671

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@salyh
Copy link
Contributor Author

salyh commented Sep 26, 2024

@YANG-DB @vamshin @anirudha

I pushed the scaffold for the CIDR function.
The real implementation which validates the ip address and check if its within the cidr is missing because we need to discuss the introduction of a new 3rd party library:

I suggest to add a dependency to https://github.com/seancfoley/IPAddress because this library seems to provide ip validation and in range checking for ipv4 and ipv6 addresses/cidrs. The library is Apache licensed.

Other options are the following libraries or code snippets (or of course manual implementation with java standard library which is error prone in my view):

Let me know what you think and what the general process is to discuss new dependencies

@YANG-DB
Copy link
Member

YANG-DB commented Sep 26, 2024

Hi @salyh
I agree - let's use https://github.com/seancfoley/IPAddress library since it's in use in our SQL repo already

@LantaoJin
Copy link
Member

LantaoJin commented Sep 27, 2024

Hi @salyh
Can you check if the Guava library can meet our needs?

@YANG-DB YANG-DB added Lang:PPL Pipe Processing Language support 0.6 labels Sep 27, 2024
@salyh
Copy link
Contributor Author

salyh commented Sep 27, 2024

Hi @salyh Can you check if the Guava library can meet our needs?

I checked but it does not support cidr checks. https://github.com/seancfoley/IPAddress is also already used in the sql project.

@salyh
Copy link
Contributor Author

salyh commented Sep 27, 2024

Hi @salyh I agree - let's use https://github.com/seancfoley/IPAddress library since it's in use in our SQL repo already

done

@YANG-DB
Copy link
Member

YANG-DB commented Sep 30, 2024

@salyh plz resolve conflict
thanks

@salyh
Copy link
Contributor Author

salyh commented Sep 30, 2024

@salyh plz resolve conflict thanks

done

@salyh
Copy link
Contributor Author

salyh commented Sep 30, 2024

@YANG-DB @vamshin @anirudha

Regarding validation of the CIDR function parameters:

The IPAddress library is very lenient regarding validation of ip addresss and cidr blocks.

I suggest we at least disallow partial ip address segements and empty or null adresses:

  IPAddressStringParameters valOptions = new IPAddressStringParameters.Builder()
                .allowEmpty(false)
                .setEmptyAsLoopback(false)
                .allow_inet_aton(false)
                .allowSingleSegment(false)
                .toParams();

Then the remaining question is wether we should enforce other syntax checks like which the library is not enforcing:

  • check that cidr block is a really a in cicdr notation (containing a '/')
  • check that ip address and cidr are either both ipv6 or both ipv4
  • define the behaviour for edge cases like 0.0.0.0 (or just rely on the api)
  • define handling of special ip adresses like multicast, anycast, 255...* etc

My suggestion is to only

  • disallow partial ip address segements and empty or null adresses (like already implemented) and leave everything else
  • disallow mixed ipv4/ipv6 adresses and cidr blocks

and leave everything else to the library.

@YANG-DB
Copy link
Member

YANG-DB commented Oct 7, 2024

@salyh
please add the needed documentation in the following locations:

@YANG-DB
Copy link
Member

YANG-DB commented Oct 7, 2024

@YANG-DB @vamshin @anirudha

Regarding validation of the CIDR function parameters:

The IPAddress library is very lenient regarding validation of ip addresss and cidr blocks.

I suggest we at least disallow partial ip address segements and empty or null adresses:

  IPAddressStringParameters valOptions = new IPAddressStringParameters.Builder()
                .allowEmpty(false)
                .setEmptyAsLoopback(false)
                .allow_inet_aton(false)
                .allowSingleSegment(false)
                .toParams();

Then the remaining question is wether we should enforce other syntax checks like which the library is not enforcing:

  • check that cidr block is a really a in cicdr notation (containing a '/')
  • check that ip address and cidr are either both ipv6 or both ipv4
  • define the behaviour for edge cases like 0.0.0.0 (or just rely on the api)
  • define handling of special ip adresses like multicast, anycast, 255...* etc

My suggestion is to only

  • disallow partial ip address segements and empty or null adresses (like already implemented) and leave everything else
  • disallow mixed ipv4/ipv6 adresses and cidr blocks

and leave everything else to the library.

@salyh
Thanks for this review - I support your suggestion

  • disallow partial ip address segements and empty or null adresses (like already implemented) and leave everything else
  • disallow mixed ipv4/ipv6 adresses and cidr blocks

In addition plz document the additional validations as future work:

check that cidr block is a really a in cicdr notation (containing a '/')
check that ip address and cidr are either both ipv6 or both ipv4
define the behaviour for edge cases like 0.0.0.0 (or just rely on the api)
define handling of special ip adresses like multicast, anycast, 255...* etc

Thanks

Copy link
Member

@YANG-DB YANG-DB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YANG-DB
Copy link
Member

YANG-DB commented Oct 11, 2024

@dr-lilienthal can u plz resolve the conflicts and also signOff the commits ?( DCO failure )
thanks

@YANG-DB YANG-DB changed the title Initial commit for cidr function PPL cidr function Oct 29, 2024
@YANG-DB
Copy link
Member

YANG-DB commented Oct 29, 2024

@salyh @dr-lilienthal can u plz resolve the conflicts ?
thanks

@salyh
Copy link
Contributor Author

salyh commented Oct 29, 2024

@salyh @dr-lilienthal can u plz resolve the conflicts ? thanks

@YANG-DB done

salyh and others added 13 commits October 29, 2024 19:50
Signed-off-by: Hendrik Saly <[email protected]>
Signed-off-by: Hendrik Saly <[email protected]>
…h exception runtime exception in case of a mixed adress type

Signed-off-by: Jens Schmidt <[email protected]>
Signed-off-by: Hendrik Saly <[email protected]>
Signed-off-by: Hendrik Saly <[email protected]>
Signed-off-by: Hendrik Saly <[email protected]>
Signed-off-by: Hendrik Saly <[email protected]>
Signed-off-by: Hendrik Saly <[email protected]>
Signed-off-by: Hendrik Saly <[email protected]>
@YANG-DB YANG-DB merged commit d2213c5 into opensearch-project:main Oct 30, 2024
4 checks passed
kenrickyap pushed a commit to Bit-Quill/opensearch-spark that referenced this pull request Dec 11, 2024
* Initial commit for cidr function

Signed-off-by: Hendrik Saly <[email protected]>

* Add inet.ipaddr library and implement basic cidr check

Signed-off-by: Hendrik Saly <[email protected]>

* Refactor for using lombok

Signed-off-by: Hendrik Saly <[email protected]>

* Add unittests

Signed-off-by: Hendrik Saly <[email protected]>

* add check for mixed ip address types like ipv4 and ipv6; add test with exception runtime exception in case of a mixed adress type

Signed-off-by: Jens Schmidt <[email protected]>

* Fix antlr

Signed-off-by: Hendrik Saly <[email protected]>

* rename cird function cirdmatch

Signed-off-by: Jens Schmidt <[email protected]>

* Fix imports

Signed-off-by: Hendrik Saly <[email protected]>

* Prepare integ tests

Signed-off-by: Hendrik Saly <[email protected]>

* Added IT tests

Signed-off-by: Hendrik Saly <[email protected]>

* Refactor SerializableUdf to be an interface

Signed-off-by: Hendrik Saly <[email protected]>

* Fix imports

Signed-off-by: Hendrik Saly <[email protected]>

* Added docs

Signed-off-by: Hendrik Saly <[email protected]>

---------

Signed-off-by: Hendrik Saly <[email protected]>
Signed-off-by: Jens Schmidt <[email protected]>
Co-authored-by: Jens Schmidt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.6 Lang:PPL Pipe Processing Language support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants