Skip to content

Socket::bind_device_by_index_{v4,v6} should be available on linux and android #569

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

Open
ningyuan-wang opened this issue Apr 9, 2025 · 3 comments · May be fixed by #573
Open

Socket::bind_device_by_index_{v4,v6} should be available on linux and android #569

ningyuan-wang opened this issue Apr 9, 2025 · 3 comments · May be fixed by #573

Comments

@ningyuan-wang
Copy link

SO_BINDTOIFINDEX has been added to linux since linux v5.1. It behaves similar to SO_BINDTODEVICE but takes the interface index as argument. When a user-space program has the index of a network interface, Calling it directly avoids the possibility where the network device is renamed asynchronously after the program temporarily resolves the interface name from the interface index.

Socket::bind_device_by_index{v4,v6} currently is limited to macOS-like systems and solaris/illumos only. (See also issue #560 )
While current implementation is not valid to linux, another implementation can be defined for linux guarded by cfg macro.

Android also has support for SO_BINDTODEVICE, therefore the support can be extended to android target as well.

@ningyuan-wang
Copy link
Author

The initial investigation is incorrect: SO_BINDTOIFINDEX is not defined for libc for android target. (See Android SO definitions in libc 0.2.171). Therefore the target android cannot support this syscall pending an update to it even though Android supports SO_BINDTODEVICE.

@Thomasdezeeuw
Copy link
Collaborator

Pr to add support for this would be welcome.

@ningyuan-wang
Copy link
Author

For Android and Linux, the syscalls are independent of the V4 or V6 stack used, therefore the function name should be bind_device_by_index, and not having the suffix attached.

PR 573 is created to support this issue.

boris-n added a commit to boris-n/socket2 that referenced this issue Apr 25, 2025
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 a pull request may close this issue.

2 participants