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

lib.network: first/last and next addresses in a network #322004

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

woojiq
Copy link
Contributor

@woojiq woojiq commented Jun 23, 2024

Description of changes

Depends on #318712 and #326765

  • Add functions to find the first, last and next addresses in a network using
    bitwise operations.
  • Write unit tests for such functions.

Mentor: @Janik-Haag

Things done

  • Tested, as applicable:

Add a 👍 reaction to pull requests you find important.

@woojiq woojiq requested a review from infinisil as a code owner June 23, 2024 17:11
@github-actions github-actions bot added the 6.topic: lib The Nixpkgs function library label Jun 23, 2024
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Jun 23, 2024
@woojiq woojiq force-pushed the lib-network-ipv6-first-and-last-addresses branch from 0a70fc2 to a1c1375 Compare June 29, 2024 06:48
@woojiq woojiq marked this pull request as draft June 29, 2024 06:48

- [addr] An IPv6 address with optional prefix length.
*/
fromString =
Copy link
Member

Choose a reason for hiding this comment

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

Instead of modifying fromString, we should have something like lib.ipv6.firstAddress and lib.ipv6.lastAddress.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, can you explain roughly how you want to use the library? From my point of view, I expect something like fromString <addr> and then the user takes whatever data they need from the returned attr set.

Copy link
Member

Choose a reason for hiding this comment

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

I guess that's fair, esp. since if we implement it correctly the values are lazily evaluated, which means it doesn't really increase the cost. But I still think we should expose the function to end users because it's more ergonomic to call lib.ipv6.lastAddress "f00::c0ffee/64" vs (lib.ipv6.fromString "f00::c0ffee/64").lastAddress. There will also be functions in the future that aren't really incorporatable into fromString, for example imagine something like lib.ipv6.arithmetic "f00::c0ffee/64" (-50)

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/showcase-nixpkgs-network-library/48897/1

@woojiq woojiq force-pushed the lib-network-ipv6-first-and-last-addresses branch from a1c1375 to 59063ec Compare July 11, 2024 19:03
@woojiq woojiq marked this pull request as ready for review July 11, 2024 19:05
@woojiq woojiq changed the title lib.network: first and last addresses in a network lib.network: first/last and next addresses in a network Jul 11, 2024
@woojiq woojiq marked this pull request as draft July 13, 2024 07:13
@woojiq woojiq force-pushed the lib-network-ipv6-first-and-last-addresses branch from 59063ec to 1ceb72f Compare July 13, 2024 08:25
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: documentation This PR adds or changes documentation 6.topic: module system About "NixOS" module system internals labels Jul 13, 2024
@woojiq woojiq force-pushed the lib-network-ipv6-first-and-last-addresses branch 2 times, most recently from 767e9ea to d2ff8fc Compare July 19, 2024 16:20
@woojiq woojiq force-pushed the lib-network-ipv6-first-and-last-addresses branch from d2ff8fc to 6865016 Compare July 21, 2024 20:44
woojiq added 4 commits July 27, 2024 23:00
Add ipv6 ipv6Addr and ipv6AddrAttrs types.
Add ipv6.isValidIpStr function to be used as the ipv6Addr type checker.
Add mkNetworkingOption that uses `coercedTo` function to convert string
IP to parsed attr set ipv6AddrAttrs.

Change the design of `ipv6.fromString` function. It used to be created
to return an attrset of data like `nextAddr`, `firstAddr`, etc. But
now it returns an attrset with a string representation of the address
(default and Cidr) and contains an internal representation. That way,
other future functions like `nextAddr` can easily take such type and
create a new one, because there is no need to reparse the string.
README.md explains the design and purpose of the network library. At the
time of writing, IPv4 functionality is not yet merged.
Add functions to calculate first and last addresses.
Add unit tests.
Add a functions to calculate the next address from the specified or null.
Add unit tests.
@woojiq woojiq force-pushed the lib-network-ipv6-first-and-last-addresses branch from 6865016 to ac56c45 Compare July 27, 2024 20:34
@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: lib The Nixpkgs function library 6.topic: module system About "NixOS" module system internals 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants