-
Notifications
You must be signed in to change notification settings - Fork 1.1k
if_tun.h ioctls for android #4379
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
Conversation
Some changes occurred in the Android module cc @maurer |
@rustbot label stable-nominated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Main thing is we should probably use IOW/R to mimic what's in the bionic header. This will help us make sure things are synced up + structs people expect are available.
@@ -232,6 +232,12 @@ pub const UT_HOSTSIZE: usize = 16; | |||
pub const SIGSTKSZ: size_t = 8192; | |||
pub const MINSIGSTKSZ: size_t = 2048; | |||
|
|||
// linux/if_tun.h | |||
// Ioctl operation codes | |||
pub const TUNATTACHFILTER: c_int = 0x400854d5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be declared via _IOW
/_IOR
, as they are in the source of truth.
We have this functionality in libc already, so we should use it rather than pre-expanding things like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I was not aware we already had this functionality. I've updated the PR.
@@ -288,6 +288,12 @@ pub const UT_LINESIZE: usize = 32; | |||
pub const UT_NAMESIZE: usize = 32; | |||
pub const UT_HOSTSIZE: usize = 256; | |||
|
|||
// linux/if_tun.h | |||
// Ioctl operation codes | |||
pub const TUNATTACHFILTER: c_int = 0x401054d5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, IOW/R
@@ -2646,6 +2647,36 @@ pub const TUN_F_TSO_ECN: c_uint = 0x08; | |||
pub const TUN_F_UFO: c_uint = 0x10; | |||
pub const TUN_F_USO4: c_uint = 0x20; | |||
pub const TUN_F_USO6: c_uint = 0x40; | |||
// Protocol info prepended to the packets (when IFF_NO_PI is not set) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IOW/R
src/unix/linux_like/android/mod.rs
Outdated
@@ -2623,7 +2623,7 @@ pub const SND_CNT: usize = SND_MAX as usize + 1; | |||
pub const UINPUT_VERSION: c_uint = 5; | |||
pub const UINPUT_MAX_NAME_SIZE: usize = 80; | |||
|
|||
// bionic/libc/kernel/uapi/linux/if_tun.h | |||
// linux/if_tun.h |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should ideally remain sourced from bionic, as these are libc bindings, not kernel bindings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted
dca2ef4
to
f48364d
Compare
Add missing constants from linux/if_tun.h header on android platform. Mainly ioctl operation codes
@maurer Updated. Please re-review |
pub const fn _IO(ty: u32, nr: u32) -> u32 { | ||
super::_IOC(super::_IOC_NONE, ty, nr, 0) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could these just move to src/unix/linux_like/mod.rs
next to _IOC
? Rather than duplicating between linux and android.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not strictly duplicates. They differ when it comes to the return type. Of course I could put them in some non public module (e.g. mod internal
) inside of linux_like/mod.rs
and then reexport it in e.g. linux and wrap in android to cast the returned value. I thought about it but in the end I thought that that's just cleaner to duplicate those two small pieces. Let me know what you prefer. I can do it as I described here.
BTW using those _IO*
macros are nice because the remove duplication when it comes IOCTL definitions on different architectures. I could use them for if_tun.h
ioctl numbers in linux tree as well in separate PR if you're interested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed the return type difference, as-is is fine then 👍
Updating any hardcoded ioctl values would be appreciated if you are interested in doing that. A lot of these definitions come from before we had const fn
available, it would be great to clean that up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the PR and thanks @maurer for reviewing
Add missing constants from linux/if_tun.h header on android platform. Mainly ioctl operation codes (backport <rust-lang#4379>) (cherry picked from commit 610eb02)
Add missing constants from linux/if_tun.h header on android platform. Mainly ioctl operation codes (backport <rust-lang#4379>) (cherry picked from commit 610eb02)
Description
Add missing constants from linux/if_tun.h header on android platform. Mainly ioctl operation codes
Sources
https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/kernel/uapi/linux/if_tun.h;drc=180edefbd287c39caeb9d48784a9a10ac35f3636
Checklist
libc-test/semver
have been updated*LAST
or*MAX
areincluded (see #3131)
cd libc-test && cargo test --target mytarget
);especially relevant for platforms that may not be checked in CI