Overflow when borrowed network bits >= 8 bits #2

Closed
opened 2023-04-30 17:27:56 +00:00 by luke-else · 5 comments
Owner

it appears that when we are borrowing more than 7 bits to create more networks, there is an overflow we end up trying to place 2 octets worth of values into a u8 (num networks).

  • In order to combat this we can either use a 32 bit integer and have a loop count every 8 bits and determine the networks that way.

  • Otherwise we can implement the adding / XORing addresses as suggested in #1

it appears that when we are borrowing more than 7 bits to create more networks, there is an overflow we end up trying to place 2 octets worth of values into a u8 (num networks). * In order to combat this we can either use a 32 bit integer and have a loop count every 8 bits and determine the networks that way. * Otherwise we can implement the adding / XORing addresses as suggested in #1
luke-else added the
bug
label 2023-04-30 17:27:56 +00:00
Author
Owner

I have fixed the overflow now, however, the logic still isn't quite right. When I create a subnet that has more than 8 borrowed bits, the addresses aren't quite incremented in the way that I would like / need them to be.

I have fixed the overflow now, however, the logic still isn't quite right. When I create a subnet that has more than 8 borrowed bits, the addresses aren't quite incremented in the way that I would like / need them to be.
Author
Owner

The problem comes from the network spacing variable. This only specifies the spacing in the last octet that has borrowed bits. What I mean by this is that any octets before this should have a spacing of 1 in order to get the max number of networks.

The problem comes from the network spacing variable. This only specifies the spacing in the last octet that has borrowed bits. What I mean by this is that any octets before this should have a spacing of 1 in order to get the max number of networks.
Author
Owner

From here, I think the best way is to look at making a function that allows for IP address incrementation given the subnet mask.

So for example we use the base network, we can create an implementation of ip.inc() / ip++ that takes this as '&mut self' as well as the CIDR in order to determine which bits we are able to update. From here, given the current state of the IP, we can determine which is the next bit to get updated. The next bit to really think about is how am I going to determine which octet to start at... and where to end at + how much of a given octet can be edited :)

I was also of thinking of using some sort of recursion to go through and produce all the IPs one octet at a time however, I don't think that this will be a very good solution.

From here, I think the best way is to look at making a function that allows for IP address incrementation given the subnet mask. So for example we use the base network, we can create an implementation of ip.inc() / ip++ that takes this as '&mut self' as well as the CIDR in order to determine which bits we are able to update. From here, given the current state of the IP, we can determine which is the next bit to get updated. The next bit to really think about is how am I going to determine which octet to start at... and where to end at + how much of a given octet can be edited :) I was also of thinking of using some sort of recursion to go through and produce all the IPs one octet at a time however, I don't think that this will be a very good solution.
Author
Owner

What I am currently thinking is the idea of converting an IP address to a 32 bit integer... and then using a window which what the CIDR allows the editing of. As a result, we cna just increment this value using rusts native type 'u32'. This will be a lot more performant...

All I really need now is the ability to convert IP addresses between i32 and back to IpAddr.

This might remove the need to have conversion to and from an array.

What I am currently thinking is the idea of converting an IP address to a 32 bit integer... and then using a window which what the CIDR allows the editing of. As a result, we cna just increment this value using rusts native type 'u32'. This will be a lot more performant... All I really need now is the ability to convert IP addresses between i32 and back to IpAddr. This might remove the need to have conversion to and from an array.
Author
Owner

This appears to be fully functional now :) Yayyyyy

This appears to be fully functional now :) Yayyyyy
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: luke-else/subnet_calculator#2
No description provided.