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

Increment IP addrress safely #258

Merged
merged 1 commit into from
Dec 15, 2018
Merged

Increment IP addrress safely #258

merged 1 commit into from
Dec 15, 2018

Conversation

nak3
Copy link
Contributor

@nak3 nak3 commented Dec 5, 2018

To define gateway address, current code increments network
address. However, the code does not care endian and overflow. (Since
it increments network address, overflow should not happen, though.)

This patch introduces incrementIPv4Addr() and increments the address
safely.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mogren
Copy link
Contributor

mogren commented Dec 5, 2018

Hmm, unit tests failed.

@nak3
Copy link
Contributor Author

nak3 commented Dec 6, 2018

Oh, sorry, it was my mistake. Fixed it.

{"increment", net.IPv4(10, 0, 0, 1), net.IPv4(10, 0, 0, 2).To4(), false},
{"carry up 1", net.IPv4(10, 0, 0, 255), net.IPv4(10, 0, 1, 0).To4(), false},
{"carry up 2", net.IPv4(10, 0, 255, 255), net.IPv4(10, 1, 0, 0).To4(), false},
{"overflow", net.IPv4(255, 255, 255, 255), nil, true},
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice test cases.

gw.IP[3] = gw.IP[3] + 1
gw, err := incrementIPv4Addr(ipnet.IP)
if err != nil {
return errors.Wrapf(err, "eni network setup: faild to define gateway address from %v", ipnet.IP)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Misspelled faild

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you 👍 Fixed it to failed

To define gateway address, current code increments network
address. However, the code does not care endian and overflow. (Since
it increments network address, overflow should not happens, though.)

This patch introduces incrementIPv4Addr() and increments the address
safely.
@mogren mogren merged commit 87052b1 into aws:master Dec 15, 2018
@nak3 nak3 deleted the ipv4inc branch December 15, 2018 03:21
@mogren mogren added this to the v1.4 milestone Mar 5, 2019
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.

2 participants