Skip to content

Commit

Permalink
Auto merge of #3420 - elecm:main, r=JohnTitor
Browse files Browse the repository at this point in the history
feat: add GSO flags for linux and android

Add Generic Segmentation Offload (GSO) flags based on [if_tun.h](https://github.com/torvalds/linux/blob/master/include/uapi/linux/if_tun.h#L87) header in Linux  and [if_tun.h](https://android.googlesource.com/platform/bionic/+/HEAD/libc/kernel/uapi/linux/if_tun.h#71) header in Android source code.
Include the `IFF_NO_CARRIER` flag as well (found in the same files mentioned in the previous paragraph).

There is a [PR](#3320 (comment)) similar to mine, but that PR doesn't include GSO flags for UDP (`TUN_F_USO4` and `TUN_F_USO6`), and it is only for Linux. And also, I used `c_uint`type for GSO flags because related ioctl function (`#define TUNSETOFFLOAD  _IOW('T', 208, unsigned int)`) get `unsigned int` but that PR uses `c_ushort`.
  • Loading branch information
bors committed Nov 6, 2023
2 parents bbd3e20 + 5a6c5f7 commit 88c6565
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
3 changes: 3 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3855,6 +3855,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 88c6565

Please sign in to comment.