aboutgitcodebugslistschat
path: root/tcp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-10-21 18:40:29 +1100
committerStefano Brivio <sbrivio@redhat.com>2024-10-21 18:51:04 +0200
commit9e5df350d63b0819f04b44bb57ea146274a6b42f (patch)
treef82072c8b3db051be64510e97e335340cb96492d /tcp.c
parentb4dace8f462b346ae2135af1f8d681a99a849a5f (diff)
downloadpasst-9e5df350d63b0819f04b44bb57ea146274a6b42f.tar
passt-9e5df350d63b0819f04b44bb57ea146274a6b42f.tar.gz
passt-9e5df350d63b0819f04b44bb57ea146274a6b42f.tar.bz2
passt-9e5df350d63b0819f04b44bb57ea146274a6b42f.tar.lz
passt-9e5df350d63b0819f04b44bb57ea146274a6b42f.tar.xz
passt-9e5df350d63b0819f04b44bb57ea146274a6b42f.tar.zst
passt-9e5df350d63b0819f04b44bb57ea146274a6b42f.zip
tcp: Use structures to construct initial TCP optionsHEADmaster
As a rule, we prefer constructing packets with matching C structures, rather than building them byte by byte. However, one case we still build byte by byte is the TCP options we include in SYN packets (in fact the only time we generate TCP options on the tap interface). Rework this to use a structure and initialisers which make it a bit clearer what's going on. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by; Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp.c')
-rw-r--r--tcp.c17
1 files changed, 3 insertions, 14 deletions
diff --git a/tcp.c b/tcp.c
index b2155ab..0d22e07 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1232,7 +1232,7 @@ static void tcp_update_seqack_from_tap(const struct ctx *c,
* 1 otherwise
*/
int tcp_prepare_flags(const struct ctx *c, struct tcp_tap_conn *conn,
- int flags, struct tcphdr *th, char *data,
+ int flags, struct tcphdr *th, struct tcp_syn_opts *opts,
size_t *optlen)
{
struct tcp_info tinfo = { 0 };
@@ -1258,12 +1258,6 @@ int tcp_prepare_flags(const struct ctx *c, struct tcp_tap_conn *conn,
if (flags & SYN) {
int mss;
- /* Options: MSS, NOP and window scale (8 bytes) */
- *optlen = OPT_MSS_LEN + 1 + OPT_WS_LEN;
-
- *data++ = OPT_MSS;
- *data++ = OPT_MSS_LEN;
-
if (c->mtu == -1) {
mss = tinfo.tcpi_snd_mss;
} else {
@@ -1279,16 +1273,11 @@ int tcp_prepare_flags(const struct ctx *c, struct tcp_tap_conn *conn,
else if (mss > PAGE_SIZE)
mss = ROUND_DOWN(mss, PAGE_SIZE);
}
- *(uint16_t *)data = htons(MIN(USHRT_MAX, mss));
-
- data += OPT_MSS_LEN - 2;
conn->ws_to_tap = MIN(MAX_WS, tinfo.tcpi_snd_wscale);
- *data++ = OPT_NOP;
- *data++ = OPT_WS;
- *data++ = OPT_WS_LEN;
- *data++ = conn->ws_to_tap;
+ *opts = TCP_SYN_OPTS(mss, conn->ws_to_tap);
+ *optlen = sizeof(*opts);
} else if (!(flags & RST)) {
flags |= ACK;
}