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

Fix for wrongly matching IPv6 address line problem in GetNicNameByIp #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mchtech
Copy link

@mchtech mchtech commented Aug 5, 2018

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 like 2001: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 like 2001: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 with ethx and secondary, so return os[len(os)-1] will return global as interface name and then ......

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.

None yet

1 participant