Fix for wrongly matching IPv6 address line problem in GetNicNameByIp #15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Modify IPv4 regex pattern from
"a.b.c.d"to"a\.b\.c\.d"to avoid matching the line that contains IPv6 address, of which pattern is like2001:db8::a:b:c:dWe have used ZStack to provide dual-stack access (support by ourselves) and encountered some subtle and magic problems.
If the vrouter use an IPv4 address like
A.B.C.Dand add an IPv6 address with IPv4-mixed-format like2001:db8::A:B:C:D, the GetNicNameByIp will return a non-existent interface named"global", leading to trigger another error where this function is called.The line that contains IPv6 address with style 2001:db8::A:B:C:D will be matched by 'A.B.C.D' , because
greptreats it as a regex by default.inet A.B.C.D/24 brd A.B.C.255 scope global (secondary) ethxinet6 2001:db8::A:B:C:D/64 scope globalMeanwhile, IPv6 address line that outputed by
ip addrdo not end withethxandsecondary, soreturn os[len(os)-1]will returnglobalas interface name and then ......