Skip to content

Commit f2c1788

Browse files
committed
Auto merge of #3420 - elecm:main, r=JohnTitor
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`.
2 parents f741161 + ab83142 commit f2c1788

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

libc-test/build.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,9 @@ fn test_android(target: &str) {
18241824
// kernel 5.6 minimum required
18251825
"IPPROTO_MPTCP" | "IPPROTO_ETHERNET" => true,
18261826

1827+
// kernel 6.2 minimum
1828+
"TUN_F_USO4" | "TUN_F_USO6" | "IFF_NO_CARRIER" => true,
1829+
18271830
// FIXME: NDK r22 minimum required
18281831
| "FDB_NOTIFY_BIT"
18291832
| "FDB_NOTIFY_INACTIVE_BIT"
@@ -3857,6 +3860,9 @@ fn test_linux(target: &str) {
38573860
// kernel 6.1 minimum
38583861
"MADV_COLLAPSE" => true,
38593862

3863+
// kernel 6.2 minimum
3864+
"TUN_F_USO4" | "TUN_F_USO6" | "IFF_NO_CARRIER" => true,
3865+
38603866
// FIXME: Requires more recent kernel headers
38613867
| "IFLA_PARENT_DEV_NAME" // linux v5.13+
38623868
| "IFLA_PARENT_DEV_BUS_NAME" // linux v5.13+

libc-test/semver/android.txt

+8
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ IFF_MASTER
699699
IFF_MULTICAST
700700
IFF_NOARP
701701
IFF_NOTRAILERS
702+
IFF_NO_CARRIER
702703
IFF_NO_PI
703704
IFF_POINTOPOINT
704705
IFF_PORTSEL
@@ -708,6 +709,13 @@ IFF_SLAVE
708709
IFF_TAP
709710
IFF_TUN
710711
IFF_UP
712+
TUN_F_CSUM
713+
TUN_F_TSO4
714+
TUN_F_TSO6
715+
TUN_F_TSO_ECN
716+
TUN_F_UFO
717+
TUN_F_USO4
718+
TUN_F_USO6
711719
IFNAMSIZ
712720
IF_NAMESIZE
713721
IFA_UNSPEC

libc-test/semver/linux.txt

+3
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ IFF_LOWER_UP
932932
IFF_MASTER
933933
IFF_MULTICAST
934934
IFF_MULTI_QUEUE
935+
IFF_NO_CARRIER
935936
IFF_NOARP
936937
IFF_NOFILTER
937938
TUN_TX_TIMESTAMP
@@ -940,6 +941,8 @@ TUN_F_TSO4
940941
TUN_F_TSO6
941942
TUN_F_TSO_ECN
942943
TUN_F_UFO
944+
TUN_F_USO4
945+
TUN_F_USO6
943946
TUN_PKT_STRIP
944947
TUN_FLT_ALLMULTI
945948
IFF_NOTRAILERS

src/unix/linux_like/android/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -2481,6 +2481,7 @@ pub const IFF_TUN: ::c_int = 0x0001;
24812481
pub const IFF_TAP: ::c_int = 0x0002;
24822482
pub const IFF_NAPI: ::c_int = 0x0010;
24832483
pub const IFF_NAPI_FRAGS: ::c_int = 0x0020;
2484+
pub const IFF_NO_CARRIER: ::c_int = 0x0040;
24842485
pub const IFF_NO_PI: ::c_int = 0x1000;
24852486
pub const IFF_ONE_QUEUE: ::c_int = 0x2000;
24862487
pub const IFF_VNET_HDR: ::c_int = 0x4000;
@@ -2490,6 +2491,14 @@ pub const IFF_ATTACH_QUEUE: ::c_int = 0x0200;
24902491
pub const IFF_DETACH_QUEUE: ::c_int = 0x0400;
24912492
pub const IFF_PERSIST: ::c_int = 0x0800;
24922493
pub const IFF_NOFILTER: ::c_int = 0x1000;
2494+
// Features for GSO (TUNSETOFFLOAD)
2495+
pub const TUN_F_CSUM: ::c_uint = 0x01;
2496+
pub const TUN_F_TSO4: ::c_uint = 0x02;
2497+
pub const TUN_F_TSO6: ::c_uint = 0x04;
2498+
pub const TUN_F_TSO_ECN: ::c_uint = 0x08;
2499+
pub const TUN_F_UFO: ::c_uint = 0x10;
2500+
pub const TUN_F_USO4: ::c_uint = 0x20;
2501+
pub const TUN_F_USO6: ::c_uint = 0x40;
24932502

24942503
// start android/platform/bionic/libc/kernel/uapi/linux/if_ether.h
24952504
// from https://android.googlesource.com/platform/bionic/+/HEAD/libc/kernel/uapi/linux/if_ether.h

src/unix/linux_like/linux/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1866,6 +1866,8 @@ pub const IFF_TUN: ::c_int = 0x0001;
18661866
pub const IFF_TAP: ::c_int = 0x0002;
18671867
pub const IFF_NAPI: ::c_int = 0x0010;
18681868
pub const IFF_NAPI_FRAGS: ::c_int = 0x0020;
1869+
// Used in TUNSETIFF to bring up tun/tap without carrier
1870+
pub const IFF_NO_CARRIER: ::c_int = 0x0040;
18691871
pub const IFF_NO_PI: ::c_int = 0x1000;
18701872
// Read queue size
18711873
pub const TUN_READQ_SIZE: ::c_short = 500;
@@ -1886,11 +1888,13 @@ pub const IFF_NOFILTER: ::c_int = 0x1000;
18861888
// Socket options
18871889
pub const TUN_TX_TIMESTAMP: ::c_int = 1;
18881890
// Features for GSO (TUNSETOFFLOAD)
1889-
pub const TUN_F_CSUM: ::c_ushort = 0x01; /* You can hand me unchecksummed packets. */
1890-
pub const TUN_F_TSO4: ::c_ushort = 0x02; /* I can handle TSO for IPv4 packets */
1891-
pub const TUN_F_TSO6: ::c_ushort = 0x04; /* I can handle TSO for IPv6 packets */
1892-
pub const TUN_F_TSO_ECN: ::c_ushort = 0x08; /* I can handle TSO with ECN bits. */
1893-
pub const TUN_F_UFO: ::c_ushort = 0x10; /* I can handle UFO packets */
1891+
pub const TUN_F_CSUM: ::c_uint = 0x01;
1892+
pub const TUN_F_TSO4: ::c_uint = 0x02;
1893+
pub const TUN_F_TSO6: ::c_uint = 0x04;
1894+
pub const TUN_F_TSO_ECN: ::c_uint = 0x08;
1895+
pub const TUN_F_UFO: ::c_uint = 0x10;
1896+
pub const TUN_F_USO4: ::c_uint = 0x20;
1897+
pub const TUN_F_USO6: ::c_uint = 0x40;
18941898
// Protocol info prepended to the packets (when IFF_NO_PI is not set)
18951899
pub const TUN_PKT_STRIP: ::c_int = 0x0001;
18961900
// Accept all multicast packets

0 commit comments

Comments
 (0)