Skip to content

CP-50108: Use Ipaddr instead of string-based CIDR address handling #5794

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

Merged

Conversation

last-genius
Copy link
Contributor

Refactored several string-based functions that handled CIDR addresses to use the Ipaddr module instead.

Expanded test cases, kept the existent exception behaviour.

My first time doing this with modules (in helpers.ml) - not sure if it's in the right direction at all, please do correct me. The idea was to model the common interface for v4 and v6 to avoid code duplication in the logic part. The common interface the library itself offers (in the top-level Ipaddr.) does not have the functionality I would need here. In particular I'm wondering if I'm not exposing this interface into the public unnecessarily and how would I fix that?

==

These changes passed the BST+BVT test suites.

@last-genius last-genius force-pushed the private/asultanov/ipaddr-prefix branch from aea39d5 to 575180b Compare July 10, 2024 08:17
@last-genius
Copy link
Contributor Author

Addressed the review comments in a fixup commit - will be squashed before merging

@psafont
Copy link
Member

psafont commented Jul 10, 2024

I recommend doing fixups without signing them off, it will make the DCO check to fail and make it obvious the PR shouldn't be merged before the fixups are gone

@last-genius last-genius force-pushed the private/asultanov/ipaddr-prefix branch from 575180b to 84856c8 Compare July 10, 2024 11:20
@last-genius last-genius force-pushed the private/asultanov/ipaddr-prefix branch from 84856c8 to 79130a4 Compare July 10, 2024 14:23
@last-genius
Copy link
Contributor Author

This CI failure is weird:

File "ocaml/xapi/nm.ml", line 623, characters 53-80:
623 |                               Prefix.address ip_t |> Ipaddr_unix.V6.to_inet_addr
                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Unbound module Ipaddr_unix

I didn't add this in any of the fixups, and it passed before. Did something in xs-opam change in the meantime?

@last-genius last-genius force-pushed the private/asultanov/ipaddr-prefix branch from 79130a4 to 24d418b Compare July 10, 2024 15:30
@last-genius
Copy link
Contributor Author

Got it, transitive dependencies were turned off on master, had to add the submodule to dune as well. CI passes now.

32 - List.fold_left length 0 masks
let raise_on_ipaddr_err = function
| `Msg str ->
raise (Scanf.Scan_failure str)
Copy link
Contributor

@lindig lindig Jul 10, 2024

Choose a reason for hiding this comment

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

We are no longer using Scanf for parsing - so I think we should not use this exception (I understand the argument for maintaining previous behaviour). I doubt this exception is handled except at the highest level (might want to grep for it). So with could be a failwith which also would be turned into an internal error at the outermost level. I am fine to merge this as is, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced with a failwith

In nm.ml; helpers.ml.
Expands test cases, keeps the existent exception behaviour.

Signed-off-by: Andrii Sultanov <andrii.sultanov@cloud.com>
@last-genius last-genius force-pushed the private/asultanov/ipaddr-prefix branch from 24d418b to b23a64a Compare July 11, 2024 08:16
@lindig lindig merged commit 55963c4 into xapi-project:master Jul 11, 2024
15 checks passed
@last-genius last-genius deleted the private/asultanov/ipaddr-prefix branch July 11, 2024 08:45
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.

5 participants