Skip to content

Commit

Permalink
feat: add GSO flags for linux and android
Browse files Browse the repository at this point in the history
  • Loading branch information
elecm committed Nov 6, 2023
1 parent 00f48a6 commit ab83142
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
6 changes: 6 additions & 0 deletions libc-test/build.rs
Expand Up @@ -1830,6 +1830,9 @@ fn test_android(target: &str) {
// kernel 5.6 minimum required
"IPPROTO_MPTCP" | "IPPROTO_ETHERNET" => true,

// kernel 6.2 minimum
"TUN_F_USO4" | "TUN_F_USO6" | "IFF_NO_CARRIER" => true,

// FIXME: NDK r22 minimum required
| "FDB_NOTIFY_BIT"
| "FDB_NOTIFY_INACTIVE_BIT"
Expand Down Expand Up @@ -3862,6 +3865,9 @@ fn test_linux(target: &str) {
// kernel 6.1 minimum
"MADV_COLLAPSE" => true,

// kernel 6.2 minimum
"TUN_F_USO4" | "TUN_F_USO6" | "IFF_NO_CARRIER" => true,

// FIXME: Requires more recent kernel headers
| "IFLA_PARENT_DEV_NAME" // linux v5.13+
| "IFLA_PARENT_DEV_BUS_NAME" // linux v5.13+
Expand Down
8 changes: 8 additions & 0 deletions libc-test/semver/android.txt
Expand Up @@ -699,6 +699,7 @@ IFF_MASTER
IFF_MULTICAST
IFF_NOARP
IFF_NOTRAILERS
IFF_NO_CARRIER
IFF_NO_PI
IFF_POINTOPOINT
IFF_PORTSEL
Expand All @@ -708,6 +709,13 @@ IFF_SLAVE
IFF_TAP
IFF_TUN
IFF_UP
TUN_F_CSUM
TUN_F_TSO4
TUN_F_TSO6
TUN_F_TSO_ECN
TUN_F_UFO
TUN_F_USO4
TUN_F_USO6
IFNAMSIZ
IF_NAMESIZE
IFA_UNSPEC
Expand Down
3 changes: 3 additions & 0 deletions libc-test/semver/linux.txt
Expand Up @@ -932,6 +932,7 @@ IFF_LOWER_UP
IFF_MASTER
IFF_MULTICAST
IFF_MULTI_QUEUE
IFF_NO_CARRIER
IFF_NOARP
IFF_NOFILTER
TUN_TX_TIMESTAMP
Expand All @@ -940,6 +941,8 @@ TUN_F_TSO4
TUN_F_TSO6
TUN_F_TSO_ECN
TUN_F_UFO
TUN_F_USO4
TUN_F_USO6
TUN_PKT_STRIP
TUN_FLT_ALLMULTI
IFF_NOTRAILERS
Expand Down
9 changes: 9 additions & 0 deletions src/unix/linux_like/android/mod.rs
Expand Up @@ -2481,6 +2481,7 @@ pub const IFF_TUN: ::c_int = 0x0001;
pub const IFF_TAP: ::c_int = 0x0002;
pub const IFF_NAPI: ::c_int = 0x0010;
pub const IFF_NAPI_FRAGS: ::c_int = 0x0020;
pub const IFF_NO_CARRIER: ::c_int = 0x0040;
pub const IFF_NO_PI: ::c_int = 0x1000;
pub const IFF_ONE_QUEUE: ::c_int = 0x2000;
pub const IFF_VNET_HDR: ::c_int = 0x4000;
Expand All @@ -2490,6 +2491,14 @@ pub const IFF_ATTACH_QUEUE: ::c_int = 0x0200;
pub const IFF_DETACH_QUEUE: ::c_int = 0x0400;
pub const IFF_PERSIST: ::c_int = 0x0800;
pub const IFF_NOFILTER: ::c_int = 0x1000;
// Features for GSO (TUNSETOFFLOAD)
pub const TUN_F_CSUM: ::c_uint = 0x01;
pub const TUN_F_TSO4: ::c_uint = 0x02;
pub const TUN_F_TSO6: ::c_uint = 0x04;
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;

// start android/platform/bionic/libc/kernel/uapi/linux/if_ether.h
// from https://android.googlesource.com/platform/bionic/+/HEAD/libc/kernel/uapi/linux/if_ether.h
Expand Down
14 changes: 9 additions & 5 deletions src/unix/linux_like/linux/mod.rs
Expand Up @@ -1866,6 +1866,8 @@ pub const IFF_TUN: ::c_int = 0x0001;
pub const IFF_TAP: ::c_int = 0x0002;
pub const IFF_NAPI: ::c_int = 0x0010;
pub const IFF_NAPI_FRAGS: ::c_int = 0x0020;
// Used in TUNSETIFF to bring up tun/tap without carrier
pub const IFF_NO_CARRIER: ::c_int = 0x0040;
pub const IFF_NO_PI: ::c_int = 0x1000;
// Read queue size
pub const TUN_READQ_SIZE: ::c_short = 500;
Expand All @@ -1886,11 +1888,13 @@ pub const IFF_NOFILTER: ::c_int = 0x1000;
// Socket options
pub const TUN_TX_TIMESTAMP: ::c_int = 1;
// Features for GSO (TUNSETOFFLOAD)
pub const TUN_F_CSUM: ::c_ushort = 0x01; /* You can hand me unchecksummed packets. */
pub const TUN_F_TSO4: ::c_ushort = 0x02; /* I can handle TSO for IPv4 packets */
pub const TUN_F_TSO6: ::c_ushort = 0x04; /* I can handle TSO for IPv6 packets */
pub const TUN_F_TSO_ECN: ::c_ushort = 0x08; /* I can handle TSO with ECN bits. */
pub const TUN_F_UFO: ::c_ushort = 0x10; /* I can handle UFO packets */
pub const TUN_F_CSUM: ::c_uint = 0x01;
pub const TUN_F_TSO4: ::c_uint = 0x02;
pub const TUN_F_TSO6: ::c_uint = 0x04;
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)
pub const TUN_PKT_STRIP: ::c_int = 0x0001;
// Accept all multicast packets
Expand Down

0 comments on commit ab83142

Please sign in to comment.