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

read ranges from env v2 #1

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

read ranges from env v2 #1

wants to merge 4 commits into from

Conversation

grische
Copy link
Collaborator

@grische grische commented Nov 9, 2024

Looking for upstream feedback (apart from the module rename ofc).

ping @SmithChart

@SmithChart
Copy link

I asusme @pslldq is the right person to have a look at this.

For better collaboration this project should probably be moved to the ffbs-github namespace?

@grische
Copy link
Collaborator Author

grische commented Nov 12, 2024

@SmithChart @pslldq I noticed that the original code is not able to handle othe sizes but exactly 10/8 and ::/48 subnets. The new code allows to specify an abitrary subnet size for clients and arbitrary available subnet sizes globally and will panic in case the request size doesn't fit anymore.

I hope the new code is also a bit more readable and has less binary operations in comparison to v1.

@grische grische changed the title Read ranges from env read ranges from env v2 Nov 12, 2024
Comment on lines +110 to +111
const CLIENT_V4_RANGE_SIZE uint = 22
const CLIENT_V6_RANGE_SIZE uint = 64

Choose a reason for hiding this comment

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

Might as well make those configurable as well, at least the v4 subnet.
Otherwise LGTM.

v2 fixes some bugs that were present in both the original code and v1
- combine IPv4 and IPv6 calculations into one
- the new version can handle abitrary IPv4 or IPv6 subnet sizes and is
  not bound to specific sizes
Copy link

@pslldq pslldq left a comment

Choose a reason for hiding this comment

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

Some of my thoughts. I agree with @SmithChart to move the project to Github to avoid cherry picking commits back and fourth.

const CLIENT_V6_RANGE_SIZE uint = 64

// IPv4 handling
v4RangeStr := os.Getenv("PARKER_V4_RANGE")
Copy link

Choose a reason for hiding this comment

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

Personally would tend to use command line options (maybe in combination with a configuration file) for all the moving parts. Mostly because of the builtin documentation of the options via --help (and showing the default option values).

v6ClientRangeStr := fmt.Sprintf("%s/%d", v6ClientSubnet, CLIENT_V6_RANGE_SIZE)
v6BigAddr := new(big.Int).SetBytes(v6ClientSubnet)
v6BigAddr.Add(v6BigAddr, big.NewInt(1)) // use the next free IPv6
v6ClientAddrStr := net.IP(v6BigAddr.Bytes()).String()
Copy link

Choose a reason for hiding this comment

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

having a function, I would prefer to integrate these variables into it, as they are equal for the V4 and V6 case. Probably as additional return values, e.g. v6ClientSubnet, v6ClientRangeString, v6ClientAddrStr, err := getNthSubnet(v6RangeStr, num, CLIENT_V6_RANGE_SIZE)

@pslldq
Copy link

pslldq commented Nov 18, 2024

@grische We've moved the etcd-tools repo to Github for collaboration purposes: https://github.com/ffbs/etcd-tools . I've also added support for configuration via command line arguments (ffbs/etcd-tools@88dcf67) and a basic test for the ip range and address generation (ffbs/etcd-tools@018c0d4). Feel free to add your refactored subnet calculation and to set the subnet and it's range.

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.

4 participants