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

Wrong type for field ifindex in struct iface #109

Closed
rene-d opened this issue Jan 29, 2019 · 7 comments
Closed

Wrong type for field ifindex in struct iface #109

rene-d opened this issue Jan 29, 2019 · 7 comments

Comments

@rene-d
Copy link

rene-d commented Jan 29, 2019

In Linux kernel, the ifindex is stored into a int variable (aka. 4 bytes). And can take values greater than 65535 (I don't know since which version...).

The ifindex field in the structure iface (ifvc.h) is a u_short, and big indices cannot fit. It occurs especially on servers running tests that create/destroy bridges and virtual interfaces.

smcroute exits with "Failed adding VIF for iface ..." message : it tries to set an option on a inexistant interface (2000 instead of 67536 for example).

@rene-d
Copy link
Author

rene-d commented Jan 29, 2019

Nota: I haven't tried to change the type and recompile...

@troglobit
Copy link
Owner

The most obvious fix, as mentioned in #71, is to simply change from u_short to int. However, I just noticed we use if_nametoindex(3), which returns an unsigned int ... the kernel itself seems to use int for every relevant internal struct, so I propose changing to int.

@troglobit
Copy link
Owner

I've looked into this a bit further now and I don't see any other code, than the struct iface ifindex, that need to be changed.

I'm pushing a fix for that now, which will cause GitHub to automatically close this issue. Please, if you can @rene-d, test the fix. If it doesn't work we'll reopen this issue again. Thanks!

@rene-d
Copy link
Author

rene-d commented Jan 30, 2019

Ok thanks! I will test tomorrow.

@rene-d
Copy link
Author

rene-d commented Jan 31, 2019

Yes! the fix (type changed from u_short to int) solves the problem of interface indices greater than 2^16.

The test passes with ifindex below and above 65536. Without this fix, it passes with ifindex<65536 and fails otherwise.

@troglobit
Copy link
Owner

@rene-d Awesome, thank you for getting back on this! 🎉 😃

@rene-d
Copy link
Author

rene-d commented Feb 2, 2019

Thank you for having dealt with my issue so fast ;-)

I have look for ifindex in the Linux kernel: sometimes it's typed u32, sometimes int. In net/core/dev.c line ~8034 in function dev_new_index(), ifindex is a strictly positive int (aka between 1 and 2^31-1).

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

No branches or pull requests

2 participants