-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
base: v2.11
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
I changed the PR as requested. I did however retain the original error line |
There was a problem hiding this 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
?
pkg/ip/checker.go
Outdated
@@ -5,6 +5,7 @@ import ( | |||
"fmt" | |||
"net" | |||
"strings" | |||
"netip" |
There was a problem hiding this comment.
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
Hi, |
pkg/ip/checker.go
Outdated
} | ||
ip := parsedAddr.As16() | ||
return ip[:], nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it
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
Additional Notes
I never wrote any golang code before so please allow if my code has done stuff that you should not do.