From c24c516da6187916a78f4ce934e6a3989ea32f75 Mon Sep 17 00:00:00 2001 From: wlynxg Date: Thu, 10 Oct 2024 16:46:48 +0800 Subject: [PATCH] feat: add `ioctl` flags in `linux/if_tun.h` fix: values under different architectures style: update code style fix: remove `TUNSETCARRIER` and `TUNGETDEVNETNS` feat: add `TUNSETCARRIER` and `TUNGETDEVNETNS` in `gnu` style: update code style --- libc-test/semver/linux-gnu.txt | 2 ++ libc-test/semver/linux.txt | 26 ++++++++++++++ src/unix/linux_like/linux/arch/generic/mod.rs | 34 ++++++++++++++++++ src/unix/linux_like/linux/arch/mips/mod.rs | 34 ++++++++++++++++++ src/unix/linux_like/linux/arch/powerpc/mod.rs | 34 ++++++++++++++++++ src/unix/linux_like/linux/arch/sparc/mod.rs | 35 +++++++++++++++++++ src/unix/linux_like/linux/gnu/mod.rs | 23 ++++++++++++ src/unix/linux_like/linux/mod.rs | 1 + 8 files changed, 189 insertions(+) diff --git a/libc-test/semver/linux-gnu.txt b/libc-test/semver/linux-gnu.txt index 89253b6482090..cc3b580bc6247 100644 --- a/libc-test/semver/linux-gnu.txt +++ b/libc-test/semver/linux-gnu.txt @@ -472,6 +472,8 @@ TIME_WAIT TMPFS_MAGIC TMP_MAX TRACEFS_MAGIC +TUNSETCARRIER +TUNGETDEVNETNS UDF_SUPER_MAGIC UNAME26 USBDEVICE_SUPER_MAGIC diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 7a684c0902ba1..79d0b082a74a2 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -962,6 +962,32 @@ IFF_MULTI_QUEUE IFF_NO_CARRIER IFF_NOARP IFF_NOFILTER +TUNSETNOCSUM +TUNSETDEBUG +TUNSETIFF +TUNSETPERSIST +TUNSETOWNER +TUNSETLINK +TUNSETGROUP +TUNGETFEATURES +TUNSETOFFLOAD +TUNSETTXFILTER +TUNGETIFF +TUNGETSNDBUF +TUNSETSNDBUF +TUNATTACHFILTER +TUNDETACHFILTER +TUNGETVNETHDRSZ +TUNSETVNETHDRSZ +TUNSETQUEUE +TUNSETIFINDEX +TUNGETFILTER +TUNSETVNETLE +TUNGETVNETLE +TUNSETVNETBE +TUNGETVNETBE +TUNSETSTEERINGEBPF +TUNSETFILTEREBPF TUN_TX_TIMESTAMP TUN_F_CSUM TUN_F_TSO4 diff --git a/src/unix/linux_like/linux/arch/generic/mod.rs b/src/unix/linux_like/linux/arch/generic/mod.rs index 2f437e16db26a..ba56be7a92479 100644 --- a/src/unix/linux_like/linux/arch/generic/mod.rs +++ b/src/unix/linux_like/linux/arch/generic/mod.rs @@ -210,6 +210,34 @@ pub const BLKIOMIN: ::Ioctl = 0x1278; pub const BLKIOOPT: ::Ioctl = 0x1279; pub const BLKSSZGET: ::Ioctl = 0x1268; pub const BLKPBSZGET: ::Ioctl = 0x127B; +// linux/if_tun.h +pub const TUNSETNOCSUM: ::Ioctl = 0x400454c8; +pub const TUNSETDEBUG: ::Ioctl = 0x400454c9; +pub const TUNSETIFF: ::Ioctl = 0x400454ca; +pub const TUNSETPERSIST: ::Ioctl = 0x400454cb; +pub const TUNSETOWNER: ::Ioctl = 0x400454cc; +pub const TUNSETLINK: ::Ioctl = 0x400454cd; +pub const TUNSETGROUP: ::Ioctl = 0x400454ce; +pub const TUNGETFEATURES: ::Ioctl = 0x800454cf; +pub const TUNSETOFFLOAD: ::Ioctl = 0x400454d0; +pub const TUNSETTXFILTER: ::Ioctl = 0x400454d1; +pub const TUNGETIFF: ::Ioctl = 0x800454d2; +pub const TUNGETSNDBUF: ::Ioctl = 0x800454d3; +pub const TUNSETSNDBUF: ::Ioctl = 0x400454d4; +pub const TUNGETVNETHDRSZ: ::Ioctl = 0x800454d7; +pub const TUNSETVNETHDRSZ: ::Ioctl = 0x400454d8; +pub const TUNSETQUEUE: ::Ioctl = 0x400454d9; +pub const TUNSETIFINDEX: ::Ioctl = 0x400454da; +pub const TUNSETVNETLE: ::Ioctl = 0x400454dc; +pub const TUNGETVNETLE: ::Ioctl = 0x800454dd; +/* The TUNSETVNETBE and TUNGETVNETBE ioctls are for cross-endian support on + * little-endian hosts. Not all kernel configurations support them, but all + * configurations that support SET also support GET. + */ +pub const TUNSETVNETBE: ::Ioctl = 0x400454de; +pub const TUNGETVNETBE: ::Ioctl = 0x800454df; +pub const TUNSETSTEERINGEBPF: ::Ioctl = 0x800454e0; +pub const TUNSETFILTEREBPF: ::Ioctl = 0x800454e1; cfg_if! { // Those type are constructed using the _IOC macro @@ -227,6 +255,9 @@ cfg_if! { pub const FS_IOC32_SETFLAGS: ::Ioctl = 0x40046602; pub const FS_IOC32_GETVERSION: ::Ioctl = 0x80047601; pub const FS_IOC32_SETVERSION: ::Ioctl = 0x40047602; + pub const TUNATTACHFILTER: ::Ioctl = 0x400854d5; + pub const TUNDETACHFILTER: ::Ioctl = 0x400854d6; + pub const TUNGETFILTER: ::Ioctl = 0x800854db; } else if #[cfg(any(target_arch = "x86_64", target_arch = "riscv64", target_arch = "aarch64", @@ -240,6 +271,9 @@ cfg_if! { pub const FS_IOC32_SETFLAGS: ::Ioctl = 0x40046602; pub const FS_IOC32_GETVERSION: ::Ioctl = 0x80047601; pub const FS_IOC32_SETVERSION: ::Ioctl = 0x40047602; + pub const TUNATTACHFILTER: ::Ioctl = 0x401054d5; + pub const TUNDETACHFILTER: ::Ioctl = 0x401054d6; + pub const TUNGETFILTER: ::Ioctl = 0x801054db; } } diff --git a/src/unix/linux_like/linux/arch/mips/mod.rs b/src/unix/linux_like/linux/arch/mips/mod.rs index 6a96aa9c3b159..bdce5827c07bf 100644 --- a/src/unix/linux_like/linux/arch/mips/mod.rs +++ b/src/unix/linux_like/linux/arch/mips/mod.rs @@ -192,6 +192,34 @@ pub const BLKIOMIN: ::Ioctl = 0x20001278; pub const BLKIOOPT: ::Ioctl = 0x20001279; pub const BLKSSZGET: ::Ioctl = 0x20001268; pub const BLKPBSZGET: ::Ioctl = 0x2000127B; +// linux/if_tun.h +pub const TUNSETNOCSUM: ::Ioctl = 0x800454c8; +pub const TUNSETDEBUG: ::Ioctl = 0x800454c9; +pub const TUNSETIFF: ::Ioctl = 0x800454ca; +pub const TUNSETPERSIST: ::Ioctl = 0x800454cb; +pub const TUNSETOWNER: ::Ioctl = 0x800454cc; +pub const TUNSETLINK: ::Ioctl = 0x800454cd; +pub const TUNSETGROUP: ::Ioctl = 0x800454ce; +pub const TUNGETFEATURES: ::Ioctl = 0x400454cf; +pub const TUNSETOFFLOAD: ::Ioctl = 0x800454d0; +pub const TUNSETTXFILTER: ::Ioctl = 0x800454d1; +pub const TUNGETIFF: ::Ioctl = 0x400454d2; +pub const TUNGETSNDBUF: ::Ioctl = 0x400454d3; +pub const TUNSETSNDBUF: ::Ioctl = 0x800454d4; +pub const TUNGETVNETHDRSZ: ::Ioctl = 0x400454d7; +pub const TUNSETVNETHDRSZ: ::Ioctl = 0x800454d8; +pub const TUNSETQUEUE: ::Ioctl = 0x800454d9; +pub const TUNSETIFINDEX: ::Ioctl = 0x800454da; +pub const TUNSETVNETLE: ::Ioctl = 0x800454dc; +pub const TUNGETVNETLE: ::Ioctl = 0x400454dd; +/* The TUNSETVNETBE and TUNGETVNETBE ioctls are for cross-endian support on + * little-endian hosts. Not all kernel configurations support them, but all + * configurations that support SET also support GET. + */ +pub const TUNSETVNETBE: ::Ioctl = 0x800454de; +pub const TUNGETVNETBE: ::Ioctl = 0x400454df; +pub const TUNSETSTEERINGEBPF: ::Ioctl = 0x400454e0; +pub const TUNSETFILTEREBPF: ::Ioctl = 0x400454e1; cfg_if! { // Those type are constructed using the _IOC macro @@ -209,6 +237,9 @@ cfg_if! { pub const FS_IOC32_SETFLAGS: ::Ioctl = 0x80046602; pub const FS_IOC32_GETVERSION: ::Ioctl = 0x40047601; pub const FS_IOC32_SETVERSION: ::Ioctl = 0x80047602; + pub const TUNATTACHFILTER: ::Ioctl = 0x800854d5; + pub const TUNDETACHFILTER: ::Ioctl = 0x800854d6; + pub const TUNGETFILTER: ::Ioctl = 0x400854db; } else if #[cfg(any(target_arch = "mips64", target_arch = "mips64r6"))] { pub const FS_IOC_GETFLAGS: ::Ioctl = 0x40086601; pub const FS_IOC_SETFLAGS: ::Ioctl = 0x80086602; @@ -218,6 +249,9 @@ cfg_if! { pub const FS_IOC32_SETFLAGS: ::Ioctl = 0x80046602; pub const FS_IOC32_GETVERSION: ::Ioctl = 0x40047601; pub const FS_IOC32_SETVERSION: ::Ioctl = 0x80047602; + pub const TUNATTACHFILTER: ::Ioctl = 0x801054d5; + pub const TUNDETACHFILTER: ::Ioctl = 0x801054d6; + pub const TUNGETFILTER: ::Ioctl = 0x401054db; } } diff --git a/src/unix/linux_like/linux/arch/powerpc/mod.rs b/src/unix/linux_like/linux/arch/powerpc/mod.rs index 27834dbfeabcc..93c454396d9a6 100644 --- a/src/unix/linux_like/linux/arch/powerpc/mod.rs +++ b/src/unix/linux_like/linux/arch/powerpc/mod.rs @@ -178,6 +178,34 @@ pub const BLKIOOPT: ::Ioctl = 0x20001279; pub const BLKSSZGET: ::Ioctl = 0x20001268; pub const BLKPBSZGET: ::Ioctl = 0x2000127B; //pub const FIOQSIZE: ::Ioctl = 0x40086680; +// linux/if_tun.h +pub const TUNSETNOCSUM: ::Ioctl = 0x800454c8; +pub const TUNSETDEBUG: ::Ioctl = 0x800454c9; +pub const TUNSETIFF: ::Ioctl = 0x800454ca; +pub const TUNSETPERSIST: ::Ioctl = 0x800454cb; +pub const TUNSETOWNER: ::Ioctl = 0x800454cc; +pub const TUNSETLINK: ::Ioctl = 0x800454cd; +pub const TUNSETGROUP: ::Ioctl = 0x800454ce; +pub const TUNGETFEATURES: ::Ioctl = 0x400454cf; +pub const TUNSETOFFLOAD: ::Ioctl = 0x800454d0; +pub const TUNSETTXFILTER: ::Ioctl = 0x800454d1; +pub const TUNGETIFF: ::Ioctl = 0x400454d2; +pub const TUNGETSNDBUF: ::Ioctl = 0x400454d3; +pub const TUNSETSNDBUF: ::Ioctl = 0x800454d4; +pub const TUNGETVNETHDRSZ: ::Ioctl = 0x400454d7; +pub const TUNSETVNETHDRSZ: ::Ioctl = 0x800454d8; +pub const TUNSETQUEUE: ::Ioctl = 0x800454d9; +pub const TUNSETIFINDEX: ::Ioctl = 0x800454da; +pub const TUNSETVNETLE: ::Ioctl = 0x800454dc; +pub const TUNGETVNETLE: ::Ioctl = 0x400454dd; +/* The TUNSETVNETBE and TUNGETVNETBE ioctls are for cross-endian support on + * little-endian hosts. Not all kernel configurations support them, but all + * configurations that support SET also support GET. + */ +pub const TUNSETVNETBE: ::Ioctl = 0x800454de; +pub const TUNGETVNETBE: ::Ioctl = 0x400454df; +pub const TUNSETSTEERINGEBPF: ::Ioctl = 0x400454e0; +pub const TUNSETFILTEREBPF: ::Ioctl = 0x400454e1; cfg_if! { // Those type are constructed using the _IOC macro @@ -195,6 +223,9 @@ cfg_if! { pub const FS_IOC32_SETFLAGS: ::Ioctl = 0x80046602; pub const FS_IOC32_GETVERSION: ::Ioctl = 0x40047601; pub const FS_IOC32_SETVERSION: ::Ioctl = 0x80047602; + pub const TUNATTACHFILTER: ::Ioctl = 0x800854d5; + pub const TUNDETACHFILTER: ::Ioctl = 0x800854d6; + pub const TUNGETFILTER: ::Ioctl = 0x400854db; } else if #[cfg(target_arch = "powerpc64")] { pub const FS_IOC_GETFLAGS: ::Ioctl = 0x40086601; pub const FS_IOC_SETFLAGS: ::Ioctl = 0x80086602; @@ -204,6 +235,9 @@ cfg_if! { pub const FS_IOC32_SETFLAGS: ::Ioctl = 0x80046602; pub const FS_IOC32_GETVERSION: ::Ioctl = 0x40047601; pub const FS_IOC32_SETVERSION: ::Ioctl = 0x80047602; + pub const TUNATTACHFILTER: ::Ioctl = 0x801054d5; + pub const TUNDETACHFILTER: ::Ioctl = 0x801054d6; + pub const TUNGETFILTER: ::Ioctl = 0x401054db; } } diff --git a/src/unix/linux_like/linux/arch/sparc/mod.rs b/src/unix/linux_like/linux/arch/sparc/mod.rs index fce466c778998..b64e6ce7149a5 100644 --- a/src/unix/linux_like/linux/arch/sparc/mod.rs +++ b/src/unix/linux_like/linux/arch/sparc/mod.rs @@ -183,6 +183,35 @@ pub const BLKPBSZGET: ::Ioctl = 0x2000127B; //pub const TIOCGRS485: ::Ioctl = 0x40205441; //pub const TIOCSRS485: ::Ioctl = 0xc0205442; +// linux/if_tun.h +pub const TUNSETNOCSUM: ::Ioctl = 0x800454c8; +pub const TUNSETDEBUG: ::Ioctl = 0x800454c9; +pub const TUNSETIFF: ::Ioctl = 0x800454ca; +pub const TUNSETPERSIST: ::Ioctl = 0x800454cb; +pub const TUNSETOWNER: ::Ioctl = 0x800454cc; +pub const TUNSETLINK: ::Ioctl = 0x800454cd; +pub const TUNSETGROUP: ::Ioctl = 0x800454ce; +pub const TUNGETFEATURES: ::Ioctl = 0x400454cf; +pub const TUNSETOFFLOAD: ::Ioctl = 0x800454d0; +pub const TUNSETTXFILTER: ::Ioctl = 0x800454d1; +pub const TUNGETIFF: ::Ioctl = 0x400454d2; +pub const TUNGETSNDBUF: ::Ioctl = 0x400454d3; +pub const TUNSETSNDBUF: ::Ioctl = 0x800454d4; +pub const TUNGETVNETHDRSZ: ::Ioctl = 0x400454d7; +pub const TUNSETVNETHDRSZ: ::Ioctl = 0x800454d8; +pub const TUNSETQUEUE: ::Ioctl = 0x800454d9; +pub const TUNSETIFINDEX: ::Ioctl = 0x800454da; +pub const TUNSETVNETLE: ::Ioctl = 0x800454dc; +pub const TUNGETVNETLE: ::Ioctl = 0x400454dd; +/* The TUNSETVNETBE and TUNGETVNETBE ioctls are for cross-endian support on + * little-endian hosts. Not all kernel configurations support them, but all + * configurations that support SET also support GET. + */ +pub const TUNSETVNETBE: ::Ioctl = 0x800454de; +pub const TUNGETVNETBE: ::Ioctl = 0x400454df; +pub const TUNSETSTEERINGEBPF: ::Ioctl = 0x400454e0; +pub const TUNSETFILTEREBPF: ::Ioctl = 0x400454e1; + pub const TIOCM_LE: ::c_int = 0x001; pub const TIOCM_DTR: ::c_int = 0x002; pub const TIOCM_RTS: ::c_int = 0x004; @@ -246,6 +275,9 @@ cfg_if! { pub const FS_IOC32_SETFLAGS: ::Ioctl = 0x80046602; pub const FS_IOC32_GETVERSION: ::Ioctl = 0x40047601; pub const FS_IOC32_SETVERSION: ::Ioctl = 0x80047602; + pub const TUNATTACHFILTER: ::Ioctl = 0x800854d5; + pub const TUNDETACHFILTER: ::Ioctl = 0x800854d6; + pub const TUNGETFILTER: ::Ioctl = 0x400854db; } else if #[cfg(target_arch = "sparc64")] { pub const FS_IOC_GETFLAGS: ::Ioctl = 0x40086601; pub const FS_IOC_SETFLAGS: ::Ioctl = 0x80086602; @@ -255,5 +287,8 @@ cfg_if! { pub const FS_IOC32_SETFLAGS: ::Ioctl = 0x80046602; pub const FS_IOC32_GETVERSION: ::Ioctl = 0x40047601; pub const FS_IOC32_SETVERSION: ::Ioctl = 0x80047602; + pub const TUNATTACHFILTER: ::Ioctl = 0x801054d5; + pub const TUNDETACHFILTER: ::Ioctl = 0x801054d6; + pub const TUNGETFILTER: ::Ioctl = 0x401054db; } } diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index a22e5484abcd2..552b95329c0ee 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -1289,6 +1289,29 @@ pub const REG_EEND: ::c_int = 14; pub const REG_ESIZE: ::c_int = 15; pub const REG_ERPAREN: ::c_int = 16; +cfg_if! { + if #[cfg(any(target_arch = "x86", + target_arch = "x86_64", + target_arch = "arm", + target_arch = "aarch64", + target_arch = "loongarch64", + target_arch = "riscv64", + target_arch = "s390x"))] { + pub const TUNSETCARRIER: ::Ioctl = 0x400454e2; + pub const TUNGETDEVNETNS: ::Ioctl = 0x54e3; + } else if #[cfg(any(target_arch = "mips", + target_arch = "mips64", + target_arch = "powerpc", + target_arch = "powerpc64", + target_arch = "sparc", + target_arch = "sparc64"))] { + pub const TUNSETCARRIER: ::Ioctl = 0x800454e2; + pub const TUNGETDEVNETNS: ::Ioctl = 0x200054e3; + } else { + // Unknown target_arch + } +} + extern "C" { pub fn fgetspent_r( fp: *mut ::FILE, diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index b52f65927fbe5..7253ee934ea90 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -2363,6 +2363,7 @@ pub const IFLA_INFO_SLAVE_KIND: ::c_ushort = 4; pub const IFLA_INFO_SLAVE_DATA: ::c_ushort = 5; // linux/if_tun.h +/* TUNSETIFF ifr flags */ pub const IFF_TUN: ::c_int = 0x0001; pub const IFF_TAP: ::c_int = 0x0002; pub const IFF_NAPI: ::c_int = 0x0010;