Skip to content

Client TUN offload (2/3): refactorings - #503

Merged
xv-thomas-leong merged 9 commits into
mainfrom
main-tun-offload-refactor
Aug 21, 2026
Merged

Client TUN offload (2/3): refactorings#503
xv-thomas-leong merged 9 commits into
mainfrom
main-tun-offload-refactor

Conversation

@xv-thomas-leong

@xv-thomas-leong xv-thomas-leong commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Part 2 of 3 — refactorings

Second of a three-PR stack that adds client-side TUN GSO/GRO offload.
Base this on part 1 (bug fixes). This part is pure refactoring — no
behaviour change — to prepare the ground for the feature work in part 3:
hoisting shared cmsg handling, extracting the TUN send/receive syscall
plumbing into reusable helpers, and switching GSO checksums to the
internet-checksum crate. Reviewing it separately keeps the feature diff
focused on new behaviour.

No functional change. Each commit is independently buildable; the full
stack passes cargo clippy --workspace --all-targets (0 diagnostics) and
cargo test --workspace.

How Has This Been Tested?

CI and Manually tested

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • The correct base branch is being used, if not main

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Code coverage summary for a14557d:

Filename                                                          Regions    Missed Regions     Cover   Functions  Missed Functions  Executed       Lines      Missed Lines     Cover    Branches   Missed Branches     Cover
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
lightway-app-utils/src/args/cipher.rs                                   5                 5     0.00%           1                 1     0.00%           5                 5     0.00%           0                 0         -
lightway-app-utils/src/args/connection_type.rs                         11                 5    54.55%           3                 1    66.67%          11                 5    54.55%           0                 0         -
lightway-app-utils/src/args/duration.rs                               121                22    81.82%          11                 5    54.55%          64                15    76.56%           0                 0         -
lightway-app-utils/src/args/ip_map.rs                                  27                27     0.00%           5                 5     0.00%          19                19     0.00%           0                 0         -
lightway-app-utils/src/args/keyshare.rs                                 5                 5     0.00%           1                 1     0.00%           5                 5     0.00%           0                 0         -
lightway-app-utils/src/args/logging.rs                                 37                37     0.00%           3                 3     0.00%          31                31     0.00%           0                 0         -
lightway-app-utils/src/args/nonzero_duration.rs                       128                24    81.25%          10                 4    60.00%          68                16    76.47%           0                 0         -
lightway-app-utils/src/cmsg.rs                                        238                63    73.53%          20                 5    75.00%         188                49    73.94%           0                 0         -
lightway-app-utils/src/connection_ticker.rs                           229                17    92.58%          28                 4    85.71%         126                15    88.10%           0                 0         -
lightway-app-utils/src/dplpmtud_timer.rs                              209                13    93.78%          22                 4    81.82%         117                11    90.60%           0                 0         -
lightway-app-utils/src/event_stream.rs                                 19                 0   100.00%           3                 0   100.00%          11                 0   100.00%           0                 0         -
lightway-app-utils/src/metrics.rs                                       4                 4     0.00%           2                 2     0.00%           4                 4     0.00%           0                 0         -
lightway-app-utils/src/network_change_monitor.rs                      348                87    75.00%          29                 8    72.41%         200                75    62.50%           0                 0         -
lightway-app-utils/src/packet_codec.rs                                  2                 2     0.00%           1                 1     0.00%           1                 1     0.00%           0                 0         -
lightway-app-utils/src/sockopt/ip_mtu_discover.rs                      81                81     0.00%           6                 6     0.00%          72                72     0.00%           0                 0         -
lightway-app-utils/src/sockopt/ip_pktinfo.rs                           14                 1    92.86%           1                 0   100.00%          16                 1    93.75%           0                 0         -
lightway-app-utils/src/tun.rs                                         462               462     0.00%          47                47     0.00%         296               296     0.00%           0                 0         -
lightway-app-utils/src/utils.rs                                        21                21     0.00%           1                 1     0.00%          11                11     0.00%           0                 0         -
lightway-boring/src/aes256.rs                                         224                 5    97.77%          13                 0   100.00%          97                 0   100.00%           0                 0         -
lightway-boring/src/cert.rs                                            15                 1    93.33%           1                 0   100.00%           7                 0   100.00%           0                 0         -
lightway-boring/src/chacha20_poly1305.rs                              232                 6    97.41%          16                 3    81.25%         107                 3    97.20%           0                 0         -
lightway-boring/src/config.rs                                         111                17    84.68%          16                 4    75.00%          82                14    82.93%           0                 0         -
lightway-boring/src/context.rs                                        391                89    77.24%          31                 6    80.65%         247                35    85.83%           0                 0         -
lightway-boring/src/error.rs                                           37                 8    78.38%           4                 2    50.00%          28                 6    78.57%           0                 0         -
lightway-boring/src/session.rs                                        821               167    79.66%          53                 8    84.91%         448               101    77.46%           0                 0         -
lightway-boring/src/test_utils.rs                                     329                35    89.36%          25                 5    80.00%         210                24    88.57%           0                 0         -
lightway-boring/src/types.rs                                          137                10    92.70%          16                 1    93.75%          92                 9    90.22%           0                 0         -
lightway-client/src/config.rs                                         447               105    76.51%          22                 8    63.64%         294                67    77.21%           0                 0         -
lightway-client/src/dns_manager.rs                                     18                18     0.00%           4                 4     0.00%          16                16     0.00%           0                 0         -
lightway-client/src/io/inside.rs                                        3                 3     0.00%           1                 1     0.00%           3                 3     0.00%           0                 0         -
lightway-client/src/io/inside/tun.rs                                   86                86     0.00%          13                13     0.00%          63                63     0.00%           0                 0         -
lightway-client/src/io/outside.rs                                      14                14     0.00%           2                 2     0.00%          12                12     0.00%           0                 0         -
lightway-client/src/io/outside/tcp.rs                                 131               131     0.00%          15                15     0.00%          86                86     0.00%           0                 0         -
lightway-client/src/io/outside/udp.rs                                 225               225     0.00%          22                22     0.00%         154               154     0.00%           0                 0         -
lightway-client/src/io/outside/udp/batch_receive.rs                    99                13    86.87%          11                 1    90.91%          84                13    84.52%           0                 0         -
lightway-client/src/keepalive.rs                                      687                45    93.45%          59                 6    89.83%         357                24    93.28%           0                 0         -
lightway-client/src/lib.rs                                           1458               882    39.51%         114                65    42.98%        1042               696    33.21%           0                 0         -
lightway-client/src/main.rs                                           277               277     0.00%          17                17     0.00%         157               157     0.00%           0                 0         -
lightway-client/src/platform/linux/dns_manager.rs                     118                91    22.88%          14                 9    35.71%          87                62    28.74%           0                 0         -
lightway-client/src/platform/linux/dns_manager/direct_file.rs         106                42    60.38%          12                 6    50.00%          65                29    55.38%           0                 0         -
lightway-client/src/platform/linux/dns_manager/resolvconf.rs           61                61     0.00%           8                 8     0.00%          52                52     0.00%           0                 0         -
lightway-client/src/platform/linux/dns_manager/resolvectl.rs           41                41     0.00%           5                 5     0.00%          34                34     0.00%           0                 0         -
lightway-client/src/route_manager.rs                                 1161               142    87.77%          79                 4    94.94%         640                69    89.22%           0                 0         -
lightway-core/src/borrowed_bytesmut.rs                                373                 0   100.00%          24                 0   100.00%         185                 0   100.00%           0                 0         -
lightway-core/src/builder_predicates.rs                                24                12    50.00%           4                 2    50.00%          24                12    50.00%           0                 0         -
lightway-core/src/cipher.rs                                           197                21    89.34%          10                 0   100.00%          99                 4    95.96%           0                 0         -
lightway-core/src/connection.rs                                      2120               829    60.90%          95                22    76.84%        1519               566    62.74%           0                 0         -
lightway-core/src/connection/builders.rs                              252                46    81.75%          22                 8    63.64%         260                53    79.62%           0                 0         -
lightway-core/src/connection/dplpmtud.rs                             1741                81    95.35%          63                 0   100.00%         830                 7    99.16%           0                 0         -
lightway-core/src/connection/expresslane.rs                            88                 0   100.00%          10                 0   100.00%          74                 0   100.00%           0                 0         -
lightway-core/src/connection/fragment_map.rs                          366                 6    98.36%          25                 0   100.00%         254                 3    98.82%           0                 0         -
lightway-core/src/connection/io_adapter.rs                            882               154    82.54%          56                 9    83.93%         470                98    79.15%           0                 0         -
lightway-core/src/connection/key_update.rs                             34                13    61.76%           5                 0   100.00%          38                19    50.00%           0                 0         -
lightway-core/src/context.rs                                          219                42    80.82%          29                 8    72.41%         243                46    81.07%           0                 0         -
lightway-core/src/context/ip_pool.rs                                    8                 3    62.50%           1                 0   100.00%           5                 0   100.00%           0                 0         -
lightway-core/src/context/server_auth.rs                               37                37     0.00%           4                 4     0.00%          26                26     0.00%           0                 0         -
lightway-core/src/encoding_request_states.rs                            3                 0   100.00%           1                 0   100.00%           3                 0   100.00%           0                 0         -
lightway-core/src/gso.rs                                             1104                88    92.03%          41                 3    92.68%         519                55    89.40%           0                 0         -
lightway-core/src/io.rs                                                10                10     0.00%           3                 3     0.00%           9                 9     0.00%           0                 0         -
lightway-core/src/keyshare.rs                                           5                 0   100.00%           1                 0   100.00%           5                 0   100.00%           0                 0         -
lightway-core/src/lib.rs                                                9                 0   100.00%           3                 0   100.00%           9                 0   100.00%           0                 0         -
lightway-core/src/metrics.rs                                           81                66    18.52%          33                27    18.18%          73                58    20.55%           0                 0         -
lightway-core/src/packet.rs                                            38                10    73.68%           4                 1    75.00%          30                 6    80.00%           0                 0         -
lightway-core/src/plugin.rs                                           307                17    94.46%          22                 4    81.82%         148                10    93.24%           0                 0         -
lightway-core/src/tls/mod.rs                                            4                 4     0.00%           1                 1     0.00%           3                 3     0.00%           0                 0         -
lightway-core/src/utils.rs                                            341                28    91.79%          24                 3    87.50%         170                18    89.41%           0                 0         -
lightway-core/src/version.rs                                           93                 0   100.00%          17                 0   100.00%          82                 0   100.00%           0                 0         -
lightway-core/src/wire.rs                                             438                39    91.10%          29                 0   100.00%         235                 9    96.17%           0                 0         -
lightway-core/src/wire/auth_failure.rs                                 27                 1    96.30%           3                 0   100.00%          17                 0   100.00%           0                 0         -
lightway-core/src/wire/auth_request.rs                                684                57    91.67%          34                 1    97.06%         351                24    93.16%           0                 0         -
lightway-core/src/wire/auth_success_with_config_ipv4.rs               222                 3    98.65%          11                 0   100.00%         124                 0   100.00%           0                 0         -
lightway-core/src/wire/data.rs                                         51                 1    98.04%           5                 0   100.00%          33                 0   100.00%           0                 0         -
lightway-core/src/wire/data_frag.rs                                   127                 1    99.21%          14                 0   100.00%          80                 0   100.00%           0                 0         -
lightway-core/src/wire/encoding_request.rs                             82                 2    97.56%           6                 0   100.00%          42                 1    97.62%           0                 0         -
lightway-core/src/wire/encoding_response.rs                            82                 2    97.56%           6                 0   100.00%          42                 1    97.62%           0                 0         -
lightway-core/src/wire/expresslane_config.rs                          188                 1    99.47%          10                 0   100.00%         113                 0   100.00%           0                 0         -
lightway-core/src/wire/expresslane_data.rs                             48                21    56.25%           5                 2    60.00%          52                23    55.77%           0                 0         -
lightway-core/src/wire/ping.rs                                         95                 2    97.89%           7                 0   100.00%          59                 0   100.00%           0                 0         -
lightway-core/src/wire/pong.rs                                        109                 2    98.17%           8                 0   100.00%          72                 0   100.00%           0                 0         -
lightway-core/src/wire/server_config.rs                                69                 2    97.10%           4                 0   100.00%          37                 0   100.00%           0                 0         -
lightway-expresslane/src/aead.rs                                       29                29     0.00%           2                 2     0.00%          23                23     0.00%           0                 0         -
lightway-expresslane/src/aead/pool.rs                                 127                71    44.09%           9                 4    55.56%          90                50    44.44%           0                 0         -
lightway-expresslane/src/key.rs                                        24                 0   100.00%           5                 0   100.00%          17                 0   100.00%           0                 0         -
lightway-expresslane/src/replay_window.rs                             269                 4    98.51%          20                 0   100.00%         174                 4    97.70%           0                 0         -
lightway-expresslane/src/session.rs                                   469               195    58.42%          19                 2    89.47%         283               114    59.72%           0                 0         -
lightway-expresslane/src/version.rs                                    32                 0   100.00%           4                 0   100.00%          25                 0   100.00%           0                 0         -
lightway-server/src/auth.rs                                           273                49    82.05%          22                 6    72.73%         171                28    83.63%           0                 0         -
lightway-server/src/config.rs                                         135                 0   100.00%           9                 0   100.00%         112                 0   100.00%           0                 0         -
lightway-server/src/connection.rs                                     137               137     0.00%          11                11     0.00%         110               110     0.00%           0                 0         -
lightway-server/src/connection_manager.rs                             346               346     0.00%          42                42     0.00%         303               303     0.00%           0                 0         -
lightway-server/src/connection_manager/connection_map.rs              407                20    95.09%          21                 1    95.24%         228                 8    96.49%           0                 0         -
lightway-server/src/io/inside.rs                                      100                21    79.00%          23                 9    60.87%          69                19    72.46%           0                 0         -
lightway-server/src/io/inside/tun.rs                                   61                61     0.00%          14                14     0.00%          45                45     0.00%           0                 0         -
lightway-server/src/io/outside/tcp.rs                                  93                93     0.00%          10                10     0.00%          68                68     0.00%           0                 0         -
lightway-server/src/io/outside/udp.rs                                 483               428    11.39%          27                24    11.11%         331               297    10.27%           0                 0         -
lightway-server/src/io/outside/udp/batch_receive.rs                   467                19    95.93%          20                 1    95.00%         266                15    94.36%           0                 0         -
lightway-server/src/io/outside/udp/send_queue.rs                      381                26    93.18%          24                 1    95.83%         209                16    92.34%           0                 0         -
lightway-server/src/ip_manager.rs                                     542                50    90.77%          22                 4    81.82%         242                23    90.50%           0                 0         -
lightway-server/src/ip_manager/ip_pool.rs                             545                 0   100.00%          28                 0   100.00%         257                 0   100.00%           0                 0         -
lightway-server/src/lib.rs                                            603               499    17.25%          34                26    23.53%         413               340    17.68%           0                 0         -
lightway-server/src/main.rs                                           201               201     0.00%          10                10     0.00%          96                96     0.00%           0                 0         -
lightway-server/src/metrics.rs                                        287               265     7.67%          99                89    10.10%         243               223     8.23%           0                 0         -
lightway-server/src/offload_stats.rs                                  125                74    40.80%           8                 3    62.50%          82                42    48.78%           0                 0         -
lightway-server/src/statistics.rs                                     133                59    55.64%           8                 4    50.00%          91                39    57.14%           0                 0         -
uniffi-bindgen/src/uniffi-bindgen.rs                                    3                 3     0.00%           1                 1     0.00%           3                 3     0.00%           0                 0         -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                               26020              7641    70.63%        1899               675    64.45%       15995              5277    67.01%           0                 0         -

