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 <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2021-10-14 12:10:24 +02:00
parent f45891cf26
commit c61944a1f8

26
tcp.c
View file

@ -583,12 +583,13 @@ static struct tcp4_l2_buf_t {
uint32_t tsum; /* 4 */ uint32_t tsum; /* 4 */
#ifdef __AVX2__ #ifdef __AVX2__
uint8_t pad[18]; /* 8, align th to 32 bytes */ uint8_t pad[18]; /* 8, align th to 32 bytes */
#else
uint8_t pad[2]; /* align iph to 4 bytes 8 */
#endif #endif
uint32_t vnet_len; /* 26 10 */
uint32_t vnet_len; /* 26 */ struct ethhdr eh; /* 30 14 */
struct ethhdr eh; /* 30 */ struct iphdr iph; /* 44 28 */
struct iphdr iph; /* 44 */ struct tcphdr th; /* 64 48 */
struct tcphdr th; /* 64 */
uint8_t data[USHRT_MAX - sizeof(struct tcphdr)]; uint8_t data[USHRT_MAX - sizeof(struct tcphdr)];
#ifdef __AVX2__ #ifdef __AVX2__
} __attribute__ ((packed, aligned(32))) } __attribute__ ((packed, aligned(32)))
@ -669,12 +670,13 @@ static struct tcp4_l2_flags_buf_t {
uint32_t tsum; /* 4 */ uint32_t tsum; /* 4 */
#ifdef __AVX2__ #ifdef __AVX2__
uint8_t pad[18]; /* 8, align th to 32 bytes */ uint8_t pad[18]; /* 8, align th to 32 bytes */
#else
uint8_t pad[2]; /* align iph to 4 bytes 8 */
#endif #endif
uint32_t vnet_len; /* 26 10 */
uint32_t vnet_len; /* 26 */ struct ethhdr eh; /* 30 14 */
struct ethhdr eh; /* 30 */ struct iphdr iph; /* 44 28 */
struct iphdr iph; /* 44 */ struct tcphdr th; /* 64 48 */
struct tcphdr th /* 64 */ __attribute__ ((aligned(4)));
char opts[OPT_MSS_LEN + OPT_WS_LEN + 1]; char opts[OPT_MSS_LEN + OPT_WS_LEN + 1];
#ifdef __AVX2__ #ifdef __AVX2__
} __attribute__ ((packed, aligned(32))) } __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++) { for (i = 0; i < ARRAY_SIZE(tcp4_l2_buf); i++) {
tcp4_l2_buf[i] = (struct tcp4_l2_buf_t) { 0, 0, tcp4_l2_buf[i] = (struct tcp4_l2_buf_t) { 0, 0,
#ifdef __AVX2__
{ 0 }, { 0 },
#endif
0, L2_BUF_ETH_IP4_INIT, L2_BUF_IP4_INIT(IPPROTO_TCP), 0, L2_BUF_ETH_IP4_INIT, L2_BUF_IP4_INIT(IPPROTO_TCP),
{ .doff = sizeof(struct tcphdr) / 4, .ack = 1 }, { 0 }, { .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++) { for (i = 0; i < ARRAY_SIZE(tcp4_l2_flags_buf); i++) {
tcp4_l2_flags_buf[i] = (struct tcp4_l2_flags_buf_t) { 0, 0, tcp4_l2_flags_buf[i] = (struct tcp4_l2_flags_buf_t) { 0, 0,
#ifdef __AVX2__
{ 0 }, { 0 },
#endif
0, L2_BUF_ETH_IP4_INIT, L2_BUF_IP4_INIT(IPPROTO_TCP), 0, L2_BUF_ETH_IP4_INIT, L2_BUF_IP4_INIT(IPPROTO_TCP),
{ 0 }, { 0 }, { 0 }, { 0 },
}; };