Skip to content

Commit

Permalink
feat: add ioctl flags in linux/if_tun.h
Browse files Browse the repository at this point in the history
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

(backport <#3960>)
(cherry picked from commit c24c516)
  • Loading branch information
wlynxg authored and tgross35 committed Nov 7, 2024
1 parent a3ca238 commit 33a772c
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libc-test/semver/linux-gnu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ TIME_WAIT
TMPFS_MAGIC
TMP_MAX
TRACEFS_MAGIC
TUNGETDEVNETNS
TUNSETCARRIER
UDF_SUPER_MAGIC
UNAME26
USBDEVICE_SUPER_MAGIC
Expand Down
26 changes: 26 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3247,6 +3247,32 @@ TP_STATUS_USER
TP_STATUS_VLAN_TPID_VALID
TP_STATUS_VLAN_VALID
TP_STATUS_WRONG_FORMAT
TUNATTACHFILTER
TUNDETACHFILTER
TUNGETFEATURES
TUNGETFILTER
TUNGETIFF
TUNGETSNDBUF
TUNGETVNETBE
TUNGETVNETHDRSZ
TUNGETVNETLE
TUNSETDEBUG
TUNSETFILTEREBPF
TUNSETGROUP
TUNSETIFF
TUNSETIFINDEX
TUNSETLINK
TUNSETNOCSUM
TUNSETOFFLOAD
TUNSETOWNER
TUNSETPERSIST
TUNSETQUEUE
TUNSETSNDBUF
TUNSETSTEERINGEBPF
TUNSETTXFILTER
TUNSETVNETBE
TUNSETVNETHDRSZ
TUNSETVNETLE
TUN_FLT_ALLMULTI
TUN_F_CSUM
TUN_F_TSO4
Expand Down
34 changes: 34 additions & 0 deletions src/unix/linux_like/linux/arch/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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;
}
}

Expand Down
34 changes: 34 additions & 0 deletions src/unix/linux_like/linux/arch/mips/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
}
}

Expand Down
34 changes: 34 additions & 0 deletions src/unix/linux_like/linux/arch/powerpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
}
}

Expand Down
35 changes: 35 additions & 0 deletions src/unix/linux_like/linux/arch/sparc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
23 changes: 23 additions & 0 deletions src/unix/linux_like/linux/gnu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,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,
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,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;
Expand Down

0 comments on commit 33a772c

Please sign in to comment.