✅ Region coverage 70% passes
✅ Line coverage 67% passes

@xv-thomas-leong
xv-thomas-leong force-pushed the main-tun-offload-refactor branch from 1c2f53d to bf2a883 Compare August 7, 2026 03:05
@xv-thomas-leong
xv-thomas-leong force-pushed the main-tun-offload-refactor branch from bf2a883 to 89c1389 Compare August 7, 2026 03:16
@xv-thomas-leong
xv-thomas-leong force-pushed the main-tun-offload-refactor branch from 89c1389 to 10b37d8 Compare August 7, 2026 03:38
@xv-thomas-leong xv-thomas-leong changed the title TUN offload (2/3): refactorings Client TUN offload (2/3): refactorings Aug 7, 2026
@xv-thomas-leong
xv-thomas-leong force-pushed the main-tun-offload-refactor branch from 10b37d8 to 56ef56b Compare August 7, 2026 04:24
@xv-thomas-leong
xv-thomas-leong force-pushed the main-tun-offload-refactor branch from 56ef56b to c040d4c Compare August 13, 2026 05:18
@xv-thomas-leong
xv-thomas-leong force-pushed the main-tun-offload-refactor branch from c040d4c to 3cc731b Compare August 17, 2026 02:51
Base automatically changed from main-tun-offload-fixes to main August 17, 2026 04:12
@xv-thomas-leong
xv-thomas-leong force-pushed the main-tun-offload-refactor branch from 3cc731b to db6a027 Compare August 17, 2026 04:13
@xv-thomas-leong
xv-thomas-leong marked this pull request as ready for review August 17, 2026 04:22
@xv-thomas-leong
xv-thomas-leong requested a review from a team as a code owner August 17, 2026 04:22
Comment thread lightway-app-utils/src/tun.rs Outdated
/// in one vectored send — no copy, no allocation. The returned count
/// excludes the header, matching a plain send.
#[cfg(target_os = "linux")]
fn send_with_vnet_hdr(&self, hdr_bytes: &[u8], buf: &[u8]) -> IOCallbackResult<usize> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to rename it to send_chunks() and take a list of buffers ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread lightway-app-utils/src/cmsg.rs
Comment thread lightway-core/src/gso.rs Outdated
p[at] = 0;
p[at + 1] = 0;
!checksum(&p[START..], initial) == 0
let mut p = build(6, c);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid magic numbers and use macro like berfore IPPROTO_UDP

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread lightway-core/src/gso.rs Outdated
let csum = match (v4_addrs, v6_addrs) {
(Some((src, dst)), None) => {
pnet_packet::udp::ipv4_checksum(&udp.to_immutable(), &src, &dst)
transport_checksum(&src.octets(), &dst.octets(), 17, udp.packet())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid magic numbers. Also applicable to othe places around this

@xv-thomas-leong
xv-thomas-leong marked this pull request as draft August 17, 2026 07:45
@xv-thomas-leong
xv-thomas-leong force-pushed the main-tun-offload-refactor branch 2 times, most recently from bda0169 to 1ea2dc5 Compare August 19, 2026 04:03
@xv-thomas-leong
xv-thomas-leong marked this pull request as ready for review August 19, 2026 05:33
@xv-thomas-leong
xv-thomas-leong marked this pull request as draft August 19, 2026 05:38
@xv-thomas-leong
xv-thomas-leong force-pushed the main-tun-offload-refactor branch from 1ea2dc5 to 772b83f Compare August 19, 2026 05:43
@xv-thomas-leong
xv-thomas-leong marked this pull request as ready for review August 19, 2026 05:44

@kp-mariappan-ramasamy kp-mariappan-ramasamy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Changes are functionally good. Minor nits about commit cleanliness.

Comment thread lightway-app-utils/src/cmsg.rs
Comment thread lightway-app-utils/src/cmsg.rs Outdated
return Some(Message::IpPktinfo(pi));
}

Some(Message::Unknown(item))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unnecessary churn, not needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This is a leftover change when separating changes between refactoring and feature. I've removed it.

Pure code motion: relocate the control-message module verbatim from
lightway-server to lightway-app-utils so other crates can use it, make
its items `pub`, and update the import paths in the server's UDP send
and batched-receive paths. No behaviour change.
Rename `Buffer::as_mut` to `spare_capacity_mut` so the name states what
it returns (the uninitialised spare capacity, not a `&mut Self`), and add
a `Default` impl. Callers in the UDP send and batched-receive paths
updated. No behaviour change.
Two soundness fixes that matter once the module is public API:

- Back `Buffer<N>` with an inline `#[repr(C, align(16))]` array instead
  of a `BytesMut`. The old code was aligned for `cmsghdr` only because
  the global allocator happens to hand back 16-byte-aligned blocks at
  these sizes; nothing in the type system guaranteed it. A `const`
  assert confirms 16 suffices for `cmsghdr` on the target.
- Bounds-check the control length in `iter` and route iteration through a
  new `iter_control(&[u8])` that `assert!`s the buffer is aligned for a
  `cmsghdr` (kept in release, not `debug_assert!`, since `Iter::next`
  turns the pointers into `&cmsghdr` and a misaligned reference is UB).
  The old path called `BytesMut::set_len` with an unchecked kernel-
  supplied length, which could produce a slice over out-of-bounds memory.

`Iter` drops its now-unused `const N` parameter. Adds a test asserting
both buffer types meet `cmsghdr` alignment.
Now that the cmsg module is public API, review flagged the undocumented
items. Add doc comments to `Buffer::iter` and `BufferMut::builder`, and
extend the module doc to note it also covers `sendmsg(2)`.
The three-arm mapping from `io::Result<usize>` onto `IOCallbackResult`
appears once today and is about to appear twice more as the vnet-header
send paths land. Extract it first so those commits add a call rather than
a copy.

Mirrors `map_send_result` on the outside UDP path, which already does this.
Note it takes no `len` parameter: unlike the UDP side it has no
swallow-and-report-success arms, because a TUN write has no transient
errors worth hiding from the caller.

No behaviour change.
Pull the `try_io(READABLE)` WouldBlock/Interrupted/ICMP loop out of
`recv_bufs` into `try_readable_io`, so the upcoming batched GRO receive
shares it instead of copying the arms. No functional change.

The connected-UDP `send()` path is left as-is: it has grown its own
connected-socket and dead-socket handling, and the GSO send path
introduces its own result mapping where it is used.
Pull the source/DNS rewrite + ConnectionError mapping into
process_inside_packet and the tracer-trigger bookkeeping into
TracerTrigger, so an upcoming GSO variant of the inside loop can
share them instead of copying ~100 lines. No functional change.
Replaces the hand-rolled one's-complement loop used by
`gso_none_checksum`, and pnet's protocol-aware helpers used by
`build_segment`, with a single `internet_checksum::Checksum`-based
`transport_checksum` covering the TCP/UDP pseudo-header for both address
families.

pnet's helpers walk the packet per 16-bit word with bounds checks on each
access; `internet-checksum` accumulates wider and uses the carry flag, and
on x86_64 a 128-bit accumulator. Equivalence was checked by differential
fuzzing against `pnet_packet::{tcp,udp}::ipv4_checksum` -- 40,000 random
TCP and UDP cases including odd payload lengths, on x86_64 -- with one
deliberate difference noted below.

Two details worth recording, because both are easy to get wrong:

`Checksum::add_bytes` buffers a trailing byte across calls, so an
odd-length slice mid-stream is handled correctly rather than being padded
in place. docs.rs is misleading on this point; the source is not.

`checksum()` returns `to_ne_bytes()` of a `from_ne_bytes()`-accumulated
sum. That is RFC 1071 s2 byte-order independence, not a bug: on
little-endian the property yields wire order, and on big-endian native
order *is* wire order. So both `copy_from_slice(&c.checksum())` and
`u16::from_be_bytes(c.checksum())` are correct, on either endianness.

`transport_checksum` carries the RFC 768 zero substitution that
`gso_none_checksum` already applies, and needs no protocol sniffing to do
it since the protocol is a parameter here. That is the one deliberate
difference from pnet, which does not substitute and is therefore wrong for
the ~1-in-65536 case; the doc comment now scopes the equivalence claim
accordingly.

`gso_none_checksum`'s test derived its zero-folding seed from the old
internals, which this commit removes. It now derives the same seed by
calling `gso_none_checksum` itself on a TCP packet, where no substitution
applies -- implementation-agnostic, so it survives the next change to how
the sum is computed.

Also adds a `debug_assert` that the transport slice fits the 16-bit
pseudo-header length field. Unreachable from `build_segment`, whose slices
are bounded by `gso_size`, but the pnet code this replaces accumulated the
length in `u32` and so could not wrap.
The vnet-hdr branch of try_send allocated a fresh BytesMut and
memcpy'd the whole packet just to prepend the 10-byte zeroed virtio
header. Send header and packet as two IoSlices in one vectored write
instead — no copy, no allocation. No functional change (identical
bytes reach the device).
@xv-thomas-leong
xv-thomas-leong force-pushed the main-tun-offload-refactor branch from 13a87b4 to ca63247 Compare August 21, 2026 04:00
@xv-thomas-leong
xv-thomas-leong marked this pull request as ready for review August 21, 2026 04:15

@kp-mariappan-ramasamy kp-mariappan-ramasamy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thank you

@xv-thomas-leong
xv-thomas-leong merged commit 72e9863 into main Aug 21, 2026
33 checks passed
@xv-thomas-leong
xv-thomas-leong deleted the main-tun-offload-refactor branch August 21, 2026 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants