diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2023-08-22 15:29:56 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2023-08-22 12:15:30 +0200 |
commit | 5bf200ae8a1ab298cb393bf1956599d1178567cb (patch) | |
tree | 515a094e86cd613ba21963b59e1399ddc906286a /util.h | |
parent | 8aa32009edb74aa1f0b6d58e759d5111a4713346 (diff) | |
download | passt-5bf200ae8a1ab298cb393bf1956599d1178567cb.tar passt-5bf200ae8a1ab298cb393bf1956599d1178567cb.tar.gz passt-5bf200ae8a1ab298cb393bf1956599d1178567cb.tar.bz2 passt-5bf200ae8a1ab298cb393bf1956599d1178567cb.tar.lz passt-5bf200ae8a1ab298cb393bf1956599d1178567cb.tar.xz passt-5bf200ae8a1ab298cb393bf1956599d1178567cb.tar.zst passt-5bf200ae8a1ab298cb393bf1956599d1178567cb.zip |
tcp, udp: Don't include destination address in partially precomputed csums
We partially prepopulate IP and TCP header structures including, amongst
other things the destination address, which for IPv4 is always the known
address of the guest/namespace. We partially precompute both the IPv4
header checksum and the TCP checksum based on this.
In future we're going to want more flexibility with controlling the
destination for IPv4 (as we already do for IPv6), so this precomputed value
gets in the way. Therefore remove the IPv4 destination from the
precomputed checksum and fold it into the checksum update when we actually
send a packet.
Doing this means we no longer need to recompute those partial sums when
the destination address changes ({tcp,udp}_update_l2_buf()) and instead
the computation can be moved to compile time. This means while we perform
slightly more computations on each packet, we slightly reduce the amount of
memory we need to access.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'util.h')
-rw-r--r-- | util.h | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -141,11 +141,13 @@ int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size, int flags, .tot_len = 0, \ .id = 0, \ .frag_off = 0, \ - .ttl = 255, \ + .ttl = 0xff, \ .protocol = (proto), \ .saddr = 0, \ .daddr = 0, \ } +#define L2_BUF_IP4_PSUM(proto) ((uint32_t)htons_constant(0x4500) + \ + (uint32_t)htons_constant(0xff00 | (proto))) #define L2_BUF_IP6_INIT(proto) \ { \ |