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:d
We 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.D
and 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
grep
treats it as a regex by default.inet A.B.C.D/24 brd A.B.C.255 scope global (secondary) ethx
inet6 2001:db8::A:B:C:D/64 scope global
Meanwhile, IPv6 address line that outputed by
ip addr
do not end withethx
andsecondary
, soreturn os[len(os)-1]
will returnglobal
as interface name and then ......