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

Remove interface names from ipv6 #10813

Open
wants to merge 9 commits into
base: v2.11
Choose a base branch
from

Conversation

JeroenED
Copy link

What does this PR do?

Fixes #7270

This PR removes the interfacename from an IpAddress before it gets parsed as net.ParseIP does not allow the interfacename to be there

Motivation

Frankly, this is pure self service. I was suffering from this issue myself and wanted to get it fixed.

More

  • Added/updated tests
  • Added/updated documentation

Additional Notes

I never wrote any golang code before so please allow if my code has done stuff that you should not do.

@ldez ldez changed the title Remove interface names from ipv6 (fixes #7270) Remove interface names from ipv6 Jun 14, 2024
@mmatur mmatur requested a review from jspdown June 20, 2024 12:19
@mmatur mmatur removed the request for review from jspdown June 20, 2024 12:20
Copy link
Contributor

@jspdown jspdown left a comment

Choose a reason for hiding this comment

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

Thanks @JeroenED for opening this PR.

There was indeed an issue with IPv6 zones. As you've identified, the problem comes from the net.ParseIP which doesn't support zones.
Internally, net.ParseIP relies on netip.ParseAddr which does support zones.

So, instead of removing the zone I would suggest to improve our helper function parseIP to do something like this, and use the helper in the NewChecker function.

func parseIP(addr string) (net.IP, error) {
	parsedAddr, err := netip.ParseAddr(addr)
	if err != nil {
		return nil, err
	}
	
	ip := parsedAddr.As16()
	return ip[:], nil
}

This would have the benefit of relying more on the standard library and providing better errors.

@JeroenED
Copy link
Author

I changed the PR as requested. I did however retain the original error line

Copy link
Contributor

@jspdown jspdown left a comment

Choose a reason for hiding this comment

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

I've tested the changes and successfully fixes the issue 👍
One last thing before I approve the PR, could you add a new test case in TestContainsIsAllowed?

@@ -5,6 +5,7 @@ import (
"fmt"
"net"
"strings"
"netip"
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be net/netip

@JeroenED
Copy link
Author

Hi,
Fixed the import and added 2 accept and reject test case.

}
ip := parsedAddr.As16()
return ip[:], nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
}

Copy link
Author

Choose a reason for hiding this comment

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

Fixed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants