From c61944a1f8e4acdf0d86d0813eef50f88e3d7131 Mon Sep 17 00:00:00 2001 From: Stefano Brivio Date: Thu, 14 Oct 2021 12:10:24 +0200 Subject: tcp: Explicitly align IP headers in tcp4_l2_{,flags}buf_t also in non-AVX2 build Otherwise, tcp4_l2_flags_buf_t is not consistent with tcp4_l2_buf_t and header fields get all mixed up in tcp_l2_buf_fill_headers(). Signed-off-by: Stefano Brivio --- tcp.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'tcp.c') diff --git a/tcp.c b/tcp.c index 011710e..ed26c49 100644 --- a/tcp.c +++ b/tcp.c @@ -583,12 +583,13 @@ static struct tcp4_l2_buf_t { uint32_t tsum; /* 4 */ #ifdef __AVX2__ uint8_t pad[18]; /* 8, align th to 32 bytes */ +#else + uint8_t pad[2]; /* align iph to 4 bytes 8 */ #endif - - uint32_t vnet_len; /* 26 */ - struct ethhdr eh; /* 30 */ - struct iphdr iph; /* 44 */ - struct tcphdr th; /* 64 */ + uint32_t vnet_len; /* 26 10 */ + struct ethhdr eh; /* 30 14 */ + struct iphdr iph; /* 44 28 */ + struct tcphdr th; /* 64 48 */ uint8_t data[USHRT_MAX - sizeof(struct tcphdr)]; #ifdef __AVX2__ } __attribute__ ((packed, aligned(32))) @@ -669,12 +670,13 @@ static struct tcp4_l2_flags_buf_t { uint32_t tsum; /* 4 */ #ifdef __AVX2__ uint8_t pad[18]; /* 8, align th to 32 bytes */ +#else + uint8_t pad[2]; /* align iph to 4 bytes 8 */ #endif - - uint32_t vnet_len; /* 26 */ - struct ethhdr eh; /* 30 */ - struct iphdr iph; /* 44 */ - struct tcphdr th /* 64 */ __attribute__ ((aligned(4))); + uint32_t vnet_len; /* 26 10 */ + struct ethhdr eh; /* 30 14 */ + struct iphdr iph; /* 44 28 */ + struct tcphdr th; /* 64 48 */ char opts[OPT_MSS_LEN + OPT_WS_LEN + 1]; #ifdef __AVX2__ } __attribute__ ((packed, aligned(32))) @@ -953,9 +955,7 @@ static void tcp_sock4_iov_init(void) for (i = 0; i < ARRAY_SIZE(tcp4_l2_buf); i++) { tcp4_l2_buf[i] = (struct tcp4_l2_buf_t) { 0, 0, -#ifdef __AVX2__ { 0 }, -#endif 0, L2_BUF_ETH_IP4_INIT, L2_BUF_IP4_INIT(IPPROTO_TCP), { .doff = sizeof(struct tcphdr) / 4, .ack = 1 }, { 0 }, }; @@ -963,9 +963,7 @@ static void tcp_sock4_iov_init(void) for (i = 0; i < ARRAY_SIZE(tcp4_l2_flags_buf); i++) { tcp4_l2_flags_buf[i] = (struct tcp4_l2_flags_buf_t) { 0, 0, -#ifdef __AVX2__ { 0 }, -#endif 0, L2_BUF_ETH_IP4_INIT, L2_BUF_IP4_INIT(IPPROTO_TCP), { 0 }, { 0 }, }; -- cgit v1.2.3