diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2024-10-24 15:59:20 +1100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-10-25 14:26:48 +0200 |
commit | 13f0291ede19fc6baea02e8327acec144bdf79e6 (patch) | |
tree | 326b0c815818e4b56549e71edf5623c6c40c65e5 /tcp_internal.h | |
parent | 9e4615b40bfa7f1b692c3c3360d88a22c453b016 (diff) | |
download | passt-13f0291ede19fc6baea02e8327acec144bdf79e6.tar passt-13f0291ede19fc6baea02e8327acec144bdf79e6.tar.gz passt-13f0291ede19fc6baea02e8327acec144bdf79e6.tar.bz2 passt-13f0291ede19fc6baea02e8327acec144bdf79e6.tar.lz passt-13f0291ede19fc6baea02e8327acec144bdf79e6.tar.xz passt-13f0291ede19fc6baea02e8327acec144bdf79e6.tar.zst passt-13f0291ede19fc6baea02e8327acec144bdf79e6.zip |
tcp: Remove compile-time dependency on struct tcp_info version
In the Makefile we probe to create several defines based on the presence
of particular fields in struct tcp_info. These defines are used for two
purposes, neither of which they accomplish well:
1) Determining if the tcp_info fields are available at runtime. For this
purpose the defines are Just Plain Wrong, since the runtime kernel may
not be the same as the compile time kernel. We corrected this for
tcp_snd_wnd, but not for tcpi_bytes_acked or tcpi_min_rtt
2) Allowing the source to compile against older kernel headers which don't
have the fields in question. This works in theory, but it does mean
we won't be able to use the fields, even if later run against a
newer kernel. Furthermore, it's quite fragile: without much more
thorough tests of builds in different environments that we're currently
set up for, it's very easy to miss cases where we're accessing a field
without protection from an #ifdef. For example we currently access
tcpi_snd_wnd without #ifdefs in tcp_update_seqack_wnd().
Improve this with a different approach, borrowed from qemu (which has many
instances of similar problems). Don't compile against linux/tcp.h, using
netinet/tcp.h instead. Then for when we need an extension field, define
a struct tcp_info_linux, copied from the kernel, with all the fields we're
interested in. That may need updating from future kernel versions, but
only when we want to use a new extension, so it shouldn't be frequent.
This allows us to remove the HAS_SND_WND define entirely. We keep
HAS_BYTES_ACKED and HAS_MIN_RTT now, since they're used for purpose (1),
we'll fix that in a later patch.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
[sbrivio: Trivial grammar fixes in comments]
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp_internal.h')
-rw-r--r-- | tcp_internal.h | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/tcp_internal.h b/tcp_internal.h index 1ab8ce2..a5a47df 100644 --- a/tcp_internal.h +++ b/tcp_internal.h @@ -175,12 +175,14 @@ void tcp_rst_do(const struct ctx *c, struct tcp_tap_conn *conn); tcp_rst_do(c, conn); \ } while (0) +struct tcp_info_linux; + size_t tcp_l2_buf_fill_headers(const struct tcp_tap_conn *conn, struct iovec *iov, size_t dlen, const uint16_t *check, uint32_t seq, bool no_tcp_csum); int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn *conn, - bool force_seq, struct tcp_info *tinfo); + bool force_seq, struct tcp_info_linux *tinfo); int tcp_prepare_flags(const struct ctx *c, struct tcp_tap_conn *conn, int flags, struct tcphdr *th, struct tcp_syn_opts *opts, size_t *optlen); |